@@ -25,12 +25,29 @@ package k8sutil
2525import (
2626 "testing"
2727
28+ v1 "k8s.io/api/core/v1"
29+
2830 "github.com/stretchr/testify/assert"
2931 "github.com/stretchr/testify/require"
3032)
3133
3234// TestCreateAffinity tests createAffinity
3335func TestCreateAffinity (t * testing.T ) {
36+ expectedNodeAffinity := & v1.NodeAffinity {
37+ RequiredDuringSchedulingIgnoredDuringExecution : & v1.NodeSelector {
38+ NodeSelectorTerms : []v1.NodeSelectorTerm {
39+ {
40+ MatchExpressions : []v1.NodeSelectorRequirement {
41+ {
42+ Key : "beta.kubernetes.io/arch" ,
43+ Operator : "In" ,
44+ Values : []string {"amd64" },
45+ },
46+ },
47+ },
48+ },
49+ },
50+ }
3451 // Required
3552 a := createAffinity ("test" , "role" , true , "" )
3653 assert .Nil (t , a .PodAffinity )
@@ -42,6 +59,7 @@ func TestCreateAffinity(t *testing.T) {
4259 assert .Equal (t , "test" , a .PodAntiAffinity .RequiredDuringSchedulingIgnoredDuringExecution [0 ].LabelSelector .MatchLabels ["arango_deployment" ])
4360 assert .Equal (t , "arangodb" , a .PodAntiAffinity .RequiredDuringSchedulingIgnoredDuringExecution [0 ].LabelSelector .MatchLabels ["app" ])
4461 assert .Equal (t , "role" , a .PodAntiAffinity .RequiredDuringSchedulingIgnoredDuringExecution [0 ].LabelSelector .MatchLabels ["role" ])
62+ assert .Equal (t , expectedNodeAffinity , a .NodeAffinity )
4563
4664 // Require & affinity with role dbserver
4765 a = createAffinity ("test" , "role" , true , "dbserver" )
@@ -53,6 +71,7 @@ func TestCreateAffinity(t *testing.T) {
5371 assert .Equal (t , "test" , a .PodAffinity .RequiredDuringSchedulingIgnoredDuringExecution [0 ].LabelSelector .MatchLabels ["arango_deployment" ])
5472 assert .Equal (t , "arangodb" , a .PodAffinity .RequiredDuringSchedulingIgnoredDuringExecution [0 ].LabelSelector .MatchLabels ["app" ])
5573 assert .Equal (t , "dbserver" , a .PodAffinity .RequiredDuringSchedulingIgnoredDuringExecution [0 ].LabelSelector .MatchLabels ["role" ])
74+ assert .Equal (t , expectedNodeAffinity , a .NodeAffinity )
5675
5776 require .NotNil (t , a .PodAntiAffinity )
5877 require .Len (t , a .PodAntiAffinity .RequiredDuringSchedulingIgnoredDuringExecution , 1 )
@@ -62,6 +81,7 @@ func TestCreateAffinity(t *testing.T) {
6281 assert .Equal (t , "test" , a .PodAntiAffinity .RequiredDuringSchedulingIgnoredDuringExecution [0 ].LabelSelector .MatchLabels ["arango_deployment" ])
6382 assert .Equal (t , "arangodb" , a .PodAntiAffinity .RequiredDuringSchedulingIgnoredDuringExecution [0 ].LabelSelector .MatchLabels ["app" ])
6483 assert .Equal (t , "role" , a .PodAntiAffinity .RequiredDuringSchedulingIgnoredDuringExecution [0 ].LabelSelector .MatchLabels ["role" ])
84+ assert .Equal (t , expectedNodeAffinity , a .NodeAffinity )
6585
6686 // Not Required
6787 a = createAffinity ("test" , "role" , false , "" )
@@ -74,6 +94,7 @@ func TestCreateAffinity(t *testing.T) {
7494 assert .Equal (t , "test" , a .PodAntiAffinity .PreferredDuringSchedulingIgnoredDuringExecution [0 ].PodAffinityTerm .LabelSelector .MatchLabels ["arango_deployment" ])
7595 assert .Equal (t , "arangodb" , a .PodAntiAffinity .PreferredDuringSchedulingIgnoredDuringExecution [0 ].PodAffinityTerm .LabelSelector .MatchLabels ["app" ])
7696 assert .Equal (t , "role" , a .PodAntiAffinity .PreferredDuringSchedulingIgnoredDuringExecution [0 ].PodAffinityTerm .LabelSelector .MatchLabels ["role" ])
97+ assert .Equal (t , expectedNodeAffinity , a .NodeAffinity )
7798
7899 // Not Required & affinity with role dbserver
79100 a = createAffinity ("test" , "role" , false , "dbserver" )
@@ -85,6 +106,7 @@ func TestCreateAffinity(t *testing.T) {
85106 assert .Equal (t , "test" , a .PodAffinity .PreferredDuringSchedulingIgnoredDuringExecution [0 ].PodAffinityTerm .LabelSelector .MatchLabels ["arango_deployment" ])
86107 assert .Equal (t , "arangodb" , a .PodAffinity .PreferredDuringSchedulingIgnoredDuringExecution [0 ].PodAffinityTerm .LabelSelector .MatchLabels ["app" ])
87108 assert .Equal (t , "dbserver" , a .PodAffinity .PreferredDuringSchedulingIgnoredDuringExecution [0 ].PodAffinityTerm .LabelSelector .MatchLabels ["role" ])
109+ assert .Equal (t , expectedNodeAffinity , a .NodeAffinity )
88110
89111 require .NotNil (t , a .PodAntiAffinity )
90112 require .Len (t , a .PodAntiAffinity .PreferredDuringSchedulingIgnoredDuringExecution , 1 )
@@ -94,4 +116,5 @@ func TestCreateAffinity(t *testing.T) {
94116 assert .Equal (t , "test" , a .PodAntiAffinity .PreferredDuringSchedulingIgnoredDuringExecution [0 ].PodAffinityTerm .LabelSelector .MatchLabels ["arango_deployment" ])
95117 assert .Equal (t , "arangodb" , a .PodAntiAffinity .PreferredDuringSchedulingIgnoredDuringExecution [0 ].PodAffinityTerm .LabelSelector .MatchLabels ["app" ])
96118 assert .Equal (t , "role" , a .PodAntiAffinity .PreferredDuringSchedulingIgnoredDuringExecution [0 ].PodAffinityTerm .LabelSelector .MatchLabels ["role" ])
119+ assert .Equal (t , expectedNodeAffinity , a .NodeAffinity )
97120}
0 commit comments