Skip to content

Commit

Permalink
Allow setting labels, annotations, node selector, tolerations and pri…
Browse files Browse the repository at this point in the history
…ority class name on objects. Fixes SKY-1484.

This way, we can e.g. allow Pods to be scheduled in particular availability
zones, allow network firewall rules to refer to them, and other kinds of
features.
  • Loading branch information
sgielen committed Aug 11, 2024
1 parent 35f9a53 commit 165840c
Show file tree
Hide file tree
Showing 9 changed files with 377 additions and 36 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,12 @@ $ kubectl set image -n backsnap deployment/backsnap-operator manager=my-private-
Note, on subsequent runs, that the last command does nothing if the image is
already set to that value. If you just pushed a new image with the same name,
ensure that the imagePullPolicy is set to Always and simply delete the Pod.

Also, the commands above do not update the CRDs, so you may need to update them
manually:

```
$ make
$ kubectl apply -f config/crd/bases/backsnap.skyb.it_pvcbackups.yaml
$ kubectl apply -f config/crd/bases/backsnap.skyb.it_pvcrestores.yaml
```
36 changes: 33 additions & 3 deletions api/v1alpha1/pvcbackup_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -13,10 +14,39 @@ type PVCBackupSpec struct {
PVCName string `json:"pvc"`

// How long will the backup object be retained after the backup completes.
// If not set, the object will be retained for at least one day. The
// controller will also always keep the last PVCBackup for a particular PVC
// around, so that it knows when the last backup was completed.
// The controller will also always keep the last PVCBackup for a particular
// PVC around, so that it knows when the last backup was completed.
TTL metav1.Duration `json:"ttl,omitempty"`

// NodeSelector is a selector which must be true for the backup Pod to fit
// on a node. This can be used e.g. to select which type of node, or which
// Availability Zone, performs a backup.
// More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
// +optional
// +mapType=atomic
NodeSelector map[string]string `json:"nodeSelector,omitempty"`

// If specified, the backup Pod's tolerations.
// +optional
// +listType=atomic
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`

// If specified, indicates the backup Pod's priority.
// +optional
PriorityClassName string `json:"priorityClassName,omitempty"`

// If specified, indicates the labels to be put on the backup
// VolumeSnapshot, backup temporary PVC, backup Job and backup Pod.
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels
// +optional
Labels map[string]string `json:"labels,omitempty"`

// If specified, indicates the annotations to be put on the backup
// VolumeSnapshot, backup temporary PVC, backup Job and backup Pod. This
// SHOULD NOT include any backsnap.skyb.it annotations.
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations
// +optional
Annotations map[string]string `json:"annotations,omitempty"`
}

// +kubebuilder:validation:Enum=Succeeded;Failed
Expand Down
32 changes: 32 additions & 0 deletions api/v1alpha1/pvcrestore_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -25,6 +26,37 @@ type PVCRestoreSpec struct {
// The size of the target PVC. Must be large enough to contain the backup's
// contents.
TargetPVCSize resource.Quantity `json:"targetPvcSize,omitempty"`

// NodeSelector is a selector which must be true for the restore Pod to fit
// on a node. This can be used e.g. to select which type of node, or which
// Availability Zone, performs a restore. This, in turn, may also determine
// in which Availability Zone the restored volume is created.
// More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
// +optional
// +mapType=atomic
NodeSelector map[string]string `json:"nodeSelector,omitempty"`

// If specified, the restore Pod's tolerations.
// +optional
// +listType=atomic
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`

// If specified, indicates the restore Pod's priority.
// +optional
PriorityClassName string `json:"priorityClassName,omitempty"`

// If specified, indicates the labels to be put on the restored PVC, restore
// Job and restore Pod.
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels
// +optional
Labels map[string]string `json:"labels,omitempty"`

// If specified, indicates the annotations to be put on the restored PVC,
// restore Job and restore Pod. This SHOULD NOT include any backsnap.skyb.it
// annotations.
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations
// +optional
Annotations map[string]string `json:"annotations,omitempty"`
}

// PVCRestoreStatus defines the observed state of PVCRestore
Expand Down
65 changes: 61 additions & 4 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 72 additions & 3 deletions config/crd/bases/backsnap.skyb.it_pvcbackups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,84 @@ spec:
type: object
spec:
properties:
annotations:
additionalProperties:
type: string
description: |-
If specified, indicates the annotations to be put on the backup
VolumeSnapshot, backup temporary PVC, backup Job and backup Pod. This
SHOULD NOT include any backsnap.skyb.it annotations.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations
type: object
labels:
additionalProperties:
type: string
description: |-
If specified, indicates the labels to be put on the backup
VolumeSnapshot, backup temporary PVC, backup Job and backup Pod.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels
type: object
nodeSelector:
additionalProperties:
type: string
description: |-
NodeSelector is a selector which must be true for the backup Pod to fit
on a node. This can be used e.g. to select which type of node, or which
Availability Zone, performs a backup.
More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
type: object
x-kubernetes-map-type: atomic
priorityClassName:
description: If specified, indicates the backup Pod's priority.
type: string
pvc:
description: Name of the PVC to back up. Must be in the same namespace.
type: string
tolerations:
description: If specified, the backup Pod's tolerations.
items:
description: |-
The pod this Toleration is attached to tolerates any taint that matches
the triple <key,value,effect> using the matching operator <operator>.
properties:
effect:
description: |-
Effect indicates the taint effect to match. Empty means match all taint effects.
When specified, allowed values are NoSchedule, PreferNoSchedule and NoExecute.
type: string
key:
description: |-
Key is the taint key that the toleration applies to. Empty means match all taint keys.
If the key is empty, operator must be Exists; this combination means to match all values and all keys.
type: string
operator:
description: |-
Operator represents a key's relationship to the value.
Valid operators are Exists and Equal. Defaults to Equal.
Exists is equivalent to wildcard for value, so that a pod can
tolerate all taints of a particular category.
type: string
tolerationSeconds:
description: |-
TolerationSeconds represents the period of time the toleration (which must be
of effect NoExecute, otherwise this field is ignored) tolerates the taint. By default,
it is not set, which means tolerate the taint forever (do not evict). Zero and
negative values will be treated as 0 (evict immediately) by the system.
format: int64
type: integer
value:
description: |-
Value is the taint value the toleration matches to.
If the operator is Exists, the value should be empty, otherwise just a regular string.
type: string
type: object
type: array
x-kubernetes-list-type: atomic
ttl:
description: |-
How long will the backup object be retained after the backup completes.
If not set, the object will be retained for at least one day. The
controller will also always keep the last PVCBackup for a particular PVC
around, so that it knows when the last backup was completed.
The controller will also always keep the last PVCBackup for a particular
PVC around, so that it knows when the last backup was completed.
type: string
required:
- pvc
Expand Down
71 changes: 71 additions & 0 deletions config/crd/bases/backsnap.skyb.it_pvcrestores.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,37 @@ spec:
spec:
description: PVCRestoreSpec defines the desired state of PVCRestore
properties:
annotations:
additionalProperties:
type: string
description: |-
If specified, indicates the annotations to be put on the restored PVC,
restore Job and restore Pod. This SHOULD NOT include any backsnap.skyb.it
annotations.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations
type: object
labels:
additionalProperties:
type: string
description: |-
If specified, indicates the labels to be put on the restored PVC, restore
Job and restore Pod.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels
type: object
nodeSelector:
additionalProperties:
type: string
description: |-
NodeSelector is a selector which must be true for the restore Pod to fit
on a node. This can be used e.g. to select which type of node, or which
Availability Zone, performs a restore. This, in turn, may also determine
in which Availability Zone the restored volume is created.
More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
type: object
x-kubernetes-map-type: atomic
priorityClassName:
description: If specified, indicates the restore Pod's priority.
type: string
sourceNamespace:
description: |-
The namespace that the source PVC used to exist in. If empty, assume that
Expand Down Expand Up @@ -86,6 +117,46 @@ spec:
contents.
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
tolerations:
description: If specified, the restore Pod's tolerations.
items:
description: |-
The pod this Toleration is attached to tolerates any taint that matches
the triple <key,value,effect> using the matching operator <operator>.
properties:
effect:
description: |-
Effect indicates the taint effect to match. Empty means match all taint effects.
When specified, allowed values are NoSchedule, PreferNoSchedule and NoExecute.
type: string
key:
description: |-
Key is the taint key that the toleration applies to. Empty means match all taint keys.
If the key is empty, operator must be Exists; this combination means to match all values and all keys.
type: string
operator:
description: |-
Operator represents a key's relationship to the value.
Valid operators are Exists and Equal. Defaults to Equal.
Exists is equivalent to wildcard for value, so that a pod can
tolerate all taints of a particular category.
type: string
tolerationSeconds:
description: |-
TolerationSeconds represents the period of time the toleration (which must be
of effect NoExecute, otherwise this field is ignored) tolerates the taint. By default,
it is not set, which means tolerate the taint forever (do not evict). Zero and
negative values will be treated as 0 (evict immediately) by the system.
format: int64
type: integer
value:
description: |-
Value is the taint value the toleration matches to.
If the operator is Exists, the value should be empty, otherwise just a regular string.
type: string
type: object
type: array
x-kubernetes-list-type: atomic
type: object
status:
description: PVCRestoreStatus defines the observed state of PVCRestore
Expand Down
Loading

0 comments on commit 165840c

Please sign in to comment.