Skip to content

Commit

Permalink
WIP: allow OSC to be ignored by webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBatschner committed May 23, 2024
1 parent 8d2be15 commit 737f4f6
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion pkg/webhook/operatingsystemconfig/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import (
const (
// Name is the webhook name.
Name = "gardenlinux-operatingsystemconfig-webhook"
// AnnotationKey is the annotation key that controls the webhook
AnnotationKey = "extensions.gardener.cloud/os-garden-linux"
// IgnoreAnnotationValue is the annotation value that tells the webhook to ignore an OSC
IgnoreAnnotationValue = "Ignore"
)

var logger = log.Log.WithName(Name)
Expand All @@ -45,7 +49,7 @@ func AddToManager(mgr manager.Manager) (*extensionswebhook.Webhook, error) {
{Obj: &extensionsv1alpha1.OperatingSystemConfig{}},
}

handler, err := extensionswebhook.NewBuilder(mgr, logger).WithPredicates(isGardenLinuxOsc()).WithMutator(mutator, types...).Build()
handler, err := extensionswebhook.NewBuilder(mgr, logger).WithPredicates(isGardenLinuxOsc(), hasNoIgnoreAnnotation()).WithMutator(mutator, types...).Build()
if err != nil {
return nil, err
}
Expand All @@ -71,3 +75,17 @@ func isGardenLinuxOsc() predicate.Predicate {
return osc.Spec.Type == gardenlinux.OSTypeGardenLinux
})
}

func hasNoIgnoreAnnotation() predicate.Predicate {
return predicate.NewPredicateFuncs(func(obj client.Object) bool {
osc, ok := obj.(*extensionsv1alpha1.OperatingSystemConfig)
if !ok {
return false
}
annotation, ok := osc.Annotations[AnnotationKey]
if ok {
return annotation != IgnoreAnnotationValue
}
return true
})
}

0 comments on commit 737f4f6

Please sign in to comment.