diff --git a/controllers/actions.github.com/autoscalingrunnerset_controller.go b/controllers/actions.github.com/autoscalingrunnerset_controller.go index fe2a5953..773541b8 100644 --- a/controllers/actions.github.com/autoscalingrunnerset_controller.go +++ b/controllers/actions.github.com/autoscalingrunnerset_controller.go @@ -45,7 +45,6 @@ const ( labelKeyRunnerSpecHash = "runner-spec-hash" autoscalingRunnerSetFinalizerName = "autoscalingrunnerset.actions.github.com/finalizer" runnerScaleSetIdAnnotationKey = "runner-scale-set-id" - runnerScaleSetNameAnnotationKey = "runner-scale-set-name" ) type UpdateStrategy string @@ -205,7 +204,7 @@ func (r *AutoscalingRunnerSetReconciler) Reconcile(ctx context.Context, req ctrl } // Make sure the runner scale set name is up to date - currentRunnerScaleSetName, ok := autoscalingRunnerSet.Annotations[runnerScaleSetNameAnnotationKey] + currentRunnerScaleSetName, ok := autoscalingRunnerSet.Annotations[AnnotationKeyGitHubRunnerScaleSetName] if !ok || (len(autoscalingRunnerSet.Spec.RunnerScaleSetName) > 0 && !strings.EqualFold(currentRunnerScaleSetName, autoscalingRunnerSet.Spec.RunnerScaleSetName)) { log.Info("AutoScalingRunnerSet runner scale set name changed. Updating the runner scale set.") return r.updateRunnerScaleSetName(ctx, autoscalingRunnerSet, log) @@ -480,7 +479,7 @@ func (r *AutoscalingRunnerSetReconciler) createRunnerScaleSet(ctx context.Contex logger.Info("Adding runner scale set ID, name and runner group name as an annotation and url labels") if err = patch(ctx, r.Client, autoscalingRunnerSet, func(obj *v1alpha1.AutoscalingRunnerSet) { - obj.Annotations[runnerScaleSetNameAnnotationKey] = runnerScaleSet.Name + obj.Annotations[AnnotationKeyGitHubRunnerScaleSetName] = runnerScaleSet.Name obj.Annotations[runnerScaleSetIdAnnotationKey] = strconv.Itoa(runnerScaleSet.Id) obj.Annotations[AnnotationKeyGitHubRunnerGroupName] = runnerScaleSet.RunnerGroupName if err := applyGitHubURLLabels(obj.Spec.GitHubConfigUrl, obj.Labels); err != nil { // should never happen @@ -528,9 +527,10 @@ func (r *AutoscalingRunnerSetReconciler) updateRunnerScaleSetRunnerGroup(ctx con return ctrl.Result{}, err } - logger.Info("Updating runner scale set runner group name as an annotation") + logger.Info("Updating runner scale set name and runner group name as annotations") if err := patch(ctx, r.Client, autoscalingRunnerSet, func(obj *v1alpha1.AutoscalingRunnerSet) { obj.Annotations[AnnotationKeyGitHubRunnerGroupName] = updatedRunnerScaleSet.RunnerGroupName + obj.Annotations[AnnotationKeyGitHubRunnerScaleSetName] = updatedRunnerScaleSet.Name }); err != nil { logger.Error(err, "Failed to update runner group name annotation") return ctrl.Result{}, err @@ -566,7 +566,7 @@ func (r *AutoscalingRunnerSetReconciler) updateRunnerScaleSetName(ctx context.Co logger.Info("Updating runner scale set name as an annotation") if err := patch(ctx, r.Client, autoscalingRunnerSet, func(obj *v1alpha1.AutoscalingRunnerSet) { - obj.Annotations[runnerScaleSetNameAnnotationKey] = updatedRunnerScaleSet.Name + obj.Annotations[AnnotationKeyGitHubRunnerScaleSetName] = updatedRunnerScaleSet.Name }); err != nil { logger.Error(err, "Failed to update runner scale set name annotation") return ctrl.Result{}, err diff --git a/controllers/actions.github.com/autoscalingrunnerset_controller_test.go b/controllers/actions.github.com/autoscalingrunnerset_controller_test.go index 73abc929..ab325185 100644 --- a/controllers/actions.github.com/autoscalingrunnerset_controller_test.go +++ b/controllers/actions.github.com/autoscalingrunnerset_controller_test.go @@ -698,7 +698,7 @@ var _ = Describe("Test AutoScalingController updates", Ordered, func() { return "", err } - if val, ok := ars.Annotations[runnerScaleSetNameAnnotationKey]; ok { + if val, ok := ars.Annotations[AnnotationKeyGitHubRunnerScaleSetName]; ok { return val, nil } @@ -722,7 +722,7 @@ var _ = Describe("Test AutoScalingController updates", Ordered, func() { return "", err } - if val, ok := ars.Annotations[runnerScaleSetNameAnnotationKey]; ok { + if val, ok := ars.Annotations[AnnotationKeyGitHubRunnerScaleSetName]; ok { return val, nil } diff --git a/controllers/actions.github.com/constants.go b/controllers/actions.github.com/constants.go index a9fcb727..8aef858a 100644 --- a/controllers/actions.github.com/constants.go +++ b/controllers/actions.github.com/constants.go @@ -39,7 +39,10 @@ const ( // Finalizer used to protect resources from deletion while AutoscalingRunnerSet is running const AutoscalingRunnerSetCleanupFinalizerName = "actions.github.com/cleanup-protection" -const AnnotationKeyGitHubRunnerGroupName = "actions.github.com/runner-group-name" +const ( + AnnotationKeyGitHubRunnerGroupName = "actions.github.com/runner-group-name" + AnnotationKeyGitHubRunnerScaleSetName = "actions.github.com/runner-scale-set-name" +) // Labels applied to listener roles const ( diff --git a/controllers/actions.github.com/resourcebuilder.go b/controllers/actions.github.com/resourcebuilder.go index 0ee48326..b8cff486 100644 --- a/controllers/actions.github.com/resourcebuilder.go +++ b/controllers/actions.github.com/resourcebuilder.go @@ -511,7 +511,8 @@ func (b *resourceBuilder) newEphemeralRunnerSet(autoscalingRunnerSet *v1alpha1.A } newAnnotations := map[string]string{ - AnnotationKeyGitHubRunnerGroupName: autoscalingRunnerSet.Annotations[AnnotationKeyGitHubRunnerGroupName], + AnnotationKeyGitHubRunnerGroupName: autoscalingRunnerSet.Annotations[AnnotationKeyGitHubRunnerGroupName], + AnnotationKeyGitHubRunnerScaleSetName: autoscalingRunnerSet.Annotations[AnnotationKeyGitHubRunnerScaleSetName], } newEphemeralRunnerSet := &v1alpha1.EphemeralRunnerSet{ diff --git a/controllers/actions.github.com/resourcebuilder_test.go b/controllers/actions.github.com/resourcebuilder_test.go index 8b98b891..4257ae31 100644 --- a/controllers/actions.github.com/resourcebuilder_test.go +++ b/controllers/actions.github.com/resourcebuilder_test.go @@ -23,8 +23,9 @@ func TestLabelPropagation(t *testing.T) { LabelKeyKubernetesVersion: "0.2.0", }, Annotations: map[string]string{ - runnerScaleSetIdAnnotationKey: "1", - AnnotationKeyGitHubRunnerGroupName: "test-group", + runnerScaleSetIdAnnotationKey: "1", + AnnotationKeyGitHubRunnerGroupName: "test-group", + AnnotationKeyGitHubRunnerScaleSetName: "test-scale-set", }, }, Spec: v1alpha1.AutoscalingRunnerSetSpec{ @@ -45,6 +46,7 @@ func TestLabelPropagation(t *testing.T) { assert.Equal(t, "org", ephemeralRunnerSet.Labels[LabelKeyGitHubOrganization]) assert.Equal(t, "repo", ephemeralRunnerSet.Labels[LabelKeyGitHubRepository]) assert.Equal(t, autoscalingRunnerSet.Annotations[AnnotationKeyGitHubRunnerGroupName], ephemeralRunnerSet.Annotations[AnnotationKeyGitHubRunnerGroupName]) + assert.Equal(t, autoscalingRunnerSet.Annotations[AnnotationKeyGitHubRunnerScaleSetName], ephemeralRunnerSet.Annotations[AnnotationKeyGitHubRunnerScaleSetName]) listener, err := b.newAutoScalingListener(&autoscalingRunnerSet, ephemeralRunnerSet, autoscalingRunnerSet.Namespace, "test:latest", nil) require.NoError(t, err) @@ -83,6 +85,7 @@ func TestLabelPropagation(t *testing.T) { } assert.Equal(t, "runner", ephemeralRunner.Labels[LabelKeyKubernetesComponent]) assert.Equal(t, autoscalingRunnerSet.Annotations[AnnotationKeyGitHubRunnerGroupName], ephemeralRunner.Annotations[AnnotationKeyGitHubRunnerGroupName]) + assert.Equal(t, autoscalingRunnerSet.Annotations[AnnotationKeyGitHubRunnerScaleSetName], ephemeralRunnerSet.Annotations[AnnotationKeyGitHubRunnerScaleSetName]) runnerSecret := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ @@ -109,8 +112,9 @@ func TestGitHubURLTrimLabelValues(t *testing.T) { LabelKeyKubernetesVersion: "0.2.0", }, Annotations: map[string]string{ - runnerScaleSetIdAnnotationKey: "1", - AnnotationKeyGitHubRunnerGroupName: "test-group", + runnerScaleSetIdAnnotationKey: "1", + AnnotationKeyGitHubRunnerGroupName: "test-group", + AnnotationKeyGitHubRunnerScaleSetName: "test-scale-set", }, }, }