diff --git a/apis/oss/v1alpha1/oss_types.go b/apis/oss/v1alpha1/oss_types.go index 7ae28ee..caee0c8 100644 --- a/apis/oss/v1alpha1/oss_types.go +++ b/apis/oss/v1alpha1/oss_types.go @@ -51,7 +51,11 @@ type Bucket struct { // BucketSpec defines the desired state of Bucket type BucketSpec struct { runtimev1.ResourceSpec `json:",inline"` - ForProvider BucketParameters `json:"forProvider"` + BucketParameter `json:",inline"` + + // Profile is used to extend store business information + // +kubebuilder:pruning:PreserveUnknownFields + Profile map[string]string `json:"profile,omitempty"` } // BucketStatus defines the observed state of Bucket @@ -68,11 +72,6 @@ type BucketParameter struct { DataRedundancyType string `json:"dataRedundancyType,omitempty"` } -// BucketParameters define the desired state of an Bucket -type BucketParameters struct { - Bucket BucketParameter `json:"bucket,omitempty"` -} - // BucketObservation is the representation of the current state that is observed. type BucketObservation struct { BucketName string `json:"bucketName,omitempty"` diff --git a/apis/oss/v1alpha1/zz_generated.deepcopy.go b/apis/oss/v1alpha1/zz_generated.deepcopy.go index 521772a..31b9c5d 100644 --- a/apis/oss/v1alpha1/zz_generated.deepcopy.go +++ b/apis/oss/v1alpha1/zz_generated.deepcopy.go @@ -113,27 +113,18 @@ func (in *BucketParameter) DeepCopy() *BucketParameter { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *BucketParameters) DeepCopyInto(out *BucketParameters) { - *out = *in - out.Bucket = in.Bucket -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BucketParameters. -func (in *BucketParameters) DeepCopy() *BucketParameters { - if in == nil { - return nil - } - out := new(BucketParameters) - in.DeepCopyInto(out) - return out -} - // 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 in.ResourceSpec.DeepCopyInto(&out.ResourceSpec) - out.ForProvider = in.ForProvider + out.BucketParameter = in.BucketParameter + if in.Profile != nil { + in, out := &in.Profile, &out.Profile + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BucketSpec. diff --git a/apis/v1alpha1/types.go b/apis/v1alpha1/types.go index 949707f..7727cbb 100644 --- a/apis/v1alpha1/types.go +++ b/apis/v1alpha1/types.go @@ -60,10 +60,6 @@ type ProviderConfigSpec struct { // Region for managed resources created using this Alibaba Cloud provider, // e.g. "cn-hangzhou". Region string `json:"region"` - - // Profile is used to extend fields of ProviderConfigSpec. - // +kubebuilder:pruning:PreserveUnknownFields - Profile map[string]string `json:"profile,omitempty"` } // A ProviderConfigStatus represents the status of a ProviderConfig. diff --git a/apis/v1alpha1/zz_generated.deepcopy.go b/apis/v1alpha1/zz_generated.deepcopy.go index 20bd74c..d140304 100644 --- a/apis/v1alpha1/zz_generated.deepcopy.go +++ b/apis/v1alpha1/zz_generated.deepcopy.go @@ -113,13 +113,6 @@ func (in *ProviderConfigList) DeepCopyObject() runtime.Object { func (in *ProviderConfigSpec) DeepCopyInto(out *ProviderConfigSpec) { *out = *in in.ProviderConfigSpec.DeepCopyInto(&out.ProviderConfigSpec) - if in.Profile != nil { - in, out := &in.Profile, &out.Profile - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProviderConfigSpec. diff --git a/examples/oss/oss.yaml b/examples/oss/oss.yaml index 833a80e..42a27cd 100644 --- a/examples/oss/oss.yaml +++ b/examples/oss/oss.yaml @@ -1,14 +1,12 @@ apiVersion: oss.alibaba.crossplane.io/v1alpha1 kind: Bucket metadata: - name: example-oss + name: example-oss-0320 spec: - forProvider: - bucket: - name: example-oss-bucket - acl: private - storageClass: Standard - dataRedundancyType: LRS + name: example-oss-bucket-0320 + acl: private + storageClass: Standard + dataRedundancyType: LRS writeConnectionSecretToRef: - name: example-oss + name: example-oss-0320 namespace: default diff --git a/package/crds/alibaba.crossplane.io_providerconfigs.yaml b/package/crds/alibaba.crossplane.io_providerconfigs.yaml index 752296a..0912344 100644 --- a/package/crds/alibaba.crossplane.io_providerconfigs.yaml +++ b/package/crds/alibaba.crossplane.io_providerconfigs.yaml @@ -72,12 +72,6 @@ spec: required: - source type: object - profile: - additionalProperties: - type: string - description: Profile is used to extend fields of ProviderConfigSpec. - type: object - x-kubernetes-preserve-unknown-fields: true region: description: Region for managed resources created using this Alibaba Cloud provider, e.g. "cn-hangzhou". type: string diff --git a/package/crds/oss.alibaba.crossplane.io_buckets.yaml b/package/crds/oss.alibaba.crossplane.io_buckets.yaml index c2dc2aa..881cf97 100644 --- a/package/crds/oss.alibaba.crossplane.io_buckets.yaml +++ b/package/crds/oss.alibaba.crossplane.io_buckets.yaml @@ -44,30 +44,24 @@ spec: spec: description: BucketSpec defines the desired state of Bucket properties: + acl: + type: string + dataRedundancyType: + type: string deletionPolicy: description: DeletionPolicy specifies what will happen to the underlying external when this managed resource is deleted - either "Delete" or "Orphan" the external resource. The "Delete" policy is the default when no policy is specified. enum: - Orphan - Delete type: string - forProvider: - description: BucketParameters define the desired state of an Bucket - properties: - bucket: - description: BucketParameter is the isolated place to store files - properties: - acl: - type: string - dataRedundancyType: - type: string - name: - type: string - storageClass: - type: string - required: - - name - type: object + name: + type: string + profile: + additionalProperties: + type: string + description: Profile is used to extend store business information type: object + x-kubernetes-preserve-unknown-fields: true providerConfigRef: description: ProviderConfigReference specifies how the provider that will be used to create, observe, update, and delete this managed resource should be configured. properties: @@ -86,6 +80,8 @@ spec: required: - name type: object + storageClass: + type: string writeConnectionSecretToRef: description: WriteConnectionSecretToReference specifies the namespace and name of a Secret to which any connection details for this managed resource should be written. Connection details frequently include the endpoint, username, and password required to connect to the managed resource. properties: @@ -100,7 +96,7 @@ spec: - namespace type: object required: - - forProvider + - name type: object status: description: BucketStatus defines the observed state of Bucket diff --git a/pkg/clients/oss/oss.go b/pkg/clients/oss/oss.go index 3cafcab..9f0609a 100644 --- a/pkg/clients/oss/oss.go +++ b/pkg/clients/oss/oss.go @@ -197,8 +197,7 @@ func validateOSSDataRedundancyType(dataRedundancyTypeStr string) (sdk.DataRedund // IsUpdateToDate checks whether cr is up to date func IsUpdateToDate(cr *v1alpha1.Bucket, bucket *sdk.GetBucketInfoResult) bool { - bucketSpec := cr.Spec.ForProvider.Bucket - if (bucketSpec.ACL == bucket.BucketInfo.ACL) || (bucketSpec.ACL == "" && bucket.BucketInfo.ACL == "private") { + if (cr.Spec.ACL == bucket.BucketInfo.ACL) || (cr.Spec.ACL == "" && bucket.BucketInfo.ACL == "private") { return true } return false diff --git a/pkg/controller/oss/base.go b/pkg/controller/oss/base.go index e129fb4..54f23b6 100644 --- a/pkg/controller/oss/base.go +++ b/pkg/controller/oss/base.go @@ -39,10 +39,9 @@ func BaseObserve(mg resource.Managed, c ossclient.ClientInterface) (managed.Exte if !ok { return managed.ExternalObservation{}, errors.New(errNotOSS) } - bucketSpec := cr.Spec.ForProvider.Bucket - klog.InfoS("observing Bucket resource", "Name", bucketSpec.Name) + klog.InfoS("observing Bucket resource", "Name", cr.Spec.Name) - bucket, err := c.Describe(bucketSpec.Name) + bucket, err := c.Describe(cr.Spec.Name) if ossclient.IsNotFoundError(err) { return managed.ExternalObservation{ ResourceExists: false, @@ -54,10 +53,10 @@ func BaseObserve(mg resource.Managed, c ossclient.ClientInterface) (managed.Exte } cr.Status.AtProvider = ossclient.GenerateObservation(*bucket) - if bucketSpec.StorageClass != "" && bucketSpec.StorageClass != bucket.BucketInfo.StorageClass { + if cr.Spec.StorageClass != "" && cr.Spec.StorageClass != bucket.BucketInfo.StorageClass { cr.Status.AtProvider.Message += "[Warning] StorageClass is not allowed to update after creation; " } - if bucketSpec.DataRedundancyType != "" && bucketSpec.DataRedundancyType != bucket.BucketInfo.RedundancyType { + if cr.Spec.DataRedundancyType != "" && cr.Spec.DataRedundancyType != bucket.BucketInfo.RedundancyType { cr.Status.AtProvider.Message += "[Warning] DataRedundancyType is not allowed to update after creation; " } var upToDate = ossclient.IsUpdateToDate(cr, bucket) @@ -78,9 +77,15 @@ func BaseCreate(mg resource.Managed, c ossclient.ClientInterface) (managed.Exter if !ok { return managed.ExternalCreation{}, errors.New(errNotOSS) } - klog.InfoS("creating Bucket resource", "Name", cr.Spec.ForProvider.Bucket.Name) + klog.InfoS("creating Bucket resource", "Name", cr.Spec.Name) cr.SetConditions(xpv1.Creating()) - if err := c.Create(cr.Spec.ForProvider.Bucket); err != nil { + bucketParameter := v1alpha1.BucketParameter{ + Name: cr.Spec.Name, + ACL: cr.Spec.ACL, + StorageClass: cr.Spec.StorageClass, + DataRedundancyType: cr.Spec.DataRedundancyType, + } + if err := c.Create(bucketParameter); err != nil { return managed.ExternalCreation{}, err } return managed.ExternalCreation{ConnectionDetails: GetConnectionDetails(cr)}, nil @@ -92,17 +97,14 @@ func BaseUpdate(mg resource.Managed, client ossclient.ClientInterface) (managed. if !ok { return managed.ExternalUpdate{}, errors.New(errNotOSS) } - klog.InfoS("updating Bucket resource", "Name", cr.Spec.ForProvider.Bucket.Name) cr.Status.SetConditions(xpv1.Creating()) - got, err := client.Describe(cr.Spec.ForProvider.Bucket.Name) + got, err := client.Describe(cr.Spec.Name) if err != nil { return managed.ExternalUpdate{}, err } - target := cr.Spec.ForProvider.Bucket - - if target.ACL != "" && target.ACL != got.BucketInfo.ACL { - if err := client.Update(target.Name, target.ACL); err != nil { + if cr.Spec.ACL != "" && cr.Spec.ACL != got.BucketInfo.ACL { + if err := client.Update(cr.Spec.Name, cr.Spec.ACL); err != nil { return managed.ExternalUpdate{}, err } } @@ -116,9 +118,9 @@ func BaseDelete(mg resource.Managed, client ossclient.ClientInterface) error { if !ok { return errors.New(errNotOSS) } - klog.InfoS("deleting Bucket resource", "Name", cr.Spec.ForProvider.Bucket.Name) + klog.InfoS("deleting Bucket resource", "Name", cr.Spec.Name) cr.SetConditions(xpv1.Deleting()) - if err := client.Delete(cr.Spec.ForProvider.Bucket.Name); err != nil && !ossclient.IsNotFoundError(err) { + if err := client.Delete(cr.Spec.Name); err != nil && !ossclient.IsNotFoundError(err) { return err } return nil @@ -142,7 +144,7 @@ func BaseSetupOSS(mgr ctrl.Manager, l logging.Logger, o ...managed.ReconcilerOpt // GetConnectionDetails generates connection details func GetConnectionDetails(cr *v1alpha1.Bucket) managed.ConnectionDetails { cd := managed.ConnectionDetails{ - "Bucket": []byte(cr.Spec.ForProvider.Bucket.Name), + "Bucket": []byte(cr.Spec.Name), } if cr.Status.AtProvider.ExtranetEndpoint != "" { cd["ExtranetEndpoint"] = []byte(cr.Status.AtProvider.ExtranetEndpoint) diff --git a/pkg/controller/oss/oss_controller_test.go b/pkg/controller/oss/oss_controller_test.go index d22f5db..566de9e 100644 --- a/pkg/controller/oss/oss_controller_test.go +++ b/pkg/controller/oss/oss_controller_test.go @@ -81,8 +81,11 @@ func TestObserve(t *testing.T) { var ( ctx = context.Background() ) + validCR := &ossv1alpha1.Bucket{} + validCR.Spec.Name = "def" - validCR := &ossv1alpha1.Bucket{Spec: ossv1alpha1.BucketSpec{ForProvider: ossv1alpha1.BucketParameters{Bucket: ossv1alpha1.BucketParameter{Name: "def"}}}} + invalidCR := &ossv1alpha1.Bucket{} + invalidCR.Spec.Name = "abc" type want struct { o managed.ExternalObservation @@ -114,8 +117,7 @@ func TestObserve(t *testing.T) { }, "OSSOtherError": { reason: "We should report an unknown error", - mg: &ossv1alpha1.Bucket{ - Spec: ossv1alpha1.BucketSpec{ForProvider: ossv1alpha1.BucketParameters{Bucket: ossv1alpha1.BucketParameter{Name: "abc"}}}}, + mg: invalidCR, want: want{ o: managed.ExternalObservation{}, err: errors.New("unknown error"), @@ -153,7 +155,9 @@ func TestCreate(t *testing.T) { ctx = context.Background() ) - validCR := &ossv1alpha1.Bucket{Spec: ossv1alpha1.BucketSpec{ForProvider: ossv1alpha1.BucketParameters{Bucket: ossv1alpha1.BucketParameter{Name: "def"}}}} + spec := ossv1alpha1.BucketSpec{} + spec.Name = "def" + validCR := &ossv1alpha1.Bucket{Spec: spec} type want struct { o managed.ExternalCreation @@ -203,7 +207,9 @@ func TestUpdate(t *testing.T) { ctx = context.Background() ) - validCR := &ossv1alpha1.Bucket{Spec: ossv1alpha1.BucketSpec{ForProvider: ossv1alpha1.BucketParameters{Bucket: ossv1alpha1.BucketParameter{Name: "def"}}}} + spec := ossv1alpha1.BucketSpec{} + spec.Name = "def" + validCR := &ossv1alpha1.Bucket{Spec: spec} type want struct { o managed.ExternalUpdate @@ -252,7 +258,9 @@ func TestDelete(t *testing.T) { ctx = context.Background() ) - validCR := &ossv1alpha1.Bucket{Spec: ossv1alpha1.BucketSpec{ForProvider: ossv1alpha1.BucketParameters{Bucket: ossv1alpha1.BucketParameter{Name: "def"}}}} + spec := ossv1alpha1.BucketSpec{} + spec.Name = "def" + validCR := &ossv1alpha1.Bucket{Spec: spec} type want struct { err error