Skip to content

Commit 9e4460e

Browse files
committed
add extraLabels to both subcontroller and vbsc pods
Signed-off-by: Jeremy Doupe <jeremy@doupe.com>
1 parent 4065875 commit 9e4460e

13 files changed

Lines changed: 230 additions & 17 deletions

deploy/crds/planetscale.com_vitessbackupschedules.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ spec:
4444
- Forbid
4545
example: Forbid
4646
type: string
47+
extraLabels:
48+
additionalProperties:
49+
type: string
50+
type: object
4751
failedJobsHistoryLimit:
4852
format: int32
4953
minimum: 0

deploy/crds/planetscale.com_vitessbackupstorages.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ spec:
2828
type: object
2929
spec:
3030
properties:
31+
extraLabels:
32+
additionalProperties:
33+
type: string
34+
type: object
3135
location:
3236
properties:
3337
annotations:

deploy/crds/planetscale.com_vitessclusters.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ spec:
3636
- xtrabackup
3737
- mysqlshell
3838
type: string
39+
extraLabels:
40+
additionalProperties:
41+
type: string
42+
type: object
3943
locations:
4044
items:
4145
properties:

docs/api.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,20 @@ This is a list of VitessBackupScheduleTemplate where the &ldquo;name&rdquo; fiel
775775
across all the items of the list.</p>
776776
</td>
777777
</tr>
778+
<tr>
779+
<td>
780+
<code>extraLabels</code><br>
781+
<em>
782+
map[string]string
783+
</em>
784+
</td>
785+
<td>
786+
<em>(Optional)</em>
787+
<p>ExtraLabels can optionally be used to attach custom labels to pods created by backup schedules
788+
and the VitessBackupStorage subcontroller. These labels will be applied to both the backup
789+
schedule job pods and the subcontroller pod.</p>
790+
</td>
791+
</tr>
778792
</tbody>
779793
</table>
780794
<h3 id="planetscale.com/v2.ConcurrencyPolicy">ConcurrencyPolicy
@@ -2540,6 +2554,19 @@ Kubernetes core/v1.PullPolicy
25402554
The PullPolicy used will be the same as the one used to pull the vtctld image.</p>
25412555
</td>
25422556
</tr>
2557+
<tr>
2558+
<td>
2559+
<code>extraLabels</code><br>
2560+
<em>
2561+
map[string]string
2562+
</em>
2563+
</td>
2564+
<td>
2565+
<em>(Optional)</em>
2566+
<p>ExtraLabels can optionally be used to attach custom labels to the pods created by VitessBackupSchedule.
2567+
This is populated from ClusterBackupSpec.ExtraLabels when the schedule is created.</p>
2568+
</td>
2569+
</tr>
25432570
</table>
25442571
</td>
25452572
</tr>
@@ -2628,6 +2655,19 @@ Kubernetes core/v1.PullPolicy
26282655
The PullPolicy used will be the same as the one used to pull the vtctld image.</p>
26292656
</td>
26302657
</tr>
2658+
<tr>
2659+
<td>
2660+
<code>extraLabels</code><br>
2661+
<em>
2662+
map[string]string
2663+
</em>
2664+
</td>
2665+
<td>
2666+
<em>(Optional)</em>
2667+
<p>ExtraLabels can optionally be used to attach custom labels to the pods created by VitessBackupSchedule.
2668+
This is populated from ClusterBackupSpec.ExtraLabels when the schedule is created.</p>
2669+
</td>
2670+
</tr>
26312671
</tbody>
26322672
</table>
26332673
<h3 id="planetscale.com/v2.VitessBackupScheduleStatus">VitessBackupScheduleStatus
@@ -3232,6 +3272,19 @@ VitessBackupSubcontrollerSpec
32323272
<p>Subcontroller specifies any parameters needed for launching the VitessBackupStorage subcontroller pod.</p>
32333273
</td>
32343274
</tr>
3275+
<tr>
3276+
<td>
3277+
<code>extraLabels</code><br>
3278+
<em>
3279+
map[string]string
3280+
</em>
3281+
</td>
3282+
<td>
3283+
<em>(Optional)</em>
3284+
<p>ExtraLabels can optionally be used to attach custom labels to the VitessBackupStorage subcontroller pod.
3285+
This is populated from ClusterBackupSpec.ExtraLabels when the storage object is created.</p>
3286+
</td>
3287+
</tr>
32353288
</table>
32363289
</td>
32373290
</tr>
@@ -3293,6 +3346,19 @@ VitessBackupSubcontrollerSpec
32933346
<p>Subcontroller specifies any parameters needed for launching the VitessBackupStorage subcontroller pod.</p>
32943347
</td>
32953348
</tr>
3349+
<tr>
3350+
<td>
3351+
<code>extraLabels</code><br>
3352+
<em>
3353+
map[string]string
3354+
</em>
3355+
</td>
3356+
<td>
3357+
<em>(Optional)</em>
3358+
<p>ExtraLabels can optionally be used to attach custom labels to the VitessBackupStorage subcontroller pod.
3359+
This is populated from ClusterBackupSpec.ExtraLabels when the storage object is created.</p>
3360+
</td>
3361+
</tr>
32963362
</tbody>
32973363
</table>
32983364
<h3 id="planetscale.com/v2.VitessBackupStorageStatus">VitessBackupStorageStatus

docs/api/index.html

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,20 @@ <h3 id="planetscale.com/v2.ClusterBackupSpec">ClusterBackupSpec
777777
across all the items of the list.</p>
778778
</td>
779779
</tr>
780+
<tr>
781+
<td>
782+
<code>extraLabels</code><br>
783+
<em>
784+
map[string]string
785+
</em>
786+
</td>
787+
<td>
788+
<em>(Optional)</em>
789+
<p>ExtraLabels can optionally be used to attach custom labels to pods created by backup schedules
790+
and the VitessBackupStorage subcontroller. These labels will be applied to both the backup
791+
schedule job pods and the subcontroller pod.</p>
792+
</td>
793+
</tr>
780794
</tbody>
781795
</table>
782796
<h3 id="planetscale.com/v2.ConcurrencyPolicy">ConcurrencyPolicy
@@ -2542,6 +2556,19 @@ <h3 id="planetscale.com/v2.VitessBackupSchedule">VitessBackupSchedule
25422556
The PullPolicy used will be the same as the one used to pull the vtctld image.</p>
25432557
</td>
25442558
</tr>
2559+
<tr>
2560+
<td>
2561+
<code>extraLabels</code><br>
2562+
<em>
2563+
map[string]string
2564+
</em>
2565+
</td>
2566+
<td>
2567+
<em>(Optional)</em>
2568+
<p>ExtraLabels can optionally be used to attach custom labels to the pods created by VitessBackupSchedule.
2569+
This is populated from ClusterBackupSpec.ExtraLabels when the schedule is created.</p>
2570+
</td>
2571+
</tr>
25452572
</table>
25462573
</td>
25472574
</tr>
@@ -2630,6 +2657,19 @@ <h3 id="planetscale.com/v2.VitessBackupScheduleSpec">VitessBackupScheduleSpec
26302657
The PullPolicy used will be the same as the one used to pull the vtctld image.</p>
26312658
</td>
26322659
</tr>
2660+
<tr>
2661+
<td>
2662+
<code>extraLabels</code><br>
2663+
<em>
2664+
map[string]string
2665+
</em>
2666+
</td>
2667+
<td>
2668+
<em>(Optional)</em>
2669+
<p>ExtraLabels can optionally be used to attach custom labels to the pods created by VitessBackupSchedule.
2670+
This is populated from ClusterBackupSpec.ExtraLabels when the schedule is created.</p>
2671+
</td>
2672+
</tr>
26332673
</tbody>
26342674
</table>
26352675
<h3 id="planetscale.com/v2.VitessBackupScheduleStatus">VitessBackupScheduleStatus
@@ -3234,6 +3274,19 @@ <h3 id="planetscale.com/v2.VitessBackupStorage">VitessBackupStorage
32343274
<p>Subcontroller specifies any parameters needed for launching the VitessBackupStorage subcontroller pod.</p>
32353275
</td>
32363276
</tr>
3277+
<tr>
3278+
<td>
3279+
<code>extraLabels</code><br>
3280+
<em>
3281+
map[string]string
3282+
</em>
3283+
</td>
3284+
<td>
3285+
<em>(Optional)</em>
3286+
<p>ExtraLabels can optionally be used to attach custom labels to the VitessBackupStorage subcontroller pod.
3287+
This is populated from ClusterBackupSpec.ExtraLabels when the storage object is created.</p>
3288+
</td>
3289+
</tr>
32373290
</table>
32383291
</td>
32393292
</tr>
@@ -3295,6 +3348,19 @@ <h3 id="planetscale.com/v2.VitessBackupStorageSpec">VitessBackupStorageSpec
32953348
<p>Subcontroller specifies any parameters needed for launching the VitessBackupStorage subcontroller pod.</p>
32963349
</td>
32973350
</tr>
3351+
<tr>
3352+
<td>
3353+
<code>extraLabels</code><br>
3354+
<em>
3355+
map[string]string
3356+
</em>
3357+
</td>
3358+
<td>
3359+
<em>(Optional)</em>
3360+
<p>ExtraLabels can optionally be used to attach custom labels to the VitessBackupStorage subcontroller pod.
3361+
This is populated from ClusterBackupSpec.ExtraLabels when the storage object is created.</p>
3362+
</td>
3363+
</tr>
32983364
</tbody>
32993365
</table>
33003366
<h3 id="planetscale.com/v2.VitessBackupStorageStatus">VitessBackupStorageStatus

pkg/apis/planetscale/v2/vitessbackupschedule_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ type VitessBackupScheduleSpec struct {
8484
// ImagePullPolicy defines the policy to pull the Docker image in the job's pod.
8585
// The PullPolicy used will be the same as the one used to pull the vtctld image.
8686
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
87+
88+
// ExtraLabels can optionally be used to attach custom labels to the pods created by VitessBackupSchedule.
89+
// This is populated from ClusterBackupSpec.ExtraLabels when the schedule is created.
90+
// +optional
91+
ExtraLabels map[string]string `json:"extraLabels,omitempty"`
8792
}
8893

8994
// VitessBackupScheduleTemplate contains all the user-specific fields that the user will be

pkg/apis/planetscale/v2/vitessbackupstorage_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ type VitessBackupStorageSpec struct {
6161
Location VitessBackupLocation `json:"location"`
6262
// Subcontroller specifies any parameters needed for launching the VitessBackupStorage subcontroller pod.
6363
Subcontroller *VitessBackupSubcontrollerSpec `json:"subcontroller,omitempty"`
64+
// ExtraLabels can optionally be used to attach custom labels to the VitessBackupStorage subcontroller pod.
65+
// This is populated from ClusterBackupSpec.ExtraLabels when the storage object is created.
66+
// +optional
67+
ExtraLabels map[string]string `json:"extraLabels,omitempty"`
6468
}
6569

6670
type VitessBackupSubcontrollerSpec struct {

pkg/apis/planetscale/v2/vitesscluster_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,12 @@ type ClusterBackupSpec struct {
327327
// +patchMergeKey=name
328328
// +patchStrategy=merge
329329
Schedules []VitessBackupScheduleTemplate `json:"schedules,omitempty"`
330+
331+
// ExtraLabels can optionally be used to attach custom labels to pods created by backup schedules
332+
// and the VitessBackupStorage subcontroller. These labels will be applied to both the backup
333+
// schedule job pods and the subcontroller pod.
334+
// +optional
335+
ExtraLabels map[string]string `json:"extraLabels,omitempty"`
330336
}
331337

332338
// VitessBackupEngine is the backup implementation to use.

pkg/apis/planetscale/v2/zz_generated.deepcopy.go

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controller/vitessbackupschedule/vitessbackupschedule_controller.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343
"planetscale.dev/vitess-operator/pkg/operator/reconciler"
4444
"planetscale.dev/vitess-operator/pkg/operator/results"
4545
"planetscale.dev/vitess-operator/pkg/operator/resync"
46+
"planetscale.dev/vitess-operator/pkg/operator/update"
4647
"planetscale.dev/vitess-operator/pkg/operator/vitessbackup"
4748
"planetscale.dev/vitess-operator/pkg/operator/vttablet"
4849
"sigs.k8s.io/controller-runtime/pkg/controller"
@@ -616,6 +617,10 @@ func (r *ReconcileVitessBackupsSchedule) createJob(
616617
planetscalev2.KeyspaceLabel: strategy.Keyspace,
617618
planetscalev2.ShardLabel: vkr.SafeName(),
618619
}
620+
// Merge user-provided extra labels.
621+
if vbsc.Spec.ExtraLabels != nil {
622+
update.Labels(&labels, vbsc.Spec.ExtraLabels)
623+
}
619624

620625
meta := metav1.ObjectMeta{
621626
Labels: labels,
@@ -629,6 +634,10 @@ func (r *ReconcileVitessBackupsSchedule) createJob(
629634
meta.Annotations[scheduledTimeAnnotation] = scheduledTime.Format(time.RFC3339)
630635

631636
maps.Copy(meta.Labels, vbsc.Labels)
637+
// Merge user-provided extra labels into meta as well.
638+
if vbsc.Spec.ExtraLabels != nil {
639+
update.Labels(&meta.Labels, vbsc.Spec.ExtraLabels)
640+
}
632641

633642
pod, vtbackupSpec, err := r.createJobPod(ctx, vbsc, strategy, name, vkr, labels)
634643
if err != nil {

0 commit comments

Comments
 (0)