github.com/verrazzano/verrazzano@v1.7.0/pkg/k8s/webhook/webhook.go (about) 1 // Copyright (c) 2022, 2023, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package webhook 5 6 import ( 7 "context" 8 9 "github.com/verrazzano/verrazzano/pkg/log/vzlog" 10 adminv1 "k8s.io/api/admissionregistration/v1" 11 "k8s.io/apimachinery/pkg/api/errors" 12 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 13 ctrlcli "sigs.k8s.io/controller-runtime/pkg/client" 14 ) 15 16 func DeleteMutatingWebhookConfiguration(log vzlog.VerrazzanoLogger, client ctrlcli.Client, names []string) error { 17 for _, name := range names { 18 wh := adminv1.MutatingWebhookConfiguration{ 19 ObjectMeta: metav1.ObjectMeta{Name: name}, 20 } 21 log.Progressf("Deleting MutatingWebhookConfiguration %s", name) 22 if err := client.Delete(context.TODO(), &wh); err != nil { 23 if errors.IsNotFound(err) { 24 return nil 25 } 26 return log.ErrorfThrottledNewErr("Failed to delete MutatingWebhookConfiguration %:, %v", name, err) 27 } 28 } 29 return nil 30 } 31 32 func DeleteValidatingWebhookConfiguration(log vzlog.VerrazzanoLogger, client ctrlcli.Client, name string) error { 33 wh := adminv1.ValidatingWebhookConfiguration{ 34 ObjectMeta: metav1.ObjectMeta{Name: name}, 35 } 36 log.Progressf("Deleting ValidatingWebhookConfiguration %s", name) 37 if err := client.Delete(context.TODO(), &wh); err != nil { 38 if errors.IsNotFound(err) { 39 return nil 40 } 41 return log.ErrorfThrottledNewErr("Failed to delete ValidatingWebhookConfiguration %s: %v", name, err) 42 } 43 return nil 44 }