Skip to content

Commit b4c2053

Browse files
authored
Merge pull request #18 from DWSR/add-pod-annotations
feat: add pod annotations
2 parents 4c6cfcf + af88b97 commit b4c2053

File tree

6 files changed

+40
-1
lines changed

6 files changed

+40
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ with these fields:
4444
- image: optional image to use for the upgrade Job.
4545
- container: optional name of a container from the selected template Pod. The selected container will be used to run the upgrader.
4646
- labels: optional map of labels to set on the Job's pod template,
47+
- annotations: optional map of annotations to set on the Job's pod template,
4748

4849
The migrator Job will contain only the single template container, initContainers will be included but sidecars will not. Any livenessProbes and readinessProbes in the template will be ignored.
4950

api/v1beta1/migrator_types.go

Lines changed: 1 addition & 0 deletions
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

api/v1beta1/zz_generated.deepcopy.go

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

components/migrations.go

Lines changed: 11 additions & 1 deletion
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
},

components/migrations_test.go

Lines changed: 16 additions & 0 deletions
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{

config/crd/bases/migrations.coderanger.net_migrators.yaml

Lines changed: 4 additions & 0 deletions
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)