Commit b64dcf83 authored by Mikhail Shevtsov's avatar Mikhail Shevtsov
Browse files

feat: affinity support

Adds support for affinity along with required Go test
parent 4c145b22
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
| podAnnotations                | Pod annotations | `{}`                           |
| nodeSelector                  | Node labels for pod assignment | `{}`           |
| tolerations                   | List of node taints to tolerate | `[]`          |
| affinity                      | Node affinity for pod assignment | `{}`          |
| application.track             |             | `stable`                           |
| application.tier              |             | `web`                              |
| application.migrateCommand    | If present, this variable will run as a shell command within an application Container as a Helm pre-upgrade Hook. Intended to run migration commands. | `nil` |
+5 −1
Original line number Diff line number Diff line
@@ -48,6 +48,10 @@ spec:
{{- if .Values.tolerations }}
      tolerations:
{{ toYaml .Values.tolerations | indent 8 }}
{{- end }}
{{- if .Values.affinity }}
      affinity:
{{ toYaml .Values.affinity | indent 8 }}
{{- end }}
      containers:
      - name: {{ .Chart.Name }}
+36 −0
Original line number Diff line number Diff line
@@ -275,6 +275,7 @@ func TestDeploymentTemplate(t *testing.T) {
		ExpectedSelector     *metav1.LabelSelector
		ExpectedNodeSelector map[string]string
		ExpectedTolerations  []coreV1.Toleration
		ExpectedAffinity	 *coreV1.Affinity
	}{
		{
			CaseName:        "selector",
@@ -338,6 +339,40 @@ func TestDeploymentTemplate(t *testing.T) {
				},
			},
		},
		{
			CaseName:		  "affinity",
			Release:		  "production",
			Values: map[string]string{
				"affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0].key":	  "key1",
				"affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0].operator": "DoesNotExist",
			},
			ExpectedName: 	  "production",
			ExpectedRelease:  "production",
			ExpectedSelector: &metav1.LabelSelector{
				MatchLabels: map[string]string{
					"app":     "production",
					"release": "production",
					"tier":    "web",
					"track":   "stable",
				},
			},
			ExpectedAffinity: &coreV1.Affinity{
				NodeAffinity: &coreV1.NodeAffinity{
					RequiredDuringSchedulingIgnoredDuringExecution: &coreV1.NodeSelector{
						NodeSelectorTerms: []coreV1.NodeSelectorTerm{
							{
								MatchExpressions: []coreV1.NodeSelectorRequirement{
									{
										Key:	  "key1",
										Operator: "DoesNotExist",
									},
								},
							},
						},
					},
				},
			},
		},
	} {
		t.Run(tc.CaseName, func(t *testing.T) {
			namespaceName := "minimal-ruby-app-" + strings.ToLower(random.UniqueId())
@@ -390,6 +425,7 @@ func TestDeploymentTemplate(t *testing.T) {

			require.Equal(t, tc.ExpectedNodeSelector, deployment.Spec.Template.Spec.NodeSelector)
			require.Equal(t, tc.ExpectedTolerations, deployment.Spec.Template.Spec.Tolerations)
			require.Equal(t, tc.ExpectedAffinity, deployment.Spec.Template.Spec.Affinity)
		})
	}
}
+2 −1
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ image:
extraLabels: {}
podAnnotations: {}
nodeSelector: {}
affinity: {}
tolerations: []
application:
  track: stable