From cc0c9824e9391781ca5980b1e4829bc8d7219cb9 Mon Sep 17 00:00:00 2001 From: maslow Date: Thu, 25 Aug 2022 23:33:34 +0800 Subject: [PATCH] feat(oss): add bucket crd --- controllers/oss/PROJECT | 9 ++ controllers/oss/api/v1/bucket_types.go | 111 ++++++++++++++++++ controllers/oss/api/v1/user_types.go | 27 +++-- .../oss/api/v1/zz_generated.deepcopy.go | 105 +++++++++++++++++ .../config/crd/bases/oss.laf.dev_buckets.yaml | 91 ++++++++++++++ .../config/crd/bases/oss.laf.dev_stores.yaml | 16 ++- .../config/crd/bases/oss.laf.dev_users.yaml | 41 ++++--- controllers/oss/config/crd/kustomization.yaml | 3 + .../crd/patches/cainjection_in_buckets.yaml | 7 ++ .../crd/patches/webhook_in_buckets.yaml | 16 +++ .../oss/config/rbac/bucket_editor_role.yaml | 24 ++++ .../oss/config/rbac/bucket_viewer_role.yaml | 20 ++++ controllers/oss/config/rbac/role.yaml | 26 ++++ .../oss/config/samples/oss_v1_bucket.yaml | 6 + .../oss/controllers/bucket_controller.go | 62 ++++++++++ controllers/oss/main.go | 7 ++ 16 files changed, 537 insertions(+), 34 deletions(-) create mode 100644 controllers/oss/api/v1/bucket_types.go create mode 100644 controllers/oss/config/crd/bases/oss.laf.dev_buckets.yaml create mode 100644 controllers/oss/config/crd/patches/cainjection_in_buckets.yaml create mode 100644 controllers/oss/config/crd/patches/webhook_in_buckets.yaml create mode 100644 controllers/oss/config/rbac/bucket_editor_role.yaml create mode 100644 controllers/oss/config/rbac/bucket_viewer_role.yaml create mode 100644 controllers/oss/config/samples/oss_v1_bucket.yaml create mode 100644 controllers/oss/controllers/bucket_controller.go diff --git a/controllers/oss/PROJECT b/controllers/oss/PROJECT index 661f503905..831df1d766 100644 --- a/controllers/oss/PROJECT +++ b/controllers/oss/PROJECT @@ -22,4 +22,13 @@ resources: kind: User path: github.com/labring/laf/controllers/oss/api/v1 version: v1 +- api: + crdVersion: v1 + namespaced: true + controller: true + domain: laf.dev + group: oss + kind: Bucket + path: github.com/labring/laf/controllers/oss/api/v1 + version: v1 version: "3" diff --git a/controllers/oss/api/v1/bucket_types.go b/controllers/oss/api/v1/bucket_types.go new file mode 100644 index 0000000000..c4a1d1b8b3 --- /dev/null +++ b/controllers/oss/api/v1/bucket_types.go @@ -0,0 +1,111 @@ +/* +Copyright 2022. + +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. + +// BucketPolicy mode +type BucketPolicy string + +const ( + BucketPolicyReadOnly BucketPolicy = "readonly" + BucketPolicyReadWrite BucketPolicy = "public" + BucketPolicyPrivate BucketPolicy = "private" +) + +// BucketSpec defines the desired state of Bucket +type BucketSpec struct { + // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster + // Important: Run "make" to regenerate code after modifying this file + + // Name of bucket in oss. It's read-only after creation. + // This will be used as the bucket name in storage store. + // The length is between 3-63 and can only include letters, numbers and short horizontal lines (-). + //+kubebuilder:validation:Required + //+kubebuilder:validation:MinLength=3 + //+kubebuilder:validation:MaxLength=64 + //+kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$ + Name string `json:"name"` + + // Policy of bucket in oss. required. + //+kubebuilder:validation:Required + Policy BucketPolicy `json:"policy"` + + // Storage space of this bucket, in MB. It defaults to 0, which means no limit. + //+kubebuilder:validation:Required + //+kubebuilder:validation:Minimum=0 + //+kubebuilder:default=0 + Storage int64 `json:"storage"` + + // The name of oss user. + //+kubebuilder:validation:Required + User string `json:"user"` +} + +// BucketStatus defines the observed state of Bucket +type BucketStatus struct { + // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster + // Important: Run "make" to regenerate code after modifying this file + + // Capacity of this bucket. + Capacity BucketCapacity `json:"capacity,omitempty"` +} + +type BucketCapacity struct { + // The user's storage space. The unit is MB. + // The default value is 0 which means unlimited. + //+kubebuilder:validation:Minimum=0 + //+kubebuilder:default=0 + //+optional + Storage int64 `json:"storage,omitempty"` + + // The user's number of objects. + //+optional + //+kubebuilder:validation:Minimum=0 + //+kubebuilder:default=0 + ObjectCount int64 `json:"objectCount,omitempty"` +} + +//+kubebuilder:object:root=true +//+kubebuilder:subresource:status + +// Bucket is the Schema for the buckets API +type Bucket struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec BucketSpec `json:"spec,omitempty"` + Status BucketStatus `json:"status,omitempty"` +} + +//+kubebuilder:object:root=true + +// BucketList contains a list of Bucket +type BucketList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []Bucket `json:"items"` +} + +func init() { + SchemeBuilder.Register(&Bucket{}, &BucketList{}) +} diff --git a/controllers/oss/api/v1/user_types.go b/controllers/oss/api/v1/user_types.go index 8d28d45d91..b239bfe81f 100644 --- a/controllers/oss/api/v1/user_types.go +++ b/controllers/oss/api/v1/user_types.go @@ -38,18 +38,6 @@ type UserSpec struct { //+kubebuilder:validation:Required Region string `json:"region"` - // AccessKey for this user. It's read-only after creation. - // This field is used to specify the user's access Key. This key is used to access OSS. - // If you do not specify an accesskey, the accessKey will be automatically generated by Controller. - //+optional - AccessKey string `json:"accessKey,omitempty"` - - // SecretKey for this user. It's read-only after creation. - // This field is used to specify the user's secret Key. This key is used to access OSS. - // If you do not specify an secretkey, the secretKey will be automatically generated by Controller. - //+optional - SecretKey string `json:"secretKey,omitempty"` - // Capacity that user desired. Capacity UserCapacity `json:"capacity,omitempty"` } @@ -65,12 +53,25 @@ type UserStatus struct { // SecretKey for this user. This field might be generated by controller if accessKey not given in spec. SecretKey string `json:"secretKey,omitempty"` + // Store name of a oss store. It's read-only after creation. + // The controller has created the corresponding storage resources based on this store. + //+kubebuilder:validation:Required + Store string `json:"store,omitempty"` + + // The region name identifies the location of the store. + //+kubebuilder:validation:Required + //+kubebuilder:validation:MinLength=2 + //+kubebuilder:validation:MaxLength=64 + //+kubebuilder:default=default + //+kubebuilder:validation:Pattern=[a-zA-Z0-9-]+ + Region string `json:"region,omitempty"` + // Endpoint is the store service endpoint. //+kubebuilder:validation:Required Endpoint string `json:"endpoint,omitempty"` // The user's capacity observed by the controller. - Capacity UserCapacity `json:"usedCapacity,omitempty"` + Capacity UserCapacity `json:"capacity,omitempty"` } // UserCapacity is used to obtain the user's used capacity. diff --git a/controllers/oss/api/v1/zz_generated.deepcopy.go b/controllers/oss/api/v1/zz_generated.deepcopy.go index 773fbc8f8c..2f0e77468c 100644 --- a/controllers/oss/api/v1/zz_generated.deepcopy.go +++ b/controllers/oss/api/v1/zz_generated.deepcopy.go @@ -25,6 +25,111 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Bucket) DeepCopyInto(out *Bucket) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Bucket. +func (in *Bucket) DeepCopy() *Bucket { + if in == nil { + return nil + } + out := new(Bucket) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Bucket) 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 *BucketCapacity) DeepCopyInto(out *BucketCapacity) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BucketCapacity. +func (in *BucketCapacity) DeepCopy() *BucketCapacity { + if in == nil { + return nil + } + out := new(BucketCapacity) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BucketList) DeepCopyInto(out *BucketList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Bucket, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BucketList. +func (in *BucketList) DeepCopy() *BucketList { + if in == nil { + return nil + } + out := new(BucketList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *BucketList) 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 *BucketSpec) DeepCopyInto(out *BucketSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BucketSpec. +func (in *BucketSpec) DeepCopy() *BucketSpec { + if in == nil { + return nil + } + out := new(BucketSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BucketStatus) DeepCopyInto(out *BucketStatus) { + *out = *in + out.Capacity = in.Capacity +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BucketStatus. +func (in *BucketStatus) DeepCopy() *BucketStatus { + if in == nil { + return nil + } + out := new(BucketStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Store) DeepCopyInto(out *Store) { *out = *in diff --git a/controllers/oss/config/crd/bases/oss.laf.dev_buckets.yaml b/controllers/oss/config/crd/bases/oss.laf.dev_buckets.yaml new file mode 100644 index 0000000000..f16d3b98b1 --- /dev/null +++ b/controllers/oss/config/crd/bases/oss.laf.dev_buckets.yaml @@ -0,0 +1,91 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.9.0 + creationTimestamp: null + name: buckets.oss.laf.dev +spec: + group: oss.laf.dev + names: + kind: Bucket + listKind: BucketList + plural: buckets + singular: bucket + scope: Namespaced + versions: + - name: v1 + schema: + openAPIV3Schema: + description: Bucket is the Schema for the buckets 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 + spec: + description: BucketSpec defines the desired state of Bucket + properties: + name: + description: Name of bucket in oss. It's read-only after creation. + This will be used as the bucket name in storage store. The length + is between 3-63 and can only include letters, numbers and short + horizontal lines (-). + maxLength: 64 + minLength: 3 + pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$ + type: string + policy: + description: Policy of bucket in oss. required. + type: string + storage: + default: 0 + description: Storage space of this bucket, in MB. It defaults to 0, + which means no limit. + format: int64 + minimum: 0 + type: integer + user: + description: The name of oss user. + type: string + required: + - name + - policy + - storage + - user + type: object + status: + description: BucketStatus defines the observed state of Bucket + properties: + capacity: + description: Capacity of this bucket. + properties: + objectCount: + default: 0 + description: The user's number of objects. + format: int64 + minimum: 0 + type: integer + storage: + default: 0 + description: The user's storage space. The unit is MB. The default + value is 0 which means unlimited. + format: int64 + minimum: 0 + type: integer + type: object + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/controllers/oss/config/crd/bases/oss.laf.dev_stores.yaml b/controllers/oss/config/crd/bases/oss.laf.dev_stores.yaml index 8251be434a..2b981031b6 100644 --- a/controllers/oss/config/crd/bases/oss.laf.dev_stores.yaml +++ b/controllers/oss/config/crd/bases/oss.laf.dev_stores.yaml @@ -42,15 +42,17 @@ spec: capacity: description: Capacity is the maximum capacity of the store. properties: - bucketNumber: + bucketCount: default: 0 - description: The number of buckets. + description: The number of buckets. The default value is 0 which + means unlimited. format: int64 minimum: 0 type: integer objectCount: default: 0 - description: The number of objects. + description: The number of objects. The default value is 0 which + means unlimited. format: int64 minimum: 0 type: integer @@ -118,15 +120,17 @@ spec: capacity: description: The observed capacity of Store. properties: - bucketNumber: + bucketCount: default: 0 - description: The number of buckets. + description: The number of buckets. The default value is 0 which + means unlimited. format: int64 minimum: 0 type: integer objectCount: default: 0 - description: The number of objects. + description: The number of objects. The default value is 0 which + means unlimited. format: int64 minimum: 0 type: integer diff --git a/controllers/oss/config/crd/bases/oss.laf.dev_users.yaml b/controllers/oss/config/crd/bases/oss.laf.dev_users.yaml index 68934aa18f..907fbd4e02 100644 --- a/controllers/oss/config/crd/bases/oss.laf.dev_users.yaml +++ b/controllers/oss/config/crd/bases/oss.laf.dev_users.yaml @@ -35,16 +35,10 @@ spec: spec: description: UserSpec defines the desired state of User properties: - accessKey: - description: AccessKey for this user. It's read-only after creation. - This field is used to specify the user's access Key. This key is - used to access OSS. If you do not specify an accesskey, the accessKey - will be automatically generated by Controller. - type: string capacity: description: Capacity that user desired. properties: - bucketNumber: + bucketCount: default: 0 description: The user's number of buckets. format: int64 @@ -74,12 +68,6 @@ spec: controller will create the corresponding storage resources based on this region. type: string - secretKey: - description: SecretKey for this user. It's read-only after creation. - This field is used to specify the user's secret Key. This key is - used to access OSS. If you do not specify an secretkey, the secretKey - will be automatically generated by Controller. - type: string required: - provider - region @@ -87,10 +75,14 @@ spec: status: description: UserStatus defines the observed state of User properties: - usedCapacity: + accessKey: + description: AccessKey for this user. This field might be generated + by controller if accessKey not given in spec. + type: string + capacity: description: The user's capacity observed by the controller. properties: - bucketNumber: + bucketCount: default: 0 description: The user's number of buckets. format: int64 @@ -110,6 +102,25 @@ spec: minimum: 0 type: integer type: object + endpoint: + description: Endpoint is the store service endpoint. + type: string + region: + default: default + description: The region name identifies the location of the store. + maxLength: 64 + minLength: 2 + pattern: '[a-zA-Z0-9-]+' + type: string + secretKey: + description: SecretKey for this user. This field might be generated + by controller if accessKey not given in spec. + type: string + store: + description: Store name of a oss store. It's read-only after creation. + The controller has created the corresponding storage resources based + on this store. + type: string type: object type: object served: true diff --git a/controllers/oss/config/crd/kustomization.yaml b/controllers/oss/config/crd/kustomization.yaml index b46e2c0140..88216257ad 100644 --- a/controllers/oss/config/crd/kustomization.yaml +++ b/controllers/oss/config/crd/kustomization.yaml @@ -4,17 +4,20 @@ resources: - bases/oss.laf.dev_stores.yaml - bases/oss.laf.dev_users.yaml +- bases/oss.laf.dev_buckets.yaml #+kubebuilder:scaffold:crdkustomizeresource patchesStrategicMerge: # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix. # patches here are for enabling the conversion webhook for each CRD #- patches/webhook_in_osses.yaml +#- patches/webhook_in_buckets.yaml #+kubebuilder:scaffold:crdkustomizewebhookpatch # [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix. # patches here are for enabling the CA injection for each CRD #- patches/cainjection_in_osses.yaml +#- patches/cainjection_in_buckets.yaml #+kubebuilder:scaffold:crdkustomizecainjectionpatch # the following config is for teaching kustomize how to do kustomization for CRDs. diff --git a/controllers/oss/config/crd/patches/cainjection_in_buckets.yaml b/controllers/oss/config/crd/patches/cainjection_in_buckets.yaml new file mode 100644 index 0000000000..44e742b38f --- /dev/null +++ b/controllers/oss/config/crd/patches/cainjection_in_buckets.yaml @@ -0,0 +1,7 @@ +# 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: buckets.oss.laf.dev diff --git a/controllers/oss/config/crd/patches/webhook_in_buckets.yaml b/controllers/oss/config/crd/patches/webhook_in_buckets.yaml new file mode 100644 index 0000000000..471a37561a --- /dev/null +++ b/controllers/oss/config/crd/patches/webhook_in_buckets.yaml @@ -0,0 +1,16 @@ +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: buckets.oss.laf.dev +spec: + conversion: + strategy: Webhook + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert + conversionReviewVersions: + - v1 diff --git a/controllers/oss/config/rbac/bucket_editor_role.yaml b/controllers/oss/config/rbac/bucket_editor_role.yaml new file mode 100644 index 0000000000..007bf07208 --- /dev/null +++ b/controllers/oss/config/rbac/bucket_editor_role.yaml @@ -0,0 +1,24 @@ +# permissions for end users to edit buckets. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: bucket-editor-role +rules: +- apiGroups: + - oss.laf.dev + resources: + - buckets + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - oss.laf.dev + resources: + - buckets/status + verbs: + - get diff --git a/controllers/oss/config/rbac/bucket_viewer_role.yaml b/controllers/oss/config/rbac/bucket_viewer_role.yaml new file mode 100644 index 0000000000..9e34677086 --- /dev/null +++ b/controllers/oss/config/rbac/bucket_viewer_role.yaml @@ -0,0 +1,20 @@ +# permissions for end users to view buckets. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: bucket-viewer-role +rules: +- apiGroups: + - oss.laf.dev + resources: + - buckets + verbs: + - get + - list + - watch +- apiGroups: + - oss.laf.dev + resources: + - buckets/status + verbs: + - get diff --git a/controllers/oss/config/rbac/role.yaml b/controllers/oss/config/rbac/role.yaml index a36ab965c3..db223485cc 100644 --- a/controllers/oss/config/rbac/role.yaml +++ b/controllers/oss/config/rbac/role.yaml @@ -5,6 +5,32 @@ metadata: creationTimestamp: null name: manager-role rules: +- apiGroups: + - oss.laf.dev + resources: + - buckets + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - oss.laf.dev + resources: + - buckets/finalizers + verbs: + - update +- apiGroups: + - oss.laf.dev + resources: + - buckets/status + verbs: + - get + - patch + - update - apiGroups: - oss.laf.dev resources: diff --git a/controllers/oss/config/samples/oss_v1_bucket.yaml b/controllers/oss/config/samples/oss_v1_bucket.yaml new file mode 100644 index 0000000000..16d9161171 --- /dev/null +++ b/controllers/oss/config/samples/oss_v1_bucket.yaml @@ -0,0 +1,6 @@ +apiVersion: oss.laf.dev/v1 +kind: Bucket +metadata: + name: bucket-sample +spec: + # TODO(user): Add fields here diff --git a/controllers/oss/controllers/bucket_controller.go b/controllers/oss/controllers/bucket_controller.go new file mode 100644 index 0000000000..f74cc22022 --- /dev/null +++ b/controllers/oss/controllers/bucket_controller.go @@ -0,0 +1,62 @@ +/* +Copyright 2022. + +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" + + "k8s.io/apimachinery/pkg/runtime" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/log" + + ossv1 "github.com/labring/laf/controllers/oss/api/v1" +) + +// BucketReconciler reconciles a Bucket object +type BucketReconciler struct { + client.Client + Scheme *runtime.Scheme +} + +//+kubebuilder:rbac:groups=oss.laf.dev,resources=buckets,verbs=get;list;watch;create;update;patch;delete +//+kubebuilder:rbac:groups=oss.laf.dev,resources=buckets/status,verbs=get;update;patch +//+kubebuilder:rbac:groups=oss.laf.dev,resources=buckets/finalizers,verbs=update + +// 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 Bucket 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 *BucketReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + _ = log.FromContext(ctx) + + // TODO(user): your logic here + + return ctrl.Result{}, nil +} + +// SetupWithManager sets up the controller with the Manager. +func (r *BucketReconciler) SetupWithManager(mgr ctrl.Manager) error { + return ctrl.NewControllerManagedBy(mgr). + For(&ossv1.Bucket{}). + Complete(r) +} diff --git a/controllers/oss/main.go b/controllers/oss/main.go index 0ed65b307a..3241128527 100644 --- a/controllers/oss/main.go +++ b/controllers/oss/main.go @@ -103,6 +103,13 @@ func main() { setupLog.Error(err, "unable to create controller", "controller", "User") os.Exit(1) } + if err = (&controllers.BucketReconciler{ + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + }).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "Bucket") + os.Exit(1) + } //+kubebuilder:scaffold:builder if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {