Skip to content

Commit

Permalink
Merge pull request #292 from elmiko/fix-taint-value-field
Browse files Browse the repository at this point in the history
OCPBUGS-31421: add check for taint.value == nil
  • Loading branch information
openshift-merge-bot[bot] committed Mar 27, 2024
2 parents 9d29c92 + 0a9d00d commit c852679
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
Expand Up @@ -353,6 +353,10 @@ func createTestConfigs(specs ...testSpec) []*testConfig {
"value": "test",
"effect": "NoSchedule",
},
map[string]interface{}{
"key": "test-no-value",
"effect": "NoSchedule",
},
},
},
},
Expand Down Expand Up @@ -398,6 +402,10 @@ func createTestConfigs(specs ...testSpec) []*testConfig {
"value": "test",
"effect": "NoSchedule",
},
map[string]interface{}{
"key": "test-no-value",
"effect": "NoSchedule",
},
},
},
},
Expand Down
Expand Up @@ -243,7 +243,10 @@ func unstructuredToTaint(unstructuredTaintInterface interface{}) *corev1.Taint {

taint := &corev1.Taint{}
taint.Key = unstructuredTaint["key"].(string)
taint.Value = unstructuredTaint["value"].(string)
// value is optional and could be nil if not present
if unstructuredTaint["value"] != nil {
taint.Value = unstructuredTaint["value"].(string)
}
taint.Effect = corev1.TaintEffect(unstructuredTaint["effect"].(string))
return taint
}
Expand Down
Expand Up @@ -226,8 +226,16 @@ func TestReplicas(t *testing.T) {
func TestTaints(t *testing.T) {
initialReplicas := 1

expectedTaints := []v1.Taint{{Key: "test", Effect: v1.TaintEffectNoSchedule, Value: "test"}}
expectedTaintsWithAnnotations := []v1.Taint{{Key: "test", Effect: v1.TaintEffectNoSchedule, Value: "test"}, {Key: "key1", Effect: v1.TaintEffectNoSchedule, Value: "value1"}, {Key: "key2", Effect: v1.TaintEffectNoExecute, Value: "value2"}}
expectedTaints := []v1.Taint{
{Key: "test", Effect: v1.TaintEffectNoSchedule, Value: "test"},
{Key: "test-no-value", Effect: v1.TaintEffectNoSchedule},
}
expectedTaintsWithAnnotations := []v1.Taint{
{Key: "test", Effect: v1.TaintEffectNoSchedule, Value: "test"},
{Key: "test-no-value", Effect: v1.TaintEffectNoSchedule},
{Key: "key1", Effect: v1.TaintEffectNoSchedule, Value: "value1"},
{Key: "key2", Effect: v1.TaintEffectNoExecute, Value: "value2"},
}
taintAnnotation := "key1=value1:NoSchedule,key2=value2:NoExecute"

test := func(t *testing.T, testConfig *testConfig) {
Expand Down Expand Up @@ -350,8 +358,14 @@ func TestAnnotations(t *testing.T) {
gpuQuantity := resource.MustParse("1")
maxPodsQuantity := resource.MustParse("42")

// Note, the first taint comes from the spec of the machine template, the rest from the annotations.
expectedTaints := []v1.Taint{{Key: "test", Effect: v1.TaintEffectNoSchedule, Value: "test"}, {Key: "key1", Effect: v1.TaintEffectNoSchedule, Value: "value1"}, {Key: "key2", Effect: v1.TaintEffectNoExecute, Value: "value2"}}
// Note, the first two taints comes from the spec of the machine template, the rest from the annotations.
expectedTaints := []v1.Taint{
{Key: "test", Effect: v1.TaintEffectNoSchedule, Value: "test"},
{Key: "test-no-value", Effect: v1.TaintEffectNoSchedule},
{Key: "key1", Effect: v1.TaintEffectNoSchedule, Value: "value1"},
{Key: "key2", Effect: v1.TaintEffectNoExecute, Value: "value2"},
}

annotations := map[string]string{
cpuKey: cpuQuantity.String(),
memoryKey: memQuantity.String(),
Expand Down

0 comments on commit c852679

Please sign in to comment.