From 3e0882dbc87ba313c28912d43a4e740177345b0c Mon Sep 17 00:00:00 2001 From: Dario Tranchitella Date: Wed, 30 Jun 2021 10:13:21 +0200 Subject: [PATCH] refactor: domains is now API utils --- api/{v1alpha1/domain => utils}/allowed.go | 2 +- api/{v1alpha1/domain => utils}/imagepullpolicy.go | 2 +- api/{v1alpha1/domain => utils}/podpriority.go | 2 +- api/{v1alpha1/domain => utils}/registry.go | 2 +- api/{v1alpha1/domain => utils}/registry_test.go | 2 +- pkg/webhook/pod/containerregistry.go | 4 ++-- pkg/webhook/pod/imagepullpolicy.go | 4 ++-- pkg/webhook/pod/priorityclass.go | 4 ++-- 8 files changed, 11 insertions(+), 11 deletions(-) rename api/{v1alpha1/domain => utils}/allowed.go (91%) rename api/{v1alpha1/domain => utils}/imagepullpolicy.go (98%) rename api/{v1alpha1/domain => utils}/podpriority.go (98%) rename api/{v1alpha1/domain => utils}/registry.go (98%) rename api/{v1alpha1/domain => utils}/registry_test.go (98%) diff --git a/api/v1alpha1/domain/allowed.go b/api/utils/allowed.go similarity index 91% rename from api/v1alpha1/domain/allowed.go rename to api/utils/allowed.go index d2273953..a61a04f4 100644 --- a/api/v1alpha1/domain/allowed.go +++ b/api/utils/allowed.go @@ -1,7 +1,7 @@ // Copyright 2020-2021 Clastix Labs // SPDX-License-Identifier: Apache-2.0 -package domain +package utils type AllowedList interface { ExactMatch(value string) bool diff --git a/api/v1alpha1/domain/imagepullpolicy.go b/api/utils/imagepullpolicy.go similarity index 98% rename from api/v1alpha1/domain/imagepullpolicy.go rename to api/utils/imagepullpolicy.go index cbbbe597..6b449a1b 100644 --- a/api/v1alpha1/domain/imagepullpolicy.go +++ b/api/utils/imagepullpolicy.go @@ -1,7 +1,7 @@ // Copyright 2020-2021 Clastix Labs // SPDX-License-Identifier: Apache-2.0 -package domain +package utils import ( "strings" diff --git a/api/v1alpha1/domain/podpriority.go b/api/utils/podpriority.go similarity index 98% rename from api/v1alpha1/domain/podpriority.go rename to api/utils/podpriority.go index a58be96f..eb3ee013 100644 --- a/api/v1alpha1/domain/podpriority.go +++ b/api/utils/podpriority.go @@ -1,7 +1,7 @@ // Copyright 2020-2021 Clastix Labs // SPDX-License-Identifier: Apache-2.0 -package domain +package utils import ( "regexp" diff --git a/api/v1alpha1/domain/registry.go b/api/utils/registry.go similarity index 98% rename from api/v1alpha1/domain/registry.go rename to api/utils/registry.go index cd840cd8..4134f724 100644 --- a/api/v1alpha1/domain/registry.go +++ b/api/utils/registry.go @@ -1,7 +1,7 @@ // Copyright 2020-2021 Clastix Labs // SPDX-License-Identifier: Apache-2.0 -package domain +package utils import ( "regexp" diff --git a/api/v1alpha1/domain/registry_test.go b/api/utils/registry_test.go similarity index 98% rename from api/v1alpha1/domain/registry_test.go rename to api/utils/registry_test.go index 9f9bece8..a58154fa 100644 --- a/api/v1alpha1/domain/registry_test.go +++ b/api/utils/registry_test.go @@ -1,7 +1,7 @@ // Copyright 2020-2021 Clastix Labs // SPDX-License-Identifier: Apache-2.0 -package domain +package utils import ( "testing" diff --git a/pkg/webhook/pod/containerregistry.go b/pkg/webhook/pod/containerregistry.go index 17ccab72..c4286cf8 100644 --- a/pkg/webhook/pod/containerregistry.go +++ b/pkg/webhook/pod/containerregistry.go @@ -12,8 +12,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/webhook/admission" + apiutils "github.com/clastix/capsule/api/utils" capsulev1alpha1 "github.com/clastix/capsule/api/v1alpha1" - "github.com/clastix/capsule/api/v1alpha1/domain" capsulewebhook "github.com/clastix/capsule/pkg/webhook" "github.com/clastix/capsule/pkg/webhook/utils" ) @@ -49,7 +49,7 @@ func (h *containerRegistryHandler) OnCreate(c client.Client, decoder *admission. var valid, matched bool for _, container := range pod.Spec.Containers { - registry := domain.NewRegistry(container.Image) + registry := apiutils.NewRegistry(container.Image) valid = tnt.Spec.ContainerRegistries.ExactMatch(registry.Registry()) diff --git a/pkg/webhook/pod/imagepullpolicy.go b/pkg/webhook/pod/imagepullpolicy.go index 0f54849b..bdcc2312 100644 --- a/pkg/webhook/pod/imagepullpolicy.go +++ b/pkg/webhook/pod/imagepullpolicy.go @@ -12,8 +12,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/webhook/admission" + apiutils "github.com/clastix/capsule/api/utils" "github.com/clastix/capsule/api/v1alpha1" - "github.com/clastix/capsule/api/v1alpha1/domain" capsulewebhook "github.com/clastix/capsule/pkg/webhook" "github.com/clastix/capsule/pkg/webhook/utils" ) @@ -44,7 +44,7 @@ func (r *imagePullPolicy) OnCreate(c client.Client, decoder *admission.Decoder, tnt := tntList.Items[0] - policy := domain.NewImagePullPolicy(&tnt) + policy := apiutils.NewImagePullPolicy(&tnt) // if Tenant doesn't enforce the pull policy, exit if policy == nil { return nil diff --git a/pkg/webhook/pod/priorityclass.go b/pkg/webhook/pod/priorityclass.go index 6997c590..09602350 100644 --- a/pkg/webhook/pod/priorityclass.go +++ b/pkg/webhook/pod/priorityclass.go @@ -12,8 +12,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/webhook/admission" + apiutils "github.com/clastix/capsule/api/utils" capsulev1alpha1 "github.com/clastix/capsule/api/v1alpha1" - "github.com/clastix/capsule/api/v1alpha1/domain" capsulewebhook "github.com/clastix/capsule/pkg/webhook" "github.com/clastix/capsule/pkg/webhook/utils" ) @@ -44,7 +44,7 @@ func (h *priorityClass) OnCreate(c client.Client, decoder *admission.Decoder, re return nil } - var allowed = domain.NewPodPriority(&tntList.Items[0]) + var allowed = apiutils.NewPodPriority(&tntList.Items[0]) var priorityClassName = pod.Spec.PriorityClassName