Fix name override labels when runnerScaleSetName value is set (#2915)
This commit is contained in:
		
							parent
							
								
									ead26ab18f
								
							
						
					
					
						commit
						db061b33e7
					
				|  | @ -10,6 +10,10 @@ gha-rs | ||||||
| {{- default (include "gha-base-name" .) .Values.nameOverride | trunc 63 | trimSuffix "-" }} | {{- default (include "gha-base-name" .) .Values.nameOverride | trunc 63 | trimSuffix "-" }} | ||||||
| {{- end }} | {{- end }} | ||||||
| 
 | 
 | ||||||
|  | {{- define "gha-runner-scale-set.scale-set-name" -}} | ||||||
|  | {{ .Values.runnerScaleSetName | default .Release.Name }} | ||||||
|  | {{- end }} | ||||||
|  | 
 | ||||||
| {{/* | {{/* | ||||||
| Create a default fully qualified app name. | Create a default fully qualified app name. | ||||||
| We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). | We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). | ||||||
|  | @ -17,7 +21,7 @@ If release name contains chart name it will be used as a full name. | ||||||
| */}} | */}} | ||||||
| {{- define "gha-runner-scale-set.fullname" -}} | {{- define "gha-runner-scale-set.fullname" -}} | ||||||
| {{- $name := default (include "gha-base-name" .) }} | {{- $name := default (include "gha-base-name" .) }} | ||||||
| {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} | {{- printf "%s-%s" (include "gha-runner-scale-set.scale-set-name" .) $name | trunc 63 | trimSuffix "-" }} | ||||||
| {{- end }} | {{- end }} | ||||||
| 
 | 
 | ||||||
| {{/* | {{/* | ||||||
|  | @ -38,7 +42,7 @@ app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} | ||||||
| {{- end }} | {{- end }} | ||||||
| app.kubernetes.io/managed-by: {{ .Release.Service }} | app.kubernetes.io/managed-by: {{ .Release.Service }} | ||||||
| app.kubernetes.io/part-of: gha-rs | app.kubernetes.io/part-of: gha-rs | ||||||
| actions.github.com/scale-set-name: {{ .Release.Name }} | actions.github.com/scale-set-name: {{ include "gha-runner-scale-set.scale-set-name" . }} | ||||||
| actions.github.com/scale-set-namespace: {{ .Release.Namespace }} | actions.github.com/scale-set-namespace: {{ .Release.Namespace }} | ||||||
| {{- end }} | {{- end }} | ||||||
| 
 | 
 | ||||||
|  | @ -46,8 +50,8 @@ actions.github.com/scale-set-namespace: {{ .Release.Namespace }} | ||||||
| Selector labels | Selector labels | ||||||
| */}} | */}} | ||||||
| {{- define "gha-runner-scale-set.selectorLabels" -}} | {{- define "gha-runner-scale-set.selectorLabels" -}} | ||||||
| app.kubernetes.io/name: {{ include "gha-runner-scale-set.name" . }} | app.kubernetes.io/name: {{ include "gha-runner-scale-set.scale-set-name" . }} | ||||||
| app.kubernetes.io/instance: {{ .Release.Name }} | app.kubernetes.io/instance: {{ include "gha-runner-scale-set.scale-set-name" . }} | ||||||
| {{- end }} | {{- end }} | ||||||
| 
 | 
 | ||||||
| {{- define "gha-runner-scale-set.githubsecret" -}} | {{- define "gha-runner-scale-set.githubsecret" -}} | ||||||
|  |  | ||||||
|  | @ -1,13 +1,13 @@ | ||||||
| apiVersion: actions.github.com/v1alpha1 | apiVersion: actions.github.com/v1alpha1 | ||||||
| kind: AutoscalingRunnerSet | kind: AutoscalingRunnerSet | ||||||
| metadata: | metadata: | ||||||
|   {{- if or (not .Release.Name) (gt (len .Release.Name) 45) }} |   {{- if or (not (include "gha-runner-scale-set.scale-set-name" .)) (gt (len (include "gha-runner-scale-set.scale-set-name" .)) 45) }} | ||||||
|   {{ fail "Name must have up to 45 characters" }} |   {{ fail "Name must have up to 45 characters" }} | ||||||
|   {{- end }} |   {{- end }} | ||||||
|   {{- if gt (len .Release.Namespace) 63 }} |   {{- if gt (len .Release.Namespace) 63 }} | ||||||
|   {{ fail "Namespace must have up to 63 characters" }} |   {{ fail "Namespace must have up to 63 characters" }} | ||||||
|   {{- end }} |   {{- end }} | ||||||
|   name: {{ .Values.runnerScaleSetName | default .Release.Name }} |   name: {{ include "gha-runner-scale-set.scale-set-name" . }} | ||||||
|   namespace: {{ .Release.Namespace }} |   namespace: {{ .Release.Namespace }} | ||||||
|   labels: |   labels: | ||||||
|     app.kubernetes.io/component: "autoscaling-runner-set" |     app.kubernetes.io/component: "autoscaling-runner-set" | ||||||
|  |  | ||||||
|  | @ -330,7 +330,7 @@ func TestTemplateRenderedAutoScalingRunnerSet(t *testing.T) { | ||||||
| 	assert.Equal(t, namespaceName, ars.Namespace) | 	assert.Equal(t, namespaceName, ars.Namespace) | ||||||
| 	assert.Equal(t, "test-runners", ars.Name) | 	assert.Equal(t, "test-runners", ars.Name) | ||||||
| 
 | 
 | ||||||
| 	assert.Equal(t, "gha-rs", ars.Labels["app.kubernetes.io/name"]) | 	assert.Equal(t, "test-runners", ars.Labels["app.kubernetes.io/name"]) | ||||||
| 	assert.Equal(t, "test-runners", ars.Labels["app.kubernetes.io/instance"]) | 	assert.Equal(t, "test-runners", ars.Labels["app.kubernetes.io/instance"]) | ||||||
| 	assert.Equal(t, "gha-rs", ars.Labels["app.kubernetes.io/part-of"]) | 	assert.Equal(t, "gha-rs", ars.Labels["app.kubernetes.io/part-of"]) | ||||||
| 	assert.Equal(t, "autoscaling-runner-set", ars.Labels["app.kubernetes.io/component"]) | 	assert.Equal(t, "autoscaling-runner-set", ars.Labels["app.kubernetes.io/component"]) | ||||||
|  | @ -361,6 +361,7 @@ func TestTemplateRenderedAutoScalingRunnerSet_RunnerScaleSetName(t *testing.T) { | ||||||
| 	require.NoError(t, err) | 	require.NoError(t, err) | ||||||
| 
 | 
 | ||||||
| 	releaseName := "test-runners" | 	releaseName := "test-runners" | ||||||
|  | 	nameOverride := "test-runner-scale-set-name" | ||||||
| 	namespaceName := "test-" + strings.ToLower(random.UniqueId()) | 	namespaceName := "test-" + strings.ToLower(random.UniqueId()) | ||||||
| 
 | 
 | ||||||
| 	options := &helm.Options{ | 	options := &helm.Options{ | ||||||
|  | @ -368,7 +369,7 @@ func TestTemplateRenderedAutoScalingRunnerSet_RunnerScaleSetName(t *testing.T) { | ||||||
| 		SetValues: map[string]string{ | 		SetValues: map[string]string{ | ||||||
| 			"githubConfigUrl":                    "https://github.com/actions", | 			"githubConfigUrl":                    "https://github.com/actions", | ||||||
| 			"githubConfigSecret.github_token":    "gh_token12345", | 			"githubConfigSecret.github_token":    "gh_token12345", | ||||||
| 			"runnerScaleSetName":                 "test-runner-scale-set-name", | 			"runnerScaleSetName":                 nameOverride, | ||||||
| 			"controllerServiceAccount.name":      "arc", | 			"controllerServiceAccount.name":      "arc", | ||||||
| 			"controllerServiceAccount.namespace": "arc-system", | 			"controllerServiceAccount.namespace": "arc-system", | ||||||
| 		}, | 		}, | ||||||
|  | @ -381,12 +382,15 @@ func TestTemplateRenderedAutoScalingRunnerSet_RunnerScaleSetName(t *testing.T) { | ||||||
| 	helm.UnmarshalK8SYaml(t, output, &ars) | 	helm.UnmarshalK8SYaml(t, output, &ars) | ||||||
| 
 | 
 | ||||||
| 	assert.Equal(t, namespaceName, ars.Namespace) | 	assert.Equal(t, namespaceName, ars.Namespace) | ||||||
| 	assert.Equal(t, "test-runner-scale-set-name", ars.Name) | 	assert.Equal(t, nameOverride, ars.Name) | ||||||
| 
 | 
 | ||||||
| 	assert.Equal(t, "gha-rs", ars.Labels["app.kubernetes.io/name"]) | 	assert.Equal(t, nameOverride, ars.Labels["app.kubernetes.io/name"]) | ||||||
| 	assert.Equal(t, releaseName, ars.Labels["app.kubernetes.io/instance"]) | 	assert.Equal(t, nameOverride, ars.Labels["app.kubernetes.io/instance"]) | ||||||
|  | 	assert.Equal(t, nameOverride, ars.Labels["actions.github.com/scale-set-name"]) | ||||||
|  | 	assert.Equal(t, namespaceName, ars.Labels["actions.github.com/scale-set-namespace"]) | ||||||
|  | 	assert.Equal(t, "gha-rs", ars.Labels["app.kubernetes.io/part-of"]) | ||||||
| 	assert.Equal(t, "https://github.com/actions", ars.Spec.GitHubConfigUrl) | 	assert.Equal(t, "https://github.com/actions", ars.Spec.GitHubConfigUrl) | ||||||
| 	assert.Equal(t, "test-runners-gha-rs-github-secret", ars.Spec.GitHubConfigSecret) | 	assert.Equal(t, nameOverride+"-gha-rs-github-secret", ars.Spec.GitHubConfigSecret) | ||||||
| 	assert.Equal(t, "test-runner-scale-set-name", ars.Spec.RunnerScaleSetName) | 	assert.Equal(t, "test-runner-scale-set-name", ars.Spec.RunnerScaleSetName) | ||||||
| 
 | 
 | ||||||
| 	assert.Empty(t, ars.Spec.RunnerGroup, "RunnerGroup should be empty") | 	assert.Empty(t, ars.Spec.RunnerGroup, "RunnerGroup should be empty") | ||||||
|  | @ -840,7 +844,7 @@ func TestTemplateRenderedAutoScalingRunnerSet_EnableDinD(t *testing.T) { | ||||||
| 	assert.Equal(t, namespaceName, ars.Namespace) | 	assert.Equal(t, namespaceName, ars.Namespace) | ||||||
| 	assert.Equal(t, "test-runners", ars.Name) | 	assert.Equal(t, "test-runners", ars.Name) | ||||||
| 
 | 
 | ||||||
| 	assert.Equal(t, "gha-rs", ars.Labels["app.kubernetes.io/name"]) | 	assert.Equal(t, "test-runners", ars.Labels["app.kubernetes.io/name"]) | ||||||
| 	assert.Equal(t, "test-runners", ars.Labels["app.kubernetes.io/instance"]) | 	assert.Equal(t, "test-runners", ars.Labels["app.kubernetes.io/instance"]) | ||||||
| 	assert.Equal(t, "https://github.com/actions", ars.Spec.GitHubConfigUrl) | 	assert.Equal(t, "https://github.com/actions", ars.Spec.GitHubConfigUrl) | ||||||
| 	assert.Equal(t, "test-runners-gha-rs-github-secret", ars.Spec.GitHubConfigSecret) | 	assert.Equal(t, "test-runners-gha-rs-github-secret", ars.Spec.GitHubConfigSecret) | ||||||
|  | @ -928,7 +932,7 @@ func TestTemplateRenderedAutoScalingRunnerSet_EnableKubernetesMode(t *testing.T) | ||||||
| 	assert.Equal(t, namespaceName, ars.Namespace) | 	assert.Equal(t, namespaceName, ars.Namespace) | ||||||
| 	assert.Equal(t, "test-runners", ars.Name) | 	assert.Equal(t, "test-runners", ars.Name) | ||||||
| 
 | 
 | ||||||
| 	assert.Equal(t, "gha-rs", ars.Labels["app.kubernetes.io/name"]) | 	assert.Equal(t, "test-runners", ars.Labels["app.kubernetes.io/name"]) | ||||||
| 	assert.Equal(t, "test-runners", ars.Labels["app.kubernetes.io/instance"]) | 	assert.Equal(t, "test-runners", ars.Labels["app.kubernetes.io/instance"]) | ||||||
| 	assert.Equal(t, "https://github.com/actions", ars.Spec.GitHubConfigUrl) | 	assert.Equal(t, "https://github.com/actions", ars.Spec.GitHubConfigUrl) | ||||||
| 	assert.Equal(t, "test-runners-gha-rs-github-secret", ars.Spec.GitHubConfigSecret) | 	assert.Equal(t, "test-runners-gha-rs-github-secret", ars.Spec.GitHubConfigSecret) | ||||||
|  | @ -1029,7 +1033,7 @@ func TestTemplateRenderedAutoScalingRunnerSet_UsePredefinedSecret(t *testing.T) | ||||||
| 	assert.Equal(t, namespaceName, ars.Namespace) | 	assert.Equal(t, namespaceName, ars.Namespace) | ||||||
| 	assert.Equal(t, "test-runners", ars.Name) | 	assert.Equal(t, "test-runners", ars.Name) | ||||||
| 
 | 
 | ||||||
| 	assert.Equal(t, "gha-rs", ars.Labels["app.kubernetes.io/name"]) | 	assert.Equal(t, "test-runners", ars.Labels["app.kubernetes.io/name"]) | ||||||
| 	assert.Equal(t, "test-runners", ars.Labels["app.kubernetes.io/instance"]) | 	assert.Equal(t, "test-runners", ars.Labels["app.kubernetes.io/instance"]) | ||||||
| 	assert.Equal(t, "https://github.com/actions", ars.Spec.GitHubConfigUrl) | 	assert.Equal(t, "https://github.com/actions", ars.Spec.GitHubConfigUrl) | ||||||
| 	assert.Equal(t, "pre-defined-secrets", ars.Spec.GitHubConfigSecret) | 	assert.Equal(t, "pre-defined-secrets", ars.Spec.GitHubConfigSecret) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue