Skip to content

Commit

Permalink
Propagate metadata labels & annotations from podTemplateSpec (#203)
Browse files Browse the repository at this point in the history
Co-authored-by: David J. M. Karlsen <david@davidkarlsen.com>
  • Loading branch information
ekarlso and davidkarlsen authored Feb 22, 2021
1 parent 5f824c9 commit d1f59b9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
2 changes: 2 additions & 0 deletions controllers/githubactionrunner_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ func (r *GithubActionRunnerReconciler) scaleUp(ctx context.Context, amount int,
ObjectMeta: metav1.ObjectMeta{
GenerateName: fmt.Sprintf("%s-pod-", instance.Name),
Namespace: instance.Namespace,
Labels: instance.Spec.PodTemplateSpec.GetObjectMeta().GetLabels(),
Annotations: instance.Spec.PodTemplateSpec.GetObjectMeta().GetAnnotations(),
},
}
result, err := controllerutil.CreateOrUpdate(ctx, r.GetClient(), pod, func() error {
Expand Down
31 changes: 26 additions & 5 deletions controllers/githubactionrunner_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ func TestGithubactionRunnerController(t *testing.T) {
const token = "someToken"
const tokenKey = "GH_TOKEN"

const someLabel = "someLabel"
const someLabelValue = "someLabelValue"

var mockResult []*github.Runner

mockAPI := new(mockAPI)
Expand All @@ -63,11 +66,20 @@ func TestGithubactionRunnerController(t *testing.T) {
},
},
Spec: v1alpha1.GithubActionRunnerSpec{
Organization: org,
Repository: repo,
MinRunners: 2,
MaxRunners: 2,
PodTemplateSpec: v1.PodTemplateSpec{},
Organization: org,
Repository: repo,
MinRunners: 2,
MaxRunners: 2,
PodTemplateSpec: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
someLabel: someLabelValue,
},
Annotations: map[string]string{
"someAnnotationKey": "someAnnotationValue",
},
},
},
TokenRef: v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: secretName,
Expand Down Expand Up @@ -120,6 +132,15 @@ func TestGithubactionRunnerController(t *testing.T) {
numEvents := len(fakeRecorder.Events)
testhelper.AssertEquals(t, runner.Spec.MinRunners, numEvents)

expectedLabels := map[string]string{
someLabel: someLabelValue,
poolLabel: name,
}

podObjectMeta := podList.Items[0].GetObjectMeta()
testhelper.AssertDeepEquals(t, expectedLabels, podObjectMeta.GetLabels())
testhelper.AssertDeepEquals(t, runner.Spec.PodTemplateSpec.GetObjectMeta().GetAnnotations(), podObjectMeta.GetAnnotations())

// then scale down
mockResult = append(mockResult, &github.Runner{
ID: pointer.Int64Ptr(1),
Expand Down

0 comments on commit d1f59b9

Please sign in to comment.