Skip to content

Commit

Permalink
run go fmt
Browse files Browse the repository at this point in the history
Signed-off-by: Cornelis Boon <[email protected]>
  • Loading branch information
cjidboon94 committed Jun 7, 2024
1 parent 599de8d commit f91fe22
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 48 deletions.
22 changes: 11 additions & 11 deletions backend/src/v2/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,39 +538,39 @@ func extendPodSpecPatch(
var nodeSelectorTerms []k8score.NodeSelectorTerm
var preferredSchedulingTerms []k8score.PreferredSchedulingTerm
var requiredDuringSchedulingIgnoredDuringExecution *k8score.NodeSelector
for _ , nodeAffinityTerm := range nodeAffinity {

for _, nodeAffinityTerm := range nodeAffinity {
if nodeAffinityTerm != nil {
var matchExpressions []k8score.NodeSelectorRequirement
var matchFields []k8score.NodeSelectorRequirement
for _, requirement := range nodeAffinityTerm.MatchExpressions {
if requirement != nil {
matchExpressions = append(matchExpressions, k8score.NodeSelectorRequirement{
Key: requirement.Key,
Key: requirement.Key,
Operator: k8score.NodeSelectorOperator(requirement.Operator),
Values: requirement.Values,
Values: requirement.Values,
})
}
}

for _, requirement := range nodeAffinityTerm.MatchFields {
if requirement != nil {
matchFields = append(matchFields, k8score.NodeSelectorRequirement{
Key: requirement.Key,
Key: requirement.Key,
Operator: k8score.NodeSelectorOperator(requirement.Operator),
Values: requirement.Values,
Values: requirement.Values,
})
}
}

nodeSelectorTerm := k8score.NodeSelectorTerm{
MatchExpressions: matchExpressions,
MatchFields: matchFields,
MatchFields: matchFields,
}

if (0 < nodeAffinityTerm.GetWeight()) && (nodeAffinityTerm.GetWeight() < 101) {
preferredSchedulingTerms = append(preferredSchedulingTerms, k8score.PreferredSchedulingTerm{
Weight: nodeAffinityTerm.GetWeight(),
Weight: nodeAffinityTerm.GetWeight(),
Preference: nodeSelectorTerm,
})
} else {
Expand All @@ -581,13 +581,13 @@ func extendPodSpecPatch(
}
if nodeSelectorTerms != nil {
requiredDuringSchedulingIgnoredDuringExecution = &k8score.NodeSelector{
NodeSelectorTerms: nodeSelectorTerms,
NodeSelectorTerms: nodeSelectorTerms,
}
}

podSpec.Affinity = &k8score.Affinity{
NodeAffinity: &k8score.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: requiredDuringSchedulingIgnoredDuringExecution,
RequiredDuringSchedulingIgnoredDuringExecution: requiredDuringSchedulingIgnoredDuringExecution,
PreferredDuringSchedulingIgnoredDuringExecution: preferredSchedulingTerms,
},
}
Expand Down
63 changes: 26 additions & 37 deletions backend/src/v2/driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ func Test_extendPodSpecPatch_Secret(t *testing.T) {
{
Name: "secret1",
VolumeSource: k8score.VolumeSource{
Secret: &k8score.SecretVolumeSource{SecretName: "secret1", Optional: &[]bool{false}[0],},
Secret: &k8score.SecretVolumeSource{SecretName: "secret1", Optional: &[]bool{false}[0]},
},
},
},
Expand Down Expand Up @@ -730,7 +730,7 @@ func Test_extendPodSpecPatch_ConfigMap(t *testing.T) {
VolumeSource: k8score.VolumeSource{
ConfigMap: &k8score.ConfigMapVolumeSource{
LocalObjectReference: k8score.LocalObjectReference{Name: "cm1"},
Optional: &[]bool{false}[0],},
Optional: &[]bool{false}[0]},
},
},
},
Expand Down Expand Up @@ -1040,11 +1040,11 @@ func Test_extendPodSpecPatch_Tolerations(t *testing.T) {
}
}

func Test_extendPodSpecPatch_NodeAffinity(t *testing.T){
var preferredWeightA int32 = 50
func Test_extendPodSpecPatch_NodeAffinity(t *testing.T) {
var preferredWeightA int32 = 50
var preferredWeightB int32 = 42
tests := []struct{
name string
tests := []struct {
name string
k8sExecCfg *kubernetesplatform.KubernetesExecutorConfig
expected *k8score.PodSpec
}{
Expand All @@ -1057,7 +1057,7 @@ func Test_extendPodSpecPatch_NodeAffinity(t *testing.T){
Name: "main",
},
},
},
},
},
{
"Valid - Affinity with terms without weight",
Expand All @@ -1066,7 +1066,7 @@ func Test_extendPodSpecPatch_NodeAffinity(t *testing.T){
{
MatchExpressions: []*kubernetesplatform.SelectorRequirement{
{
Key: "key1",
Key: "key1",
Operator: "In",
Values: []string{
"val1",
Expand All @@ -1076,7 +1076,7 @@ func Test_extendPodSpecPatch_NodeAffinity(t *testing.T){
},
MatchFields: []*kubernetesplatform.SelectorRequirement{
{
Key: "key2",
Key: "key2",
Operator: "In",
Values: []string{
"val1",
Expand All @@ -1085,7 +1085,6 @@ func Test_extendPodSpecPatch_NodeAffinity(t *testing.T){
},
},
},

},
},
&k8score.PodSpec{
Expand All @@ -1101,7 +1100,7 @@ func Test_extendPodSpecPatch_NodeAffinity(t *testing.T){
{
MatchExpressions: []k8score.NodeSelectorRequirement{
{
Key: "key1",
Key: "key1",
Operator: "In",
Values: []string{
"val1",
Expand All @@ -1111,22 +1110,20 @@ func Test_extendPodSpecPatch_NodeAffinity(t *testing.T){
},
MatchFields: []k8score.NodeSelectorRequirement{
{
Key: "key2",
Key: "key2",
Operator: "In",
Values: []string{
"val1",
"val2",
},

},
},
},
},
},
},
},

},
},
},
{
"Valid - Affinity with terms with weight",
Expand All @@ -1135,7 +1132,7 @@ func Test_extendPodSpecPatch_NodeAffinity(t *testing.T){
{
MatchExpressions: []*kubernetesplatform.SelectorRequirement{
{
Key: "key1",
Key: "key1",
Operator: "In",
Values: []string{
"val1",
Expand All @@ -1145,7 +1142,7 @@ func Test_extendPodSpecPatch_NodeAffinity(t *testing.T){
},
MatchFields: []*kubernetesplatform.SelectorRequirement{
{
Key: "key2",
Key: "key2",
Operator: "In",
Values: []string{
"val1",
Expand All @@ -1155,7 +1152,6 @@ func Test_extendPodSpecPatch_NodeAffinity(t *testing.T){
},
Weight: &preferredWeightA,
},

},
},
&k8score.PodSpec{
Expand All @@ -1166,15 +1162,15 @@ func Test_extendPodSpecPatch_NodeAffinity(t *testing.T){
},
Affinity: &k8score.Affinity{
NodeAffinity: &k8score.NodeAffinity{

PreferredDuringSchedulingIgnoredDuringExecution: []k8score.PreferredSchedulingTerm{
{
Weight: preferredWeightA,
Preference: k8score.NodeSelectorTerm{

MatchExpressions: []k8score.NodeSelectorRequirement{
{
Key: "key1",
Key: "key1",
Operator: "In",
Values: []string{
"val1",
Expand All @@ -1184,22 +1180,20 @@ func Test_extendPodSpecPatch_NodeAffinity(t *testing.T){
},
MatchFields: []k8score.NodeSelectorRequirement{
{
Key: "key2",
Key: "key2",
Operator: "In",
Values: []string{
"val1",
"val2",
},
},
},

},
},
},
},
},

},
},
},
{
"Valid - Affinity mixed terms",
Expand All @@ -1208,7 +1202,7 @@ func Test_extendPodSpecPatch_NodeAffinity(t *testing.T){
{
MatchExpressions: []*kubernetesplatform.SelectorRequirement{
{
Key: "key1",
Key: "key1",
Operator: "In",
Values: []string{
"val1",
Expand All @@ -1220,12 +1214,11 @@ func Test_extendPodSpecPatch_NodeAffinity(t *testing.T){
Weight: &preferredWeightB,
MatchFields: []*kubernetesplatform.SelectorRequirement{
{
Key: "field1",
Key: "field1",
Operator: "Exists",
},
},
},

},
},
&k8score.PodSpec{
Expand All @@ -1241,36 +1234,33 @@ func Test_extendPodSpecPatch_NodeAffinity(t *testing.T){
{
MatchExpressions: []k8score.NodeSelectorRequirement{
{
Key: "key1",
Key: "key1",
Operator: "In",
Values: []string{
"val1",
},
},
},
},
},
},
},
PreferredDuringSchedulingIgnoredDuringExecution: []k8score.PreferredSchedulingTerm{
{
Weight: preferredWeightB,
Preference: k8score.NodeSelectorTerm{

MatchFields: []k8score.NodeSelectorRequirement{
{
Key: "field1",
Key: "field1",
Operator: "Exists",
},
},


},
},
},
},
},

},
},
},
}
for _, tt := range tests {
Expand All @@ -1288,7 +1278,6 @@ func Test_extendPodSpecPatch_NodeAffinity(t *testing.T){
}
}


func Test_extendPodSpecPatch_FieldPathAsEnv(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit f91fe22

Please sign in to comment.