From c47da9de592f0de4b8712dbe79bcf1008adc8b1c Mon Sep 17 00:00:00 2001 From: Maksim Fedotov Date: Thu, 8 Jul 2021 11:36:47 +0300 Subject: [PATCH 1/4] feat: support multiple tenant owners(add applications to act as tenant owners) --- api/v1alpha1/conversion_hub.go | 218 +++++++++++++++++- api/v1alpha1/conversion_hub_test.go | 141 ++++++++++- api/v1beta1/owner.go | 30 ++- api/v1beta1/tenant_types.go | 4 +- api/v1beta1/zz_generated.deepcopy.go | 35 ++- .../crd/bases/capsule.clastix.io_tenants.yaml | 63 +++-- controllers/tenant_controller.go | 26 ++- pkg/indexer/tenant/owner.go | 2 +- pkg/utils/owner.go | 13 +- pkg/webhook/ownerreference/patching.go | 38 ++- pkg/webhook/utils/is_tenant_or_sa_request.go | 27 +-- 11 files changed, 511 insertions(+), 86 deletions(-) diff --git a/api/v1alpha1/conversion_hub.go b/api/v1alpha1/conversion_hub.go index 691f342c..5b5bcd2e 100644 --- a/api/v1alpha1/conversion_hub.go +++ b/api/v1alpha1/conversion_hub.go @@ -17,11 +17,112 @@ import ( const ( podAllowedImagePullPolicyAnnotation = "capsule.clastix.io/allowed-image-pull-policy" - podPriorityAllowedAnnotation = "priorityclass.capsule.clastix.io/allowed" - podPriorityAllowedRegexAnnotation = "priorityclass.capsule.clastix.io/allowed-regex" - enableNodePortsAnnotation = "capsule.clastix.io/enable-node-ports" + + podPriorityAllowedAnnotation = "priorityclass.capsule.clastix.io/allowed" + podPriorityAllowedRegexAnnotation = "priorityclass.capsule.clastix.io/allowed-regex" + + enableNodePortsAnnotation = "capsule.clastix.io/enable-node-ports" + + ownerGroupsAnnotation = "owners.capsule.clastix.io/group" + ownerUsersAnnotation = "owners.capsule.clastix.io/user" + ownerServiceAccountAnnotation = "owners.capsule.clastix.io/serviceaccount" + + enableNodeListingAnnotation = "capsule.clastix.io/enable-node-listing" + enableNodeUpdateAnnotation = "capsule.clastix.io/enable-node-update" + enableNodeDeletionAnnotation = "capsule.clastix.io/enable-node-deletion" + enableStorageClassListingAnnotation = "capsule.clastix.io/enable-storageclass-listing" + enableStorageClassUpdateAnnotation = "capsule.clastix.io/enable-storageclass-update" + enableStorageClassDeletionAnnotation = "capsule.clastix.io/enable-storageclass-deletion" + enableIngressClassListingAnnotation = "capsule.clastix.io/enable-ingressclass-listing" + enableIngressClassUpdateAnnotation = "capsule.clastix.io/enable-ingressclass-update" + enableIngressClassDeletionAnnotation = "capsule.clastix.io/enable-ingressclass-deletion" + + listOperation = "List" + updateOperation = "Update" + deleteOperation = "Delete" + + nodesServiceKind = "Nodes" + storageClassesServiceKind = "StorageClasses" + ingressClassesServiceKind = "IngressClasses" ) +func (t *Tenant) convertV1Alpha1OwnerToV1Beta1() []capsulev1beta1.OwnerSpec { + var serviceKindToAnnotationMap = map[capsulev1beta1.ProxyServiceKind][]string{ + nodesServiceKind: {enableNodeListingAnnotation, enableNodeUpdateAnnotation, enableNodeDeletionAnnotation}, + storageClassesServiceKind: {enableStorageClassListingAnnotation, enableStorageClassUpdateAnnotation, enableStorageClassDeletionAnnotation}, + ingressClassesServiceKind: {enableIngressClassListingAnnotation, enableIngressClassUpdateAnnotation, enableIngressClassDeletionAnnotation}, + } + var annotationToOperationMap = map[string]capsulev1beta1.ProxyOperation{ + enableNodeListingAnnotation: listOperation, + enableNodeUpdateAnnotation: updateOperation, + enableNodeDeletionAnnotation: deleteOperation, + enableStorageClassListingAnnotation: listOperation, + enableStorageClassUpdateAnnotation: updateOperation, + enableStorageClassDeletionAnnotation: deleteOperation, + enableIngressClassListingAnnotation: listOperation, + enableIngressClassUpdateAnnotation: updateOperation, + enableIngressClassDeletionAnnotation: deleteOperation, + } + var annotationToOwnerKindMap = map[string]capsulev1beta1.OwnerKind{ + ownerUsersAnnotation: "User", + ownerGroupsAnnotation: "Group", + ownerServiceAccountAnnotation: "ServiceAccount", + } + annotations := t.GetAnnotations() + + var operations = make(map[string]map[capsulev1beta1.ProxyServiceKind][]capsulev1beta1.ProxyOperation) + + for serviceKind, operationAnnotations := range serviceKindToAnnotationMap { + for _, operationAnnotation := range operationAnnotations { + val, ok := annotations[operationAnnotation] + if ok { + for _, owner := range strings.Split(val, ",") { + if _, exists := operations[owner]; !exists { + operations[owner] = make(map[capsulev1beta1.ProxyServiceKind][]capsulev1beta1.ProxyOperation) + } + operations[owner][serviceKind] = append(operations[owner][serviceKind], annotationToOperationMap[operationAnnotation]) + } + } + } + } + + var owners []capsulev1beta1.OwnerSpec + + var getProxySettingsForOwner = func(ownerName string) (settings []capsulev1beta1.ProxySettings) { + ownerOperations, ok := operations[ownerName] + if ok { + for k, v := range ownerOperations { + settings = append(settings, capsulev1beta1.ProxySettings{ + Kind: k, + Operations: v, + }) + } + } + return + } + + owners = append(owners, capsulev1beta1.OwnerSpec{ + Kind: capsulev1beta1.OwnerKind(t.Spec.Owner.Kind), + Name: t.Spec.Owner.Name, + ProxyOperations: getProxySettingsForOwner(t.Spec.Owner.Name), + }) + + for ownerAnnotation, ownerKind := range annotationToOwnerKindMap { + val, ok := annotations[ownerAnnotation] + if ok { + for _, owner := range strings.Split(val, ",") { + owners = append(owners, capsulev1beta1.OwnerSpec{ + Kind: ownerKind, + Name: owner, + ProxyOperations: getProxySettingsForOwner(owner), + }) + } + } + } + + return owners +} + func (t *Tenant) ConvertTo(dstRaw conversion.Hub) error { dst := dstRaw.(*capsulev1beta1.Tenant) annotations := t.GetAnnotations() @@ -33,10 +134,7 @@ func (t *Tenant) ConvertTo(dstRaw conversion.Hub) error { dst.Spec.NamespaceQuota = t.Spec.NamespaceQuota dst.Spec.NodeSelector = t.Spec.NodeSelector - dst.Spec.Owner = capsulev1beta1.OwnerSpec{ - Name: t.Spec.Owner.Name, - Kind: capsulev1beta1.Kind(t.Spec.Owner.Kind), - } + dst.Spec.Owners = t.convertV1Alpha1OwnerToV1Beta1() if t.Spec.NamespacesMetadata != nil { dst.Spec.NamespacesMetadata = &capsulev1beta1.AdditionalMetadataSpec{ @@ -150,10 +248,109 @@ func (t *Tenant) ConvertTo(dstRaw conversion.Hub) error { delete(dst.ObjectMeta.Annotations, podPriorityAllowedAnnotation) delete(dst.ObjectMeta.Annotations, podPriorityAllowedRegexAnnotation) delete(dst.ObjectMeta.Annotations, enableNodePortsAnnotation) + delete(dst.ObjectMeta.Annotations, ownerGroupsAnnotation) + delete(dst.ObjectMeta.Annotations, ownerUsersAnnotation) + delete(dst.ObjectMeta.Annotations, ownerServiceAccountAnnotation) + delete(dst.ObjectMeta.Annotations, enableNodeListingAnnotation) + delete(dst.ObjectMeta.Annotations, enableNodeUpdateAnnotation) + delete(dst.ObjectMeta.Annotations, enableNodeDeletionAnnotation) + delete(dst.ObjectMeta.Annotations, enableStorageClassListingAnnotation) + delete(dst.ObjectMeta.Annotations, enableStorageClassUpdateAnnotation) + delete(dst.ObjectMeta.Annotations, enableStorageClassDeletionAnnotation) + delete(dst.ObjectMeta.Annotations, enableIngressClassListingAnnotation) + delete(dst.ObjectMeta.Annotations, enableIngressClassUpdateAnnotation) + delete(dst.ObjectMeta.Annotations, enableIngressClassDeletionAnnotation) return nil } +func (t *Tenant) convertV1Beta1OwnerToV1Alpha1(src *capsulev1beta1.Tenant) { + var ownersAnnotations = map[string][]string{ + ownerGroupsAnnotation: nil, + ownerUsersAnnotation: nil, + ownerServiceAccountAnnotation: nil, + } + + var proxyAnnotations = map[string][]string{ + enableNodeListingAnnotation: nil, + enableNodeUpdateAnnotation: nil, + enableNodeDeletionAnnotation: nil, + enableStorageClassListingAnnotation: nil, + enableStorageClassUpdateAnnotation: nil, + enableStorageClassDeletionAnnotation: nil, + enableIngressClassListingAnnotation: nil, + enableIngressClassUpdateAnnotation: nil, + enableIngressClassDeletionAnnotation: nil, + } + + + for i, owner := range src.Spec.Owners { + if i == 0 { + t.Spec.Owner = OwnerSpec{ + Name: owner.Name, + Kind: Kind(owner.Kind), + } + } else { + switch owner.Kind { + case "User": + ownersAnnotations[ownerUsersAnnotation] = append(ownersAnnotations[ownerUsersAnnotation], owner.Name) + case "Group": + ownersAnnotations[ownerGroupsAnnotation] = append(ownersAnnotations[ownerGroupsAnnotation], owner.Name) + case "ServiceAccount": + ownersAnnotations[ownerServiceAccountAnnotation] = append(ownersAnnotations[ownerServiceAccountAnnotation], owner.Name) + } + } + for _, setting := range owner.ProxyOperations { + switch setting.Kind { + case nodesServiceKind: + for _, operation := range setting.Operations { + switch operation { + case listOperation: + proxyAnnotations[enableNodeListingAnnotation] = append(proxyAnnotations[enableNodeListingAnnotation], owner.Name) + case updateOperation: + proxyAnnotations[enableNodeUpdateAnnotation] = append(proxyAnnotations[enableNodeUpdateAnnotation], owner.Name) + case deleteOperation: + proxyAnnotations[enableNodeDeletionAnnotation] = append(proxyAnnotations[enableNodeDeletionAnnotation], owner.Name) + } + } + case storageClassesServiceKind: + for _, operation := range setting.Operations { + switch operation { + case listOperation: + proxyAnnotations[enableStorageClassListingAnnotation] = append(proxyAnnotations[enableStorageClassListingAnnotation], owner.Name) + case updateOperation: + proxyAnnotations[enableStorageClassUpdateAnnotation] = append(proxyAnnotations[enableStorageClassUpdateAnnotation], owner.Name) + case deleteOperation: + proxyAnnotations[enableStorageClassDeletionAnnotation] = append(proxyAnnotations[enableStorageClassDeletionAnnotation], owner.Name) + } + } + case ingressClassesServiceKind: + for _, operation := range setting.Operations { + switch operation { + case listOperation: + proxyAnnotations[enableIngressClassListingAnnotation] = append(proxyAnnotations[enableIngressClassListingAnnotation], owner.Name) + case updateOperation: + proxyAnnotations[enableIngressClassUpdateAnnotation] = append(proxyAnnotations[enableIngressClassUpdateAnnotation], owner.Name) + case deleteOperation: + proxyAnnotations[enableIngressClassDeletionAnnotation] = append(proxyAnnotations[enableIngressClassDeletionAnnotation], owner.Name) + } + } + } + } + } + + for k, v := range ownersAnnotations { + if len(v) > 0 { + t.Annotations[k] = strings.Join(v, ",") + } + } + for k, v := range proxyAnnotations { + if len(v) > 0 { + t.Annotations[k] = strings.Join(v, ",") + } + } +} + func (t *Tenant) ConvertFrom(srcRaw conversion.Hub) error { src := srcRaw.(*capsulev1beta1.Tenant) @@ -164,11 +361,12 @@ func (t *Tenant) ConvertFrom(srcRaw conversion.Hub) error { t.Spec.NamespaceQuota = src.Spec.NamespaceQuota t.Spec.NodeSelector = src.Spec.NodeSelector - t.Spec.Owner = OwnerSpec{ - Name: src.Spec.Owner.Name, - Kind: Kind(src.Spec.Owner.Kind), + if t.Annotations == nil { + t.Annotations = make(map[string]string) } + t.convertV1Beta1OwnerToV1Alpha1(src) + if src.Spec.NamespacesMetadata != nil { t.Spec.NamespacesMetadata = &AdditionalMetadataSpec{ AdditionalLabels: src.Spec.NamespacesMetadata.AdditionalLabels, diff --git a/api/v1alpha1/conversion_hub_test.go b/api/v1alpha1/conversion_hub_test.go index bdde038d..02924808 100644 --- a/api/v1alpha1/conversion_hub_test.go +++ b/api/v1alpha1/conversion_hub_test.go @@ -4,6 +4,7 @@ package v1alpha1 import ( + "sort" "testing" "github.com/stretchr/testify/assert" @@ -113,9 +114,101 @@ func generateTenantsSpecs() (Tenant, capsulev1beta1.Tenant) { }, }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "alice", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Kind: "User", + Name: "alice", + ProxyOperations: []capsulev1beta1.ProxySettings{ + { + Kind: "IngressClasses", + Operations: []capsulev1beta1.ProxyOperation{"List", "Update", "Delete"}, + }, + { + Kind: "Nodes", + Operations: []capsulev1beta1.ProxyOperation{"Update", "Delete"}, + }, + { + Kind: "StorageClasses", + Operations: []capsulev1beta1.ProxyOperation{"Update", "Delete"}, + }, + }, + }, + { + Kind: "User", + Name: "bob", + ProxyOperations: []capsulev1beta1.ProxySettings{ + { + Kind: "IngressClasses", + Operations: []capsulev1beta1.ProxyOperation{"Update"}, + }, + { + Kind: "StorageClasses", + Operations: []capsulev1beta1.ProxyOperation{"List"}, + }, + }, + }, + { + Kind: "User", + Name: "jack", + ProxyOperations: []capsulev1beta1.ProxySettings{ + { + Kind: "IngressClasses", + Operations: []capsulev1beta1.ProxyOperation{"Delete"}, + }, + { + Kind: "Nodes", + Operations: []capsulev1beta1.ProxyOperation{"Delete"}, + }, + { + Kind: "StorageClasses", + Operations: []capsulev1beta1.ProxyOperation{"List"}, + }, + }, + }, + { + Kind: "Group", + Name: "owner-foo", + ProxyOperations: []capsulev1beta1.ProxySettings{ + { + Kind: "IngressClasses", + Operations: []capsulev1beta1.ProxyOperation{"List"}, + }, + }, + }, + { + Kind: "Group", + Name: "owner-bar", + ProxyOperations: []capsulev1beta1.ProxySettings{ + { + Kind: "IngressClasses", + Operations: []capsulev1beta1.ProxyOperation{"List"}, + }, + { + Kind: "StorageClasses", + Operations: []capsulev1beta1.ProxyOperation{"Delete"}, + }, + }, + }, + { + Kind: "ServiceAccount", + Name: "system:serviceaccount:oil-production:default", + ProxyOperations: []capsulev1beta1.ProxySettings{ + { + Kind: "Nodes", + Operations: []capsulev1beta1.ProxyOperation{"Update"}, + }, + }, + }, + { + Kind: "ServiceAccount", + Name: "system:serviceaccount:gas-production:gas", + ProxyOperations: []capsulev1beta1.ProxySettings{ + { + Kind: "StorageClasses", + Operations: []capsulev1beta1.ProxyOperation{"Update"}, + }, + }, + }, }, NamespaceQuota: &namespaceQuota, NamespacesMetadata: v1beta1AdditionalMetadataSpec, @@ -170,11 +263,22 @@ func generateTenantsSpecs() (Tenant, capsulev1beta1.Tenant) { "foo": "bar", }, Annotations: map[string]string{ - "foo": "bar", - podAllowedImagePullPolicyAnnotation: "Always,IfNotPresent", - enableNodePortsAnnotation: "false", - podPriorityAllowedAnnotation: "default", - podPriorityAllowedRegexAnnotation: "^tier-.*$", + "foo": "bar", + podAllowedImagePullPolicyAnnotation: "Always,IfNotPresent", + enableNodePortsAnnotation: "false", + podPriorityAllowedAnnotation: "default", + podPriorityAllowedRegexAnnotation: "^tier-.*$", + ownerGroupsAnnotation: "owner-foo,owner-bar", + ownerUsersAnnotation: "bob,jack", + ownerServiceAccountAnnotation: "system:serviceaccount:oil-production:default,system:serviceaccount:gas-production:gas", + enableNodeUpdateAnnotation: "alice,system:serviceaccount:oil-production:default", + enableNodeDeletionAnnotation: "alice,jack", + enableStorageClassListingAnnotation: "bob,jack", + enableStorageClassUpdateAnnotation: "alice,system:serviceaccount:gas-production:gas", + enableStorageClassDeletionAnnotation: "alice,owner-bar", + enableIngressClassListingAnnotation: "alice,owner-foo,owner-bar", + enableIngressClassUpdateAnnotation: "alice,bob", + enableIngressClassDeletionAnnotation: "alice,jack", }, }, Spec: TenantSpec{ @@ -224,7 +328,24 @@ func TestConversionHub_ConvertTo(t *testing.T) { v1alpha1Tnt, v1beta1tnt := generateTenantsSpecs() err := v1alpha1Tnt.ConvertTo(&v1beta1ConvertedTnt) if assert.NoError(t, err) { - assert.Equal(t, v1beta1ConvertedTnt, v1beta1tnt) + sort.Slice(v1beta1tnt.Spec.Owners, func(i, j int) bool { + return v1beta1tnt.Spec.Owners[i].Name < v1beta1tnt.Spec.Owners[j].Name + }) + sort.Slice(v1beta1ConvertedTnt.Spec.Owners, func(i, j int) bool { + return v1beta1ConvertedTnt.Spec.Owners[i].Name < v1beta1ConvertedTnt.Spec.Owners[j].Name + }) + + for _, owner := range v1beta1tnt.Spec.Owners { + sort.Slice(owner.ProxyOperations, func(i, j int) bool { + return owner.ProxyOperations[i].Kind < owner.ProxyOperations[j].Kind + }) + } + for _, owner := range v1beta1ConvertedTnt.Spec.Owners { + sort.Slice(owner.ProxyOperations, func(i, j int) bool { + return owner.ProxyOperations[i].Kind < owner.ProxyOperations[j].Kind + }) + } + assert.Equal(t, v1beta1tnt, v1beta1ConvertedTnt) } } @@ -234,6 +355,6 @@ func TestConversionHub_ConvertFrom(t *testing.T) { err := v1alpha1ConvertedTnt.ConvertFrom(&v1beta1tnt) if assert.NoError(t, err) { - assert.Equal(t, v1alpha1ConvertedTnt, v1alpha1Tnt) + assert.EqualValues(t, v1alpha1Tnt, v1alpha1ConvertedTnt) } } diff --git a/api/v1beta1/owner.go b/api/v1beta1/owner.go index bc50cc32..8b2793c4 100644 --- a/api/v1beta1/owner.go +++ b/api/v1beta1/owner.go @@ -5,13 +5,33 @@ package v1beta1 // OwnerSpec defines tenant owner name and kind type OwnerSpec struct { - Name string `json:"name"` - Kind Kind `json:"kind"` + Kind OwnerKind `json:"kind"` + Name string `json:"name"` + ProxyOperations []ProxySettings `json:"proxySettings,omitempty"` } -// +kubebuilder:validation:Enum=User;Group -type Kind string +// +kubebuilder:validation:Enum=User;Group;ServiceAccount +type OwnerKind string -func (k Kind) String() string { +func (k OwnerKind) String() string { return string(k) } + +type ProxySettings struct { + Kind ProxyServiceKind `json:"kind"` + Operations []ProxyOperation `json:"operations"` +} + +// +kubebuilder:validation:Enum=List;Update;Delete +type ProxyOperation string + +func (p ProxyOperation) String() string { + return string(p) +} + +// +kubebuilder:validation:Enum=Nodes;StorageClasses;IngressClasses +type ProxyServiceKind string + +func (p ProxyServiceKind) String() string { + return string(p) +} diff --git a/api/v1beta1/tenant_types.go b/api/v1beta1/tenant_types.go index 55fd50e5..246219fb 100644 --- a/api/v1beta1/tenant_types.go +++ b/api/v1beta1/tenant_types.go @@ -9,7 +9,7 @@ import ( // TenantSpec defines the desired state of Tenant type TenantSpec struct { - Owner OwnerSpec `json:"owner"` + Owners []OwnerSpec `json:"owners"` //+kubebuilder:validation:Minimum=1 NamespaceQuota *int32 `json:"namespaceQuota,omitempty"` @@ -39,8 +39,6 @@ type TenantSpec struct { // +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state",description="The actual state of the Tenant" // +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" diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 7147ed3c..7dbcadbc 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -150,6 +150,13 @@ func (in *NetworkPolicySpec) DeepCopy() *NetworkPolicySpec { // 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 + if in.ProxyOperations != nil { + in, out := &in.ProxyOperations, &out.ProxyOperations + *out = make([]ProxySettings, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OwnerSpec. @@ -162,6 +169,26 @@ func (in *OwnerSpec) DeepCopy() *OwnerSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ProxySettings) DeepCopyInto(out *ProxySettings) { + *out = *in + if in.Operations != nil { + in, out := &in.Operations, &out.Operations + *out = make([]ProxyOperation, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProxySettings. +func (in *ProxySettings) DeepCopy() *ProxySettings { + if in == nil { + return nil + } + out := new(ProxySettings) + 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 @@ -246,7 +273,13 @@ 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.Owners != nil { + in, out := &in.Owners, &out.Owners + *out = make([]OwnerSpec, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } if in.NamespaceQuota != nil { in, out := &in.NamespaceQuota, &out.NamespaceQuota *out = new(int32) diff --git a/config/crd/bases/capsule.clastix.io_tenants.yaml b/config/crd/bases/capsule.clastix.io_tenants.yaml index 70164085..74d55d19 100644 --- a/config/crd/bases/capsule.clastix.io_tenants.yaml +++ b/config/crd/bases/capsule.clastix.io_tenants.yaml @@ -579,14 +579,6 @@ spec: 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 @@ -1035,20 +1027,45 @@ spec: 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 + owners: + items: + description: OwnerSpec defines tenant owner name and kind + properties: + kind: + enum: + - User + - Group + - ServiceAccount + type: string + name: + type: string + proxySettings: + items: + properties: + kind: + enum: + - Nodes + - StorageClasses + - IngressClasses + type: string + operations: + items: + enum: + - List + - Update + - Delete + type: string + type: array + required: + - kind + - operations + type: object + type: array + required: + - kind + - name + type: object + type: array priorityClasses: properties: allowed: @@ -1128,7 +1145,7 @@ spec: type: string type: object required: - - owner + - owners type: object status: description: TenantStatus defines the observed state of Tenant diff --git a/controllers/tenant_controller.go b/controllers/tenant_controller.go index 967b8de7..fd4af997 100644 --- a/controllers/tenant_controller.go +++ b/controllers/tenant_controller.go @@ -621,18 +621,30 @@ func (r *TenantReconciler) syncNetworkPolicies(tenant *capsulev1beta1.Tenant) er // TODO(prometherion): we could create a capsule:admin role rather than hitting webhooks for each action func (r *TenantReconciler) ownerRoleBinding(tenant *capsulev1beta1.Tenant) error { // getting RoleBinding label for the mutateFn + var subjects []rbacv1.Subject + tl, err := capsulev1beta1.GetTypeLabel(&capsulev1beta1.Tenant{}) if err != nil { return err } l := map[string]string{tl: tenant.Name} - s := []rbacv1.Subject{ - { - APIGroup: "rbac.authorization.k8s.io", - Kind: tenant.Spec.Owner.Kind.String(), - Name: tenant.Spec.Owner.Name, - }, + + for _, owner := range tenant.Spec.Owners { + if owner.Kind == "ServiceAccount" { + splitName := strings.Split(owner.Name, ":") + subjects = append(subjects, rbacv1.Subject{ + Kind: owner.Kind.String(), + Name: splitName[len(splitName)-1], + Namespace: splitName[len(splitName)-2], + }) + } else { + subjects = append(subjects, rbacv1.Subject{ + APIGroup: "rbac.authorization.k8s.io", + Kind: owner.Kind.String(), + Name: owner.Name, + }) + } } rbl := make(map[types.NamespacedName]rbacv1.RoleRef) @@ -660,7 +672,7 @@ func (r *TenantReconciler) ownerRoleBinding(tenant *capsulev1beta1.Tenant) error var res controllerutil.OperationResult res, err = controllerutil.CreateOrUpdate(context.TODO(), r.Client, target, func() (err error) { target.ObjectMeta.Labels = l - target.Subjects = s + target.Subjects = subjects target.RoleRef = rr return controllerutil.SetControllerReference(tenant, target, r.Scheme) }) diff --git a/pkg/indexer/tenant/owner.go b/pkg/indexer/tenant/owner.go index 23a95afe..0b42a5b3 100644 --- a/pkg/indexer/tenant/owner.go +++ b/pkg/indexer/tenant/owner.go @@ -24,6 +24,6 @@ func (o OwnerReference) Field() string { func (o OwnerReference) Func() client.IndexerFunc { return func(object client.Object) []string { tenant := object.(*capsulev1beta1.Tenant) - return []string{utils.GetOwnerWithKind(tenant)} + return utils.GetOwnersWithKinds(tenant) } } diff --git a/pkg/utils/owner.go b/pkg/utils/owner.go index 5d10dd86..e45b945f 100644 --- a/pkg/utils/owner.go +++ b/pkg/utils/owner.go @@ -3,8 +3,15 @@ package utils -import capsulev1beta1 "github.com/clastix/capsule/api/v1beta1" +import ( + "fmt" -func GetOwnerWithKind(tenant *capsulev1beta1.Tenant) string { - return tenant.Spec.Owner.Kind.String() + ":" + tenant.Spec.Owner.Name + capsulev1beta1 "github.com/clastix/capsule/api/v1beta1" +) + +func GetOwnersWithKinds(tenant *capsulev1beta1.Tenant) (owners []string) { + for _, owner := range tenant.Spec.Owners { + owners = append(owners, fmt.Sprintf("%s:%s", owner.Kind.String(), owner.Name)) + } + return } diff --git a/pkg/webhook/ownerreference/patching.go b/pkg/webhook/ownerreference/patching.go index 3006bbb9..8a35da43 100644 --- a/pkg/webhook/ownerreference/patching.go +++ b/pkg/webhook/ownerreference/patching.go @@ -59,7 +59,7 @@ func (h *handler) OnCreate(clt client.Client, decoder *admission.Decoder, record return &response } // Tenant owner must adhere to user that asked for NS creation - if !h.isTenantOwner(tnt.Spec.Owner, req.UserInfo) { + if !h.isTenantOwner(tnt.Spec.Owners, req.UserInfo) { recorder.Eventf(tnt, corev1.EventTypeWarning, "NonOwnedTenant", "Namespace %s cannot be assigned to the current Tenant", ns.GetName()) response := admission.Denied("Cannot assign the desired namespace to a non-owned Tenant") @@ -75,8 +75,20 @@ func (h *handler) OnCreate(clt client.Client, decoder *admission.Decoder, record // If we forceTenantPrefix -> find Tenant from NS name var tenants sortedTenants - // Find tenants belonging to user - { + // Find tenants belonging to user (it can be regular user or ServiceAccount) + if strings.HasPrefix(req.UserInfo.Username, "system:serviceaccount:") { + var tntList *capsulev1beta1.TenantList + + if tntList, err = h.listTenantsForOwnerKind(ctx, "ServiceAccount", req.UserInfo.Username, clt); err != nil { + response := admission.Errored(http.StatusBadRequest, err) + + return &response + } + + for _, tnt := range tntList.Items { + tenants = append(tenants, tnt) + } + } else { var tntList *capsulev1beta1.TenantList if tntList, err = h.listTenantsForOwnerKind(ctx, "User", req.UserInfo.Username, clt); err != nil { @@ -89,6 +101,7 @@ func (h *handler) OnCreate(clt client.Client, decoder *admission.Decoder, record tenants = append(tenants, tnt) } } + // Find tenants belonging to user groups { for _, group := range req.UserInfo.Groups { @@ -176,17 +189,22 @@ func (h *handler) listTenantsForOwnerKind(ctx context.Context, ownerKind string, return tntList, err } -func (h *handler) isTenantOwner(ownerSpec capsulev1beta1.OwnerSpec, userInfo authenticationv1.UserInfo) bool { - if ownerSpec.Kind == "User" && userInfo.Username == ownerSpec.Name { - return true - } - if ownerSpec.Kind == "Group" { - for _, group := range userInfo.Groups { - if group == ownerSpec.Name { +func (h *handler) isTenantOwner(owners []capsulev1beta1.OwnerSpec, userInfo authenticationv1.UserInfo) bool { + for _, owner := range owners { + switch owner.Kind { + case "User", "ServiceAccount": + if userInfo.Username == owner.Name { return true } + case "Group": + for _, group := range userInfo.Groups { + if group == owner.Name { + return true + } + } } } + return false } diff --git a/pkg/webhook/utils/is_tenant_or_sa_request.go b/pkg/webhook/utils/is_tenant_or_sa_request.go index 519db07c..1b478204 100644 --- a/pkg/webhook/utils/is_tenant_or_sa_request.go +++ b/pkg/webhook/utils/is_tenant_or_sa_request.go @@ -10,21 +10,22 @@ import ( ) func RequestFromOwnerOrSA(tenant capsulev1beta1.Tenant, req admission.Request, userGroups []string) bool { - switch { - case tenant.Spec.Owner.Kind == "User" && req.UserInfo.Username == tenant.Spec.Owner.Name: - return true - case tenant.Spec.Owner.Kind == "Group": - groupList := utils.NewUserGroupList(req.UserInfo.Groups) - for _, group := range userGroups { - if groupList.Find(group) { - return true + for _, owner := range tenant.Spec.Owners { + switch { + case (owner.Kind == "User" || owner.Kind == "ServiceAccount") && req.UserInfo.Username == owner.Name: + return true + case owner.Kind == "Group": + groupList := utils.NewUserGroupList(req.UserInfo.Groups) + for _, group := range userGroups { + if groupList.Find(group) { + return true + } } } - default: - for _, group := range req.UserInfo.Groups { - if len(req.Namespace) > 0 && strings.HasPrefix(group, "system:serviceaccounts:"+req.Namespace) { - return true - } + } + for _, group := range req.UserInfo.Groups { + if len(req.Namespace) > 0 && strings.HasPrefix(group, "system:serviceaccounts:"+req.Namespace) { + return true } } return false From 480b8971d49fe11f6db6f97493cec3260b362d03 Mon Sep 17 00:00:00 2001 From: Maksim Fedotov Date: Thu, 8 Jul 2021 11:37:13 +0300 Subject: [PATCH 2/4] build(helm): support multiple tenant owners(add applications to act as tenant owners) --- charts/capsule/crds/tenant-crd.yaml | 964 ++++++---------------------- 1 file changed, 211 insertions(+), 753 deletions(-) diff --git a/charts/capsule/crds/tenant-crd.yaml b/charts/capsule/crds/tenant-crd.yaml index 1d44c2bb..9029bef0 100644 --- a/charts/capsule/crds/tenant-crd.yaml +++ b/charts/capsule/crds/tenant-crd.yaml @@ -48,14 +48,10 @@ spec: description: Tenant is the Schema for the tenants API properties: apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' type: string kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' type: string metadata: type: object @@ -70,31 +66,19 @@ spec: 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. + 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. + 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. + 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. + 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 @@ -145,15 +129,12 @@ spec: type: object limitRanges: items: - description: LimitRangeSpec defines a min/max usage limit for resources - that match on kind. + 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. + 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. + description: LimitRangeItem defines a min/max usage limit for any resource that matches on kind. properties: default: additionalProperties: @@ -162,8 +143,7 @@ spec: - 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. + description: Default resource requirement limit value by resource name if resource limit is omitted. type: object defaultRequest: additionalProperties: @@ -172,9 +152,7 @@ spec: - 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. + description: DefaultRequest is the default resource requirement request value by resource name if resource request is omitted. type: object max: additionalProperties: @@ -183,8 +161,7 @@ spec: - 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. + description: Max usage constraints on this kind by resource name. type: object maxLimitRequestRatio: additionalProperties: @@ -193,11 +170,7 @@ spec: - 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. + 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: @@ -206,12 +179,10 @@ spec: - 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. + description: Min usage constraints on this kind by resource name. type: object type: - description: Type of resource that this limit applies - to. + description: Type of resource that this limit applies to. type: string required: - type @@ -241,80 +212,40 @@ spec: 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 + 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 + 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. + 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 + 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. + 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. + 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. + 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 + 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. + 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" + 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 + 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 @@ -322,43 +253,21 @@ spec: - 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." + 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. + 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. + 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. + 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. + 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. + 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 @@ -370,53 +279,25 @@ spec: 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. + 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." + 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. + 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. + 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. + 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. + 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. + 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 @@ -428,12 +309,7 @@ spec: 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. + 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 @@ -441,51 +317,23 @@ spec: 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) + 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. + 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. + 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 + 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. + 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" + 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 + 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 @@ -493,43 +341,21 @@ spec: - 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." + 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. + 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. + 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. + 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. + 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. + 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 @@ -541,53 +367,25 @@ spec: 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. + 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." + 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. + 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. + 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. + 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. + 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. + 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 @@ -599,80 +397,46 @@ spec: 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. + 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. + 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 + 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. + 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. + 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. + 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. + 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. + 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. + 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. + 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. + 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 @@ -684,30 +448,13 @@ spec: 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. + 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 + 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 + description: Policy Type string describes the NetworkPolicy type This type is beta-level in 1.8 type: string type: array required: @@ -734,8 +481,7 @@ spec: type: object resourceQuotas: items: - description: ResourceQuotaSpec defines the desired hard limits to - enforce for Quota. + description: ResourceQuotaSpec defines the desired hard limits to enforce for Quota. properties: hard: additionalProperties: @@ -744,39 +490,24 @@ spec: - 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/' + 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. + 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. + 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. + 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. + 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. + 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. + 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 @@ -787,12 +518,9 @@ spec: 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. + 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 + description: A ResourceQuotaScope defines a filter that must match each object tracked by a quota type: string type: array type: object @@ -836,7 +564,7 @@ spec: served: true storage: false subresources: - status: {} + status: { } - additionalPrinterColumns: - description: The actual state of the Tenant jsonPath: .status.state @@ -850,14 +578,6 @@ spec: 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 @@ -872,14 +592,10 @@ spec: description: Tenant is the Schema for the tenants API properties: apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' type: string kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' type: string metadata: type: object @@ -894,31 +610,19 @@ spec: 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. + 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. + 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. + 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. + 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 @@ -982,15 +686,12 @@ spec: properties: items: items: - description: LimitRangeSpec defines a min/max usage limit for - resources that match on kind. + 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. + 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. + description: LimitRangeItem defines a min/max usage limit for any resource that matches on kind. properties: default: additionalProperties: @@ -999,8 +700,7 @@ spec: - 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. + description: Default resource requirement limit value by resource name if resource limit is omitted. type: object defaultRequest: additionalProperties: @@ -1009,9 +709,7 @@ spec: - 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. + description: DefaultRequest is the default resource requirement request value by resource name if resource request is omitted. type: object max: additionalProperties: @@ -1020,8 +718,7 @@ spec: - 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. + description: Max usage constraints on this kind by resource name. type: object maxLimitRequestRatio: additionalProperties: @@ -1030,11 +727,7 @@ spec: - 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. + 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: @@ -1043,12 +736,10 @@ spec: - 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. + description: Min usage constraints on this kind by resource name. type: object type: - description: Type of resource that this limit applies - to. + description: Type of resource that this limit applies to. type: string required: - type @@ -1078,87 +769,43 @@ spec: properties: items: items: - description: NetworkPolicySpec provides the specification of - a NetworkPolicy + 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 + 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 + 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. + 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 + 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. + 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. + 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. + 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 + 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. + 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" + 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 + 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 @@ -1166,45 +813,21 @@ spec: - 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." + 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. + 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. + 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. + 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. + 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. + 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 @@ -1216,54 +839,25 @@ spec: 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. + 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." + 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. + 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. + 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. + 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. + 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. + 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 @@ -1275,12 +869,7 @@ spec: 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. + 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 @@ -1288,53 +877,23 @@ spec: 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) + 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. + 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. + 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 + 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. + 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" + 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 + 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 @@ -1342,45 +901,21 @@ spec: - 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." + 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. + 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. + 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. + 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. + 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. + 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 @@ -1392,54 +927,25 @@ spec: 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. + 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." + 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. + 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. + 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. + 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. + 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. + 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 @@ -1451,81 +957,46 @@ spec: 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. + 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. + 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 + 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. + 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. + 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. + 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. + 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. + 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. + 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. + 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. + 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 @@ -1537,31 +1008,13 @@ spec: 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. + 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 + 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 + description: Policy Type string describes the NetworkPolicy type This type is beta-level in 1.8 type: string type: array required: @@ -1573,20 +1026,45 @@ spec: 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 + owners: + items: + description: OwnerSpec defines tenant owner name and kind + properties: + kind: + enum: + - User + - Group + - ServiceAccount + type: string + name: + type: string + proxySettings: + items: + properties: + kind: + enum: + - Nodes + - StorageClasses + - IngressClasses + type: string + operations: + items: + enum: + - List + - Update + - Delete + type: string + type: array + required: + - kind + - operations + type: object + type: array + required: + - kind + - name + type: object + type: array priorityClasses: properties: allowed: @@ -1600,8 +1078,7 @@ spec: properties: items: items: - description: ResourceQuotaSpec defines the desired hard limits - to enforce for Quota. + description: ResourceQuotaSpec defines the desired hard limits to enforce for Quota. properties: hard: additionalProperties: @@ -1610,40 +1087,24 @@ spec: - 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/' + 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. + 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. + 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. + 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. + 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. + 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. + 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 @@ -1654,12 +1115,9 @@ spec: 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. + 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 + description: A ResourceQuotaScope defines a filter that must match each object tracked by a quota type: string type: array type: object @@ -1686,7 +1144,7 @@ spec: type: string type: object required: - - owner + - owners type: object status: description: TenantStatus defines the observed state of Tenant @@ -1711,7 +1169,7 @@ spec: served: true storage: true subresources: - status: {} + status: { } status: acceptedNames: kind: "" From 74d84949ed429a93a8a2e1c385990d6abb62ce2c Mon Sep 17 00:00:00 2001 From: Maksim Fedotov Date: Thu, 8 Jul 2021 11:39:29 +0300 Subject: [PATCH 3/4] test(e2e): support multiple tenant owners(add applications to act as tenant owners) --- e2e/additional_role_bindings_test.go | 12 +++-- e2e/allowed_external_ips_test.go | 20 ++++---- e2e/container_registry_test.go | 22 +++++---- e2e/custom_capsule_group_test.go | 14 +++--- e2e/disable_node_ports_test.go | 12 +++-- e2e/enable_node_ports_test.go | 12 +++-- e2e/force_tenant_prefix_test.go | 24 +++++---- e2e/imagepullpolicy_multiple_test.go | 12 +++-- e2e/imagepullpolicy_single_test.go | 12 +++-- e2e/ingress_class_test.go | 28 ++++++----- ...ngress_hostnames_allowed_collision_test.go | 16 +++--- ...ingress_hostnames_denied_collision_test.go | 12 +++-- e2e/ingress_hostnames_test.go | 32 ++++++------ e2e/missing_tenant_test.go | 10 ++-- e2e/namespace_capsule_label_test.go | 10 ++-- e2e/namespace_metadata_test.go | 10 ++-- e2e/new_namespace_test.go | 46 ++++++++++++++--- e2e/overquota_namespace_test.go | 12 +++-- e2e/owner_webhooks_test.go | 36 +++++++------- e2e/pod_priority_class_test.go | 20 ++++---- e2e/protected_namespace_regex_test.go | 12 +++-- e2e/resource_quota_exceeded_test.go | 14 +++--- e2e/selecting_non_owned_tenant_test.go | 10 ++-- e2e/selecting_tenant_fail_test.go | 48 ++++++++++-------- e2e/selecting_tenant_with_label_test.go | 18 ++++--- e2e/service_metadata_test.go | 14 +++--- e2e/storage_class_test.go | 18 ++++--- e2e/suite_test.go | 6 +-- e2e/tenant_cordoning_test.go | 12 +++-- ...ngress_hostnames_collision_allowed_test.go | 24 +++++---- ...ngress_hostnames_collision_blocked_test.go | 16 +++--- e2e/tenant_name_webhook_test.go | 8 +-- e2e/tenant_owner_group_test.go | 49 ------------------- e2e/tenant_resources_changes_test.go | 10 ++-- e2e/tenant_resources_test.go | 10 ++-- e2e/utils_test.go | 14 ++++-- 36 files changed, 360 insertions(+), 295 deletions(-) delete mode 100644 e2e/tenant_owner_group_test.go diff --git a/e2e/additional_role_bindings_test.go b/e2e/additional_role_bindings_test.go index 84acfb0d..2c98305d 100644 --- a/e2e/additional_role_bindings_test.go +++ b/e2e/additional_role_bindings_test.go @@ -23,9 +23,11 @@ var _ = Describe("creating a Namespace with an additional Role Binding", func() Name: "additional-role-binding", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "dale", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "dale", + Kind: "User", + }, }, AdditionalRoleBindings: []capsulev1beta1.AdditionalRoleBindingsSpec{ { @@ -55,13 +57,13 @@ var _ = Describe("creating a Namespace with an additional Role Binding", func() It("should be assigned to each Namespace", func() { for _, ns := range []string{"rb-1", "rb-2", "rb-3"} { ns := NewNamespace(ns) - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) var rb *rbacv1.RoleBinding Eventually(func() (err error) { - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) rb, err = cs.RbacV1().RoleBindings(ns.Name).Get(context.Background(), fmt.Sprintf("capsule-%s-0-%s", tnt.Name, "crds-rolebinding"), metav1.GetOptions{}) return err }, defaultTimeoutInterval, defaultPollInterval).Should(Succeed()) diff --git a/e2e/allowed_external_ips_test.go b/e2e/allowed_external_ips_test.go index 69f34d20..c3f1cbb1 100644 --- a/e2e/allowed_external_ips_test.go +++ b/e2e/allowed_external_ips_test.go @@ -23,9 +23,11 @@ var _ = Describe("enforcing an allowed set of Service external IPs", func() { Name: "allowed-external-ip", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "google", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "google", + Kind: "User", + }, }, ExternalServiceIPs: &capsulev1beta1.ExternalServiceIPsSpec{ Allowed: []capsulev1beta1.AllowedIP{ @@ -48,7 +50,7 @@ var _ = Describe("enforcing an allowed set of Service external IPs", func() { It("should fail creating an evil service", func() { ns := NewNamespace("evil-service") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) svc := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ @@ -73,7 +75,7 @@ var _ = Describe("enforcing an allowed set of Service external IPs", func() { }, } EventuallyCreation(func() error { - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) _, err := cs.CoreV1().Services(ns.Name).Create(context.Background(), svc, metav1.CreateOptions{}) return err }).ShouldNot(Succeed()) @@ -81,7 +83,7 @@ var _ = Describe("enforcing an allowed set of Service external IPs", func() { It("should allow the first CIDR block", func() { ns := NewNamespace("allowed-service-cidr") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) svc := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ @@ -106,7 +108,7 @@ var _ = Describe("enforcing an allowed set of Service external IPs", func() { }, } EventuallyCreation(func() error { - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) _, err := cs.CoreV1().Services(ns.Name).Create(context.Background(), svc, metav1.CreateOptions{}) return err }).Should(Succeed()) @@ -114,7 +116,7 @@ var _ = Describe("enforcing an allowed set of Service external IPs", func() { It("should allow the /32 CIDR block", func() { ns := NewNamespace("allowed-service-strict") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) svc := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ @@ -138,7 +140,7 @@ var _ = Describe("enforcing an allowed set of Service external IPs", func() { }, } EventuallyCreation(func() error { - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) _, err := cs.CoreV1().Services(ns.Name).Create(context.Background(), svc, metav1.CreateOptions{}) return err }).Should(Succeed()) diff --git a/e2e/container_registry_test.go b/e2e/container_registry_test.go index 9bc8096d..94c68a6d 100644 --- a/e2e/container_registry_test.go +++ b/e2e/container_registry_test.go @@ -23,9 +23,11 @@ var _ = Describe("enforcing a Container Registry", func() { Name: "container-registry", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "matt", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "matt", + Kind: "User", + }, }, ContainerRegistries: &capsulev1beta1.AllowedListSpec{ Exact: []string{"docker.io", "docker.tld"}, @@ -46,7 +48,7 @@ var _ = Describe("enforcing a Container Registry", func() { It("should add labels to Namespace", func() { ns := NewNamespace("registry-labels") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) Eventually(func() (ok bool) { Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: ns.Name}, ns)).Should(Succeed()) ok, _ = HaveKeyWithValue("capsule.clastix.io/allowed-registries", "docker.io,docker.tld").Match(ns.Annotations) @@ -63,7 +65,7 @@ var _ = Describe("enforcing a Container Registry", func() { It("should deny running a gcr.io container", func() { ns := NewNamespace("registry-deny") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) pod := &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ @@ -78,14 +80,14 @@ var _ = Describe("enforcing a Container Registry", func() { }, }, } - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) _, err := cs.CoreV1().Pods(ns.Name).Create(context.Background(), pod, metav1.CreateOptions{}) Expect(err).ShouldNot(Succeed()) }) It("should allow using an exact match", func() { ns := NewNamespace("registry-list") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) pod := &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ @@ -101,7 +103,7 @@ var _ = Describe("enforcing a Container Registry", func() { }, } - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) EventuallyCreation(func() error { _, err := cs.CoreV1().Pods(ns.Name).Create(context.Background(), pod, metav1.CreateOptions{}) return err @@ -110,7 +112,7 @@ var _ = Describe("enforcing a Container Registry", func() { It("should allow using a regex match", func() { ns := NewNamespace("registry-regex") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) pod := &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ @@ -126,7 +128,7 @@ var _ = Describe("enforcing a Container Registry", func() { }, } - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) EventuallyCreation(func() error { _, err := cs.CoreV1().Pods(ns.Name).Create(context.Background(), pod, metav1.CreateOptions{}) return err diff --git a/e2e/custom_capsule_group_test.go b/e2e/custom_capsule_group_test.go index fd964c2d..2d11fd78 100644 --- a/e2e/custom_capsule_group_test.go +++ b/e2e/custom_capsule_group_test.go @@ -23,9 +23,11 @@ var _ = Describe("creating a Namespace as Tenant owner with custom --capsule-gro Name: "tenant-assigned-custom-group", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "alice", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "alice", + Kind: "User", + }, }, }, } @@ -46,7 +48,7 @@ var _ = Describe("creating a Namespace as Tenant owner with custom --capsule-gro }) ns := NewNamespace("cg-namespace-fail") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).ShouldNot(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).ShouldNot(Succeed()) }) It("should succeed and be available in Tenant namespaces list with multiple groups", func() { @@ -56,7 +58,7 @@ var _ = Describe("creating a Namespace as Tenant owner with custom --capsule-gro ns := NewNamespace("cg-namespace-1") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) }) @@ -67,7 +69,7 @@ var _ = Describe("creating a Namespace as Tenant owner with custom --capsule-gro ns := NewNamespace("cg-namespace-2") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) }) }) diff --git a/e2e/disable_node_ports_test.go b/e2e/disable_node_ports_test.go index d488f369..ef0ebd76 100644 --- a/e2e/disable_node_ports_test.go +++ b/e2e/disable_node_ports_test.go @@ -23,9 +23,11 @@ var _ = Describe("creating a nodePort service when it is disabled for Tenant", f Name: "disable-node-ports", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "google", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "google", + Kind: "User", + }, }, EnableNodePorts: false, }, @@ -43,7 +45,7 @@ var _ = Describe("creating a nodePort service when it is disabled for Tenant", f It("should fail creating a service with NodePort type", func() { ns := NewNamespace("disable-node-ports") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) svc := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ @@ -65,7 +67,7 @@ var _ = Describe("creating a nodePort service when it is disabled for Tenant", f }, } EventuallyCreation(func() error { - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) _, err := cs.CoreV1().Services(ns.Name).Create(context.Background(), svc, metav1.CreateOptions{}) return err }).ShouldNot(Succeed()) diff --git a/e2e/enable_node_ports_test.go b/e2e/enable_node_ports_test.go index 0e121933..434ec31e 100644 --- a/e2e/enable_node_ports_test.go +++ b/e2e/enable_node_ports_test.go @@ -23,9 +23,11 @@ var _ = Describe("creating a nodePort service when it is enabled for Tenant", fu Name: "enable-node-ports", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "google", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "google", + Kind: "User", + }, }, }, } @@ -42,7 +44,7 @@ var _ = Describe("creating a nodePort service when it is enabled for Tenant", fu It("should allow creating a service with NodePort type", func() { ns := NewNamespace("enable-node-ports") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) svc := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ @@ -64,7 +66,7 @@ var _ = Describe("creating a nodePort service when it is enabled for Tenant", fu }, } EventuallyCreation(func() error { - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) _, err := cs.CoreV1().Services(ns.Name).Create(context.Background(), svc, metav1.CreateOptions{}) return err }).Should(Succeed()) diff --git a/e2e/force_tenant_prefix_test.go b/e2e/force_tenant_prefix_test.go index 71700189..d197d14c 100644 --- a/e2e/force_tenant_prefix_test.go +++ b/e2e/force_tenant_prefix_test.go @@ -23,9 +23,11 @@ var _ = Describe("creating a Namespace with Tenant name prefix enforcement", fun Name: "awesome", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "john", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "john", + Kind: "User", + }, }, }, } @@ -34,9 +36,11 @@ var _ = Describe("creating a Namespace with Tenant name prefix enforcement", fun Name: "awesome-tenant", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "john", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "john", + Kind: "User", + }, }, }, } @@ -66,20 +70,20 @@ var _ = Describe("creating a Namespace with Tenant name prefix enforcement", fun It("should fail when non using prefix", func() { ns := NewNamespace("awesome") - NamespaceCreation(ns, t1, defaultTimeoutInterval).ShouldNot(Succeed()) + NamespaceCreation(ns, t1.Spec.Owners[0], defaultTimeoutInterval).ShouldNot(Succeed()) }) It("should succeed using prefix", func() { ns := NewNamespace("awesome-namespace") - NamespaceCreation(ns, t1, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, t1.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) }) It("should succeed and assigned according to closest match", func() { ns1 := NewNamespace("awesome-tenant") ns2 := NewNamespace("awesome-tenant-namespace") - NamespaceCreation(ns1, t1, defaultTimeoutInterval).Should(Succeed()) - NamespaceCreation(ns2, t2, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns1, t1.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns2, t2.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(t1, defaultTimeoutInterval).Should(ContainElement(ns1.GetName())) TenantNamespaceList(t2, defaultTimeoutInterval).Should(ContainElement(ns2.GetName())) diff --git a/e2e/imagepullpolicy_multiple_test.go b/e2e/imagepullpolicy_multiple_test.go index 89221540..4dcb6a8a 100644 --- a/e2e/imagepullpolicy_multiple_test.go +++ b/e2e/imagepullpolicy_multiple_test.go @@ -22,9 +22,11 @@ var _ = Describe("enforcing some defined ImagePullPolicy", func() { Name: "image-pull-policies", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "alex", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "alex", + Kind: "User", + }, }, ImagePullPolicies: []capsulev1beta1.ImagePullPolicySpec{"Always", "IfNotPresent"}, }, @@ -43,9 +45,9 @@ var _ = Describe("enforcing some defined ImagePullPolicy", func() { It("should just allow the defined policies", func() { ns := NewNamespace("allow-policy") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) By("allowing Always", func() { pod := &corev1.Pod{ diff --git a/e2e/imagepullpolicy_single_test.go b/e2e/imagepullpolicy_single_test.go index 7d59f9a4..e3ca4fc1 100644 --- a/e2e/imagepullpolicy_single_test.go +++ b/e2e/imagepullpolicy_single_test.go @@ -22,9 +22,11 @@ var _ = Describe("enforcing a defined ImagePullPolicy", func() { Name: "image-pull-policy", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "axel", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "axel", + Kind: "User", + }, }, ImagePullPolicies: []capsulev1beta1.ImagePullPolicySpec{"Always"}, }, @@ -43,9 +45,9 @@ var _ = Describe("enforcing a defined ImagePullPolicy", func() { It("should just allow the defined policy", func() { ns := NewNamespace("allow-policies") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) By("allowing Always", func() { pod := &corev1.Pod{ diff --git a/e2e/ingress_class_test.go b/e2e/ingress_class_test.go index 1f46b120..7b149fb0 100644 --- a/e2e/ingress_class_test.go +++ b/e2e/ingress_class_test.go @@ -24,9 +24,11 @@ var _ = Describe("when Tenant handles Ingress classes", func() { Name: "ingress-class", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "ingress", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "ingress", + Kind: "User", + }, }, IngressClasses: &capsulev1beta1.AllowedListSpec{ Exact: []string{ @@ -50,9 +52,9 @@ var _ = Describe("when Tenant handles Ingress classes", func() { It("should block a non allowed class", func() { ns := NewNamespace("ingress-class-disallowed") - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) By("non-specifying at all", func() { @@ -114,9 +116,9 @@ var _ = Describe("when Tenant handles Ingress classes", func() { It("should allow enabled class using the deprecated annotation", func() { ns := NewNamespace("ingress-class-allowed-annotation") - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) for _, c := range tnt.Spec.IngressClasses.Exact { @@ -143,14 +145,14 @@ var _ = Describe("when Tenant handles Ingress classes", func() { It("should allow enabled class using the ingressClassName field", func() { ns := NewNamespace("ingress-class-allowed-annotation") - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) maj, min, v := GetKubernetesSemVer() if maj == 1 && min < 18 { Skip("Running test on Kubernetes " + v + ", doesn't provide .spec.ingressClassName") } - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) for _, c := range tnt.Spec.IngressClasses.Exact { @@ -175,10 +177,10 @@ var _ = Describe("when Tenant handles Ingress classes", func() { It("should allow enabled Ingress by regex using the deprecated annotation", func() { ns := NewNamespace("ingress-class-allowed-annotation") - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) ingressClass := "oil-ingress" - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) Eventually(func() (err error) { @@ -203,7 +205,7 @@ var _ = Describe("when Tenant handles Ingress classes", func() { It("should allow enabled Ingress by regex using the ingressClassName field", func() { ns := NewNamespace("ingress-class-allowed-annotation") - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) ingressClass := "oil-haproxy" maj, min, v := GetKubernetesSemVer() @@ -211,7 +213,7 @@ var _ = Describe("when Tenant handles Ingress classes", func() { Skip("Running test on Kubernetes " + v + ", doesn't provide .spec.ingressClassName") } - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) Eventually(func() (err error) { diff --git a/e2e/ingress_hostnames_allowed_collision_test.go b/e2e/ingress_hostnames_allowed_collision_test.go index 484965d8..34d73059 100644 --- a/e2e/ingress_hostnames_allowed_collision_test.go +++ b/e2e/ingress_hostnames_allowed_collision_test.go @@ -25,9 +25,11 @@ var _ = Describe("when handling Ingress hostnames collision", func() { Name: "ingress-hostnames-allowed-collision", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "ingress-allowed", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "ingress-allowed", + Kind: "User", + }, }, }, } @@ -91,9 +93,9 @@ var _ = Describe("when handling Ingress hostnames collision", func() { maj, min, _ := GetKubernetesSemVer() ns := NewNamespace("denied-collision") - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) if maj == 1 && min > 18 { @@ -132,9 +134,9 @@ var _ = Describe("when handling Ingress hostnames collision", func() { maj, min, _ := GetKubernetesSemVer() ns := NewNamespace("allowed-collision") - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) if maj == 1 && min > 18 { diff --git a/e2e/ingress_hostnames_denied_collision_test.go b/e2e/ingress_hostnames_denied_collision_test.go index 39495d84..af0690ee 100644 --- a/e2e/ingress_hostnames_denied_collision_test.go +++ b/e2e/ingress_hostnames_denied_collision_test.go @@ -25,9 +25,11 @@ var _ = Describe("when handling Ingress hostnames collision", func() { Name: "ingress-hostnames-denied-collision", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "ingress-denied", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "ingress-denied", + Kind: "User", + }, }, }, } @@ -85,9 +87,9 @@ var _ = Describe("when handling Ingress hostnames collision", func() { maj, min, _ := GetKubernetesSemVer() ns := NewNamespace("allowed-collision") - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) if maj == 1 && min > 18 { diff --git a/e2e/ingress_hostnames_test.go b/e2e/ingress_hostnames_test.go index 6239515d..19da0a0d 100644 --- a/e2e/ingress_hostnames_test.go +++ b/e2e/ingress_hostnames_test.go @@ -25,9 +25,11 @@ var _ = Describe("when Tenant handles Ingress hostnames", func() { Name: "ingress-hostnames", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "hostname", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "hostname", + Kind: "User", + }, }, IngressHostnames: &capsulev1beta1.AllowedListSpec{ Exact: []string{"sigs.k8s.io", "operator.sdk", "domain.tld"}, @@ -118,9 +120,9 @@ var _ = Describe("when Tenant handles Ingress hostnames", func() { if maj == 1 && min > 18 { ns := NewNamespace("disallowed-hostname-networking") - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) By("testing networking.k8s.io", func() { @@ -143,9 +145,9 @@ var _ = Describe("when Tenant handles Ingress hostnames", func() { if maj == 1 && min < 22 { By("testing extensions", func() { ns := NewNamespace("disallowed-hostname-extensions") - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) Eventually(func() (err error) { @@ -166,9 +168,9 @@ var _ = Describe("when Tenant handles Ingress hostnames", func() { if maj == 1 && min > 18 { ns := NewNamespace("allowed-hostname-list-networking") - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) By("testing networking.k8s.io", func() { @@ -192,9 +194,9 @@ var _ = Describe("when Tenant handles Ingress hostnames", func() { if maj == 1 && min < 22 { ns := NewNamespace("allowed-hostname-list-extensions") - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) By("testing extensions", func() { @@ -218,9 +220,9 @@ var _ = Describe("when Tenant handles Ingress hostnames", func() { if maj == 1 && min > 18 { ns := NewNamespace("allowed-hostname-regex-networking") - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) By("testing networking.k8s.io", func() { @@ -245,9 +247,9 @@ var _ = Describe("when Tenant handles Ingress hostnames", func() { if maj == 1 && min < 22 { By("testing extensions", func() { ns := NewNamespace("allowed-hostname-regex-extensions") - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) for _, h := range []string{"foo", "bar", "bizz"} { diff --git a/e2e/missing_tenant_test.go b/e2e/missing_tenant_test.go index b6afd585..c2952f85 100644 --- a/e2e/missing_tenant_test.go +++ b/e2e/missing_tenant_test.go @@ -19,14 +19,16 @@ var _ = Describe("creating a Namespace creation with no Tenant assigned", func() It("should fail", func() { tnt := &capsulev1beta1.Tenant{ Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "missing", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "missing", + Kind: "User", + }, }, }, } ns := NewNamespace("no-namespace") - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) _, err := cs.CoreV1().Namespaces().Create(context.TODO(), ns, metav1.CreateOptions{}) Expect(err).ShouldNot(Succeed()) }) diff --git a/e2e/namespace_capsule_label_test.go b/e2e/namespace_capsule_label_test.go index 290179ed..4dd0f787 100644 --- a/e2e/namespace_capsule_label_test.go +++ b/e2e/namespace_capsule_label_test.go @@ -23,9 +23,11 @@ var _ = Describe("creating several Namespaces for a Tenant", func() { Name: "capsule-labels", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "charlie", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "charlie", + Kind: "User", + }, }, }, } @@ -47,7 +49,7 @@ var _ = Describe("creating several Namespaces for a Tenant", func() { NewNamespace("third-capsule-ns"), } for _, ns := range namespaces { - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) Eventually(func() (ok bool) { Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: ns.GetName()}, ns)).Should(Succeed()) ok, _ = HaveKeyWithValue("capsule.clastix.io/tenant", tnt.Name).Match(ns.Labels) diff --git a/e2e/namespace_metadata_test.go b/e2e/namespace_metadata_test.go index bb902219..98f366a5 100644 --- a/e2e/namespace_metadata_test.go +++ b/e2e/namespace_metadata_test.go @@ -22,9 +22,11 @@ var _ = Describe("creating a Namespace for a Tenant with additional metadata", f Name: "tenant-metadata", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "gatsby", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "gatsby", + Kind: "User", + }, }, NamespacesMetadata: &capsulev1beta1.AdditionalMetadataSpec{ AdditionalLabels: map[string]string{ @@ -50,7 +52,7 @@ var _ = Describe("creating a Namespace for a Tenant with additional metadata", f It("should contain additional Namespace metadata", func() { ns := NewNamespace("namespace-metadata") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) By("checking additional labels", func() { diff --git a/e2e/new_namespace_test.go b/e2e/new_namespace_test.go index 97f5a28e..16ee61ad 100644 --- a/e2e/new_namespace_test.go +++ b/e2e/new_namespace_test.go @@ -15,21 +15,32 @@ import ( capsulev1beta1 "github.com/clastix/capsule/api/v1beta1" ) -var _ = Describe("creating a Namespace as Tenant owner", func() { +var _ = Describe("creating a Namespaces as different type of Tenant owners", func() { tnt := &capsulev1beta1.Tenant{ ObjectMeta: metav1.ObjectMeta{ Name: "tenant-assigned", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "alice", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "alice", + Kind: "User", + }, + { + Name: "bob", + Kind: "Group", + }, + { + Name: "system:serviceaccount:new-namespace-sa:default", + Kind: "ServiceAccount", + }, }, }, } JustBeforeEach(func() { EventuallyCreation(func() error { + tnt.ResourceVersion = "" return k8sClient.Create(context.TODO(), tnt) }).Should(Succeed()) }) @@ -37,9 +48,28 @@ var _ = Describe("creating a Namespace as Tenant owner", func() { Expect(k8sClient.Delete(context.TODO(), tnt)).Should(Succeed()) }) - It("should be available in Tenant namespaces list", func() { - ns := NewNamespace("new-namespace") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) - TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) + It("should be available in Tenant namespaces list and rolebindigs should present when created as User", func() { + ns := NewNamespace("new-namespace-user") + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) + TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElements(ns.GetName())) + for _, a := range KindInTenantRoleBindingAssertions(ns, defaultTimeoutInterval) { + a.Should(ContainElements("User", "Group", "ServiceAccount")) + } + }) + It("should be available in Tenant namespaces list and rolebindigs should present when created as Group", func() { + ns := NewNamespace("new-namespace-group") + NamespaceCreation(ns, tnt.Spec.Owners[1], defaultTimeoutInterval).Should(Succeed()) + TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElements(ns.GetName())) + for _, a := range KindInTenantRoleBindingAssertions(ns, defaultTimeoutInterval) { + a.Should(ContainElements("User", "Group", "ServiceAccount")) + } + }) + It("should be available in Tenant namespaces list and rolebindigs should present when created as ServiceAccount", func() { + ns := NewNamespace("new-namespace-sa") + NamespaceCreation(ns, tnt.Spec.Owners[2], defaultTimeoutInterval).Should(Succeed()) + TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElements(ns.GetName())) + for _, a := range KindInTenantRoleBindingAssertions(ns, defaultTimeoutInterval) { + a.Should(ContainElements("User", "Group", "ServiceAccount")) + } }) }) diff --git a/e2e/overquota_namespace_test.go b/e2e/overquota_namespace_test.go index e175db5f..aad70c8a 100644 --- a/e2e/overquota_namespace_test.go +++ b/e2e/overquota_namespace_test.go @@ -22,9 +22,11 @@ var _ = Describe("creating a Namespace in over-quota of three", func() { Name: "over-quota-tenant", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "bob", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "bob", + Kind: "User", + }, }, NamespaceQuota: pointer.Int32Ptr(3), }, @@ -43,13 +45,13 @@ var _ = Describe("creating a Namespace in over-quota of three", func() { By("creating three Namespaces", func() { for _, name := range []string{"bob-dev", "bob-staging", "bob-production"} { ns := NewNamespace(name) - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) } }) ns := NewNamespace("bob-fail") - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) _, err := cs.CoreV1().Namespaces().Create(context.TODO(), ns, metav1.CreateOptions{}) Expect(err).ShouldNot(Succeed()) }) diff --git a/e2e/owner_webhooks_test.go b/e2e/owner_webhooks_test.go index e98e31a7..37c18846 100644 --- a/e2e/owner_webhooks_test.go +++ b/e2e/owner_webhooks_test.go @@ -26,9 +26,11 @@ var _ = Describe("when Tenant owner interacts with the webhooks", func() { Name: "tenant-owner", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "ruby", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "ruby", + Kind: "User", + }, }, StorageClasses: &capsulev1beta1.AllowedListSpec{ Exact: []string{ @@ -98,7 +100,7 @@ var _ = Describe("when Tenant owner interacts with the webhooks", func() { It("should disallow deletions", func() { By("blocking Capsule Limit ranges", func() { ns := NewNamespace("limit-range-disallow") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) lr := &corev1.LimitRange{} @@ -107,12 +109,12 @@ var _ = Describe("when Tenant owner interacts with the webhooks", func() { return k8sClient.Get(context.TODO(), types.NamespacedName{Name: n, Namespace: ns.GetName()}, lr) }, defaultTimeoutInterval, defaultPollInterval).Should(Succeed()) - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) Expect(cs.CoreV1().LimitRanges(ns.GetName()).Delete(context.TODO(), lr.Name, metav1.DeleteOptions{})).ShouldNot(Succeed()) }) By("blocking Capsule Network Policy", func() { ns := NewNamespace("network-policy-disallow") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) np := &networkingv1.NetworkPolicy{} @@ -121,12 +123,12 @@ var _ = Describe("when Tenant owner interacts with the webhooks", func() { return k8sClient.Get(context.TODO(), types.NamespacedName{Name: n, Namespace: ns.GetName()}, np) }, defaultTimeoutInterval, defaultPollInterval).Should(Succeed()) - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) Expect(cs.NetworkingV1().NetworkPolicies(ns.GetName()).Delete(context.TODO(), np.Name, metav1.DeleteOptions{})).ShouldNot(Succeed()) }) By("blocking Capsule Resource Quota", func() { ns := NewNamespace("resource-quota-disallow") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) rq := &corev1.ResourceQuota{} @@ -135,7 +137,7 @@ var _ = Describe("when Tenant owner interacts with the webhooks", func() { return k8sClient.Get(context.TODO(), types.NamespacedName{Name: n, Namespace: ns.GetName()}, rq) }, defaultTimeoutInterval, defaultPollInterval).Should(Succeed()) - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) Expect(cs.NetworkingV1().NetworkPolicies(ns.GetName()).Delete(context.TODO(), rq.Name, metav1.DeleteOptions{})).ShouldNot(Succeed()) }) }) @@ -143,33 +145,33 @@ var _ = Describe("when Tenant owner interacts with the webhooks", func() { It("should allow", func() { By("listing Limit Range", func() { ns := NewNamespace("limit-range-list") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) Eventually(func() (err error) { - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) _, err = cs.CoreV1().LimitRanges(ns.GetName()).List(context.TODO(), metav1.ListOptions{}) return }, defaultTimeoutInterval, defaultPollInterval).Should(Succeed()) }) By("listing Network Policy", func() { ns := NewNamespace("network-policy-list") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) Eventually(func() (err error) { - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) _, err = cs.NetworkingV1().NetworkPolicies(ns.GetName()).List(context.TODO(), metav1.ListOptions{}) return }, defaultTimeoutInterval, defaultPollInterval).Should(Succeed()) }) By("listing Resource Quota", func() { ns := NewNamespace("resource-quota-list") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) Eventually(func() (err error) { - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) _, err = cs.NetworkingV1().NetworkPolicies(ns.GetName()).List(context.TODO(), metav1.ListOptions{}) return }, defaultTimeoutInterval, defaultPollInterval).Should(Succeed()) @@ -178,10 +180,10 @@ var _ = Describe("when Tenant owner interacts with the webhooks", func() { It("should allow all actions to Tenant owner Network Policy", func() { ns := NewNamespace("network-policy-allow") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) np := &networkingv1.NetworkPolicy{ ObjectMeta: metav1.ObjectMeta{ Name: "custom-network-policy", diff --git a/e2e/pod_priority_class_test.go b/e2e/pod_priority_class_test.go index e4b5bef2..dd49abc7 100644 --- a/e2e/pod_priority_class_test.go +++ b/e2e/pod_priority_class_test.go @@ -23,9 +23,11 @@ var _ = Describe("enforcing a Priority Class", func() { Name: "priority-class", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "george", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "george", + Kind: "User", + }, }, PriorityClasses: &capsulev1beta1.AllowedListSpec{ Exact: []string{"gold"}, @@ -46,7 +48,7 @@ var _ = Describe("enforcing a Priority Class", func() { It("should block non allowed Priority Class", func() { ns := NewNamespace("system-node-critical") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) pod := &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ @@ -63,7 +65,7 @@ var _ = Describe("enforcing a Priority Class", func() { }, } - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) EventuallyCreation(func() error { _, err := cs.CoreV1().Pods(ns.GetName()).Create(context.Background(), pod, metav1.CreateOptions{}) return err @@ -85,7 +87,7 @@ var _ = Describe("enforcing a Priority Class", func() { }() ns := NewNamespace("pc-exact-match") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) pod := &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ @@ -102,7 +104,7 @@ var _ = Describe("enforcing a Priority Class", func() { }, } - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) EventuallyCreation(func() error { _, err := cs.CoreV1().Pods(ns.GetName()).Create(context.Background(), pod, metav1.CreateOptions{}) return err @@ -112,7 +114,7 @@ var _ = Describe("enforcing a Priority Class", func() { It("should allow regex match", func() { ns := NewNamespace("pc-regex-match") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) for i, pc := range []string{"pc-bronze", "pc-silver", "pc-gold"} { class := &v1.PriorityClass{ @@ -140,7 +142,7 @@ var _ = Describe("enforcing a Priority Class", func() { }, } - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) EventuallyCreation(func() error { _, err := cs.CoreV1().Pods(ns.GetName()).Create(context.Background(), pod, metav1.CreateOptions{}) diff --git a/e2e/protected_namespace_regex_test.go b/e2e/protected_namespace_regex_test.go index 6ed07588..45a65804 100644 --- a/e2e/protected_namespace_regex_test.go +++ b/e2e/protected_namespace_regex_test.go @@ -23,9 +23,11 @@ var _ = Describe("creating a Namespace with a protected Namespace regex enabled" Name: "tenant-protected-namespace", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "alice", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "alice", + Kind: "User", + }, }, }, } @@ -47,13 +49,13 @@ var _ = Describe("creating a Namespace with a protected Namespace regex enabled" ns := NewNamespace("test-ok") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) }) It("should fail using a value non matching the regex", func() { ns := NewNamespace("test-system") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).ShouldNot(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).ShouldNot(Succeed()) ModifyCapsuleConfigurationOpts(func(configuration *capsulev1alpha1.CapsuleConfiguration) { configuration.Spec.ProtectedNamespaceRegexpString = "" diff --git a/e2e/resource_quota_exceeded_test.go b/e2e/resource_quota_exceeded_test.go index 6c2ee395..efb3e0c3 100644 --- a/e2e/resource_quota_exceeded_test.go +++ b/e2e/resource_quota_exceeded_test.go @@ -27,9 +27,11 @@ var _ = Describe("exceeding a Tenant resource quota", func() { Name: "tenant-resources-changes", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "bobby", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "bobby", + Kind: "User", + }, }, LimitRanges: &capsulev1beta1.LimitRangesSpec{Items: []corev1.LimitRangeSpec{ { @@ -113,7 +115,7 @@ var _ = Describe("exceeding a Tenant resource quota", func() { By("creating the Namespaces", func() { for _, i := range nsl { ns := NewNamespace(i) - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) } }) @@ -123,7 +125,7 @@ var _ = Describe("exceeding a Tenant resource quota", func() { }) It("should block new Pods", func() { - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) for _, namespace := range nsl { Eventually(func() (err error) { d := &appsv1.Deployment{ @@ -186,7 +188,7 @@ var _ = Describe("exceeding a Tenant resource quota", func() { }, }, } - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) EventuallyCreation(func() error { _, err := cs.CoreV1().Pods(ns).Create(context.Background(), pod, metav1.CreateOptions{}) return err diff --git a/e2e/selecting_non_owned_tenant_test.go b/e2e/selecting_non_owned_tenant_test.go index 85a55e46..69acb4d3 100644 --- a/e2e/selecting_non_owned_tenant_test.go +++ b/e2e/selecting_non_owned_tenant_test.go @@ -22,9 +22,11 @@ var _ = Describe("creating a Namespace trying to select a third Tenant", func() Name: "tenant-non-owned", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "undefined", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "undefined", + Kind: "User", + }, }, }, } @@ -51,7 +53,7 @@ var _ = Describe("creating a Namespace trying to select a third Tenant", func() }) }) - cs := ownerClient(&capsulev1beta1.Tenant{Spec: capsulev1beta1.TenantSpec{Owner: capsulev1beta1.OwnerSpec{Name: "dale", Kind: "User"}}}) + cs := ownerClient(capsulev1beta1.OwnerSpec{Name: "dale", Kind: "User"}) _, err := cs.CoreV1().Namespaces().Create(context.TODO(), ns, metav1.CreateOptions{}) Expect(err).To(HaveOccurred()) }) diff --git a/e2e/selecting_tenant_fail_test.go b/e2e/selecting_tenant_fail_test.go index 45851c81..86485301 100644 --- a/e2e/selecting_tenant_fail_test.go +++ b/e2e/selecting_tenant_fail_test.go @@ -21,9 +21,11 @@ var _ = Describe("creating a Namespace without a Tenant selector when user owns Name: "tenant-one", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "john", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "john", + Kind: "User", + }, }, }, } @@ -32,9 +34,11 @@ var _ = Describe("creating a Namespace without a Tenant selector when user owns Name: "tenant-two", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "john", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "john", + Kind: "User", + }, }, }, } @@ -43,9 +47,11 @@ var _ = Describe("creating a Namespace without a Tenant selector when user owns Name: "tenant-three", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "john", - Kind: "Group", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "john", + Kind: "Group", + }, }, }, } @@ -54,9 +60,11 @@ var _ = Describe("creating a Namespace without a Tenant selector when user owns Name: "tenant-four", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "john", - Kind: "Group", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "john", + Kind: "Group", + }, }, }, } @@ -66,16 +74,16 @@ var _ = Describe("creating a Namespace without a Tenant selector when user owns By("user owns 2 tenants", func() { EventuallyCreation(func() error { return k8sClient.Create(context.TODO(), t1) }).Should(Succeed()) EventuallyCreation(func() error { return k8sClient.Create(context.TODO(), t2) }).Should(Succeed()) - NamespaceCreation(ns, t1, defaultTimeoutInterval).ShouldNot(Succeed()) - NamespaceCreation(ns, t2, defaultTimeoutInterval).ShouldNot(Succeed()) + NamespaceCreation(ns, t1.Spec.Owners[0], defaultTimeoutInterval).ShouldNot(Succeed()) + NamespaceCreation(ns, t2.Spec.Owners[0], defaultTimeoutInterval).ShouldNot(Succeed()) Expect(k8sClient.Delete(context.TODO(), t1)).Should(Succeed()) Expect(k8sClient.Delete(context.TODO(), t2)).Should(Succeed()) }) By("group owns 2 tenants", func() { EventuallyCreation(func() error { return k8sClient.Create(context.TODO(), t3) }).Should(Succeed()) EventuallyCreation(func() error { return k8sClient.Create(context.TODO(), t4) }).Should(Succeed()) - NamespaceCreation(ns, t3, defaultTimeoutInterval).ShouldNot(Succeed()) - NamespaceCreation(ns, t4, defaultTimeoutInterval).ShouldNot(Succeed()) + NamespaceCreation(ns, t3.Spec.Owners[0], defaultTimeoutInterval).ShouldNot(Succeed()) + NamespaceCreation(ns, t4.Spec.Owners[0], defaultTimeoutInterval).ShouldNot(Succeed()) Expect(k8sClient.Delete(context.TODO(), t3)).Should(Succeed()) Expect(k8sClient.Delete(context.TODO(), t4)).Should(Succeed()) }) @@ -85,10 +93,10 @@ var _ = Describe("creating a Namespace without a Tenant selector when user owns EventuallyCreation(func() error { return k8sClient.Create(context.TODO(), t2) }).Should(Succeed()) EventuallyCreation(func() error { return k8sClient.Create(context.TODO(), t3) }).Should(Succeed()) EventuallyCreation(func() error { return k8sClient.Create(context.TODO(), t4) }).Should(Succeed()) - NamespaceCreation(ns, t1, defaultTimeoutInterval).ShouldNot(Succeed()) - NamespaceCreation(ns, t2, defaultTimeoutInterval).ShouldNot(Succeed()) - NamespaceCreation(ns, t3, defaultTimeoutInterval).ShouldNot(Succeed()) - NamespaceCreation(ns, t4, defaultTimeoutInterval).ShouldNot(Succeed()) + NamespaceCreation(ns, t1.Spec.Owners[0], defaultTimeoutInterval).ShouldNot(Succeed()) + NamespaceCreation(ns, t2.Spec.Owners[0], defaultTimeoutInterval).ShouldNot(Succeed()) + NamespaceCreation(ns, t3.Spec.Owners[0], defaultTimeoutInterval).ShouldNot(Succeed()) + NamespaceCreation(ns, t4.Spec.Owners[0], defaultTimeoutInterval).ShouldNot(Succeed()) Expect(k8sClient.Delete(context.TODO(), t1)).Should(Succeed()) Expect(k8sClient.Delete(context.TODO(), t2)).Should(Succeed()) Expect(k8sClient.Delete(context.TODO(), t3)).Should(Succeed()) diff --git a/e2e/selecting_tenant_with_label_test.go b/e2e/selecting_tenant_with_label_test.go index c16f4848..e5b35789 100644 --- a/e2e/selecting_tenant_with_label_test.go +++ b/e2e/selecting_tenant_with_label_test.go @@ -21,9 +21,11 @@ var _ = Describe("creating a Namespace with Tenant selector when user owns multi Name: "tenant-one", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "john", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "john", + Kind: "User", + }, }, }, } @@ -32,9 +34,11 @@ var _ = Describe("creating a Namespace with Tenant selector when user owns multi Name: "tenant-two", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "john", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "john", + Kind: "User", + }, }, }, } @@ -61,7 +65,7 @@ var _ = Describe("creating a Namespace with Tenant selector when user owns multi l: t2.Name, } }) - NamespaceCreation(ns, t2, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, t2.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(t2, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) }) }) diff --git a/e2e/service_metadata_test.go b/e2e/service_metadata_test.go index ac93fb9e..b62be21e 100644 --- a/e2e/service_metadata_test.go +++ b/e2e/service_metadata_test.go @@ -27,9 +27,11 @@ var _ = Describe("adding metadata to Service objects", func() { Name: "service-metadata", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "gatsby", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "gatsby", + Kind: "User", + }, }, ServicesMetadata: &capsulev1beta1.AdditionalMetadataSpec{ AdditionalLabels: map[string]string{ @@ -67,7 +69,7 @@ var _ = Describe("adding metadata to Service objects", func() { It("should apply them to Service", func() { ns := NewNamespace("service-metadata") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) svc := &corev1.Service{ @@ -121,7 +123,7 @@ var _ = Describe("adding metadata to Service objects", func() { It("should apply them to Endpoints", func() { ns := NewNamespace("endpoints-metadata") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) ep := &corev1.Endpoints{ @@ -181,7 +183,7 @@ var _ = Describe("adding metadata to Service objects", func() { } ns := NewNamespace("endpointslice-metadata") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) eps := &discoveryv1beta1.EndpointSlice{ diff --git a/e2e/storage_class_test.go b/e2e/storage_class_test.go index a71e7b95..8771cc8a 100644 --- a/e2e/storage_class_test.go +++ b/e2e/storage_class_test.go @@ -24,9 +24,11 @@ var _ = Describe("when Tenant handles Storage classes", func() { Name: "storage-class", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "storage", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "storage", + Kind: "User", + }, }, StorageClasses: &capsulev1beta1.AllowedListSpec{ Exact: []string{ @@ -50,12 +52,12 @@ var _ = Describe("when Tenant handles Storage classes", func() { It("should fails", func() { ns := NewNamespace("storage-class-disallowed") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) By("non-specifying it", func() { Eventually(func() (err error) { - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) p := &corev1.PersistentVolumeClaim{ ObjectMeta: metav1.ObjectMeta{ Name: "denied-pvc", @@ -75,7 +77,7 @@ var _ = Describe("when Tenant handles Storage classes", func() { }) By("specifying a forbidden one", func() { Eventually(func() (err error) { - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) p := &corev1.PersistentVolumeClaim{ ObjectMeta: metav1.ObjectMeta{ Name: "mighty-storage", @@ -97,9 +99,9 @@ var _ = Describe("when Tenant handles Storage classes", func() { It("should allow", func() { ns := NewNamespace("storage-class-allowed") - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) By("using exact matches", func() { for _, c := range tnt.Spec.StorageClasses.Exact { diff --git a/e2e/suite_test.go b/e2e/suite_test.go index ec092b6d..19cfd150 100644 --- a/e2e/suite_test.go +++ b/e2e/suite_test.go @@ -77,11 +77,11 @@ var _ = AfterSuite(func() { Expect(testEnv.Stop()).ToNot(HaveOccurred()) }) -func ownerClient(tenant *capsulev1beta1.Tenant) (cs kubernetes.Interface) { +func ownerClient(owner capsulev1beta1.OwnerSpec) (cs kubernetes.Interface) { c, err := config.GetConfig() Expect(err).ToNot(HaveOccurred()) - c.Impersonate.Groups = []string{capsulev1beta1.GroupVersion.Group, tenant.Spec.Owner.Name} - c.Impersonate.UserName = tenant.Spec.Owner.Name + c.Impersonate.Groups = []string{capsulev1beta1.GroupVersion.Group, owner.Name} + c.Impersonate.UserName = owner.Name cs, err = kubernetes.NewForConfig(c) Expect(err).ToNot(HaveOccurred()) return diff --git a/e2e/tenant_cordoning_test.go b/e2e/tenant_cordoning_test.go index 7e0fb6a6..c4814464 100644 --- a/e2e/tenant_cordoning_test.go +++ b/e2e/tenant_cordoning_test.go @@ -24,9 +24,11 @@ var _ = Describe("cordoning a Tenant", func() { Name: "tenant-cordoning", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "jim", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "jim", + Kind: "User", + }, }, }, } @@ -42,7 +44,7 @@ var _ = Describe("cordoning a Tenant", func() { }) It("should block or allow operations", func() { - cs := ownerClient(tnt) + cs := ownerClient(tnt.Spec.Owners[0]) ns := NewNamespace("cordoned-namespace") @@ -61,7 +63,7 @@ var _ = Describe("cordoning a Tenant", func() { } By("creating a Namespace", func() { - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) EventuallyCreation(func() error { _, err := cs.CoreV1().Pods(ns.Name).Create(context.Background(), pod, metav1.CreateOptions{}) diff --git a/e2e/tenant_ingress_hostnames_collision_allowed_test.go b/e2e/tenant_ingress_hostnames_collision_allowed_test.go index 38206bcb..27ed1ce2 100644 --- a/e2e/tenant_ingress_hostnames_collision_allowed_test.go +++ b/e2e/tenant_ingress_hostnames_collision_allowed_test.go @@ -23,9 +23,11 @@ var _ = Describe("when a second Tenant contains an already declared allowed Ingr Name: "allowed-collision-ingress-hostnames", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "first-user", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "first-user", + Kind: "User", + }, }, IngressHostnames: &capsulev1beta1.AllowedListSpec{ Exact: []string{"capsule.clastix.io", "docs.capsule.k8s", "42.clatix.io"}, @@ -57,9 +59,11 @@ var _ = Describe("when a second Tenant contains an already declared allowed Ingr Name: fmt.Sprintf("%s-%d", tnt.GetName(), i), }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "second-user", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "second-user", + Kind: "User", + }, }, IngressHostnames: &capsulev1beta1.AllowedListSpec{ Exact: []string{h}, @@ -96,9 +100,11 @@ var _ = Describe("when a second Tenant contains an already declared allowed Ingr Name: fmt.Sprintf("%s-%d", tnt.GetName(), i), }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "second-user", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "second-user", + Kind: "User", + }, }, IngressHostnames: &capsulev1beta1.AllowedListSpec{ Exact: []string{h}, diff --git a/e2e/tenant_ingress_hostnames_collision_blocked_test.go b/e2e/tenant_ingress_hostnames_collision_blocked_test.go index 16ad5ec1..d8afbab6 100644 --- a/e2e/tenant_ingress_hostnames_collision_blocked_test.go +++ b/e2e/tenant_ingress_hostnames_collision_blocked_test.go @@ -22,9 +22,11 @@ var _ = Describe("when a second Tenant contains an already declared allowed Ingr Name: "no-collision-ingress-hostnames", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "first-user", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "first-user", + Kind: "User", + }, }, IngressHostnames: &capsulev1beta1.AllowedListSpec{ Exact: []string{"capsule.clastix.io", "docs.capsule.k8s", "42.clatix.io"}, @@ -51,9 +53,11 @@ var _ = Describe("when a second Tenant contains an already declared allowed Ingr Name: fmt.Sprintf("%s-%d", tnt.GetName(), i), }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "second-user", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "second-user", + Kind: "User", + }, }, IngressHostnames: &capsulev1beta1.AllowedListSpec{ Exact: []string{h}, diff --git a/e2e/tenant_name_webhook_test.go b/e2e/tenant_name_webhook_test.go index 39893103..4a72ea45 100644 --- a/e2e/tenant_name_webhook_test.go +++ b/e2e/tenant_name_webhook_test.go @@ -21,9 +21,11 @@ var _ = Describe("creating a Tenant with wrong name", func() { Name: "non_rfc_dns_1123", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "john", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "john", + Kind: "User", + }, }, }, } diff --git a/e2e/tenant_owner_group_test.go b/e2e/tenant_owner_group_test.go deleted file mode 100644 index 29a7dbcb..00000000 --- a/e2e/tenant_owner_group_test.go +++ /dev/null @@ -1,49 +0,0 @@ -//+build e2e - -// Copyright 2020-2021 Clastix Labs -// SPDX-License-Identifier: Apache-2.0 - -package e2e - -import ( - "context" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - capsulev1beta1 "github.com/clastix/capsule/api/v1beta1" -) - -var _ = Describe("creating a Namespace with group Tenant owner", func() { - tnt := &capsulev1beta1.Tenant{ - ObjectMeta: metav1.ObjectMeta{ - Name: "tenant-group-owner", - }, - Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "alice", - Kind: "Group", - }, - }, - } - - JustBeforeEach(func() { - EventuallyCreation(func() error { - tnt.ResourceVersion = "" - return k8sClient.Create(context.TODO(), tnt) - }).Should(Succeed()) - }) - JustAfterEach(func() { - Expect(k8sClient.Delete(context.TODO(), tnt)).Should(Succeed()) - }) - - It("should succeed and be available in Tenant namespaces list", func() { - ns := NewNamespace("gto-namespace") - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) - TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) - for _, a := range KindInTenantRoleBindingAssertions(ns, defaultTimeoutInterval) { - a.Should(BeIdenticalTo("Group")) - } - }) -}) diff --git a/e2e/tenant_resources_changes_test.go b/e2e/tenant_resources_changes_test.go index 2d0491ce..2bf7c97e 100644 --- a/e2e/tenant_resources_changes_test.go +++ b/e2e/tenant_resources_changes_test.go @@ -27,9 +27,11 @@ var _ = Describe("changing Tenant managed Kubernetes resources", func() { Name: "tenant-resources-changes", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "laura", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "laura", + Kind: "User", + }, }, LimitRanges: &capsulev1beta1.LimitRangesSpec{Items: []corev1.LimitRangeSpec{ { @@ -160,7 +162,7 @@ var _ = Describe("changing Tenant managed Kubernetes resources", func() { By("creating the Namespaces", func() { for _, i := range nsl { ns := NewNamespace(i) - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) } }) diff --git a/e2e/tenant_resources_test.go b/e2e/tenant_resources_test.go index eb8cd108..54ce2c7c 100644 --- a/e2e/tenant_resources_test.go +++ b/e2e/tenant_resources_test.go @@ -27,9 +27,11 @@ var _ = Describe("creating namespaces within a Tenant with resources", func() { Name: "tenant-resources", }, Spec: capsulev1beta1.TenantSpec{ - Owner: capsulev1beta1.OwnerSpec{ - Name: "john", - Kind: "User", + Owners: []capsulev1beta1.OwnerSpec{ + { + Name: "john", + Kind: "User", + }, }, LimitRanges: &capsulev1beta1.LimitRangesSpec{Items: []corev1.LimitRangeSpec{ { @@ -159,7 +161,7 @@ var _ = Describe("creating namespaces within a Tenant with resources", func() { By("creating the Namespaces", func() { for _, i := range nsl { ns := NewNamespace(i) - NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) + NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) } }) diff --git a/e2e/utils_test.go b/e2e/utils_test.go index 5a10d4a1..1910c4c5 100644 --- a/e2e/utils_test.go +++ b/e2e/utils_test.go @@ -35,8 +35,8 @@ func NewNamespace(name string) *corev1.Namespace { } } -func NamespaceCreation(ns *corev1.Namespace, t *capsulev1beta1.Tenant, timeout time.Duration) AsyncAssertion { - cs := ownerClient(t) +func NamespaceCreation(ns *corev1.Namespace, owner capsulev1beta1.OwnerSpec, timeout time.Duration) AsyncAssertion { + cs := ownerClient(owner) return Eventually(func() (err error) { _, err = cs.CoreV1().Namespaces().Create(context.TODO(), ns, metav1.CreateOptions{}) return @@ -68,11 +68,15 @@ func ModifyCapsuleConfigurationOpts(fn func(configuration *capsulev1alpha1.Capsu func KindInTenantRoleBindingAssertions(ns *corev1.Namespace, timeout time.Duration) (out []AsyncAssertion) { for _, rbn := range tenantRoleBindingNames { rb := &rbacv1.RoleBinding{} - out = append(out, Eventually(func() string { + out = append(out, Eventually(func() []string { if err := k8sClient.Get(context.TODO(), types.NamespacedName{Name: rbn, Namespace: ns.GetName()}, rb); err != nil { - return "" + return nil } - return rb.Subjects[0].Kind + var subjects []string + for _, subject := range rb.Subjects { + subjects = append(subjects, subject.Kind) + } + return subjects }, timeout, defaultPollInterval)) } return From 02f35686acf6f6713cd8c931255d15f32acd308e Mon Sep 17 00:00:00 2001 From: Maksim Fedotov Date: Mon, 12 Jul 2021 12:18:12 +0300 Subject: [PATCH 4/4] chore: fix linting issues --- api/v1alpha1/conversion_hub.go | 1 - 1 file changed, 1 deletion(-) diff --git a/api/v1alpha1/conversion_hub.go b/api/v1alpha1/conversion_hub.go index 5b5bcd2e..51138caf 100644 --- a/api/v1alpha1/conversion_hub.go +++ b/api/v1alpha1/conversion_hub.go @@ -283,7 +283,6 @@ func (t *Tenant) convertV1Beta1OwnerToV1Alpha1(src *capsulev1beta1.Tenant) { enableIngressClassDeletionAnnotation: nil, } - for i, owner := range src.Spec.Owners { if i == 0 { t.Spec.Owner = OwnerSpec{