Add cases to tests AdmissionWebhook MatchConditions size limit (#119404)

This commit is contained in:
Amine 2023-07-25 23:36:19 +01:00 committed by GitHub
parent ef4907eddd
commit eb4063f0ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,6 +24,7 @@ import (
"io"
"net/http"
"net/http/httptest"
"strconv"
"sync"
"testing"
"time"
@ -649,7 +650,16 @@ func TestMatchConditions_validation(t *testing.T) {
Expression: "oldObject == null",
}},
expectError: true,
}}
}, {
name: "less than 65 match conditions should pass",
matchConditions: repeatedMatchConditions(64),
expectError: false,
}, {
name: "more than 64 match conditions should error",
matchConditions: repeatedMatchConditions(65),
expectError: true,
},
}
dryRunCreate := metav1.CreateOptions{
DryRun: []string{metav1.DryRunAll},
@ -952,3 +962,14 @@ func newMarkerPod(namespace string) *corev1.Pod {
},
}
}
func repeatedMatchConditions(size int) []admissionregistrationv1.MatchCondition {
matchConditions := make([]admissionregistrationv1.MatchCondition, 0, size)
for i := 0; i < size; i++ {
matchConditions = append(matchConditions, admissionregistrationv1.MatchCondition{
Name: "repeated-" + strconv.Itoa(i),
Expression: "true",
})
}
return matchConditions
}