From b30aa099391803b8d151bb0a331e365bf9925880 Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Tue, 28 May 2024 15:06:43 -0600 Subject: [PATCH] Remove Cluster field in Strategy Signed-off-by: Florent Poinsard --- ...planetscale.com_vitessbackupschedules.yaml | 6 ++-- .../crds/planetscale.com_vitessclusters.yaml | 3 -- docs/api/index.html | 34 ++++++++++++------- .../v2/vitessbackupschedule_types.go | 7 ++-- .../vitessbackupschedule_controller.go | 6 ++-- pkg/operator/vitessbackup/schedule.go | 2 ++ test/endtoend/operator/operator-latest.yaml | 9 ++--- test/endtoend/operator/operator.yaml | 9 ++--- 8 files changed, 39 insertions(+), 37 deletions(-) diff --git a/deploy/crds/planetscale.com_vitessbackupschedules.yaml b/deploy/crds/planetscale.com_vitessbackupschedules.yaml index 434cf038..5e523e92 100644 --- a/deploy/crds/planetscale.com_vitessbackupschedules.yaml +++ b/deploy/crds/planetscale.com_vitessbackupschedules.yaml @@ -30,6 +30,8 @@ spec: allowedMissedRun: minimum: 0 type: integer + cluster: + type: string concurrencyPolicy: enum: - Allow @@ -97,8 +99,6 @@ spec: strategies: items: properties: - cluster: - type: string extraFlags: additionalProperties: type: string @@ -116,7 +116,6 @@ spec: example: '-' type: string required: - - cluster - name type: object minItems: 1 @@ -128,6 +127,7 @@ spec: suspend: type: boolean required: + - cluster - name - resources - schedule diff --git a/deploy/crds/planetscale.com_vitessclusters.yaml b/deploy/crds/planetscale.com_vitessclusters.yaml index 2ef9eca0..a2d9575b 100644 --- a/deploy/crds/planetscale.com_vitessclusters.yaml +++ b/deploy/crds/planetscale.com_vitessclusters.yaml @@ -221,8 +221,6 @@ spec: strategies: items: properties: - cluster: - type: string extraFlags: additionalProperties: type: string @@ -240,7 +238,6 @@ spec: example: '-' type: string required: - - cluster - name type: object minItems: 1 diff --git a/docs/api/index.html b/docs/api/index.html index 23fd488a..7de58f93 100644 --- a/docs/api/index.html +++ b/docs/api/index.html @@ -2361,6 +2361,17 @@

VitessBackupSchedule +cluster
+ +string + + + +

Cluster on which this schedule runs.

+ + + + image
string @@ -2438,6 +2449,17 @@

VitessBackupScheduleSpec +cluster
+ +string + + + +

Cluster on which this schedule runs.

+ + + + image
string @@ -2545,18 +2567,6 @@

VitessBackupScheduleStr -cluster
- -string - - - -

Cluster defines on which cluster you want to take the backup. -This field is mandatory regardless of the chosen strategy.

- - - - keyspace
string diff --git a/pkg/apis/planetscale/v2/vitessbackupschedule_types.go b/pkg/apis/planetscale/v2/vitessbackupschedule_types.go index bb584307..d4548836 100644 --- a/pkg/apis/planetscale/v2/vitessbackupschedule_types.go +++ b/pkg/apis/planetscale/v2/vitessbackupschedule_types.go @@ -80,6 +80,9 @@ type VitessBackupScheduleSpec struct { // These are the parts that are configurable through the VitessCluster CRD. VitessBackupScheduleTemplate `json:",inline"` + // Cluster on which this schedule runs. + Cluster string `json:"cluster"` + // Image should be any image that already contains vtctldclient installed. // The controller will re-use the vtctld image by default. Image string `json:"image,omitempty"` @@ -178,10 +181,6 @@ type VitessBackupScheduleStrategy struct { // Name of the backup strategy. Name BackupStrategyName `json:"name"` - // Cluster defines on which cluster you want to take the backup. - // This field is mandatory regardless of the chosen strategy. - Cluster string `json:"cluster"` - // Keyspace defines the keyspace on which we want to take the backup. // If we have chosen the strategy BackupKeyspace or BackupShard this field // is mandatory. In other cases, the field will be ignored. diff --git a/pkg/controller/vitessbackupschedule/vitessbackupschedule_controller.go b/pkg/controller/vitessbackupschedule/vitessbackupschedule_controller.go index 14436c8b..f8816a71 100644 --- a/pkg/controller/vitessbackupschedule/vitessbackupschedule_controller.go +++ b/pkg/controller/vitessbackupschedule/vitessbackupschedule_controller.go @@ -500,7 +500,7 @@ func (r *ReconcileVitessBackupsSchedule) createJobPod(ctx context.Context, vbsc } for i, strategy := range vbsc.Spec.Strategy { - vtctldclientServerArg, err := getVtctldServiceName(strategy.Cluster) + vtctldclientServerArg, err := getVtctldServiceName(vbsc.Spec.Cluster) if err != nil { return corev1.PodSpec{}, err } @@ -519,7 +519,7 @@ func (r *ReconcileVitessBackupsSchedule) createJobPod(ctx context.Context, vbsc if strategy.Keyspace == "" { return pod, fmt.Errorf("the Keyspace field is missing from VitessBackupScheduleStrategy %s", planetscalev2.BackupKeyspace) } - shards, err := r.getAllShardsInKeyspace(ctx, vbsc.Namespace, strategy.Cluster, strategy.Keyspace) + shards, err := r.getAllShardsInKeyspace(ctx, vbsc.Namespace, vbsc.Spec.Cluster, strategy.Keyspace) if err != nil { return corev1.PodSpec{}, err } @@ -528,7 +528,7 @@ func (r *ReconcileVitessBackupsSchedule) createJobPod(ctx context.Context, vbsc createVtctldClientCommand(&cmd, vtctldclientServerArg, strategy.ExtraFlags, strategy.Keyspace, shard) } case planetscalev2.BackupCluster: - keyspaces, err := r.getAllShardsInCluster(ctx, vbsc.Namespace, strategy.Cluster) + keyspaces, err := r.getAllShardsInCluster(ctx, vbsc.Namespace, vbsc.Spec.Cluster) if err != nil { return corev1.PodSpec{}, err } diff --git a/pkg/operator/vitessbackup/schedule.go b/pkg/operator/vitessbackup/schedule.go index 5c90e210..fc5ced6b 100644 --- a/pkg/operator/vitessbackup/schedule.go +++ b/pkg/operator/vitessbackup/schedule.go @@ -42,6 +42,8 @@ func NewVitessBackupSchedule(key client.ObjectKey, vt *planetscalev2.VitessClust // We simply re-apply the same template that was written by the user. VitessBackupScheduleTemplate: *vbsc, + Cluster: vt.Name, + // To take backups we only care about having the vtctldclient installed in the container. // For this reason, we re-use the vtctld Docker image and the same image pull policy. Image: vt.Spec.Images.Vtctld, diff --git a/test/endtoend/operator/operator-latest.yaml b/test/endtoend/operator/operator-latest.yaml index 72e1cd34..b70c7833 100644 --- a/test/endtoend/operator/operator-latest.yaml +++ b/test/endtoend/operator/operator-latest.yaml @@ -410,6 +410,8 @@ spec: allowedMissedRun: minimum: 0 type: integer + cluster: + type: string concurrencyPolicy: enum: - Allow @@ -477,8 +479,6 @@ spec: strategies: items: properties: - cluster: - type: string extraFlags: additionalProperties: type: string @@ -496,7 +496,6 @@ spec: example: '-' type: string required: - - cluster - name type: object minItems: 1 @@ -508,6 +507,7 @@ spec: suspend: type: boolean required: + - cluster - name - resources - schedule @@ -1704,8 +1704,6 @@ spec: strategies: items: properties: - cluster: - type: string extraFlags: additionalProperties: type: string @@ -1723,7 +1721,6 @@ spec: example: '-' type: string required: - - cluster - name type: object minItems: 1 diff --git a/test/endtoend/operator/operator.yaml b/test/endtoend/operator/operator.yaml index 5ce83c00..a6ad00a8 100644 --- a/test/endtoend/operator/operator.yaml +++ b/test/endtoend/operator/operator.yaml @@ -410,6 +410,8 @@ spec: allowedMissedRun: minimum: 0 type: integer + cluster: + type: string concurrencyPolicy: enum: - Allow @@ -477,8 +479,6 @@ spec: strategies: items: properties: - cluster: - type: string extraFlags: additionalProperties: type: string @@ -496,7 +496,6 @@ spec: example: '-' type: string required: - - cluster - name type: object minItems: 1 @@ -508,6 +507,7 @@ spec: suspend: type: boolean required: + - cluster - name - resources - schedule @@ -1704,8 +1704,6 @@ spec: strategies: items: properties: - cluster: - type: string extraFlags: additionalProperties: type: string @@ -1723,7 +1721,6 @@ spec: example: '-' type: string required: - - cluster - name type: object minItems: 1