Skip to content

Commit 0bf7bb8

Browse files
committed
[WIP] Update deployment test - operator
1 parent fcd86c1 commit 0bf7bb8

File tree

3 files changed

+93
-15
lines changed

3 files changed

+93
-15
lines changed

charts/hcp-terraform-operator/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ operator:
5656
# - key: kubernetes.io/arch
5757
# operator: In
5858
# values:
59-
# - amd64
59+
# - amd64
6060
#
6161
# -- Kubernetes Affinity. More information: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity
6262
affinity: {}

charts/test/unit/deployment_test.go

Lines changed: 91 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,34 @@ func TestDeploymentOperatorImage(t *testing.T) {
268268
assert.Equal(t, d, deployment)
269269
}
270270

271-
// TODO
272271
func TestDeploymentOperatorResources(t *testing.T) {
273272
options := &helm.Options{
273+
SetJsonValues: map[string]string{
274+
"operator.resources.limits": `{
275+
"cpu": "2",
276+
"memory": "512Mi"
277+
}`,
278+
"operator.resources.requests": `{
279+
"cpu": "250m",
280+
"memory": "128Mi"
281+
}`,
282+
},
274283
Version: helmChartVersion,
275284
}
276285
deployment := renderDeploymentManifest(t, options)
277286
d := defaultDeployment()
278287

288+
d.Spec.Template.Spec.Containers[0].Resources = corev1.ResourceRequirements{
289+
Limits: corev1.ResourceList{
290+
corev1.ResourceCPU: resource.MustParse("2"),
291+
corev1.ResourceMemory: resource.MustParse("512Mi"),
292+
},
293+
Requests: corev1.ResourceList{
294+
corev1.ResourceCPU: resource.MustParse("250m"),
295+
corev1.ResourceMemory: resource.MustParse("128Mi"),
296+
},
297+
}
298+
279299
assert.Equal(t, d, deployment)
280300
}
281301

@@ -290,25 +310,73 @@ func TestDeploymentOperatorSecurityContext(t *testing.T) {
290310
assert.Equal(t, d, deployment)
291311
}
292312

293-
// TODO
294313
func TestDeploymentOperatorAffinity(t *testing.T) {
295314
options := &helm.Options{
315+
SetJsonValues: map[string]string{
316+
"operator.affinity": `{
317+
"nodeAffinity": {
318+
"requiredDuringSchedulingIgnoredDuringExecution": {
319+
"nodeSelectorTerms": [{
320+
"matchExpressions": [{
321+
"key": "kubernetes.io/arch",
322+
"operator": "In",
323+
"values": ["amd64"]
324+
}]
325+
}]
326+
}
327+
}
328+
}`,
329+
},
296330
Version: helmChartVersion,
297331
}
298332
deployment := renderDeploymentManifest(t, options)
299333
d := defaultDeployment()
300334

335+
d.Spec.Template.Spec.Affinity = &corev1.Affinity{
336+
NodeAffinity: &corev1.NodeAffinity{
337+
RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{
338+
NodeSelectorTerms: []corev1.NodeSelectorTerm{
339+
{
340+
MatchExpressions: []corev1.NodeSelectorRequirement{
341+
{
342+
Key: "kubernetes.io/arch",
343+
Operator: corev1.NodeSelectorOpIn,
344+
Values: []string{"amd64"},
345+
},
346+
},
347+
},
348+
},
349+
},
350+
},
351+
}
352+
301353
assert.Equal(t, d, deployment)
302354
}
303355

304-
// TODO
305356
func TestDeploymentOperatorTolerations(t *testing.T) {
306357
options := &helm.Options{
358+
SetJsonValues: map[string]string{
359+
"operator.tolerations": `[{
360+
"key": "cloud.hashicorp.com/terraform",
361+
"operator": "Equal",
362+
"value": "operator",
363+
"effect": "PreferNoSchedule"
364+
}]`,
365+
},
307366
Version: helmChartVersion,
308367
}
309368
deployment := renderDeploymentManifest(t, options)
310369
d := defaultDeployment()
311370

371+
d.Spec.Template.Spec.Tolerations = []corev1.Toleration{
372+
{
373+
Key: "cloud.hashicorp.com/terraform",
374+
Operator: corev1.TolerationOpEqual,
375+
Value: "operator",
376+
Effect: corev1.TaintEffectPreferNoSchedule,
377+
},
378+
}
379+
312380
assert.Equal(t, d, deployment)
313381
}
314382

@@ -425,21 +493,33 @@ func TestDeploymentKubeRbacProxySecurityContext(t *testing.T) {
425493
assert.Equal(t, d, deployment)
426494
}
427495

428-
// TODO
429496
func TestDeploymentKubeRbacProxyResources(t *testing.T) {
430497
options := &helm.Options{
431-
Version: helmChartVersion,
432-
SetValues: map[string]string{
433-
"kubeRbacProxy.image.repository": "this",
434-
"kubeRbacProxy.image.pullPolicy": string(corev1.PullAlways),
435-
"kubeRbacProxy.image.tag": "0.0.1",
498+
SetJsonValues: map[string]string{
499+
"kubeRbacProxy.resources.limits": `{
500+
"cpu": "2",
501+
"memory": "512Mi"
502+
}`,
503+
"kubeRbacProxy.resources.requests": `{
504+
"cpu": "250m",
505+
"memory": "128Mi"
506+
}`,
436507
},
508+
Version: helmChartVersion,
437509
}
438510
deployment := renderDeploymentManifest(t, options)
439511
d := defaultDeployment()
440512

441-
d.Spec.Template.Spec.Containers[1].Image = "this:0.0.1"
442-
d.Spec.Template.Spec.Containers[1].ImagePullPolicy = corev1.PullAlways
513+
d.Spec.Template.Spec.Containers[1].Resources = corev1.ResourceRequirements{
514+
Limits: corev1.ResourceList{
515+
corev1.ResourceCPU: resource.MustParse("2"),
516+
corev1.ResourceMemory: resource.MustParse("512Mi"),
517+
},
518+
Requests: corev1.ResourceList{
519+
corev1.ResourceCPU: resource.MustParse("250m"),
520+
corev1.ResourceMemory: resource.MustParse("128Mi"),
521+
},
522+
}
443523

444524
assert.Equal(t, d, deployment)
445525
}

charts/test/unit/helpers.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ var (
8888

8989
func init() {
9090
var err error
91-
helmChartVersion, err = getChartVersion()
92-
fmt.Println("INIT:", helmChartVersion)
93-
if err != nil {
91+
if helmChartVersion, err = getChartVersion(); err != nil {
9492
log.Fatal(err)
9593
os.Exit(1)
9694
}

0 commit comments

Comments
 (0)