Skip to content

feat: add pod annotations #18

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

Merged
merged 2 commits into from
Jun 16, 2022
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ with these fields:
- image: optional image to use for the upgrade Job.
- container: optional name of a container from the selected template Pod. The selected container will be used to run the upgrader.
- labels: optional map of labels to set on the Job's pod template,
- annotations: optional map of annotations to set on the Job's pod template,

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.

Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/migrator_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type MigratorSpec struct {
Args *[]string `json:"args,omitempty"`
Container string `json:"container,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
}

// MigratorStatus defines the observed state of Migrator
Expand Down
7 changes: 7 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

12 changes: 11 additions & 1 deletion components/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ func (comp *migrationsComponent) Reconcile(ctx *cu.Context) (cu.Result, error) {
}
}

// add annotations to the job's pod template
jobTemplateAnnotations := map[string]string{
webhook.NOWAIT_MIGRATOR_ANNOTATION: "true",
}
if obj.Spec.Annotations != nil {
for k, v := range obj.Spec.Annotations {
jobTemplateAnnotations[k] = v
}
}

Comment on lines +207 to +216
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing it in this order does technically allow the footgun of overriding the nowait annotation itself but I don't think anyone could do that by accident :)

migrationJob := &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Name: obj.Name + "-migrations",
Expand All @@ -215,7 +225,7 @@ func (comp *migrationsComponent) Reconcile(ctx *cu.Context) (cu.Result, error) {
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: jobTemplateLabels,
Annotations: map[string]string{webhook.NOWAIT_MIGRATOR_ANNOTATION: "true"},
Annotations: jobTemplateAnnotations,
},
Spec: *migrationPodSpec,
},
Expand Down
16 changes: 16 additions & 0 deletions components/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

migrationsv1beta1 "github.com/coderanger/migrations-operator/api/v1beta1"
argoprojstubsv1alpha1 "github.com/coderanger/migrations-operator/stubs/argoproj/v1alpha1"
"github.com/coderanger/migrations-operator/webhook"
)

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

It("applies nowait annotation to the migration pod", func() {
helper.TestClient.Create(pod)
helper.MustReconcile()
helper.TestClient.GetName("testing-migrations", job)
Expect(job.Spec.Template.ObjectMeta.Annotations).To(HaveKeyWithValue(webhook.NOWAIT_MIGRATOR_ANNOTATION, "true"))
})

It("applies specified annotations to the migration pod", func() {
obj.Spec.Annotations = map[string]string{"key2": "value2"}
helper.TestClient.Create(pod)
helper.MustReconcile()
helper.TestClient.GetName("testing-migrations", job)
Expect(job.Spec.Template.ObjectMeta.Annotations).To(HaveKeyWithValue("key2", "value2"))
})

It("follows owner references for an argoproj.io rollout", func() {
truep := true
rollout := &argoprojstubsv1alpha1.Rollout{
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/migrations.coderanger.net_migrators.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ spec:
spec:
description: MigratorSpec defines the desired state of Migrator
properties:
annotations:
additionalProperties:
type: string
type: object
args:
items:
type: string
Expand Down