Skip to content

Commit 8222c56

Browse files
committed
Additional fixes
- Add backup crd to charts (makefile) - Add validation of BACKUPS_TO_KEEP variable - Improve logging Signed-off-by: Ilya Bumarskov <[email protected]>
1 parent 1e7c76c commit 8222c56

File tree

8 files changed

+208
-117
lines changed

8 files changed

+208
-117
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ generate:
116116
# sync crd generated to helm-chart
117117
echo '{{- if .Values.crd.create }}' > charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml
118118
cat config/crd/bases/zookeeper.pravega.io_zookeeperclusters.yaml >> charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml
119+
cat config/crd/bases/zookeeper.pravega.io_zookeeperbackups.yaml >> charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml
119120
echo '{{- end }}' >> charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml
120121

121122

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ approach described in [article](https://www.elastic.co/blog/zookeeper-backup-a-t
375375
Exmaple CR of zookeeper backup:
376376
```yaml
377377
apiVersion: "zookeeper.pravega.io/v1beta1"
378-
kind: "ZookeeperCluster"
378+
kind: "ZookeeperBackup"
379379
metadata:
380380
name: "example-backup"
381381
spec:

api/v1beta1/zookeeperbackup_types.go

-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ import (
1414
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1515
)
1616

17-
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
18-
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
19-
2017
// ZookeeperBackupSpec defines the desired state of ZookeeperBackup
2118
type ZookeeperBackupSpec struct {
2219
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster

build_backup/backup.sh

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
echo "--------------- Check required parameters ---------------"
3+
echo "--------------- Check required env variables ---------------"
44
_req_envs="
55
Required parameters: \n
66
BACKUPDIR: $BACKUPDIR \n
@@ -14,6 +14,10 @@ if [ -z "$BACKUPDIR" ] || [ -z "$ZOOKEEPERDATADIR" ] || [ -z "$BACKUPS_TO_KEEP"
1414
exit 1
1515
fi
1616

17+
echo "--------------- Check BACKUPS_TO_KEEP variable ---------------"
18+
if ! [[ $BACKUPS_TO_KEEP =~ ^[0-9]+$ ]] ;
19+
then echo "Error: $BACKUPS_TO_KEEP not a number" >&2; exit 1
20+
fi
1721
# Create backup directory if absent.
1822
# ----------------------------------
1923
echo "--------------- Check backup/tmp dirs ---------------"
@@ -53,7 +57,7 @@ BACKUPS_AMOUNT=`find . -path "*/zookeeper-*.tar.gz" -type f -printf "\n%AD %AT %
5357
TO_DELETE=$(( $BACKUPS_AMOUNT - $BACKUPS_TO_KEEP ))
5458
if [ $TO_DELETE -gt 0 ] ; then
5559
echo "Keeping only $BACKUPS_TO_KEEP full backups"
56-
ls -t | tail -n -$TO_DELETE | xargs -d '\n' rm -rf
60+
ls -t zookeeper-*.tar.gz | tail -n -$TO_DELETE | xargs -d '\n' rm -rf
5761
else
5862
echo "There are less backups than required, nothing to delete."
5963
fi

charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml

+82
Original file line numberDiff line numberDiff line change
@@ -5849,4 +5849,86 @@ spec:
58495849
storage: true
58505850
subresources:
58515851
status: {}
5852+
---
5853+
apiVersion: apiextensions.k8s.io/v1
5854+
kind: CustomResourceDefinition
5855+
metadata:
5856+
annotations:
5857+
controller-gen.kubebuilder.io/version: v0.9.0
5858+
creationTimestamp: null
5859+
name: zookeeperbackups.zookeeper.pravega.io
5860+
spec:
5861+
group: zookeeper.pravega.io
5862+
names:
5863+
kind: ZookeeperBackup
5864+
listKind: ZookeeperBackupList
5865+
plural: zookeeperbackups
5866+
singular: zookeeperbackup
5867+
scope: Namespaced
5868+
versions:
5869+
- name: v1beta1
5870+
schema:
5871+
openAPIV3Schema:
5872+
description: ZookeeperBackup is the Schema for the zookeeperbackups API
5873+
properties:
5874+
apiVersion:
5875+
description: 'APIVersion defines the versioned schema of this representation
5876+
of an object. Servers should convert recognized schemas to the latest
5877+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
5878+
type: string
5879+
kind:
5880+
description: 'Kind is a string value representing the REST resource this
5881+
object represents. Servers may infer this from the endpoint the client
5882+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
5883+
type: string
5884+
metadata:
5885+
type: object
5886+
spec:
5887+
description: ZookeeperBackupSpec defines the desired state of ZookeeperBackup
5888+
properties:
5889+
backupsToKeep:
5890+
default: "7"
5891+
description: Number of backups to store
5892+
type: string
5893+
dataCapacity:
5894+
default: 1Gi
5895+
description: Data Storage Capacity
5896+
type: string
5897+
dataStorageClass:
5898+
description: Data Storage Class name
5899+
type: string
5900+
image:
5901+
description: Image for backup procedure
5902+
properties:
5903+
pullPolicy:
5904+
description: PullPolicy describes a policy for if/when to pull
5905+
a container image
5906+
enum:
5907+
- Always
5908+
- Never
5909+
- IfNotPresent
5910+
type: string
5911+
repository:
5912+
type: string
5913+
tag:
5914+
type: string
5915+
type: object
5916+
schedule:
5917+
default: 0 0 */1 * *
5918+
description: Schedule in Cron format
5919+
type: string
5920+
zookeeperCluster:
5921+
description: Name of the ZookeeperCluster to backup
5922+
type: string
5923+
required:
5924+
- zookeeperCluster
5925+
type: object
5926+
status:
5927+
description: ZookeeperBackupStatus defines the observed state of ZookeeperBackup
5928+
type: object
5929+
type: object
5930+
served: true
5931+
storage: true
5932+
subresources:
5933+
status: {}
58525934
{{- end }}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
apiVersion: apiextensions.k8s.io/v1
23
kind: CustomResourceDefinition
34
metadata:
@@ -14,63 +15,68 @@ spec:
1415
singular: zookeeperbackup
1516
scope: Namespaced
1617
versions:
17-
- name: v1beta1
18-
schema:
19-
openAPIV3Schema:
20-
description: ZookeeperBackup is the Schema for the zookeeperbackups API
21-
type: object
22-
properties:
23-
apiVersion:
24-
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
25-
type: string
26-
kind:
27-
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
28-
type: string
29-
metadata:
30-
type: object
31-
spec:
32-
description: ZookeeperBackupSpec defines the desired state of ZookeeperBackup
33-
type: object
34-
required:
35-
- zookeeperCluster
36-
properties:
37-
backupsToKeep:
38-
description: Number of backups to store
39-
type: string
40-
default: "7"
41-
dataCapacity:
42-
description: Data Storage Capacity
43-
type: string
44-
default: 1Gi
45-
dataStorageClass:
46-
description: Data Storage Class name
47-
type: string
48-
image:
49-
description: Image for backup procedure
50-
type: object
51-
properties:
52-
pullPolicy:
53-
description: PullPolicy describes a policy for if/when to pull a container image
54-
type: string
55-
enum:
56-
- Always
57-
- Never
58-
- IfNotPresent
59-
repository:
60-
type: string
61-
tag:
62-
type: string
63-
schedule:
64-
description: Schedule in Cron format
65-
type: string
66-
default: 0 0 */1 * *
67-
zookeeperCluster:
68-
description: Name of the ZookeeperCluster to backup
69-
type: string
70-
status:
71-
description: ZookeeperBackupStatus defines the observed state of ZookeeperBackup
72-
type: object
73-
served: true
74-
storage: true
75-
subresources:
76-
status: {}
18+
- name: v1beta1
19+
schema:
20+
openAPIV3Schema:
21+
description: ZookeeperBackup is the Schema for the zookeeperbackups API
22+
properties:
23+
apiVersion:
24+
description: 'APIVersion defines the versioned schema of this representation
25+
of an object. Servers should convert recognized schemas to the latest
26+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
27+
type: string
28+
kind:
29+
description: 'Kind is a string value representing the REST resource this
30+
object represents. Servers may infer this from the endpoint the client
31+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
32+
type: string
33+
metadata:
34+
type: object
35+
spec:
36+
description: ZookeeperBackupSpec defines the desired state of ZookeeperBackup
37+
properties:
38+
backupsToKeep:
39+
default: "7"
40+
description: Number of backups to store
41+
type: string
42+
dataCapacity:
43+
default: 1Gi
44+
description: Data Storage Capacity
45+
type: string
46+
dataStorageClass:
47+
description: Data Storage Class name
48+
type: string
49+
image:
50+
description: Image for backup procedure
51+
properties:
52+
pullPolicy:
53+
description: PullPolicy describes a policy for if/when to pull
54+
a container image
55+
enum:
56+
- Always
57+
- Never
58+
- IfNotPresent
59+
type: string
60+
repository:
61+
type: string
62+
tag:
63+
type: string
64+
type: object
65+
schedule:
66+
default: 0 0 */1 * *
67+
description: Schedule in Cron format
68+
type: string
69+
zookeeperCluster:
70+
description: Name of the ZookeeperCluster to backup
71+
type: string
72+
required:
73+
- zookeeperCluster
74+
type: object
75+
status:
76+
description: ZookeeperBackupStatus defines the observed state of ZookeeperBackup
77+
type: object
78+
type: object
79+
served: true
80+
storage: true
81+
subresources:
82+
status: {}

config/rbac/role.yaml

+46-47
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,53 @@
1-
21
---
32
apiVersion: rbac.authorization.k8s.io/v1
43
kind: ClusterRole
54
metadata:
65
creationTimestamp: null
76
name: manager-role
87
rules:
9-
- apiGroups:
10-
- zookeeper.pravega.io.zookeeper.pravega.io
11-
resources:
12-
- zookeeperbackups
13-
verbs:
14-
- create
15-
- delete
16-
- get
17-
- list
18-
- patch
19-
- update
20-
- watch
21-
- apiGroups:
22-
- zookeeper.pravega.io.zookeeper.pravega.io
23-
resources:
24-
- zookeeperbackups/finalizers
25-
verbs:
26-
- update
27-
- apiGroups:
28-
- zookeeper.pravega.io.zookeeper.pravega.io
29-
resources:
30-
- zookeeperbackups/status
31-
verbs:
32-
- get
33-
- patch
34-
- update
35-
- apiGroups:
36-
- zookeeper.pravega.io.zookeeper.pravega.io
37-
resources:
38-
- zookeeperclusters
39-
verbs:
40-
- create
41-
- delete
42-
- get
43-
- list
44-
- patch
45-
- update
46-
- watch
47-
- apiGroups:
48-
- zookeeper.pravega.io.zookeeper.pravega.io
49-
resources:
50-
- zookeeperclusters/status
51-
verbs:
52-
- get
53-
- patch
54-
- update
8+
- apiGroups:
9+
- zookeeper.pravega.io.zookeeper.pravega.io
10+
resources:
11+
- zookeeperbackups
12+
verbs:
13+
- create
14+
- delete
15+
- get
16+
- list
17+
- patch
18+
- update
19+
- watch
20+
- apiGroups:
21+
- zookeeper.pravega.io.zookeeper.pravega.io
22+
resources:
23+
- zookeeperbackups/finalizers
24+
verbs:
25+
- update
26+
- apiGroups:
27+
- zookeeper.pravega.io.zookeeper.pravega.io
28+
resources:
29+
- zookeeperbackups/status
30+
verbs:
31+
- get
32+
- patch
33+
- update
34+
- apiGroups:
35+
- zookeeper.pravega.io.zookeeper.pravega.io
36+
resources:
37+
- zookeeperclusters
38+
verbs:
39+
- create
40+
- delete
41+
- get
42+
- list
43+
- patch
44+
- update
45+
- watch
46+
- apiGroups:
47+
- zookeeper.pravega.io.zookeeper.pravega.io
48+
resources:
49+
- zookeeperclusters/status
50+
verbs:
51+
- get
52+
- patch
53+
- update

0 commit comments

Comments
 (0)