From 3de8719433cacdc82dfab6613f509545d9adcb4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20B=C3=A4hler?= Date: Mon, 27 May 2024 10:33:17 +0200 Subject: [PATCH] chore: preview --- pkg/webhook/namespace/freezed.go | 2 +- pkg/webhook/namespace/prefix.go | 2 +- pkg/webhook/namespace/quota.go | 2 +- pkg/webhook/namespace/user_metadata.go | 4 ++-- pkg/webhook/namespace/utils.go | 27 -------------------------- pkg/webhook/utils/ownerreference.go | 5 ++++- 6 files changed, 9 insertions(+), 33 deletions(-) delete mode 100644 pkg/webhook/namespace/utils.go diff --git a/pkg/webhook/namespace/freezed.go b/pkg/webhook/namespace/freezed.go index 1f488a6d3..e45c729e6 100644 --- a/pkg/webhook/namespace/freezed.go +++ b/pkg/webhook/namespace/freezed.go @@ -35,7 +35,7 @@ func (r *freezedHandler) OnCreate(client client.Client, decoder admission.Decode } for _, objectRef := range ns.ObjectMeta.OwnerReferences { - if !isTenantOwnerReference(objectRef) { + if !utils.IsTenantOwnerReference(objectRef) { continue } diff --git a/pkg/webhook/namespace/prefix.go b/pkg/webhook/namespace/prefix.go index f4e53111e..a59479f98 100644 --- a/pkg/webhook/namespace/prefix.go +++ b/pkg/webhook/namespace/prefix.go @@ -49,7 +49,7 @@ func (r *prefixHandler) OnCreate(clt client.Client, decoder admission.Decoder, r tnt := &capsulev1beta2.Tenant{} for _, or := range ns.ObjectMeta.OwnerReferences { - if !isTenantOwnerReference(or) { + if !utils.IsTenantOwnerReference(or) { continue } diff --git a/pkg/webhook/namespace/quota.go b/pkg/webhook/namespace/quota.go index 49b0a1a54..3080c3c3f 100644 --- a/pkg/webhook/namespace/quota.go +++ b/pkg/webhook/namespace/quota.go @@ -31,7 +31,7 @@ func (r *quotaHandler) OnCreate(client client.Client, decoder admission.Decoder, } for _, objectRef := range ns.ObjectMeta.OwnerReferences { - if !isTenantOwnerReference(objectRef) { + if !utils.IsTenantOwnerReference(objectRef) { continue } diff --git a/pkg/webhook/namespace/user_metadata.go b/pkg/webhook/namespace/user_metadata.go index b7627bac4..b023a43db 100644 --- a/pkg/webhook/namespace/user_metadata.go +++ b/pkg/webhook/namespace/user_metadata.go @@ -35,7 +35,7 @@ func (r *userMetadataHandler) OnCreate(client client.Client, decoder admission.D tnt := &capsulev1beta2.Tenant{} for _, objectRef := range ns.ObjectMeta.OwnerReferences { - if !isTenantOwnerReference(objectRef) { + if !utils.IsTenantOwnerReference(objectRef) { continue } @@ -90,7 +90,7 @@ func (r *userMetadataHandler) OnUpdate(client client.Client, decoder admission.D tnt := &capsulev1beta2.Tenant{} for _, objectRef := range newNs.ObjectMeta.OwnerReferences { - if !isTenantOwnerReference(objectRef) { + if !utils.IsTenantOwnerReference(objectRef) { continue } diff --git a/pkg/webhook/namespace/utils.go b/pkg/webhook/namespace/utils.go deleted file mode 100644 index bb344ae07..000000000 --- a/pkg/webhook/namespace/utils.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2020-2023 Project Capsule Authors. -// SPDX-License-Identifier: Apache-2.0 - -package namespace - -import ( - "strings" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - capsulev1beta2 "github.com/projectcapsule/capsule/api/v1beta2" -) - -const ( - ObjectReferenceTenantKind = "Tenant" -) - -func isTenantOwnerReference(or metav1.OwnerReference) bool { - parts := strings.Split(or.APIVersion, "/") - if len(parts) != 2 { - return false - } - - group := parts[0] - - return group == capsulev1beta2.GroupVersion.Group && or.Kind == ObjectReferenceTenantKind -} diff --git a/pkg/webhook/utils/ownerreference.go b/pkg/webhook/utils/ownerreference.go index 850566981..949e2afd0 100644 --- a/pkg/webhook/utils/ownerreference.go +++ b/pkg/webhook/utils/ownerreference.go @@ -1,3 +1,6 @@ +// Copyright 2020-2023 Project Capsule Authors. +// SPDX-License-Identifier: Apache-2.0 + package utils import ( @@ -12,7 +15,7 @@ const ( ObjectReferenceTenantKind = "Tenant" ) -func IsTenantOwnerReference(or metav1.OwnerReference) bool { +func isTenantOwnerReference(or metav1.OwnerReference) bool { parts := strings.Split(or.APIVersion, "/") if len(parts) != 2 { return false