diff --git a/api/v1alpha1/additional_metadata.go b/api/v1alpha1/additional_metadata.go new file mode 100644 index 000000000..0f0329977 --- /dev/null +++ b/api/v1alpha1/additional_metadata.go @@ -0,0 +1,9 @@ +// Copyright 2020-2021 Clastix Labs +// SPDX-License-Identifier: Apache-2.0 + +package v1alpha1 + +type AdditionalMetadataSpec struct { + AdditionalLabels map[string]string `json:"additionalLabels,omitempty"` + AdditionalAnnotations map[string]string `json:"additionalAnnotations,omitempty"` +} diff --git a/api/v1alpha1/additional_role_bindings.go b/api/v1alpha1/additional_role_bindings.go new file mode 100644 index 000000000..ecbe686bf --- /dev/null +++ b/api/v1alpha1/additional_role_bindings.go @@ -0,0 +1,12 @@ +// Copyright 2020-2021 Clastix Labs +// SPDX-License-Identifier: Apache-2.0 + +package v1alpha1 + +import rbacv1 "k8s.io/api/rbac/v1" + +type AdditionalRoleBindingsSpec struct { + ClusterRoleName string `json:"clusterRoleName"` + // kubebuilder:validation:Minimum=1 + Subjects []rbacv1.Subject `json:"subjects"` +} diff --git a/api/v1alpha1/conversion_hub.go b/api/v1alpha1/conversion_hub.go index 894698b6c..a6bcc9750 100644 --- a/api/v1alpha1/conversion_hub.go +++ b/api/v1alpha1/conversion_hub.go @@ -4,8 +4,9 @@ package v1alpha1 import ( - "github.com/clastix/capsule/api/v1alpha2" "sigs.k8s.io/controller-runtime/pkg/conversion" + + "github.com/clastix/capsule/api/v1alpha2" ) func (t *Tenant) ConvertTo(dstRaw conversion.Hub) error { @@ -23,4 +24,3 @@ func (t *Tenant) ConvertFrom(srcRaw conversion.Hub) error { return nil } - diff --git a/api/v1alpha1/domain/allowed.go b/api/v1alpha1/domain/allowed.go deleted file mode 100644 index d22739537..000000000 --- a/api/v1alpha1/domain/allowed.go +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2020-2021 Clastix Labs -// SPDX-License-Identifier: Apache-2.0 - -package domain - -type AllowedList interface { - ExactMatch(value string) bool - RegexMatch(value string) bool -} diff --git a/api/v1alpha1/domain/imagepullpolicy.go b/api/v1alpha1/domain/imagepullpolicy.go deleted file mode 100644 index cbbbe5974..000000000 --- a/api/v1alpha1/domain/imagepullpolicy.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2020-2021 Clastix Labs -// SPDX-License-Identifier: Apache-2.0 - -package domain - -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/v1alpha1/domain/podpriority.go b/api/v1alpha1/domain/podpriority.go deleted file mode 100644 index a58be96f2..000000000 --- a/api/v1alpha1/domain/podpriority.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2020-2021 Clastix Labs -// SPDX-License-Identifier: Apache-2.0 - -package domain - -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/v1alpha1/domain/registry.go b/api/v1alpha1/domain/registry.go deleted file mode 100644 index cd840cd8b..000000000 --- a/api/v1alpha1/domain/registry.go +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2020-2021 Clastix Labs -// SPDX-License-Identifier: Apache-2.0 - -package domain - -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/v1alpha1/domain/registry_test.go b/api/v1alpha1/domain/registry_test.go deleted file mode 100644 index 9f9bece8a..000000000 --- a/api/v1alpha1/domain/registry_test.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2020-2021 Clastix Labs -// SPDX-License-Identifier: Apache-2.0 - -package domain - -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/external_service_ips.go b/api/v1alpha1/external_service_ips.go new file mode 100644 index 000000000..2c1112d98 --- /dev/null +++ b/api/v1alpha1/external_service_ips.go @@ -0,0 +1,11 @@ +// Copyright 2020-2021 Clastix Labs +// SPDX-License-Identifier: Apache-2.0 + +package v1alpha1 + +// +kubebuilder:validation:Pattern="^([0-9]{1,3}.){3}[0-9]{1,3}(/([0-9]|[1-2][0-9]|3[0-2]))?$" +type AllowedIP string + +type ExternalServiceIPsSpec struct { + Allowed []AllowedIP `json:"allowed"` +} diff --git a/api/v1alpha1/ingress_hostnames_list.go b/api/v1alpha1/ingress_hostnames_list.go deleted file mode 100644 index 2bd966abf..000000000 --- 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/owner.go b/api/v1alpha1/owner.go new file mode 100644 index 000000000..ee83a9bf2 --- /dev/null +++ b/api/v1alpha1/owner.go @@ -0,0 +1,17 @@ +// Copyright 2020-2021 Clastix Labs +// SPDX-License-Identifier: Apache-2.0 + +package v1alpha1 + +// OwnerSpec defines tenant owner name and kind +type OwnerSpec struct { + Name string `json:"name"` + Kind Kind `json:"kind"` +} + +// +kubebuilder:validation:Enum=User;Group +type Kind string + +func (k Kind) String() string { + return string(k) +} diff --git a/api/v1alpha1/tenant_types.go b/api/v1alpha1/tenant_types.go index 98c785390..b3d445c8f 100644 --- a/api/v1alpha1/tenant_types.go +++ b/api/v1alpha1/tenant_types.go @@ -6,35 +6,17 @@ package v1alpha1 import ( corev1 "k8s.io/api/core/v1" networkingv1 "k8s.io/api/networking/v1" - rbacv1 "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -type AdditionalMetadata struct { - AdditionalLabels map[string]string `json:"additionalLabels,omitempty"` - AdditionalAnnotations map[string]string `json:"additionalAnnotations,omitempty"` -} - -type IngressHostnamesSpec struct { - Allowed IngressHostnamesList `json:"allowed"` - AllowedRegex string `json:"allowedRegex"` -} - -// +kubebuilder:validation:Pattern="^([0-9]{1,3}.){3}[0-9]{1,3}(/([0-9]|[1-2][0-9]|3[0-2]))?$" -type AllowedIP string - -type ExternalServiceIPs struct { - Allowed []AllowedIP `json:"allowed"` -} - // TenantSpec defines the desired state of Tenant type TenantSpec struct { Owner OwnerSpec `json:"owner"` //+kubebuilder:validation:Minimum=1 NamespaceQuota *int32 `json:"namespaceQuota,omitempty"` - NamespacesMetadata AdditionalMetadata `json:"namespacesMetadata,omitempty"` - ServicesMetadata AdditionalMetadata `json:"servicesMetadata,omitempty"` + NamespacesMetadata *AdditionalMetadataSpec `json:"namespacesMetadata,omitempty"` + ServicesMetadata *AdditionalMetadataSpec `json:"servicesMetadata,omitempty"` StorageClasses *AllowedListSpec `json:"storageClasses,omitempty"` IngressClasses *AllowedListSpec `json:"ingressClasses,omitempty"` IngressHostnames *AllowedListSpec `json:"ingressHostnames,omitempty"` @@ -43,27 +25,8 @@ type TenantSpec struct { NetworkPolicies []networkingv1.NetworkPolicySpec `json:"networkPolicies,omitempty"` LimitRanges []corev1.LimitRangeSpec `json:"limitRanges,omitempty"` ResourceQuota []corev1.ResourceQuotaSpec `json:"resourceQuotas,omitempty"` - AdditionalRoleBindings []AdditionalRoleBindings `json:"additionalRoleBindings,omitempty"` - ExternalServiceIPs *ExternalServiceIPs `json:"externalServiceIPs,omitempty"` -} - -type AdditionalRoleBindings struct { - ClusterRoleName string `json:"clusterRoleName"` - // kubebuilder:validation:Minimum=1 - Subjects []rbacv1.Subject `json:"subjects"` -} - -// OwnerSpec defines tenant owner name and kind -type OwnerSpec struct { - Name string `json:"name"` - Kind Kind `json:"kind"` -} - -// +kubebuilder:validation:Enum=User;Group -type Kind string - -func (k Kind) String() string { - return string(k) + AdditionalRoleBindings []AdditionalRoleBindingsSpec `json:"additionalRoleBindings,omitempty"` + ExternalServiceIPs *ExternalServiceIPsSpec `json:"externalServiceIPs,omitempty"` } // TenantStatus defines the observed state of Tenant diff --git a/api/v1alpha1/tenant_webhook.go b/api/v1alpha1/tenant_webhook.go index 565758170..cf6c84580 100644 --- a/api/v1alpha1/tenant_webhook.go +++ b/api/v1alpha1/tenant_webhook.go @@ -11,9 +11,9 @@ import ( // log is for logging in this package. var tenantlog = logf.Log.WithName("tenant-resource") -func (r *Tenant) SetupWebhookWithManager(mgr ctrl.Manager) error { +func (t *Tenant) SetupWebhookWithManager(mgr ctrl.Manager) error { return ctrl.NewWebhookManagedBy(mgr). - For(r). + For(t). Complete() } diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 2902c3223..765f44a71 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -9,13 +9,13 @@ package v1alpha1 import ( corev1 "k8s.io/api/core/v1" - "k8s.io/api/networking/v1" - rbacv1 "k8s.io/api/rbac/v1" - "k8s.io/apimachinery/pkg/runtime" + networkingv1 "k8s.io/api/networking/v1" + v1 "k8s.io/api/rbac/v1" + runtime "k8s.io/apimachinery/pkg/runtime" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *AdditionalMetadata) DeepCopyInto(out *AdditionalMetadata) { +func (in *AdditionalMetadataSpec) DeepCopyInto(out *AdditionalMetadataSpec) { *out = *in if in.AdditionalLabels != nil { in, out := &in.AdditionalLabels, &out.AdditionalLabels @@ -33,32 +33,32 @@ func (in *AdditionalMetadata) DeepCopyInto(out *AdditionalMetadata) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AdditionalMetadata. -func (in *AdditionalMetadata) DeepCopy() *AdditionalMetadata { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AdditionalMetadataSpec. +func (in *AdditionalMetadataSpec) DeepCopy() *AdditionalMetadataSpec { if in == nil { return nil } - out := new(AdditionalMetadata) + out := new(AdditionalMetadataSpec) in.DeepCopyInto(out) return out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *AdditionalRoleBindings) DeepCopyInto(out *AdditionalRoleBindings) { +func (in *AdditionalRoleBindingsSpec) DeepCopyInto(out *AdditionalRoleBindingsSpec) { *out = *in if in.Subjects != nil { in, out := &in.Subjects, &out.Subjects - *out = make([]rbacv1.Subject, len(*in)) + *out = make([]v1.Subject, len(*in)) copy(*out, *in) } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AdditionalRoleBindings. -func (in *AdditionalRoleBindings) DeepCopy() *AdditionalRoleBindings { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AdditionalRoleBindingsSpec. +func (in *AdditionalRoleBindingsSpec) DeepCopy() *AdditionalRoleBindingsSpec { if in == nil { return nil } - out := new(AdditionalRoleBindings) + out := new(AdditionalRoleBindingsSpec) in.DeepCopyInto(out) return out } @@ -162,7 +162,7 @@ func (in *CapsuleConfigurationSpec) DeepCopy() *CapsuleConfigurationSpec { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ExternalServiceIPs) DeepCopyInto(out *ExternalServiceIPs) { +func (in *ExternalServiceIPsSpec) DeepCopyInto(out *ExternalServiceIPsSpec) { *out = *in if in.Allowed != nil { in, out := &in.Allowed, &out.Allowed @@ -171,51 +171,12 @@ func (in *ExternalServiceIPs) DeepCopyInto(out *ExternalServiceIPs) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalServiceIPs. -func (in *ExternalServiceIPs) DeepCopy() *ExternalServiceIPs { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalServiceIPsSpec. +func (in *ExternalServiceIPsSpec) DeepCopy() *ExternalServiceIPsSpec { if in == nil { return nil } - out := new(ExternalServiceIPs) - in.DeepCopyInto(out) - 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 *IngressHostnamesSpec) DeepCopyInto(out *IngressHostnamesSpec) { - *out = *in - if in.Allowed != nil { - in, out := &in.Allowed, &out.Allowed - *out = make(IngressHostnamesList, len(*in)) - copy(*out, *in) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IngressHostnamesSpec. -func (in *IngressHostnamesSpec) DeepCopy() *IngressHostnamesSpec { - if in == nil { - return nil - } - out := new(IngressHostnamesSpec) + out := new(ExternalServiceIPsSpec) in.DeepCopyInto(out) return out } @@ -303,8 +264,16 @@ func (in *TenantSpec) DeepCopyInto(out *TenantSpec) { *out = new(int32) **out = **in } - in.NamespacesMetadata.DeepCopyInto(&out.NamespacesMetadata) - in.ServicesMetadata.DeepCopyInto(&out.ServicesMetadata) + if in.NamespacesMetadata != nil { + in, out := &in.NamespacesMetadata, &out.NamespacesMetadata + *out = new(AdditionalMetadataSpec) + (*in).DeepCopyInto(*out) + } + if in.ServicesMetadata != nil { + in, out := &in.ServicesMetadata, &out.ServicesMetadata + *out = new(AdditionalMetadataSpec) + (*in).DeepCopyInto(*out) + } if in.StorageClasses != nil { in, out := &in.StorageClasses, &out.StorageClasses *out = new(AllowedListSpec) @@ -334,7 +303,7 @@ func (in *TenantSpec) DeepCopyInto(out *TenantSpec) { } if in.NetworkPolicies != nil { in, out := &in.NetworkPolicies, &out.NetworkPolicies - *out = make([]v1.NetworkPolicySpec, len(*in)) + *out = make([]networkingv1.NetworkPolicySpec, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -355,14 +324,14 @@ func (in *TenantSpec) DeepCopyInto(out *TenantSpec) { } if in.AdditionalRoleBindings != nil { in, out := &in.AdditionalRoleBindings, &out.AdditionalRoleBindings - *out = make([]AdditionalRoleBindings, len(*in)) + *out = make([]AdditionalRoleBindingsSpec, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } if in.ExternalServiceIPs != nil { in, out := &in.ExternalServiceIPs, &out.ExternalServiceIPs - *out = new(ExternalServiceIPs) + *out = new(ExternalServiceIPsSpec) (*in).DeepCopyInto(*out) } } diff --git a/api/v1alpha2/additional_metadata.go b/api/v1alpha2/additional_metadata.go new file mode 100644 index 000000000..66769003c --- /dev/null +++ b/api/v1alpha2/additional_metadata.go @@ -0,0 +1,9 @@ +// Copyright 2020-2021 Clastix Labs +// SPDX-License-Identifier: Apache-2.0 + +package v1alpha2 + +type AdditionalMetadataSpec struct { + AdditionalLabels map[string]string `json:"additionalLabels,omitempty"` + AdditionalAnnotations map[string]string `json:"additionalAnnotations,omitempty"` +} diff --git a/api/v1alpha2/additional_role_bindings.go b/api/v1alpha2/additional_role_bindings.go new file mode 100644 index 000000000..4186f7c4f --- /dev/null +++ b/api/v1alpha2/additional_role_bindings.go @@ -0,0 +1,12 @@ +// Copyright 2020-2021 Clastix Labs +// SPDX-License-Identifier: Apache-2.0 + +package v1alpha2 + +import rbacv1 "k8s.io/api/rbac/v1" + +type AdditionalRoleBindingsSpec struct { + ClusterRoleName string `json:"clusterRoleName"` + // kubebuilder:validation:Minimum=1 + Subjects []rbacv1.Subject `json:"subjects"` +} diff --git a/api/v1alpha2/allowed_list.go b/api/v1alpha2/allowed_list.go new file mode 100644 index 000000000..1303f4f8a --- /dev/null +++ b/api/v1alpha2/allowed_list.go @@ -0,0 +1,33 @@ +// Copyright 2020-2021 Clastix Labs +// SPDX-License-Identifier: Apache-2.0 + +package v1alpha2 + +import ( + "regexp" + "sort" + "strings" +) + +type AllowedListSpec struct { + Exact []string `json:"allowed,omitempty"` + Regex string `json:"allowedRegex,omitempty"` +} + +func (in *AllowedListSpec) ExactMatch(value string) (ok bool) { + if len(in.Exact) > 0 { + sort.SliceStable(in.Exact, func(i, j int) bool { + return strings.ToLower(in.Exact[i]) < strings.ToLower(in.Exact[j]) + }) + i := sort.SearchStrings(in.Exact, value) + ok = i < len(in.Exact) && in.Exact[i] == value + } + return +} + +func (in AllowedListSpec) RegexMatch(value string) (ok bool) { + if len(in.Regex) > 0 { + ok = regexp.MustCompile(in.Regex).MatchString(value) + } + return +} diff --git a/api/v1alpha2/allowed_list_test.go b/api/v1alpha2/allowed_list_test.go new file mode 100644 index 000000000..e08228ba8 --- /dev/null +++ b/api/v1alpha2/allowed_list_test.go @@ -0,0 +1,67 @@ +// Copyright 2020-2021 Clastix Labs +// SPDX-License-Identifier: Apache-2.0 + +package v1alpha2 + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestAllowedListSpec_ExactMatch(t *testing.T) { + type tc struct { + In []string + True []string + False []string + } + for _, tc := range []tc{ + { + []string{"foo", "bar", "bizz", "buzz"}, + []string{"foo", "bar", "bizz", "buzz"}, + []string{"bing", "bong"}, + }, + { + []string{"one", "two", "three"}, + []string{"one", "two", "three"}, + []string{"a", "b", "c"}, + }, + { + nil, + nil, + []string{"any", "value"}, + }, + } { + a := AllowedListSpec{ + Exact: tc.In, + } + for _, ok := range tc.True { + assert.True(t, a.ExactMatch(ok)) + } + for _, ko := range tc.False { + assert.False(t, a.ExactMatch(ko)) + } + } +} + +func TestAllowedListSpec_RegexMatch(t *testing.T) { + type tc struct { + Regex string + True []string + False []string + } + for _, tc := range []tc{ + {`first-\w+-pattern`, []string{"first-date-pattern", "first-year-pattern"}, []string{"broken", "first-year", "second-date-pattern"}}, + {``, nil, []string{"any", "value"}}, + } { + a := AllowedListSpec{ + Regex: tc.Regex, + } + for _, ok := range tc.True { + assert.True(t, a.RegexMatch(ok)) + } + for _, ko := range tc.False { + assert.False(t, a.RegexMatch(ko)) + } + } +} diff --git a/api/v1alpha2/external_service_ips.go b/api/v1alpha2/external_service_ips.go new file mode 100644 index 000000000..c70f2054f --- /dev/null +++ b/api/v1alpha2/external_service_ips.go @@ -0,0 +1,11 @@ +// Copyright 2020-2021 Clastix Labs +// SPDX-License-Identifier: Apache-2.0 + +package v1alpha2 + +// +kubebuilder:validation:Pattern="^([0-9]{1,3}.){3}[0-9]{1,3}(/([0-9]|[1-2][0-9]|3[0-2]))?$" +type AllowedIP string + +type ExternalServiceIPsSpec struct { + Allowed []AllowedIP `json:"allowed"` +} diff --git a/api/v1alpha2/image_pull_policy.go b/api/v1alpha2/image_pull_policy.go new file mode 100644 index 000000000..08c607c5b --- /dev/null +++ b/api/v1alpha2/image_pull_policy.go @@ -0,0 +1,11 @@ +// Copyright 2020-2021 Clastix Labs +// SPDX-License-Identifier: Apache-2.0 + +package v1alpha2 + +// +kubebuilder:validation:Enum=Always;Never;IfNotPresent +type ImagePullPolicySpec string + +func (i ImagePullPolicySpec) String() string { + return string(i) +} diff --git a/api/v1alpha2/limit_ranges.go b/api/v1alpha2/limit_ranges.go new file mode 100644 index 000000000..0602d86f2 --- /dev/null +++ b/api/v1alpha2/limit_ranges.go @@ -0,0 +1,10 @@ +// Copyright 2020-2021 Clastix Labs +// SPDX-License-Identifier: Apache-2.0 + +package v1alpha2 + +import corev1 "k8s.io/api/core/v1" + +type LimitRangesSpec struct { + Items []corev1.LimitRangeSpec `json:"items,omitempty"` +} diff --git a/api/v1alpha2/network_policy.go b/api/v1alpha2/network_policy.go new file mode 100644 index 000000000..223e35896 --- /dev/null +++ b/api/v1alpha2/network_policy.go @@ -0,0 +1,12 @@ +// Copyright 2020-2021 Clastix Labs +// SPDX-License-Identifier: Apache-2.0 + +package v1alpha2 + +import ( + networkingv1 "k8s.io/api/networking/v1" +) + +type NetworkPolicySpec struct { + Items []networkingv1.NetworkPolicySpec `json:"items,omitempty"` +} diff --git a/api/v1alpha2/owner.go b/api/v1alpha2/owner.go new file mode 100644 index 000000000..a86b7c651 --- /dev/null +++ b/api/v1alpha2/owner.go @@ -0,0 +1,17 @@ +// Copyright 2020-2021 Clastix Labs +// SPDX-License-Identifier: Apache-2.0 + +package v1alpha2 + +// OwnerSpec defines tenant owner name and kind +type OwnerSpec struct { + Name string `json:"name"` + Kind Kind `json:"kind"` +} + +// +kubebuilder:validation:Enum=User;Group +type Kind string + +func (k Kind) String() string { + return string(k) +} diff --git a/api/v1alpha2/resource_quota.go b/api/v1alpha2/resource_quota.go new file mode 100644 index 000000000..3b70052e1 --- /dev/null +++ b/api/v1alpha2/resource_quota.go @@ -0,0 +1,10 @@ +// Copyright 2020-2021 Clastix Labs +// SPDX-License-Identifier: Apache-2.0 + +package v1alpha2 + +import corev1 "k8s.io/api/core/v1" + +type ResourceQuotaSpec struct { + Items []corev1.ResourceQuotaSpec `json:"items,omitempty"` +} diff --git a/api/v1alpha1/tenant_annotations.go b/api/v1alpha2/tenant_annotations.go similarity index 98% rename from api/v1alpha1/tenant_annotations.go rename to api/v1alpha2/tenant_annotations.go index bb3d48776..f10d16855 100644 --- a/api/v1alpha1/tenant_annotations.go +++ b/api/v1alpha2/tenant_annotations.go @@ -1,7 +1,7 @@ // Copyright 2020-2021 Clastix Labs // SPDX-License-Identifier: Apache-2.0 -package v1alpha1 +package v1alpha2 import ( "fmt" diff --git a/api/v1alpha1/tenant_func.go b/api/v1alpha2/tenant_func.go similarity index 97% rename from api/v1alpha1/tenant_func.go rename to api/v1alpha2/tenant_func.go index 6410d9aa7..312ead2c2 100644 --- a/api/v1alpha1/tenant_func.go +++ b/api/v1alpha2/tenant_func.go @@ -1,7 +1,7 @@ // Copyright 2020-2021 Clastix Labs // SPDX-License-Identifier: Apache-2.0 -package v1alpha1 +package v1alpha2 import ( "sort" diff --git a/api/v1alpha1/tenant_labels.go b/api/v1alpha2/tenant_labels.go similarity index 97% rename from api/v1alpha1/tenant_labels.go rename to api/v1alpha2/tenant_labels.go index 4e9a66306..f25f30d39 100644 --- a/api/v1alpha1/tenant_labels.go +++ b/api/v1alpha2/tenant_labels.go @@ -1,7 +1,7 @@ // Copyright 2020-2021 Clastix Labs // SPDX-License-Identifier: Apache-2.0 -package v1alpha1 +package v1alpha2 import ( "fmt" diff --git a/api/v1alpha2/tenant_types.go b/api/v1alpha2/tenant_types.go index acc85259f..311a9a5fc 100644 --- a/api/v1alpha2/tenant_types.go +++ b/api/v1alpha2/tenant_types.go @@ -7,27 +7,47 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! -// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. - // TenantSpec defines the desired state of Tenant type TenantSpec struct { - // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster - // Important: Run "make" to regenerate code after modifying this file + Owner OwnerSpec `json:"owner"` + + //+kubebuilder:validation:Minimum=1 + NamespaceQuota *int32 `json:"namespaceQuota,omitempty"` + NamespacesMetadata *AdditionalMetadataSpec `json:"namespacesMetadata,omitempty"` + ServicesMetadata *AdditionalMetadataSpec `json:"servicesMetadata,omitempty"` + StorageClasses *AllowedListSpec `json:"storageClasses,omitempty"` + IngressClasses *AllowedListSpec `json:"ingressClasses,omitempty"` + IngressHostnames *AllowedListSpec `json:"ingressHostnames,omitempty"` + ContainerRegistries *AllowedListSpec `json:"containerRegistries,omitempty"` + NodeSelector map[string]string `json:"nodeSelector,omitempty"` + NetworkPolicies *NetworkPolicySpec `json:"networkPolicies,omitempty"` + LimitRanges *LimitRangesSpec `json:"limitRanges,omitempty"` + ResourceQuota *ResourceQuotaSpec `json:"resourceQuotas,omitempty"` + AdditionalRoleBindings []AdditionalRoleBindingsSpec `json:"additionalRoleBindings,omitempty"` + ExternalServiceIPs *ExternalServiceIPsSpec `json:"externalServiceIPs,omitempty"` + ImagePullPolicies []ImagePullPolicySpec `json:"imagePullPolicies,omitempty"` + PriorityClasses *AllowedListSpec `json:"priorityClasses,omitempty"` - // Foo is an example field of Tenant. Edit tenant_types.go to remove/update - Foo string `json:"foo,omitempty"` + //+kubebuilder:default=true + EnableNodePorts bool `json:"enableNodePorts,omitempty"` } // TenantStatus defines the observed state of Tenant type TenantStatus struct { - // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster - // Important: Run "make" to regenerate code after modifying this file + Size uint `json:"size"` + Namespaces []string `json:"namespaces,omitempty"` } //+kubebuilder:object:root=true //+kubebuilder:subresource:status //+kubebuilder:storageversion +// +kubebuilder:resource:scope=Cluster,shortName=tnt +// +kubebuilder:printcolumn:name="Namespace quota",type="integer",JSONPath=".spec.namespaceQuota",description="The max amount of Namespaces can be created" +// +kubebuilder:printcolumn:name="Namespace count",type="integer",JSONPath=".status.size",description="The total amount of Namespaces in use" +// +kubebuilder:printcolumn:name="Owner name",type="string",JSONPath=".spec.owner.name",description="The assigned Tenant owner" +// +kubebuilder:printcolumn:name="Owner kind",type="string",JSONPath=".spec.owner.kind",description="The assigned Tenant owner kind" +// +kubebuilder:printcolumn:name="Node selector",type="string",JSONPath=".spec.nodeSelector",description="Node Selector applied to Pods" +// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Age" // Tenant is the Schema for the tenants API type Tenant struct { @@ -38,9 +58,7 @@ type Tenant struct { Status TenantStatus `json:"status,omitempty"` } -func (in *Tenant) Hub() { - return -} +func (t *Tenant) Hub() {} //+kubebuilder:object:root=true diff --git a/api/v1alpha2/zz_generated.deepcopy.go b/api/v1alpha2/zz_generated.deepcopy.go index c3273db76..79877259b 100644 --- a/api/v1alpha2/zz_generated.deepcopy.go +++ b/api/v1alpha2/zz_generated.deepcopy.go @@ -8,16 +8,189 @@ package v1alpha2 import ( - runtime "k8s.io/apimachinery/pkg/runtime" + corev1 "k8s.io/api/core/v1" + networkingv1 "k8s.io/api/networking/v1" + v1 "k8s.io/api/rbac/v1" + "k8s.io/apimachinery/pkg/runtime" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AdditionalMetadataSpec) DeepCopyInto(out *AdditionalMetadataSpec) { + *out = *in + if in.AdditionalLabels != nil { + in, out := &in.AdditionalLabels, &out.AdditionalLabels + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + if in.AdditionalAnnotations != nil { + in, out := &in.AdditionalAnnotations, &out.AdditionalAnnotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AdditionalMetadataSpec. +func (in *AdditionalMetadataSpec) DeepCopy() *AdditionalMetadataSpec { + if in == nil { + return nil + } + out := new(AdditionalMetadataSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AdditionalRoleBindingsSpec) DeepCopyInto(out *AdditionalRoleBindingsSpec) { + *out = *in + if in.Subjects != nil { + in, out := &in.Subjects, &out.Subjects + *out = make([]v1.Subject, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AdditionalRoleBindingsSpec. +func (in *AdditionalRoleBindingsSpec) DeepCopy() *AdditionalRoleBindingsSpec { + if in == nil { + return nil + } + out := new(AdditionalRoleBindingsSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AllowedListSpec) DeepCopyInto(out *AllowedListSpec) { + *out = *in + if in.Exact != nil { + in, out := &in.Exact, &out.Exact + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AllowedListSpec. +func (in *AllowedListSpec) DeepCopy() *AllowedListSpec { + if in == nil { + return nil + } + out := new(AllowedListSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ExternalServiceIPsSpec) DeepCopyInto(out *ExternalServiceIPsSpec) { + *out = *in + if in.Allowed != nil { + in, out := &in.Allowed, &out.Allowed + *out = make([]AllowedIP, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalServiceIPsSpec. +func (in *ExternalServiceIPsSpec) DeepCopy() *ExternalServiceIPsSpec { + if in == nil { + return nil + } + out := new(ExternalServiceIPsSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LimitRangesSpec) DeepCopyInto(out *LimitRangesSpec) { + *out = *in + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]corev1.LimitRangeSpec, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LimitRangesSpec. +func (in *LimitRangesSpec) DeepCopy() *LimitRangesSpec { + if in == nil { + return nil + } + out := new(LimitRangesSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NetworkPolicySpec) DeepCopyInto(out *NetworkPolicySpec) { + *out = *in + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]networkingv1.NetworkPolicySpec, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkPolicySpec. +func (in *NetworkPolicySpec) DeepCopy() *NetworkPolicySpec { + if in == nil { + return nil + } + out := new(NetworkPolicySpec) + 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 +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OwnerSpec. +func (in *OwnerSpec) DeepCopy() *OwnerSpec { + if in == nil { + return nil + } + out := new(OwnerSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ResourceQuotaSpec) DeepCopyInto(out *ResourceQuotaSpec) { + *out = *in + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]corev1.ResourceQuotaSpec, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceQuotaSpec. +func (in *ResourceQuotaSpec) DeepCopy() *ResourceQuotaSpec { + if in == nil { + return nil + } + out := new(ResourceQuotaSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Tenant) DeepCopyInto(out *Tenant) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - out.Status = in.Status + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Tenant. @@ -73,6 +246,86 @@ func (in *TenantList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TenantSpec) DeepCopyInto(out *TenantSpec) { *out = *in + out.Owner = in.Owner + if in.NamespaceQuota != nil { + in, out := &in.NamespaceQuota, &out.NamespaceQuota + *out = new(int32) + **out = **in + } + if in.NamespacesMetadata != nil { + in, out := &in.NamespacesMetadata, &out.NamespacesMetadata + *out = new(AdditionalMetadataSpec) + (*in).DeepCopyInto(*out) + } + if in.ServicesMetadata != nil { + in, out := &in.ServicesMetadata, &out.ServicesMetadata + *out = new(AdditionalMetadataSpec) + (*in).DeepCopyInto(*out) + } + if in.StorageClasses != nil { + in, out := &in.StorageClasses, &out.StorageClasses + *out = new(AllowedListSpec) + (*in).DeepCopyInto(*out) + } + if in.IngressClasses != nil { + in, out := &in.IngressClasses, &out.IngressClasses + *out = new(AllowedListSpec) + (*in).DeepCopyInto(*out) + } + if in.IngressHostnames != nil { + in, out := &in.IngressHostnames, &out.IngressHostnames + *out = new(AllowedListSpec) + (*in).DeepCopyInto(*out) + } + if in.ContainerRegistries != nil { + in, out := &in.ContainerRegistries, &out.ContainerRegistries + *out = new(AllowedListSpec) + (*in).DeepCopyInto(*out) + } + if in.NodeSelector != nil { + in, out := &in.NodeSelector, &out.NodeSelector + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + if in.NetworkPolicies != nil { + in, out := &in.NetworkPolicies, &out.NetworkPolicies + *out = new(NetworkPolicySpec) + (*in).DeepCopyInto(*out) + } + if in.LimitRanges != nil { + in, out := &in.LimitRanges, &out.LimitRanges + *out = new(LimitRangesSpec) + (*in).DeepCopyInto(*out) + } + if in.ResourceQuota != nil { + in, out := &in.ResourceQuota, &out.ResourceQuota + *out = new(ResourceQuotaSpec) + (*in).DeepCopyInto(*out) + } + if in.AdditionalRoleBindings != nil { + in, out := &in.AdditionalRoleBindings, &out.AdditionalRoleBindings + *out = make([]AdditionalRoleBindingsSpec, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.ExternalServiceIPs != nil { + in, out := &in.ExternalServiceIPs, &out.ExternalServiceIPs + *out = new(ExternalServiceIPsSpec) + (*in).DeepCopyInto(*out) + } + if in.ImagePullPolicies != nil { + in, out := &in.ImagePullPolicies, &out.ImagePullPolicies + *out = make([]ImagePullPolicySpec, len(*in)) + copy(*out, *in) + } + if in.PriorityClasses != nil { + in, out := &in.PriorityClasses, &out.PriorityClasses + *out = new(AllowedListSpec) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TenantSpec. @@ -88,6 +341,11 @@ func (in *TenantSpec) DeepCopy() *TenantSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TenantStatus) DeepCopyInto(out *TenantStatus) { *out = *in + if in.Namespaces != nil { + in, out := &in.Namespaces, &out.Namespaces + *out = make([]string, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TenantStatus. diff --git a/config/crd/bases/capsule.clastix.io_tenants.yaml b/config/crd/bases/capsule.clastix.io_tenants.yaml index 989bf008f..de45fe64a 100644 --- a/config/crd/bases/capsule.clastix.io_tenants.yaml +++ b/config/crd/bases/capsule.clastix.io_tenants.yaml @@ -566,7 +566,32 @@ spec: storage: false subresources: status: {} - - name: v1alpha2 + - additionalPrinterColumns: + - description: The max amount of Namespaces can be created + jsonPath: .spec.namespaceQuota + name: Namespace quota + type: integer + - description: The total amount of Namespaces in use + jsonPath: .status.size + name: Namespace count + type: integer + - description: The assigned Tenant owner + jsonPath: .spec.owner.name + name: Owner name + type: string + - description: The assigned Tenant owner kind + jsonPath: .spec.owner.kind + name: Owner kind + type: string + - description: Node Selector applied to Pods + jsonPath: .spec.nodeSelector + name: Node selector + type: string + - description: Age + jsonPath: .metadata.creationTimestamp + name: Age + type: date + name: v1alpha2 schema: openAPIV3Schema: description: Tenant is the Schema for the tenants API @@ -582,12 +607,536 @@ spec: spec: description: TenantSpec defines the desired state of Tenant properties: - foo: - description: Foo is an example field of Tenant. Edit tenant_types.go to remove/update - type: string + additionalRoleBindings: + items: + properties: + clusterRoleName: + type: string + subjects: + description: kubebuilder:validation:Minimum=1 + items: + description: Subject contains a reference to the object or user identities a role binding applies to. This can either hold a direct API object reference, or a value for non-objects such as user and group names. + properties: + apiGroup: + description: APIGroup holds the API group of the referenced subject. Defaults to "" for ServiceAccount subjects. Defaults to "rbac.authorization.k8s.io" for User and Group subjects. + type: string + kind: + description: Kind of object being referenced. Values defined by this API group are "User", "Group", and "ServiceAccount". If the Authorizer does not recognized the kind value, the Authorizer should report an error. + type: string + name: + description: Name of the object being referenced. + type: string + namespace: + description: Namespace of the referenced object. If the object kind is non-namespace, such as "User" or "Group", and this value is not empty the Authorizer should report an error. + type: string + required: + - kind + - name + type: object + type: array + required: + - clusterRoleName + - subjects + type: object + type: array + containerRegistries: + properties: + allowed: + items: + type: string + type: array + allowedRegex: + type: string + type: object + enableNodePorts: + default: true + type: boolean + externalServiceIPs: + properties: + allowed: + items: + pattern: ^([0-9]{1,3}.){3}[0-9]{1,3}(/([0-9]|[1-2][0-9]|3[0-2]))?$ + type: string + type: array + required: + - allowed + type: object + imagePullPolicies: + items: + enum: + - Always + - Never + - IfNotPresent + type: string + type: array + ingressClasses: + properties: + allowed: + items: + type: string + type: array + allowedRegex: + type: string + type: object + ingressHostnames: + properties: + allowed: + items: + type: string + type: array + allowedRegex: + type: string + type: object + limitRanges: + properties: + items: + items: + description: LimitRangeSpec defines a min/max usage limit for resources that match on kind. + properties: + limits: + description: Limits is the list of LimitRangeItem objects that are enforced. + items: + description: LimitRangeItem defines a min/max usage limit for any resource that matches on kind. + properties: + default: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: Default resource requirement limit value by resource name if resource limit is omitted. + type: object + defaultRequest: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: DefaultRequest is the default resource requirement request value by resource name if resource request is omitted. + type: object + max: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: Max usage constraints on this kind by resource name. + type: object + maxLimitRequestRatio: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: MaxLimitRequestRatio if specified, the named resource must have a request and limit that are both non-zero where limit divided by request is less than or equal to the enumerated value; this represents the max burst for the named resource. + type: object + min: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: Min usage constraints on this kind by resource name. + type: object + type: + description: Type of resource that this limit applies to. + type: string + required: + - type + type: object + type: array + required: + - limits + type: object + type: array + type: object + namespaceQuota: + format: int32 + minimum: 1 + type: integer + namespacesMetadata: + properties: + additionalAnnotations: + additionalProperties: + type: string + type: object + additionalLabels: + additionalProperties: + type: string + type: object + type: object + networkPolicies: + properties: + items: + items: + description: NetworkPolicySpec provides the specification of a NetworkPolicy + properties: + egress: + description: List of egress rules to be applied to the selected pods. Outgoing traffic is allowed if there are no NetworkPolicies selecting the pod (and cluster policy otherwise allows the traffic), OR if the traffic matches at least one egress rule across all of the NetworkPolicy objects whose podSelector matches the pod. If this field is empty then this NetworkPolicy limits all outgoing traffic (and serves solely to ensure that the pods it selects are isolated by default). This field is beta-level in 1.8 + items: + description: NetworkPolicyEgressRule describes a particular set of traffic that is allowed out of pods matched by a NetworkPolicySpec's podSelector. The traffic must match both ports and to. This type is beta-level in 1.8 + properties: + ports: + description: List of destination ports for outgoing traffic. Each item in this list is combined using a logical OR. If this field is empty or missing, this rule matches all ports (traffic not restricted by port). If this field is present and contains at least one item, then this rule allows traffic only if the traffic matches at least one port in the list. + items: + description: NetworkPolicyPort describes a port to allow traffic on + properties: + port: + anyOf: + - type: integer + - type: string + description: The port on the given protocol. This can either be a numerical or named port on a pod. If this field is not provided, this matches all port names and numbers. + x-kubernetes-int-or-string: true + protocol: + default: TCP + description: The protocol (TCP, UDP, or SCTP) which traffic must match. If not specified, this field defaults to TCP. + type: string + type: object + type: array + to: + description: List of destinations for outgoing traffic of pods selected for this rule. Items in this list are combined using a logical OR operation. If this field is empty or missing, this rule matches all destinations (traffic not restricted by destination). If this field is present and contains at least one item, this rule allows traffic only if the traffic matches at least one item in the to list. + items: + description: NetworkPolicyPeer describes a peer to allow traffic to/from. Only certain combinations of fields are allowed + properties: + ipBlock: + description: IPBlock defines policy on a particular IPBlock. If this field is set then neither of the other fields can be. + properties: + cidr: + description: CIDR is a string representing the IP Block Valid examples are "192.168.1.1/24" or "2001:db9::/64" + type: string + except: + description: Except is a slice of CIDRs that should not be included within an IP Block Valid examples are "192.168.1.1/24" or "2001:db9::/64" Except values will be rejected if they are outside the CIDR range + items: + type: string + type: array + required: + - cidr + type: object + namespaceSelector: + description: "Selects Namespaces using cluster-scoped labels. This field follows standard label selector semantics; if present but empty, it selects all namespaces. \n If PodSelector is also set, then the NetworkPolicyPeer as a whole selects the Pods matching PodSelector in the Namespaces selected by NamespaceSelector. Otherwise it selects all Pods in the Namespaces selected by NamespaceSelector." + properties: + matchExpressions: + description: matchExpressions is a list of label selector requirements. The requirements are ANDed. + items: + description: A label selector requirement is a selector that contains values, a key, and an operator that relates the key and values. + properties: + key: + description: key is the label key that the selector applies to. + type: string + operator: + description: operator represents a key's relationship to a set of values. Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: values is an array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. This array is replaced during a strategic merge patch. + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + description: matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + podSelector: + description: "This is a label selector which selects Pods. This field follows standard label selector semantics; if present but empty, it selects all pods. \n If NamespaceSelector is also set, then the NetworkPolicyPeer as a whole selects the Pods matching PodSelector in the Namespaces selected by NamespaceSelector. Otherwise it selects the Pods matching PodSelector in the policy's own Namespace." + properties: + matchExpressions: + description: matchExpressions is a list of label selector requirements. The requirements are ANDed. + items: + description: A label selector requirement is a selector that contains values, a key, and an operator that relates the key and values. + properties: + key: + description: key is the label key that the selector applies to. + type: string + operator: + description: operator represents a key's relationship to a set of values. Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: values is an array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. This array is replaced during a strategic merge patch. + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + description: matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + type: object + type: array + type: object + type: array + ingress: + description: List of ingress rules to be applied to the selected pods. Traffic is allowed to a pod if there are no NetworkPolicies selecting the pod (and cluster policy otherwise allows the traffic), OR if the traffic source is the pod's local node, OR if the traffic matches at least one ingress rule across all of the NetworkPolicy objects whose podSelector matches the pod. If this field is empty then this NetworkPolicy does not allow any traffic (and serves solely to ensure that the pods it selects are isolated by default) + items: + description: NetworkPolicyIngressRule describes a particular set of traffic that is allowed to the pods matched by a NetworkPolicySpec's podSelector. The traffic must match both ports and from. + properties: + from: + description: List of sources which should be able to access the pods selected for this rule. Items in this list are combined using a logical OR operation. If this field is empty or missing, this rule matches all sources (traffic not restricted by source). If this field is present and contains at least one item, this rule allows traffic only if the traffic matches at least one item in the from list. + items: + description: NetworkPolicyPeer describes a peer to allow traffic to/from. Only certain combinations of fields are allowed + properties: + ipBlock: + description: IPBlock defines policy on a particular IPBlock. If this field is set then neither of the other fields can be. + properties: + cidr: + description: CIDR is a string representing the IP Block Valid examples are "192.168.1.1/24" or "2001:db9::/64" + type: string + except: + description: Except is a slice of CIDRs that should not be included within an IP Block Valid examples are "192.168.1.1/24" or "2001:db9::/64" Except values will be rejected if they are outside the CIDR range + items: + type: string + type: array + required: + - cidr + type: object + namespaceSelector: + description: "Selects Namespaces using cluster-scoped labels. This field follows standard label selector semantics; if present but empty, it selects all namespaces. \n If PodSelector is also set, then the NetworkPolicyPeer as a whole selects the Pods matching PodSelector in the Namespaces selected by NamespaceSelector. Otherwise it selects all Pods in the Namespaces selected by NamespaceSelector." + properties: + matchExpressions: + description: matchExpressions is a list of label selector requirements. The requirements are ANDed. + items: + description: A label selector requirement is a selector that contains values, a key, and an operator that relates the key and values. + properties: + key: + description: key is the label key that the selector applies to. + type: string + operator: + description: operator represents a key's relationship to a set of values. Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: values is an array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. This array is replaced during a strategic merge patch. + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + description: matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + podSelector: + description: "This is a label selector which selects Pods. This field follows standard label selector semantics; if present but empty, it selects all pods. \n If NamespaceSelector is also set, then the NetworkPolicyPeer as a whole selects the Pods matching PodSelector in the Namespaces selected by NamespaceSelector. Otherwise it selects the Pods matching PodSelector in the policy's own Namespace." + properties: + matchExpressions: + description: matchExpressions is a list of label selector requirements. The requirements are ANDed. + items: + description: A label selector requirement is a selector that contains values, a key, and an operator that relates the key and values. + properties: + key: + description: key is the label key that the selector applies to. + type: string + operator: + description: operator represents a key's relationship to a set of values. Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: values is an array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. This array is replaced during a strategic merge patch. + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + description: matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + type: object + type: array + ports: + description: List of ports which should be made accessible on the pods selected for this rule. Each item in this list is combined using a logical OR. If this field is empty or missing, this rule matches all ports (traffic not restricted by port). If this field is present and contains at least one item, then this rule allows traffic only if the traffic matches at least one port in the list. + items: + description: NetworkPolicyPort describes a port to allow traffic on + properties: + port: + anyOf: + - type: integer + - type: string + description: The port on the given protocol. This can either be a numerical or named port on a pod. If this field is not provided, this matches all port names and numbers. + x-kubernetes-int-or-string: true + protocol: + default: TCP + description: The protocol (TCP, UDP, or SCTP) which traffic must match. If not specified, this field defaults to TCP. + type: string + type: object + type: array + type: object + type: array + podSelector: + description: Selects the pods to which this NetworkPolicy object applies. The array of ingress rules is applied to any pods selected by this field. Multiple network policies can select the same set of pods. In this case, the ingress rules for each are combined additively. This field is NOT optional and follows standard label selector semantics. An empty podSelector matches all pods in this namespace. + properties: + matchExpressions: + description: matchExpressions is a list of label selector requirements. The requirements are ANDed. + items: + description: A label selector requirement is a selector that contains values, a key, and an operator that relates the key and values. + properties: + key: + description: key is the label key that the selector applies to. + type: string + operator: + description: operator represents a key's relationship to a set of values. Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: values is an array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. This array is replaced during a strategic merge patch. + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + description: matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + policyTypes: + description: List of rule types that the NetworkPolicy relates to. Valid options are "Ingress", "Egress", or "Ingress,Egress". If this field is not specified, it will default based on the existence of Ingress or Egress rules; policies that contain an Egress section are assumed to affect Egress, and all policies (whether or not they contain an Ingress section) are assumed to affect Ingress. If you want to write an egress-only policy, you must explicitly specify policyTypes [ "Egress" ]. Likewise, if you want to write a policy that specifies that no egress is allowed, you must specify a policyTypes value that include "Egress" (since such a policy would not include an Egress section and would otherwise default to just [ "Ingress" ]). This field is beta-level in 1.8 + items: + description: Policy Type string describes the NetworkPolicy type This type is beta-level in 1.8 + type: string + type: array + required: + - podSelector + type: object + type: array + type: object + nodeSelector: + additionalProperties: + type: string + type: object + owner: + description: OwnerSpec defines tenant owner name and kind + properties: + kind: + enum: + - User + - Group + type: string + name: + type: string + required: + - kind + - name + type: object + priorityClasses: + properties: + allowed: + items: + type: string + type: array + allowedRegex: + type: string + type: object + resourceQuotas: + properties: + items: + items: + description: ResourceQuotaSpec defines the desired hard limits to enforce for Quota. + properties: + hard: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: 'hard is the set of desired hard limits for each named resource. More info: https://kubernetes.io/docs/concepts/policy/resource-quotas/' + type: object + scopeSelector: + description: scopeSelector is also a collection of filters like scopes that must match each object tracked by a quota but expressed using ScopeSelectorOperator in combination with possible values. For a resource to match, both scopes AND scopeSelector (if specified in spec), must be matched. + properties: + matchExpressions: + description: A list of scope selector requirements by scope of the resources. + items: + description: A scoped-resource selector requirement is a selector that contains values, a scope name, and an operator that relates the scope name and values. + properties: + operator: + description: Represents a scope's relationship to a set of values. Valid operators are In, NotIn, Exists, DoesNotExist. + type: string + scopeName: + description: The name of the scope that the selector applies to. + type: string + values: + description: An array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. This array is replaced during a strategic merge patch. + items: + type: string + type: array + required: + - operator + - scopeName + type: object + type: array + type: object + scopes: + description: A collection of filters that must match each object tracked by a quota. If not specified, the quota matches all objects. + items: + description: A ResourceQuotaScope defines a filter that must match each object tracked by a quota + type: string + type: array + type: object + type: array + type: object + servicesMetadata: + properties: + additionalAnnotations: + additionalProperties: + type: string + type: object + additionalLabels: + additionalProperties: + type: string + type: object + type: object + storageClasses: + properties: + allowed: + items: + type: string + type: array + allowedRegex: + type: string + type: object + required: + - owner type: object status: description: TenantStatus defines the observed state of Tenant + properties: + namespaces: + items: + type: string + type: array + size: + type: integer + required: + - size type: object type: object served: true