Skip to content

Commit

Permalink
Automated Config Connector import.
Browse files Browse the repository at this point in the history
  - e1a5ad3b59250c4bae0dcf231b24aed7de2a657f Update abandon-on-uninstall webhook with objectSelector by Config Connector Team <[email protected]>

GitOrigin-RevId: e1a5ad3b59250c4bae0dcf231b24aed7de2a657f
  • Loading branch information
Config Connector Team authored and copybara-github committed Jan 23, 2023
1 parent 1b29995 commit aa354f3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
2 changes: 2 additions & 0 deletions pkg/webhook/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func mutatingWebhooksForWebhookConfigs(whCfgs []WebhookConfig, svcName string, w
wh := &admissionregistration.MutatingWebhook{
Name: whCfg.Name,
Rules: whCfg.Rules,
ObjectSelector: whCfg.ObjectSelector,
FailurePolicy: &whCfg.FailurePolicy,
SideEffects: &whCfg.SideEffects,
AdmissionReviewVersions: admissionReviewVersions,
Expand All @@ -87,6 +88,7 @@ func validatingWebhooksForWebhookConfigs(whCfgs []WebhookConfig, svcName string,
wh := &admissionregistration.ValidatingWebhook{
Name: whCfg.Name,
Rules: whCfg.Rules,
ObjectSelector: whCfg.ObjectSelector,
FailurePolicy: &whCfg.FailurePolicy,
SideEffects: &whCfg.SideEffects,
AdmissionReviewVersions: admissionReviewVersions,
Expand Down
15 changes: 11 additions & 4 deletions pkg/webhook/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"path"
"strings"

"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/crd/crdgeneration"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/dcl/metadata"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/dcl/schema/dclschemaloader"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/gvks/supportedgvks"
Expand All @@ -36,6 +37,7 @@ import (
admissionregistration "k8s.io/api/admissionregistration/v1"
corev1 "k8s.io/api/core/v1"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
Expand Down Expand Up @@ -187,10 +189,15 @@ func GetCommonWebhookConfigs() ([]WebhookConfig, error) {
func RegisterAbandonOnUninstallWebhook(mgr manager.Manager, nocacheClient client.Client) error {
whCfgs := []WebhookConfig{
{
Name: "abandon-on-uninstall.cnrm.cloud.google.com",
Path: "/abandon-on-uninstall",
Type: Validating,
Handler: &abandonOnCRDUninstallWebhook{},
Name: "abandon-on-uninstall.cnrm.cloud.google.com",
Path: "/abandon-on-uninstall",
Type: Validating,
Handler: &abandonOnCRDUninstallWebhook{},
ObjectSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
crdgeneration.ManagedByKCCLabel: "true",
},
},
FailurePolicy: admissionregistration.Fail,
Rules: getRulesForOperationTypes(
getRulesFromResources([]schema.GroupVersionKind{
Expand Down
16 changes: 9 additions & 7 deletions pkg/webhook/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ package webhook

import (
admissionregistration "k8s.io/api/admissionregistration/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

type WebhookConfig struct {
Type webhookType
Name string
Path string
Handler admission.Handler
FailurePolicy admissionregistration.FailurePolicyType
Rules []admissionregistration.RuleWithOperations
SideEffects admissionregistration.SideEffectClass
Type webhookType
Name string
Path string
Handler admission.Handler
FailurePolicy admissionregistration.FailurePolicyType
ObjectSelector *metav1.LabelSelector
Rules []admissionregistration.RuleWithOperations
SideEffects admissionregistration.SideEffectClass
}

type webhookType string
Expand Down

0 comments on commit aa354f3

Please sign in to comment.