Skip to content

Commit dc7f0c2

Browse files
committed
feat: add pod annotations
Adds the ability to provide additional annotations to inject into the migration job's pod
1 parent 4c6cfcf commit dc7f0c2

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

Diff for: api/v1beta1/migrator_types.go

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type MigratorSpec struct {
3030
Args *[]string `json:"args,omitempty"`
3131
Container string `json:"container,omitempty"`
3232
Labels map[string]string `json:"labels,omitempty"`
33+
Annotations map[string]string `json:"annotations,omitempty"`
3334
}
3435

3536
// MigratorStatus defines the observed state of Migrator

Diff for: api/v1beta1/zz_generated.deepcopy.go

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: components/migrations.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,16 @@ func (comp *migrationsComponent) Reconcile(ctx *cu.Context) (cu.Result, error) {
204204
}
205205
}
206206

207+
// add annotations to the job's pod template
208+
jobTemplateAnnotations := map[string]string{
209+
webhook.NOWAIT_MIGRATOR_ANNOTATION: "true",
210+
}
211+
if obj.Spec.Annotations != nil {
212+
for k, v := range obj.Spec.Annotations {
213+
jobTemplateAnnotations[k] = v
214+
}
215+
}
216+
207217
migrationJob := &batchv1.Job{
208218
ObjectMeta: metav1.ObjectMeta{
209219
Name: obj.Name + "-migrations",
@@ -215,7 +225,7 @@ func (comp *migrationsComponent) Reconcile(ctx *cu.Context) (cu.Result, error) {
215225
Template: corev1.PodTemplateSpec{
216226
ObjectMeta: metav1.ObjectMeta{
217227
Labels: jobTemplateLabels,
218-
Annotations: map[string]string{webhook.NOWAIT_MIGRATOR_ANNOTATION: "true"},
228+
Annotations: jobTemplateAnnotations,
219229
},
220230
Spec: *migrationPodSpec,
221231
},

Diff for: components/migrations_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232

3333
migrationsv1beta1 "github.com/coderanger/migrations-operator/api/v1beta1"
3434
argoprojstubsv1alpha1 "github.com/coderanger/migrations-operator/stubs/argoproj/v1alpha1"
35+
"github.com/coderanger/migrations-operator/webhook"
3536
)
3637

3738
var _ = Describe("Migrations component", func() {
@@ -260,6 +261,21 @@ var _ = Describe("Migrations component", func() {
260261
Expect(job.Spec.Template.ObjectMeta.Labels).To(HaveKeyWithValue("migrations", "testing"))
261262
})
262263

264+
It("applies nowait annotation to the migration pod", func() {
265+
helper.TestClient.Create(pod)
266+
helper.MustReconcile()
267+
helper.TestClient.GetName("testing-migrations", job)
268+
Expect(job.Spec.Template.ObjectMeta.Annotations).To(HaveKeyWithValue(webhook.NOWAIT_MIGRATOR_ANNOTATION, "true"))
269+
})
270+
271+
It("applies specified annotations to the migration pod", func() {
272+
obj.Spec.Annotations = map[string]string{"key2": "value2"}
273+
helper.TestClient.Create(pod)
274+
helper.MustReconcile()
275+
helper.TestClient.GetName("testing-migrations", job)
276+
Expect(job.Spec.Template.ObjectMeta.Annotations).To(HaveKeyWithValue("key2", "value2"))
277+
})
278+
263279
It("follows owner references for an argoproj.io rollout", func() {
264280
truep := true
265281
rollout := &argoprojstubsv1alpha1.Rollout{

Diff for: config/crd/bases/migrations.coderanger.net_migrators.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ spec:
3636
spec:
3737
description: MigratorSpec defines the desired state of Migrator
3838
properties:
39+
annotations:
40+
additionalProperties:
41+
type: string
42+
type: object
3943
args:
4044
items:
4145
type: string

0 commit comments

Comments
 (0)