Skip to content

Add backup resources and labels #921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
* Add `KeepAfterDelete` in `.Spec.VolumeSpec` to keep pvc after mysql cluster been deleted.
* Add default resource to init container.
* Add SidecarImage fields to `.Spec` to allow specifying custom sidecar image.
* Add `MysqlCluster.Spec.BackupResources` to allow the user specifying resources for backup job container.
* Add `MysqlCluster.Spec.BackupLabels` to allow the user specifying labels for backup job pods.

### Changed
### Removed
Expand Down
27 changes: 27 additions & 0 deletions config/crd/bases/mysql.presslabs.org_mysqlclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,36 @@ spec:
items:
type: string
type: array
backupLabels:
additionalProperties:
type: string
description: BackupLabels set labels to backup pods
type: object
backupRemoteDeletePolicy:
description: BackupRemoteDeletePolicy the deletion policy that specify how to treat the data from remote storage. By default it's used softDelete.
type: string
backupResources:
description: BackupResources sets resources to backup pod container
properties:
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
backupSchedule:
description: Specify under crontab format interval to take backups leave it empty to deactivate the backup process Defaults to ""
type: string
Expand Down
8 changes: 8 additions & 0 deletions deploy/charts/mysql-cluster/templates/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ spec:
{{- if .Values.backupScheduleJobsHistoryLimit }}
backupScheduleJobsHistoryLimit: {{ .Values.backupScheduleJobsHistoryLimit }}
{{- end }}
{{- if .Values.backupResources }}
backupResources:
{{- toYaml .Values.backupResources | nindent 4 }}
{{- end }}
{{- if .Values.backupLabels }}
backupLabels:
{{- toYaml .Values.backupLabels | nindent 4 }}
{{- end }}

{{- if .Values.mysqlConf }}
mysqlConf:
Expand Down
2 changes: 2 additions & 0 deletions deploy/charts/mysql-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ backupSecretName:
backupRemoteDeletePolicy:
# backupSecretLabels: {}
# backupSecretAnnotations: {}
# backupResources: {}
# backupLabels: {}
backupCredentials:
# use s3 https://rclone.org/s3/
# S3_PROVIDER: ? # like: AWS, Minio, Ceph, and so on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,36 @@ spec:
items:
type: string
type: array
backupLabels:
additionalProperties:
type: string
description: BackupLabels set labels to backup pods
type: object
backupRemoteDeletePolicy:
description: BackupRemoteDeletePolicy the deletion policy that specify how to treat the data from remote storage. By default it's used softDelete.
type: string
backupResources:
description: BackupResources sets resources to backup pod container
properties:
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
backupSchedule:
description: Specify under crontab format interval to take backups leave it empty to deactivate the backup process Defaults to ""
type: string
Expand Down
10 changes: 8 additions & 2 deletions pkg/apis/mysql/v1alpha1/mysqlcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ type MysqlClusterSpec struct {
// +optional
BackupScheduleJobsHistoryLimit *int `json:"backupScheduleJobsHistoryLimit,omitempty"`

// BackupResources sets resources to backup pod container
// +optional
BackupResources core.ResourceRequirements `json:"backupResources,omitempty"`

// BackupLabels set labels to backup pods
// +optional
BackupLabels map[string]string `json:"backupLabels,omitempty"`

// A map[string]string that will be passed to my.cnf file.
// +optional
MysqlConf MysqlConf `json:"mysqlConf,omitempty"`
Expand Down Expand Up @@ -376,7 +384,6 @@ type MysqlClusterStatus struct {
// +kubebuilder:printcolumn:name="Replicas",type="integer",JSONPath=".spec.replicas",description="The number of desired nodes"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:resource:shortName=mysql
//
type MysqlCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -387,7 +394,6 @@ type MysqlCluster struct {

// MysqlClusterList contains a list of MysqlCluster
// +kubebuilder:object:root=true
//
type MysqlClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/mysql/v1alpha1/zz_generated.deepcopy.go

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

2 changes: 2 additions & 0 deletions pkg/controller/mysqlbackup/internal/syncer/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (s *jobSyncer) SyncFn() error {
"cluster": s.backup.Spec.ClusterName,
}

s.job.Spec.Template.Labels = s.cluster.Spec.BackupLabels
s.job.Spec.Template.Spec = s.ensurePodSpec(s.job.Spec.Template.Spec)
return nil
}
Expand Down Expand Up @@ -129,6 +130,7 @@ func (s *jobSyncer) ensurePodSpec(in core.PodSpec) core.PodSpec {
in.Containers[0].Name = "backup"
in.Containers[0].Image = s.cluster.GetSidecarImage()
in.Containers[0].ImagePullPolicy = s.opt.ImagePullPolicy
in.Containers[0].Resources = s.cluster.Spec.BackupResources
in.Containers[0].Args = []string{
"take-backup-to",
s.getBackupCandidate(),
Expand Down