Fix empty env and volumeMounts object on default setup (#3166)
This commit is contained in:
		
							parent
							
								
									3e4201ac5f
								
							
						
					
					
						commit
						31352924d7
					
				|  | @ -385,6 +385,9 @@ volumeMounts: | ||||||
|     {{- $setNodeExtraCaCerts = 1 }} |     {{- $setNodeExtraCaCerts = 1 }} | ||||||
|     {{- $setRunnerUpdateCaCerts = 1 }} |     {{- $setRunnerUpdateCaCerts = 1 }} | ||||||
|   {{- end }} |   {{- end }} | ||||||
|  | 
 | ||||||
|  |   {{- $mountGitHubServerTLS := 0 }} | ||||||
|  |   {{- if or $container.env $setNodeExtraCaCerts $setRunnerUpdateCaCerts }} | ||||||
|   env: |   env: | ||||||
|     {{- with $container.env }} |     {{- with $container.env }} | ||||||
|       {{- range $i, $env := . }} |       {{- range $i, $env := . }} | ||||||
|  | @ -405,10 +408,12 @@ volumeMounts: | ||||||
|     - name: RUNNER_UPDATE_CA_CERTS |     - name: RUNNER_UPDATE_CA_CERTS | ||||||
|       value: "1" |       value: "1" | ||||||
|     {{- end }} |     {{- end }} | ||||||
|     {{- $mountGitHubServerTLS := 0 }} |  | ||||||
|     {{- if $tlsConfig.runnerMountPath }} |     {{- if $tlsConfig.runnerMountPath }} | ||||||
|       {{- $mountGitHubServerTLS = 1 }} |       {{- $mountGitHubServerTLS = 1 }} | ||||||
|     {{- end }} |     {{- end }} | ||||||
|  |   {{- end }} | ||||||
|  | 
 | ||||||
|  |   {{- if or $container.volumeMounts $mountGitHubServerTLS }} | ||||||
|   volumeMounts: |   volumeMounts: | ||||||
|     {{- with $container.volumeMounts }} |     {{- with $container.volumeMounts }} | ||||||
|       {{- range $i, $volMount := . }} |       {{- range $i, $volMount := . }} | ||||||
|  | @ -423,6 +428,7 @@ volumeMounts: | ||||||
|       mountPath: {{ clean (print $tlsConfig.runnerMountPath "/" $tlsConfig.certificateFrom.configMapKeyRef.key) }} |       mountPath: {{ clean (print $tlsConfig.runnerMountPath "/" $tlsConfig.certificateFrom.configMapKeyRef.key) }} | ||||||
|       subPath: {{ $tlsConfig.certificateFrom.configMapKeyRef.key }} |       subPath: {{ $tlsConfig.certificateFrom.configMapKeyRef.key }} | ||||||
|     {{- end }} |     {{- end }} | ||||||
|  |   {{- end}} | ||||||
| {{- end }} | {{- end }} | ||||||
| {{- end }} | {{- end }} | ||||||
| {{- end }} | {{- end }} | ||||||
|  |  | ||||||
|  | @ -2017,3 +2017,75 @@ func TestTemplateRenderedAutoscalingRunnerSetAnnotation_KubernetesModeCleanup(t | ||||||
| 		assert.Equal(t, value, autoscalingRunnerSet.Annotations[annotation], fmt.Sprintf("Annotation %q does not match the expected value", annotation)) | 		assert.Equal(t, value, autoscalingRunnerSet.Annotations[annotation], fmt.Sprintf("Annotation %q does not match the expected value", annotation)) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | func TestRunnerContainerEnvNotEmptyMap(t *testing.T) { | ||||||
|  | 	t.Parallel() | ||||||
|  | 
 | ||||||
|  | 	// Path to the helm chart we will test
 | ||||||
|  | 	helmChartPath, err := filepath.Abs("../../gha-runner-scale-set") | ||||||
|  | 	require.NoError(t, err) | ||||||
|  | 
 | ||||||
|  | 	testValuesPath, err := filepath.Abs("../tests/values.yaml") | ||||||
|  | 	require.NoError(t, err) | ||||||
|  | 
 | ||||||
|  | 	releaseName := "test-runners" | ||||||
|  | 	namespaceName := "test-" + strings.ToLower(random.UniqueId()) | ||||||
|  | 
 | ||||||
|  | 	options := &helm.Options{ | ||||||
|  | 		Logger:         logger.Discard, | ||||||
|  | 		ValuesFiles:    []string{testValuesPath}, | ||||||
|  | 		KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/autoscalingrunnerset.yaml"}) | ||||||
|  | 	type testModel struct { | ||||||
|  | 		Spec struct { | ||||||
|  | 			Template struct { | ||||||
|  | 				Spec struct { | ||||||
|  | 					Containers []map[string]any `yaml:"containers"` | ||||||
|  | 				} `yaml:"spec"` | ||||||
|  | 			} `yaml:"template"` | ||||||
|  | 		} `yaml:"spec"` | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	var m testModel | ||||||
|  | 	helm.UnmarshalK8SYaml(t, output, &m) | ||||||
|  | 	_, ok := m.Spec.Template.Spec.Containers[0]["env"] | ||||||
|  | 	assert.False(t, ok, "env should not be set") | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func TestRunnerContainerVolumeNotEmptyMap(t *testing.T) { | ||||||
|  | 	t.Parallel() | ||||||
|  | 
 | ||||||
|  | 	// Path to the helm chart we will test
 | ||||||
|  | 	helmChartPath, err := filepath.Abs("../../gha-runner-scale-set") | ||||||
|  | 	require.NoError(t, err) | ||||||
|  | 
 | ||||||
|  | 	testValuesPath, err := filepath.Abs("../tests/values.yaml") | ||||||
|  | 	require.NoError(t, err) | ||||||
|  | 
 | ||||||
|  | 	releaseName := "test-runners" | ||||||
|  | 	namespaceName := "test-" + strings.ToLower(random.UniqueId()) | ||||||
|  | 
 | ||||||
|  | 	options := &helm.Options{ | ||||||
|  | 		Logger:         logger.Discard, | ||||||
|  | 		ValuesFiles:    []string{testValuesPath}, | ||||||
|  | 		KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/autoscalingrunnerset.yaml"}) | ||||||
|  | 	type testModel struct { | ||||||
|  | 		Spec struct { | ||||||
|  | 			Template struct { | ||||||
|  | 				Spec struct { | ||||||
|  | 					Containers []map[string]any `yaml:"containers"` | ||||||
|  | 				} `yaml:"spec"` | ||||||
|  | 			} `yaml:"template"` | ||||||
|  | 		} `yaml:"spec"` | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	var m testModel | ||||||
|  | 	helm.UnmarshalK8SYaml(t, output, &m) | ||||||
|  | 	_, ok := m.Spec.Template.Spec.Containers[0]["volumeMounts"] | ||||||
|  | 	assert.False(t, ok, "volumeMounts should not be set") | ||||||
|  | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue