diff --git a/api/utils/allowed.go b/api/utils/allowed.go deleted file mode 100644 index a61a04f4..00000000 --- a/api/utils/allowed.go +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2020-2021 Clastix Labs -// SPDX-License-Identifier: Apache-2.0 - -package utils - -type AllowedList interface { - ExactMatch(value string) bool - RegexMatch(value string) bool -} diff --git a/api/utils/imagepullpolicy.go b/api/utils/imagepullpolicy.go deleted file mode 100644 index 6b449a1b..00000000 --- a/api/utils/imagepullpolicy.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2020-2021 Clastix Labs -// SPDX-License-Identifier: Apache-2.0 - -package utils - -import ( - "strings" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -const ( - podAllowedImagePullPolicyAnnotation = "capsule.clastix.io/allowed-image-pull-policy" -) - -type ImagePullPolicy interface { - IsPolicySupported(policy string) bool - AllowedPullPolicies() []string -} - -type imagePullPolicyValidator struct { - allowedPolicies []string -} - -func (i imagePullPolicyValidator) IsPolicySupported(policy string) bool { - for _, allowed := range i.allowedPolicies { - if strings.EqualFold(allowed, policy) { - return true - } - } - - return false -} - -func (i imagePullPolicyValidator) AllowedPullPolicies() []string { - return i.allowedPolicies -} - -func NewImagePullPolicy(object metav1.Object) ImagePullPolicy { - annotations := object.GetAnnotations() - - v, ok := annotations[podAllowedImagePullPolicyAnnotation] - // the Tenant doesn't enforce the allowed image pull policy, returning nil - if !ok { - return nil - } - - return &imagePullPolicyValidator{ - allowedPolicies: strings.Split(v, ","), - } -} diff --git a/api/utils/podpriority.go b/api/utils/podpriority.go deleted file mode 100644 index eb3ee013..00000000 --- a/api/utils/podpriority.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2020-2021 Clastix Labs -// SPDX-License-Identifier: Apache-2.0 - -package utils - -import ( - "regexp" - "strings" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/clastix/capsule/api/v1alpha1" -) - -const ( - podPriorityAllowedAnnotation = "priorityclass.capsule.clastix.io/allowed" - podPriorityAllowedRegexAnnotation = "priorityclass.capsule.clastix.io/allowed-regex" -) - -func NewPodPriority(object metav1.Object) (allowed *v1alpha1.AllowedListSpec) { - annotations := object.GetAnnotations() - - if v, ok := annotations[podPriorityAllowedAnnotation]; ok { - allowed = &v1alpha1.AllowedListSpec{} - allowed.Exact = strings.Split(v, ",") - } - - if v, ok := annotations[podPriorityAllowedRegexAnnotation]; ok { - if _, err := regexp.Compile(v); err == nil { - if allowed == nil { - allowed = &v1alpha1.AllowedListSpec{} - } - allowed.Regex = v - } - } - - return -} diff --git a/api/utils/registry.go b/api/utils/registry.go deleted file mode 100644 index 4134f724..00000000 --- a/api/utils/registry.go +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2020-2021 Clastix Labs -// SPDX-License-Identifier: Apache-2.0 - -package utils - -import ( - "regexp" -) - -const defaultRegistryName = "docker.io" - -type registry map[string]string - -func (r registry) Registry() string { - res, ok := r["registry"] - if !ok { - return "" - } - if len(res) == 0 { - return defaultRegistryName - } - return res -} - -func (r registry) Repository() string { - res, ok := r["repository"] - if !ok { - return "" - } - if res == defaultRegistryName { - return "" - } - return res -} - -func (r registry) Image() string { - res, ok := r["image"] - if !ok { - return "" - } - return res -} - -func (r registry) Tag() string { - res, ok := r["tag"] - if !ok { - return "" - } - if len(res) == 0 { - res = "latest" - } - return res -} - -func NewRegistry(value string) Registry { - reg := make(registry) - r := regexp.MustCompile(`(((?P[a-zA-Z0-9-.]+)\/)?((?P[a-zA-Z0-9-.]+)\/))?(?P[a-zA-Z0-9-.]+)(:(?P[a-zA-Z0-9-.]+))?`) - match := r.FindStringSubmatch(value) - for i, name := range r.SubexpNames() { - if i > 0 && i <= len(match) { - reg[name] = match[i] - } - } - return reg -} - -type Registry interface { - Registry() string - Repository() string - Image() string - Tag() string -} diff --git a/api/utils/registry_test.go b/api/utils/registry_test.go deleted file mode 100644 index a58154fa..00000000 --- a/api/utils/registry_test.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2020-2021 Clastix Labs -// SPDX-License-Identifier: Apache-2.0 - -package utils - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestNewRegistry(t *testing.T) { - type tc struct { - registry string - repo string - image string - tag string - } - for name, tc := range map[string]tc{ - "docker.io/my-org/my-repo:v0.0.1": { - registry: "docker.io", - repo: "my-org", - image: "my-repo", - tag: "v0.0.1", - }, - "unnamed/repository:1.2.3": { - registry: "docker.io", - repo: "unnamed", - image: "repository", - tag: "1.2.3", - }, - "quay.io/clastix/capsule:v1.0.0": { - registry: "quay.io", - repo: "clastix", - image: "capsule", - tag: "v1.0.0", - }, - "docker.io/redis:alpine": { - registry: "docker.io", - repo: "", - image: "redis", - tag: "alpine", - }, - "nginx:alpine": { - registry: "docker.io", - repo: "", - image: "nginx", - tag: "alpine", - }, - "nginx": { - registry: "docker.io", - repo: "", - image: "nginx", - tag: "latest", - }, - } { - t.Run(name, func(t *testing.T) { - r := NewRegistry(name) - assert.Equal(t, tc.registry, r.Registry()) - assert.Equal(t, tc.repo, r.Repository()) - assert.Equal(t, tc.image, r.Image()) - assert.Equal(t, tc.tag, r.Tag()) - }) - } -} diff --git a/api/v1alpha1/ingress_hostnames_list.go b/api/v1alpha1/ingress_hostnames_list.go deleted file mode 100644 index 2bd966ab..00000000 --- a/api/v1alpha1/ingress_hostnames_list.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2020-2021 Clastix Labs -// SPDX-License-Identifier: Apache-2.0 - -package v1alpha1 - -import ( - "sort" -) - -type IngressHostnamesList []string - -func (hostnames IngressHostnamesList) Len() int { - return len(hostnames) -} - -func (hostnames IngressHostnamesList) Swap(i, j int) { - hostnames[i], hostnames[j] = hostnames[j], hostnames[i] -} - -func (hostnames IngressHostnamesList) Less(i, j int) bool { - return hostnames[i] < hostnames[j] -} - -func (hostnames IngressHostnamesList) IsStringInList(value string) (ok bool) { - sort.Sort(hostnames) - i := sort.SearchStrings(hostnames, value) - ok = i < hostnames.Len() && hostnames[i] == value - return -} diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 9c948341..e258ce42 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -181,25 +181,6 @@ func (in *ExternalServiceIPsSpec) DeepCopy() *ExternalServiceIPsSpec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in IngressHostnamesList) DeepCopyInto(out *IngressHostnamesList) { - { - in := &in - *out = make(IngressHostnamesList, len(*in)) - copy(*out, *in) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IngressHostnamesList. -func (in IngressHostnamesList) DeepCopy() IngressHostnamesList { - if in == nil { - return nil - } - out := new(IngressHostnamesList) - in.DeepCopyInto(out) - return *out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *OwnerSpec) DeepCopyInto(out *OwnerSpec) { *out = *in