Skip to content

Commit

Permalink
Additional fixes
Browse files Browse the repository at this point in the history
- Add backup crd to charts (makefile)
- Add validation of BACKUPS_TO_KEEP variable
- Improve logging

Signed-off-by: Ilya Bumarskov <[email protected]>
  • Loading branch information
ibumarskov committed Jun 23, 2022
1 parent 1e7c76c commit 8222c56
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 117 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ generate:
# sync crd generated to helm-chart
echo '{{- if .Values.crd.create }}' > charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml
cat config/crd/bases/zookeeper.pravega.io_zookeeperclusters.yaml >> charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml
cat config/crd/bases/zookeeper.pravega.io_zookeeperbackups.yaml >> charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml
echo '{{- end }}' >> charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ approach described in [article](https://www.elastic.co/blog/zookeeper-backup-a-t
Exmaple CR of zookeeper backup:
```yaml
apiVersion: "zookeeper.pravega.io/v1beta1"
kind: "ZookeeperCluster"
kind: "ZookeeperBackup"
metadata:
name: "example-backup"
spec:
Expand Down
3 changes: 0 additions & 3 deletions api/v1beta1/zookeeperbackup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// ZookeeperBackupSpec defines the desired state of ZookeeperBackup
type ZookeeperBackupSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
Expand Down
8 changes: 6 additions & 2 deletions build_backup/backup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

echo "--------------- Check required parameters ---------------"
echo "--------------- Check required env variables ---------------"
_req_envs="
Required parameters: \n
BACKUPDIR: $BACKUPDIR \n
Expand All @@ -14,6 +14,10 @@ if [ -z "$BACKUPDIR" ] || [ -z "$ZOOKEEPERDATADIR" ] || [ -z "$BACKUPS_TO_KEEP"
exit 1
fi

echo "--------------- Check BACKUPS_TO_KEEP variable ---------------"
if ! [[ $BACKUPS_TO_KEEP =~ ^[0-9]+$ ]] ;
then echo "Error: $BACKUPS_TO_KEEP not a number" >&2; exit 1
fi
# Create backup directory if absent.
# ----------------------------------
echo "--------------- Check backup/tmp dirs ---------------"
Expand Down Expand Up @@ -53,7 +57,7 @@ BACKUPS_AMOUNT=`find . -path "*/zookeeper-*.tar.gz" -type f -printf "\n%AD %AT %
TO_DELETE=$(( $BACKUPS_AMOUNT - $BACKUPS_TO_KEEP ))
if [ $TO_DELETE -gt 0 ] ; then
echo "Keeping only $BACKUPS_TO_KEEP full backups"
ls -t | tail -n -$TO_DELETE | xargs -d '\n' rm -rf
ls -t zookeeper-*.tar.gz | tail -n -$TO_DELETE | xargs -d '\n' rm -rf
else
echo "There are less backups than required, nothing to delete."
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5849,4 +5849,86 @@ spec:
storage: true
subresources:
status: {}
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.0
creationTimestamp: null
name: zookeeperbackups.zookeeper.pravega.io
spec:
group: zookeeper.pravega.io
names:
kind: ZookeeperBackup
listKind: ZookeeperBackupList
plural: zookeeperbackups
singular: zookeeperbackup
scope: Namespaced
versions:
- name: v1beta1
schema:
openAPIV3Schema:
description: ZookeeperBackup is the Schema for the zookeeperbackups API
properties:
apiVersion:
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'
type: string
kind:
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'
type: string
metadata:
type: object
spec:
description: ZookeeperBackupSpec defines the desired state of ZookeeperBackup
properties:
backupsToKeep:
default: "7"
description: Number of backups to store
type: string
dataCapacity:
default: 1Gi
description: Data Storage Capacity
type: string
dataStorageClass:
description: Data Storage Class name
type: string
image:
description: Image for backup procedure
properties:
pullPolicy:
description: PullPolicy describes a policy for if/when to pull
a container image
enum:
- Always
- Never
- IfNotPresent
type: string
repository:
type: string
tag:
type: string
type: object
schedule:
default: 0 0 */1 * *
description: Schedule in Cron format
type: string
zookeeperCluster:
description: Name of the ZookeeperCluster to backup
type: string
required:
- zookeeperCluster
type: object
status:
description: ZookeeperBackupStatus defines the observed state of ZookeeperBackup
type: object
type: object
served: true
storage: true
subresources:
status: {}
{{- end }}
126 changes: 66 additions & 60 deletions config/crd/bases/zookeeper.pravega.io_zookeeperbackups.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand All @@ -14,63 +15,68 @@ spec:
singular: zookeeperbackup
scope: Namespaced
versions:
- name: v1beta1
schema:
openAPIV3Schema:
description: ZookeeperBackup is the Schema for the zookeeperbackups API
type: object
properties:
apiVersion:
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'
type: string
kind:
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'
type: string
metadata:
type: object
spec:
description: ZookeeperBackupSpec defines the desired state of ZookeeperBackup
type: object
required:
- zookeeperCluster
properties:
backupsToKeep:
description: Number of backups to store
type: string
default: "7"
dataCapacity:
description: Data Storage Capacity
type: string
default: 1Gi
dataStorageClass:
description: Data Storage Class name
type: string
image:
description: Image for backup procedure
type: object
properties:
pullPolicy:
description: PullPolicy describes a policy for if/when to pull a container image
type: string
enum:
- Always
- Never
- IfNotPresent
repository:
type: string
tag:
type: string
schedule:
description: Schedule in Cron format
type: string
default: 0 0 */1 * *
zookeeperCluster:
description: Name of the ZookeeperCluster to backup
type: string
status:
description: ZookeeperBackupStatus defines the observed state of ZookeeperBackup
type: object
served: true
storage: true
subresources:
status: {}
- name: v1beta1
schema:
openAPIV3Schema:
description: ZookeeperBackup is the Schema for the zookeeperbackups API
properties:
apiVersion:
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'
type: string
kind:
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'
type: string
metadata:
type: object
spec:
description: ZookeeperBackupSpec defines the desired state of ZookeeperBackup
properties:
backupsToKeep:
default: "7"
description: Number of backups to store
type: string
dataCapacity:
default: 1Gi
description: Data Storage Capacity
type: string
dataStorageClass:
description: Data Storage Class name
type: string
image:
description: Image for backup procedure
properties:
pullPolicy:
description: PullPolicy describes a policy for if/when to pull
a container image
enum:
- Always
- Never
- IfNotPresent
type: string
repository:
type: string
tag:
type: string
type: object
schedule:
default: 0 0 */1 * *
description: Schedule in Cron format
type: string
zookeeperCluster:
description: Name of the ZookeeperCluster to backup
type: string
required:
- zookeeperCluster
type: object
status:
description: ZookeeperBackupStatus defines the observed state of ZookeeperBackup
type: object
type: object
served: true
storage: true
subresources:
status: {}
93 changes: 46 additions & 47 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
@@ -1,54 +1,53 @@

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
- zookeeper.pravega.io.zookeeper.pravega.io
resources:
- zookeeperbackups
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- zookeeper.pravega.io.zookeeper.pravega.io
resources:
- zookeeperbackups/finalizers
verbs:
- update
- apiGroups:
- zookeeper.pravega.io.zookeeper.pravega.io
resources:
- zookeeperbackups/status
verbs:
- get
- patch
- update
- apiGroups:
- zookeeper.pravega.io.zookeeper.pravega.io
resources:
- zookeeperclusters
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- zookeeper.pravega.io.zookeeper.pravega.io
resources:
- zookeeperclusters/status
verbs:
- get
- patch
- update
- apiGroups:
- zookeeper.pravega.io.zookeeper.pravega.io
resources:
- zookeeperbackups
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- zookeeper.pravega.io.zookeeper.pravega.io
resources:
- zookeeperbackups/finalizers
verbs:
- update
- apiGroups:
- zookeeper.pravega.io.zookeeper.pravega.io
resources:
- zookeeperbackups/status
verbs:
- get
- patch
- update
- apiGroups:
- zookeeper.pravega.io.zookeeper.pravega.io
resources:
- zookeeperclusters
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- zookeeper.pravega.io.zookeeper.pravega.io
resources:
- zookeeperclusters/status
verbs:
- get
- patch
- update
Loading

0 comments on commit 8222c56

Please sign in to comment.