Skip to content

Commit

Permalink
Add cases to tests AdmissionWebhook MatchConditions size limit (kub…
Browse files Browse the repository at this point in the history
  • Loading branch information
a-hilaly committed Jul 25, 2023
1 parent ef4907e commit eb4063f
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"io"
"net/http"
"net/http/httptest"
"strconv"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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
}

0 comments on commit eb4063f

Please sign in to comment.