@@ -175,7 +175,7 @@ func getSelectorClassNotExist(label string) *metav1.LabelSelector {
175175 }
176176}
177177
178- func getMatchCondition (isDefault bool , name string , excludedNamespaces string , label string ) []admissionv1.MatchCondition {
178+ func getMatchCondition (excludedNamespaces string ) []admissionv1.MatchCondition {
179179 matchConditions := []admissionv1.MatchCondition {}
180180 matchConditions = append (matchConditions , admissionv1.MatchCondition {
181181 Name : "exclude-namespaces" ,
@@ -202,11 +202,36 @@ func getObjectSelector(isDefault bool, label string, name string) *metav1.LabelS
202202}
203203
204204func CreateMutatingWebhookConfiguration (class overcommit.OvercommitClass , svc corev1.Service , cert certmanager.Certificate , label string ) * admissionv1.MutatingWebhookConfiguration {
205-
206205 var path = "/mutate--v1-pod"
207206 var scope = admissionv1 .NamespacedScope
208207 var policy = admissionv1 .Fail
209208 var sideEffect = admissionv1 .SideEffectClassNone
209+ var reinvocationPolicy = admissionv1 .IfNeededReinvocationPolicy
210+
211+ rules := []admissionv1.RuleWithOperations {
212+ {
213+ Operations : []admissionv1.OperationType {
214+ admissionv1 .Create ,
215+ },
216+ Rule : admissionv1.Rule {
217+ APIGroups : []string {"" },
218+ APIVersions : []string {"v1" },
219+ Resources : []string {"pods" },
220+ Scope : & scope ,
221+ },
222+ },
223+ {
224+ Operations : []admissionv1.OperationType {
225+ admissionv1 .Update ,
226+ },
227+ Rule : admissionv1.Rule {
228+ APIGroups : []string {"" },
229+ APIVersions : []string {"v1" },
230+ Resources : []string {"pods/resize" },
231+ Scope : & scope ,
232+ },
233+ },
234+ }
210235
211236 webhookConfig := & admissionv1.MutatingWebhookConfiguration {
212237 ObjectMeta : metav1.ObjectMeta {
@@ -225,23 +250,12 @@ func CreateMutatingWebhookConfiguration(class overcommit.OvercommitClass, svc co
225250 Path : & path ,
226251 },
227252 },
228- Rules : []admissionv1.RuleWithOperations {
229- {
230- Operations : []admissionv1.OperationType {
231- admissionv1 .Create ,
232- },
233- Rule : admissionv1.Rule {
234- APIGroups : []string {"" },
235- APIVersions : []string {"v1" },
236- Resources : []string {"pods" },
237- Scope : & scope ,
238- },
239- },
240- },
253+ Rules : rules ,
241254 AdmissionReviewVersions : []string {"v1" },
242255 FailurePolicy : & policy ,
243256 SideEffects : & sideEffect ,
244- MatchConditions : getMatchCondition (false , class .Name , class .Spec .ExcludedNamespaces , label ),
257+ ReinvocationPolicy : & reinvocationPolicy ,
258+ MatchConditions : getMatchCondition (class .Spec .ExcludedNamespaces ),
245259 ObjectSelector : getObjectSelector (false , label , class .Name ),
246260 },
247261 },
@@ -257,25 +271,15 @@ func CreateMutatingWebhookConfiguration(class overcommit.OvercommitClass, svc co
257271 Path : & path ,
258272 },
259273 },
260- Rules : []admissionv1.RuleWithOperations {
261- {
262- Operations : []admissionv1.OperationType {
263- admissionv1 .Create ,
264- },
265- Rule : admissionv1.Rule {
266- APIGroups : []string {"" },
267- APIVersions : []string {"v1" },
268- Resources : []string {"pods" },
269- Scope : & scope ,
270- },
271- },
272- },
274+ Rules : rules ,
273275 AdmissionReviewVersions : []string {"v1" },
274276 FailurePolicy : & policy ,
275277 SideEffects : & sideEffect ,
276- MatchConditions : getMatchCondition (class .Spec .IsDefault , class .Name , class .Spec .ExcludedNamespaces , label ),
278+ ReinvocationPolicy : & reinvocationPolicy ,
279+ MatchConditions : getMatchCondition (class .Spec .ExcludedNamespaces ),
277280 ObjectSelector : getObjectSelector (class .Spec .IsDefault , label , class .Name ),
278281 })
279282 }
283+
280284 return webhookConfig
281285}
0 commit comments