From 9db0a980903d5d7f87d6f7032bb9c93d5ee481eb Mon Sep 17 00:00:00 2001 From: cuisongliu Date: Wed, 5 Jul 2023 15:38:50 +0800 Subject: [PATCH] refactor(main): remove old code for convert (#3417) Signed-off-by: cuisongliu --- controllers/user/PROJECT | 24 -- controllers/user/api/v1/usergroup_types.go | 62 ----- .../user/api/v1/usergroupbinding_types.go | 83 ------- .../user/api/v1/zz_generated.deepcopy.go | 161 ------------ .../user.sealos.io_usergroupbindings.yaml | 140 ----------- .../crd/bases/user.sealos.io_usergroups.yaml | 95 ------- .../user/config/crd/kustomization.yaml | 2 - .../crd/patches/cainjection_in_groups.yaml | 7 - .../cainjection_in_usergroupbindings.yaml | 7 - ...jection_in_usergroupnamespacebindings.yaml | 7 - .../patches/cainjection_in_usergroups.yaml | 7 - .../cainjection_in_usergroupuserbindings.yaml | 7 - .../patches/webhook_in_usergroupbindings.yaml | 16 -- ...webhook_in_usergroupnamespacebindings.yaml | 16 -- .../crd/patches/webhook_in_usergroups.yaml | 16 -- .../webhook_in_usergroupuserbindings.yaml | 16 -- .../user/controllers/user_controller.go | 32 --- .../user/controllers/usergroup_controller.go | 81 ------ .../usergroupbinding_controller.go | 106 -------- controllers/user/deploy/Kubefile | 2 +- controllers/user/deploy/manifests/deploy.yaml | 235 ------------------ controllers/user/main.go | 12 - 22 files changed, 1 insertion(+), 1133 deletions(-) delete mode 100644 controllers/user/api/v1/usergroup_types.go delete mode 100644 controllers/user/api/v1/usergroupbinding_types.go delete mode 100644 controllers/user/config/crd/bases/user.sealos.io_usergroupbindings.yaml delete mode 100644 controllers/user/config/crd/bases/user.sealos.io_usergroups.yaml delete mode 100644 controllers/user/config/crd/patches/cainjection_in_groups.yaml delete mode 100644 controllers/user/config/crd/patches/cainjection_in_usergroupbindings.yaml delete mode 100644 controllers/user/config/crd/patches/cainjection_in_usergroupnamespacebindings.yaml delete mode 100644 controllers/user/config/crd/patches/cainjection_in_usergroups.yaml delete mode 100644 controllers/user/config/crd/patches/cainjection_in_usergroupuserbindings.yaml delete mode 100644 controllers/user/config/crd/patches/webhook_in_usergroupbindings.yaml delete mode 100644 controllers/user/config/crd/patches/webhook_in_usergroupnamespacebindings.yaml delete mode 100644 controllers/user/config/crd/patches/webhook_in_usergroups.yaml delete mode 100644 controllers/user/config/crd/patches/webhook_in_usergroupuserbindings.yaml delete mode 100644 controllers/user/controllers/usergroup_controller.go delete mode 100644 controllers/user/controllers/usergroupbinding_controller.go diff --git a/controllers/user/PROJECT b/controllers/user/PROJECT index 4d28c64ad..ddf7fc39c 100644 --- a/controllers/user/PROJECT +++ b/controllers/user/PROJECT @@ -16,28 +16,4 @@ resources: defaulting: true validation: true webhookVersion: v1 -- api: - crdVersion: v1 - controller: true - domain: sealos.io - group: user - kind: UserGroup - path: github.com/labring/sealos/controllers/user/api/v1 - version: v1 - webhooks: - defaulting: true - validation: true - webhookVersion: v1 -- api: - crdVersion: v1 - controller: true - domain: sealos.io - group: user - kind: UserGroupBinding - path: github.com/labring/sealos/controllers/user/api/v1 - version: v1 - webhooks: - defaulting: true - validation: true - webhookVersion: v1 version: "3" diff --git a/controllers/user/api/v1/usergroup_types.go b/controllers/user/api/v1/usergroup_types.go deleted file mode 100644 index 3fa2a433f..000000000 --- a/controllers/user/api/v1/usergroup_types.go +++ /dev/null @@ -1,62 +0,0 @@ -/* -Copyright 2022 labring. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! -// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. - -// +kubebuilder:object:root=true -// +kubebuilder:subresource:status -// +kubebuilder:resource:scope=Cluster,shortName=ug -// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase" -// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" - -// UserGroup is the Schema for the usergroups API -type UserGroup struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - Status UserGroupStatus `json:"status,omitempty"` -} - -// UserGroupStatus defines the observed state of UserGroup -type UserGroupStatus struct { - // Phase is the recently observed lifecycle phase of user group - //+kubebuilder:default:=Unknown - Phase UserPhase `json:"phase,omitempty"` - // The generation observed by the user controller. - // +optional - ObservedGeneration int64 `json:"observedGeneration,omitempty"` - // Conditions contains the different condition statuses for this user group. - Conditions []Condition `json:"conditions,omitempty"` -} - -//+kubebuilder:object:root=true - -// UserGroupList contains a list of UserGroup -type UserGroupList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []UserGroup `json:"items"` -} - -func init() { - SchemeBuilder.Register(&UserGroup{}, &UserGroupList{}) -} diff --git a/controllers/user/api/v1/usergroupbinding_types.go b/controllers/user/api/v1/usergroupbinding_types.go deleted file mode 100644 index 20e09ba0c..000000000 --- a/controllers/user/api/v1/usergroupbinding_types.go +++ /dev/null @@ -1,83 +0,0 @@ -/* -Copyright 2022 labring. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1 - -import ( - v1 "k8s.io/api/rbac/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! -// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. - -// +kubebuilder:object:root=true -// +kubebuilder:subresource:status -// +kubebuilder:resource:scope=Cluster,shortName=ugbinding -// +kubebuilder:printcolumn:name="UserGroup",type="string",JSONPath=".userGroupRef" -// +kubebuilder:printcolumn:name="Kind",type="string",JSONPath=".subject.kind" -// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase" -// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" - -// UserGroupBinding is the Schema for the usergroupbindings API -type UserGroupBinding struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - // Subject holds references to the objects the role applies to. - // +optional - Subject v1.Subject `json:"subject"` - - // RoleRef can only reference a ClusterRole in the global namespace. - //+kubebuilder:default:=user - RoleRef RoleRefType `json:"roleRef,omitempty"` - // UserGroupRef is the reference to the user group that this binding binds to. - UserGroupRef string `json:"userGroupRef"` - // Status contains the different condition statuses for this user group. - Status UserGroupBindingStatus `json:"status,omitempty"` -} - -type RoleRefType string - -const ( - RoleRefTypeManager RoleRefType = "manager" - RoleRefTypeUser RoleRefType = "user" -) - -// UserGroupBindingStatus defines the observed state of UserGroupBinding -type UserGroupBindingStatus struct { - // Phase is the recently observed lifecycle phase of user group binding - //+kubebuilder:default:=Unknown - Phase UserPhase `json:"phase,omitempty"` - // The generation observed by the user controller. - // +optional - ObservedGeneration int64 `json:"observedGeneration,omitempty"` - // Conditions contains the different condition statuses for this user group. - Conditions []Condition `json:"conditions,omitempty"` -} - -//+kubebuilder:object:root=true - -// UserGroupBindingList contains a list of UserGroupBinding -type UserGroupBindingList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []UserGroupBinding `json:"items"` -} - -func init() { - SchemeBuilder.Register(&UserGroupBinding{}, &UserGroupBindingList{}) -} diff --git a/controllers/user/api/v1/zz_generated.deepcopy.go b/controllers/user/api/v1/zz_generated.deepcopy.go index 818ae9405..ed521d668 100644 --- a/controllers/user/api/v1/zz_generated.deepcopy.go +++ b/controllers/user/api/v1/zz_generated.deepcopy.go @@ -69,167 +69,6 @@ func (in *User) DeepCopyObject() runtime.Object { return nil } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *UserGroup) DeepCopyInto(out *UserGroup) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Status.DeepCopyInto(&out.Status) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UserGroup. -func (in *UserGroup) DeepCopy() *UserGroup { - if in == nil { - return nil - } - out := new(UserGroup) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *UserGroup) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *UserGroupBinding) DeepCopyInto(out *UserGroupBinding) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Subject = in.Subject - in.Status.DeepCopyInto(&out.Status) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UserGroupBinding. -func (in *UserGroupBinding) DeepCopy() *UserGroupBinding { - if in == nil { - return nil - } - out := new(UserGroupBinding) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *UserGroupBinding) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *UserGroupBindingList) DeepCopyInto(out *UserGroupBindingList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]UserGroupBinding, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UserGroupBindingList. -func (in *UserGroupBindingList) DeepCopy() *UserGroupBindingList { - if in == nil { - return nil - } - out := new(UserGroupBindingList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *UserGroupBindingList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *UserGroupBindingStatus) DeepCopyInto(out *UserGroupBindingStatus) { - *out = *in - if in.Conditions != nil { - in, out := &in.Conditions, &out.Conditions - *out = make([]Condition, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UserGroupBindingStatus. -func (in *UserGroupBindingStatus) DeepCopy() *UserGroupBindingStatus { - if in == nil { - return nil - } - out := new(UserGroupBindingStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *UserGroupList) DeepCopyInto(out *UserGroupList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]UserGroup, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UserGroupList. -func (in *UserGroupList) DeepCopy() *UserGroupList { - if in == nil { - return nil - } - out := new(UserGroupList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *UserGroupList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *UserGroupStatus) DeepCopyInto(out *UserGroupStatus) { - *out = *in - if in.Conditions != nil { - in, out := &in.Conditions, &out.Conditions - *out = make([]Condition, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UserGroupStatus. -func (in *UserGroupStatus) DeepCopy() *UserGroupStatus { - if in == nil { - return nil - } - out := new(UserGroupStatus) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *UserList) DeepCopyInto(out *UserList) { *out = *in diff --git a/controllers/user/config/crd/bases/user.sealos.io_usergroupbindings.yaml b/controllers/user/config/crd/bases/user.sealos.io_usergroupbindings.yaml deleted file mode 100644 index b057f559e..000000000 --- a/controllers/user/config/crd/bases/user.sealos.io_usergroupbindings.yaml +++ /dev/null @@ -1,140 +0,0 @@ ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.10.0 - creationTimestamp: null - name: usergroupbindings.user.sealos.io -spec: - group: user.sealos.io - names: - kind: UserGroupBinding - listKind: UserGroupBindingList - plural: usergroupbindings - shortNames: - - ugbinding - singular: usergroupbinding - scope: Cluster - versions: - - additionalPrinterColumns: - - jsonPath: .userGroupRef - name: UserGroup - type: string - - jsonPath: .subject.kind - name: Kind - type: string - - jsonPath: .status.phase - name: Phase - type: string - - jsonPath: .metadata.creationTimestamp - name: Age - type: date - name: v1 - schema: - openAPIV3Schema: - description: UserGroupBinding is the Schema for the usergroupbindings 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' - 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' - type: string - metadata: - type: object - roleRef: - default: user - description: RoleRef can only reference a ClusterRole in the global namespace. - type: string - status: - description: Status contains the different condition statuses for this - user group. - properties: - conditions: - description: Conditions contains the different condition statuses - for this user group. - items: - properties: - lastHeartbeatTime: - description: LastHeartbeatTime is the last time this condition - was updated. - format: date-time - type: string - lastTransitionTime: - description: LastTransitionTime is the last time the condition - changed from one status to another. - format: date-time - type: string - message: - description: Message is a human-readable message indicating - details about the last status change. - type: string - reason: - description: Reason is a (brief) reason for the condition's - last status change. - type: string - status: - description: Status is the status of the condition. One of True, - False, Unknown. - type: string - type: - type: string - required: - - status - - type - type: object - type: array - observedGeneration: - description: The generation observed by the user controller. - format: int64 - type: integer - phase: - default: Unknown - description: Phase is the recently observed lifecycle phase of user - group binding - type: string - type: object - subject: - description: Subject holds references to the objects the role applies - to. - properties: - apiGroup: - description: APIGroup holds the API group of the referenced subject. - Defaults to "" for ServiceAccount subjects. Defaults to "rbac.authorization.k8s.io" - for User and Group subjects. - type: string - kind: - description: Kind of object being referenced. Values defined by this - API group are "User", "Group", and "ServiceAccount". If the Authorizer - does not recognized the kind value, the Authorizer should report - an error. - type: string - name: - description: Name of the object being referenced. - type: string - namespace: - description: Namespace of the referenced object. If the object kind - is non-namespace, such as "User" or "Group", and this value is not - empty the Authorizer should report an error. - type: string - required: - - kind - - name - type: object - x-kubernetes-map-type: atomic - userGroupRef: - description: UserGroupRef is the reference to the user group that this - binding binds to. - type: string - required: - - userGroupRef - type: object - served: true - storage: true - subresources: - status: {} diff --git a/controllers/user/config/crd/bases/user.sealos.io_usergroups.yaml b/controllers/user/config/crd/bases/user.sealos.io_usergroups.yaml deleted file mode 100644 index 44584a526..000000000 --- a/controllers/user/config/crd/bases/user.sealos.io_usergroups.yaml +++ /dev/null @@ -1,95 +0,0 @@ ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.10.0 - creationTimestamp: null - name: usergroups.user.sealos.io -spec: - group: user.sealos.io - names: - kind: UserGroup - listKind: UserGroupList - plural: usergroups - shortNames: - - ug - singular: usergroup - scope: Cluster - versions: - - additionalPrinterColumns: - - jsonPath: .status.phase - name: Phase - type: string - - jsonPath: .metadata.creationTimestamp - name: Age - type: date - name: v1 - schema: - openAPIV3Schema: - description: UserGroup is the Schema for the usergroups 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' - 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' - type: string - metadata: - type: object - status: - description: UserGroupStatus defines the observed state of UserGroup - properties: - conditions: - description: Conditions contains the different condition statuses - for this user group. - items: - properties: - lastHeartbeatTime: - description: LastHeartbeatTime is the last time this condition - was updated. - format: date-time - type: string - lastTransitionTime: - description: LastTransitionTime is the last time the condition - changed from one status to another. - format: date-time - type: string - message: - description: Message is a human-readable message indicating - details about the last status change. - type: string - reason: - description: Reason is a (brief) reason for the condition's - last status change. - type: string - status: - description: Status is the status of the condition. One of True, - False, Unknown. - type: string - type: - type: string - required: - - status - - type - type: object - type: array - observedGeneration: - description: The generation observed by the user controller. - format: int64 - type: integer - phase: - default: Unknown - description: Phase is the recently observed lifecycle phase of user - group - type: string - type: object - type: object - served: true - storage: true - subresources: - status: {} diff --git a/controllers/user/config/crd/kustomization.yaml b/controllers/user/config/crd/kustomization.yaml index 3c15e1489..4357afb0f 100644 --- a/controllers/user/config/crd/kustomization.yaml +++ b/controllers/user/config/crd/kustomization.yaml @@ -3,8 +3,6 @@ # It should be run by config/default resources: - bases/user.sealos.io_users.yaml -- bases/user.sealos.io_usergroups.yaml -- bases/user.sealos.io_usergroupbindings.yaml #+kubebuilder:scaffold:crdkustomizeresource patchesStrategicMerge: diff --git a/controllers/user/config/crd/patches/cainjection_in_groups.yaml b/controllers/user/config/crd/patches/cainjection_in_groups.yaml deleted file mode 100644 index 504c057cf..000000000 --- a/controllers/user/config/crd/patches/cainjection_in_groups.yaml +++ /dev/null @@ -1,7 +0,0 @@ -# The following patch adds a directive for certmanager to inject CA into the CRD -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) - name: groups.user.sealos.io diff --git a/controllers/user/config/crd/patches/cainjection_in_usergroupbindings.yaml b/controllers/user/config/crd/patches/cainjection_in_usergroupbindings.yaml deleted file mode 100644 index 550ba8c73..000000000 --- a/controllers/user/config/crd/patches/cainjection_in_usergroupbindings.yaml +++ /dev/null @@ -1,7 +0,0 @@ -# The following patch adds a directive for certmanager to inject CA into the CRD -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) - name: usergroupbindings.user.sealos.io diff --git a/controllers/user/config/crd/patches/cainjection_in_usergroupnamespacebindings.yaml b/controllers/user/config/crd/patches/cainjection_in_usergroupnamespacebindings.yaml deleted file mode 100644 index 95fc29c9a..000000000 --- a/controllers/user/config/crd/patches/cainjection_in_usergroupnamespacebindings.yaml +++ /dev/null @@ -1,7 +0,0 @@ -# The following patch adds a directive for certmanager to inject CA into the CRD -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) - name: usergroupnamespacebindings.user.sealos.io diff --git a/controllers/user/config/crd/patches/cainjection_in_usergroups.yaml b/controllers/user/config/crd/patches/cainjection_in_usergroups.yaml deleted file mode 100644 index 8cd5c9241..000000000 --- a/controllers/user/config/crd/patches/cainjection_in_usergroups.yaml +++ /dev/null @@ -1,7 +0,0 @@ -# The following patch adds a directive for certmanager to inject CA into the CRD -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) - name: usergroups.user.sealos.io diff --git a/controllers/user/config/crd/patches/cainjection_in_usergroupuserbindings.yaml b/controllers/user/config/crd/patches/cainjection_in_usergroupuserbindings.yaml deleted file mode 100644 index 2f609d15a..000000000 --- a/controllers/user/config/crd/patches/cainjection_in_usergroupuserbindings.yaml +++ /dev/null @@ -1,7 +0,0 @@ -# The following patch adds a directive for certmanager to inject CA into the CRD -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) - name: usergroupuserbindings.user.sealos.io diff --git a/controllers/user/config/crd/patches/webhook_in_usergroupbindings.yaml b/controllers/user/config/crd/patches/webhook_in_usergroupbindings.yaml deleted file mode 100644 index 08dae88d5..000000000 --- a/controllers/user/config/crd/patches/webhook_in_usergroupbindings.yaml +++ /dev/null @@ -1,16 +0,0 @@ -# The following patch enables a conversion webhook for the CRD -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - name: usergroupbindings.user.sealos.io -spec: - conversion: - strategy: Webhook - webhook: - clientConfig: - service: - namespace: system - name: webhook-service - path: /convert - conversionReviewVersions: - - v1 diff --git a/controllers/user/config/crd/patches/webhook_in_usergroupnamespacebindings.yaml b/controllers/user/config/crd/patches/webhook_in_usergroupnamespacebindings.yaml deleted file mode 100644 index a2879d288..000000000 --- a/controllers/user/config/crd/patches/webhook_in_usergroupnamespacebindings.yaml +++ /dev/null @@ -1,16 +0,0 @@ -# The following patch enables a conversion webhook for the CRD -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - name: usergroupnamespacebindings.user.sealos.io -spec: - conversion: - strategy: Webhook - webhook: - clientConfig: - service: - namespace: system - name: webhook-service - path: /convert - conversionReviewVersions: - - v1 diff --git a/controllers/user/config/crd/patches/webhook_in_usergroups.yaml b/controllers/user/config/crd/patches/webhook_in_usergroups.yaml deleted file mode 100644 index b8b67ad28..000000000 --- a/controllers/user/config/crd/patches/webhook_in_usergroups.yaml +++ /dev/null @@ -1,16 +0,0 @@ -# The following patch enables a conversion webhook for the CRD -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - name: usergroups.user.sealos.io -spec: - conversion: - strategy: Webhook - webhook: - clientConfig: - service: - namespace: system - name: webhook-service - path: /convert - conversionReviewVersions: - - v1 diff --git a/controllers/user/config/crd/patches/webhook_in_usergroupuserbindings.yaml b/controllers/user/config/crd/patches/webhook_in_usergroupuserbindings.yaml deleted file mode 100644 index 2247a5983..000000000 --- a/controllers/user/config/crd/patches/webhook_in_usergroupuserbindings.yaml +++ /dev/null @@ -1,16 +0,0 @@ -# The following patch enables a conversion webhook for the CRD -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - name: usergroupuserbindings.user.sealos.io -spec: - conversion: - strategy: Webhook - webhook: - clientConfig: - service: - namespace: system - name: webhook-service - path: /convert - conversionReviewVersions: - - v1 diff --git a/controllers/user/controllers/user_controller.go b/controllers/user/controllers/user_controller.go index 27a9cb83d..1fbacf92c 100644 --- a/controllers/user/controllers/user_controller.go +++ b/controllers/user/controllers/user_controller.go @@ -37,7 +37,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/source" - "github.com/labring/sealos/controllers/user/controllers/migrate" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/client-go/rest" kubecontroller "sigs.k8s.io/controller-runtime/pkg/controller" @@ -162,8 +161,6 @@ func (r *UserReconciler) reconcile(ctx context.Context, obj client.Object) (ctrl r.syncKubeConfig, r.syncRole, r.syncRoleBinding, - r.syncOwnerUG, - r.syncOwnerUGNamespaceBinding, r.syncFinalStatus, } @@ -566,35 +563,6 @@ func syncReNewConfig(user *userv1.User) (*api.Config, *string, error) { return apiConfig, event, err } -func (r *UserReconciler) syncOwnerUG(ctx context.Context, user *userv1.User) context.Context { - userConditionType := userv1.ConditionType("OwnerUGSyncReady") - user.Status.Conditions = helper.DeleteCondition(user.Status.Conditions, userConditionType) - ug := &userv1.UserGroup{} - err := r.Client.Get(ctx, types.NamespacedName{Name: fmt.Sprintf("ug-%s", user.Name)}, ug) - if err == nil { - migrate.SetOwner(ctx, r.Client, ug, nil) - migrate.RemoveFinalizer(ctx, r.Client, ug, migrate.UGFinalizer) - } - return ctx -} - -func (r *UserReconciler) syncOwnerUGNamespaceBinding(ctx context.Context, user *userv1.User) context.Context { - userConditionType := userv1.ConditionType("OwnerUGNamespaceBindingSyncReady") - user.Status.Conditions = helper.DeleteCondition(user.Status.Conditions, userConditionType) - ugBinding := &userv1.UserGroupBinding{} - err := r.Client.Get(ctx, types.NamespacedName{Name: fmt.Sprintf("ugn-%s", user.Name)}, ugBinding) - if err == nil { - migrate.SetOwner(ctx, r.Client, ugBinding, nil) - migrate.RemoveFinalizer(ctx, r.Client, ugBinding, migrate.UGBindingFinalizer) - } - uguBinding := &userv1.UserGroupBinding{} - err = r.Client.Get(ctx, types.NamespacedName{Name: fmt.Sprintf("ugu-%s", user.Name)}, uguBinding) - if err == nil { - migrate.RemoveFinalizer(ctx, r.Client, uguBinding, migrate.UGBindingFinalizer) - } - return ctx -} - func (r *UserReconciler) syncFinalStatus(ctx context.Context, user *userv1.User) context.Context { condition := &userv1.Condition{ Type: userv1.Ready, diff --git a/controllers/user/controllers/usergroup_controller.go b/controllers/user/controllers/usergroup_controller.go deleted file mode 100644 index 6c3199136..000000000 --- a/controllers/user/controllers/usergroup_controller.go +++ /dev/null @@ -1,81 +0,0 @@ -/* -Copyright 2022 labring. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package controllers - -import ( - "context" - - "github.com/go-logr/logr" - userv1 "github.com/labring/sealos/controllers/user/api/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/client-go/tools/record" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/cache" - "sigs.k8s.io/controller-runtime/pkg/client" -) - -// UserGroupReconciler reconciles a UserGroup object -type UserGroupReconciler struct { - Logger logr.Logger - Recorder record.EventRecorder - cache cache.Cache - *runtime.Scheme - client.Client -} - -// Reconcile is part of the main kubernetes reconciliation loop which aims to -// move the current state of the cluster closer to the desired state. -// TODO(user): Modify the Reconcile function to compare the state specified by -// the UserGroup object against the actual cluster state, and then -// perform operations to make the cluster state reflect the state specified by -// the user. -// -// For more details, check Reconcile and its Result here: -// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.12.2/pkg/reconcile -func (r *UserGroupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - r.Logger.V(1).Info("start reconcile for user groups") - userGroup := &userv1.UserGroup{} - if err := r.Get(ctx, req.NamespacedName, userGroup); err != nil { - return ctrl.Result{}, client.IgnoreNotFound(err) - } - //ug - if userGroup.DeletionTimestamp.IsZero() { - if len(userGroup.Finalizers) == 0 && len(userGroup.OwnerReferences) == 0 { - _ = r.Delete(ctx, userGroup) - return ctrl.Result{}, nil - } - } - return ctrl.Result{Requeue: true}, nil -} - -// SetupWithManager sets up the controller with the Manager. -func (r *UserGroupReconciler) SetupWithManager(mgr ctrl.Manager) error { - const controllerName = "user_group_controller" - if r.Client == nil { - r.Client = mgr.GetClient() - } - r.Logger = ctrl.Log.WithName(controllerName) - if r.Recorder == nil { - r.Recorder = mgr.GetEventRecorderFor(controllerName) - } - r.Scheme = mgr.GetScheme() - r.cache = mgr.GetCache() - r.Logger.V(1).Info("init reconcile controller user group") - return ctrl.NewControllerManagedBy(mgr). - For(&userv1.UserGroup{}). - Complete(r) -} diff --git a/controllers/user/controllers/usergroupbinding_controller.go b/controllers/user/controllers/usergroupbinding_controller.go deleted file mode 100644 index 89ae8f3c2..000000000 --- a/controllers/user/controllers/usergroupbinding_controller.go +++ /dev/null @@ -1,106 +0,0 @@ -/* -Copyright 2022 labring. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package controllers - -import ( - "context" - - "github.com/go-logr/logr" - v1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/client-go/tools/record" - "sigs.k8s.io/controller-runtime/pkg/cache" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - - userv1 "github.com/labring/sealos/controllers/user/api/v1" - "k8s.io/apimachinery/pkg/runtime" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/client" -) - -// UserGroupBindingReconciler reconciles a UserGroupBinding object -type UserGroupBindingReconciler struct { - Logger logr.Logger - Recorder record.EventRecorder - cache cache.Cache - *runtime.Scheme - client.Client -} - -// Reconcile is part of the main kubernetes reconciliation loop which aims to -// move the current state of the cluster closer to the desired state. -// TODO(user): Modify the Reconcile function to compare the state specified by -// the UserGroupBinding object against the actual cluster state, and then -// perform operations to make the cluster state reflect the state specified by -// the user. -// -// For more details, check Reconcile and its Result here: -// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.11.0/pkg/reconcile -func (r *UserGroupBindingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - r.Logger.V(1).Info("start reconcile for userGroupBindings") - - userGroupBinding := &userv1.UserGroupBinding{} - if err := r.Get(ctx, req.NamespacedName, userGroupBinding); err != nil { - return ctrl.Result{}, client.IgnoreNotFound(err) - } - if userGroupBinding.Subject.Name != "" && userGroupBinding.Subject.Kind == "Namespace" { - userName := userGroupBinding.Annotations[userAnnotationOwnerKey] - if userName == "" { - return ctrl.Result{}, nil - } - user := &userv1.User{} - if err := r.Get(ctx, client.ObjectKey{Name: userName}, user); err != nil { - return ctrl.Result{}, err - } - ns := &v1.Namespace{} - if err := r.Get(ctx, client.ObjectKey{Name: userGroupBinding.Subject.Name}, ns); err != nil { - return ctrl.Result{}, err - } - _, err := controllerutil.CreateOrUpdate(ctx, r.Client, ns, func() error { - ns.SetOwnerReferences([]metav1.OwnerReference{}) - return controllerutil.SetControllerReference(user, ns, r.Scheme) - }) - if err != nil { - return ctrl.Result{}, err - } - } - if userGroupBinding.DeletionTimestamp.IsZero() { - if len(userGroupBinding.Finalizers) == 0 && len(userGroupBinding.OwnerReferences) == 0 { - _ = r.Delete(ctx, userGroupBinding) - return ctrl.Result{}, nil - } - } - return ctrl.Result{Requeue: true}, nil -} - -// SetupWithManager sets up the controller with the Manager. -func (r *UserGroupBindingReconciler) SetupWithManager(mgr ctrl.Manager) error { - const controllerName = "user_group_binding_controller" - if r.Client == nil { - r.Client = mgr.GetClient() - } - r.Logger = ctrl.Log.WithName(controllerName) - if r.Recorder == nil { - r.Recorder = mgr.GetEventRecorderFor(controllerName) - } - r.Scheme = mgr.GetScheme() - r.cache = mgr.GetCache() - r.Logger.V(1).Info("init reconcile controller user group binding") - return ctrl.NewControllerManagedBy(mgr). - For(&userv1.UserGroupBinding{}). - Complete(r) -} diff --git a/controllers/user/deploy/Kubefile b/controllers/user/deploy/Kubefile index 109bcef1a..ed4ca0e7d 100644 --- a/controllers/user/deploy/Kubefile +++ b/controllers/user/deploy/Kubefile @@ -5,4 +5,4 @@ USER 65532:65532 COPY registry registry COPY manifests manifests -CMD ["kubectl apply -f manifests/deploy.yaml","kubectl delete -f manifests/rbac.yaml --ignore-not-found=true"] +CMD ["kubectl apply -f manifests/deploy.yaml","kubectl delete -f manifests/rbac.yaml --ignore-not-found=true","kubectl delete crd usergroups.user.sealos.io --ignore-not-found=true","kubectl delete crd usergroupbindings.user.sealos.io --ignore-not-found=true"] diff --git a/controllers/user/deploy/manifests/deploy.yaml b/controllers/user/deploy/manifests/deploy.yaml index 2812318c3..d101db612 100644 --- a/controllers/user/deploy/manifests/deploy.yaml +++ b/controllers/user/deploy/manifests/deploy.yaml @@ -7,241 +7,6 @@ metadata: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.10.0 - creationTimestamp: null - name: usergroupbindings.user.sealos.io -spec: - group: user.sealos.io - names: - kind: UserGroupBinding - listKind: UserGroupBindingList - plural: usergroupbindings - shortNames: - - ugbinding - singular: usergroupbinding - scope: Cluster - versions: - - additionalPrinterColumns: - - jsonPath: .userGroupRef - name: UserGroup - type: string - - jsonPath: .subject.kind - name: Kind - type: string - - jsonPath: .status.phase - name: Phase - type: string - - jsonPath: .metadata.creationTimestamp - name: Age - type: date - name: v1 - schema: - openAPIV3Schema: - description: UserGroupBinding is the Schema for the usergroupbindings 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' - 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' - type: string - metadata: - type: object - roleRef: - default: user - description: RoleRef can only reference a ClusterRole in the global namespace. - type: string - status: - description: Status contains the different condition statuses for this - user group. - properties: - conditions: - description: Conditions contains the different condition statuses - for this user group. - items: - properties: - lastHeartbeatTime: - description: LastHeartbeatTime is the last time this condition - was updated. - format: date-time - type: string - lastTransitionTime: - description: LastTransitionTime is the last time the condition - changed from one status to another. - format: date-time - type: string - message: - description: Message is a human-readable message indicating - details about the last status change. - type: string - reason: - description: Reason is a (brief) reason for the condition's - last status change. - type: string - status: - description: Status is the status of the condition. One of True, - False, Unknown. - type: string - type: - type: string - required: - - status - - type - type: object - type: array - observedGeneration: - description: The generation observed by the user controller. - format: int64 - type: integer - phase: - default: Unknown - description: Phase is the recently observed lifecycle phase of user - group binding - type: string - type: object - subject: - description: Subject holds references to the objects the role applies - to. - properties: - apiGroup: - description: APIGroup holds the API group of the referenced subject. - Defaults to "" for ServiceAccount subjects. Defaults to "rbac.authorization.k8s.io" - for User and Group subjects. - type: string - kind: - description: Kind of object being referenced. Values defined by this - API group are "User", "Group", and "ServiceAccount". If the Authorizer - does not recognized the kind value, the Authorizer should report - an error. - type: string - name: - description: Name of the object being referenced. - type: string - namespace: - description: Namespace of the referenced object. If the object kind - is non-namespace, such as "User" or "Group", and this value is not - empty the Authorizer should report an error. - type: string - required: - - kind - - name - type: object - x-kubernetes-map-type: atomic - userGroupRef: - description: UserGroupRef is the reference to the user group that this - binding binds to. - type: string - required: - - userGroupRef - type: object - served: true - storage: true - subresources: - status: {} ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.10.0 - creationTimestamp: null - name: usergroups.user.sealos.io -spec: - group: user.sealos.io - names: - kind: UserGroup - listKind: UserGroupList - plural: usergroups - shortNames: - - ug - singular: usergroup - scope: Cluster - versions: - - additionalPrinterColumns: - - jsonPath: .status.phase - name: Phase - type: string - - jsonPath: .metadata.creationTimestamp - name: Age - type: date - name: v1 - schema: - openAPIV3Schema: - description: UserGroup is the Schema for the usergroups 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' - 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' - type: string - metadata: - type: object - status: - description: UserGroupStatus defines the observed state of UserGroup - properties: - conditions: - description: Conditions contains the different condition statuses - for this user group. - items: - properties: - lastHeartbeatTime: - description: LastHeartbeatTime is the last time this condition - was updated. - format: date-time - type: string - lastTransitionTime: - description: LastTransitionTime is the last time the condition - changed from one status to another. - format: date-time - type: string - message: - description: Message is a human-readable message indicating - details about the last status change. - type: string - reason: - description: Reason is a (brief) reason for the condition's - last status change. - type: string - status: - description: Status is the status of the condition. One of True, - False, Unknown. - type: string - type: - type: string - required: - - status - - type - type: object - type: array - observedGeneration: - description: The generation observed by the user controller. - format: int64 - type: integer - phase: - default: Unknown - description: Phase is the recently observed lifecycle phase of user - group - type: string - type: object - type: object - served: true - storage: true - subresources: - status: {} ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.10.0 diff --git a/controllers/user/main.go b/controllers/user/main.go index 8cb80dc0a..69138c700 100644 --- a/controllers/user/main.go +++ b/controllers/user/main.go @@ -105,18 +105,6 @@ func main() { setupLog.Error(err, "unable to create controller", "controller", "User") os.Exit(1) } - if err = (&controllers.UserGroupReconciler{}).SetupWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create controller", "controller", "UserGroup") - os.Exit(1) - } - if err = (&controllers.UserGroupBindingReconciler{ - Client: mgr.GetClient(), - Scheme: mgr.GetScheme(), - }).SetupWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create controller", "controller", "UserGroupBinding") - os.Exit(1) - } - if err = (&controllers.NamespaceReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(),