diff --git a/apis/sls/v1alpha1/project_types.go b/apis/sls/v1alpha1/project_types.go index b3e154d..ed7095c 100644 --- a/apis/sls/v1alpha1/project_types.go +++ b/apis/sls/v1alpha1/project_types.go @@ -57,7 +57,6 @@ type ProjectStatus struct { // ProjectParameters define the desired state of an SLS project. type ProjectParameters struct { - ProjectName string `json:"name"` Description string `json:"description"` } diff --git a/examples/sls/project.yaml b/examples/sls/project.yaml index 5334c62..cd7d538 100644 --- a/examples/sls/project.yaml +++ b/examples/sls/project.yaml @@ -5,7 +5,6 @@ metadata: namespace: default spec: forProvider: - name: sls-project-sample description: provisioned by Crossplane writeConnectionSecretToRef: name: sls-endpoint diff --git a/package/crds/sls.alibaba.crossplane.io_projects.yaml b/package/crds/sls.alibaba.crossplane.io_projects.yaml index baaaf6b..1399d8c 100644 --- a/package/crds/sls.alibaba.crossplane.io_projects.yaml +++ b/package/crds/sls.alibaba.crossplane.io_projects.yaml @@ -55,11 +55,8 @@ spec: properties: description: type: string - name: - type: string required: - description - - name type: object providerConfigRef: description: ProviderConfigReference specifies how the provider that will be used to create, observe, update, and delete this managed resource should be configured. diff --git a/pkg/controller/sls/project_controller_test.go b/pkg/controller/sls/project_controller_test.go index 901984f..36a76b3 100644 --- a/pkg/controller/sls/project_controller_test.go +++ b/pkg/controller/sls/project_controller_test.go @@ -23,11 +23,13 @@ import ( "testing" sdk "github.com/aliyun/aliyun-log-go-sdk" + "github.com/crossplane/crossplane-runtime/pkg/meta" "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" "github.com/crossplane/crossplane-runtime/pkg/resource" "github.com/crossplane/crossplane-runtime/pkg/test" "github.com/google/go-cmp/cmp" "github.com/pkg/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" slsv1alpha1 "github.com/crossplane/provider-alibaba/apis/sls/v1alpha1" slsclient "github.com/crossplane/provider-alibaba/pkg/clients/sls" @@ -36,18 +38,25 @@ import ( var ( slsProjectDescription = "test project" slsProjectEndpoint = "xxx.com" - validCR = &slsv1alpha1.Project{Spec: slsv1alpha1.ProjectSpec{ForProvider: slsv1alpha1.ProjectParameters{ - ProjectName: "def", - Description: slsProjectDescription, - }}} - + validCR = &slsv1alpha1.Project{ + ObjectMeta: metav1.ObjectMeta{ + Name: "def", + Annotations: map[string]string{meta.AnnotationKeyExternalName: "def", + }, + }, + Spec: slsv1alpha1.ProjectSpec{ + ForProvider: slsv1alpha1.ProjectParameters{ + Description: slsProjectDescription, + }, + }, + } validProject = &sdk.LogProject{Name: "def", Endpoint: slsProjectEndpoint} ) type fakeSDKClient struct { } -// Describe describes Project bucket +// Describe describes SLS project func (c *fakeSDKClient) Describe(name string) (*sdk.LogProject, error) { switch name { case "": @@ -64,12 +73,12 @@ func (c *fakeSDKClient) Describe(name string) (*sdk.LogProject, error) { } } -// Create creates Project bucket +// Create creates SLS project func (c *fakeSDKClient) Create(name, description string) (*sdk.LogProject, error) { return validProject, nil } -// Update sets bucket acl +// Update sets SLS project description func (c *fakeSDKClient) Update(name, description string) (*sdk.LogProject, error) { return validProject, nil } @@ -95,7 +104,7 @@ func TestObserve(t *testing.T) { want want }{ "NotAnSLSProject": { - reason: "We should return an error if the supplied managed resource is not an Project bucket", + reason: "We should return an error if the supplied managed resource is not an SLS project", mg: nil, want: want{ o: managed.ExternalObservation{}, @@ -114,17 +123,22 @@ func TestObserve(t *testing.T) { }, "SLSProjectOtherError": { reason: "We should report an unknown error", - mg: &slsv1alpha1.Project{Spec: slsv1alpha1.ProjectSpec{ForProvider: slsv1alpha1.ProjectParameters{ - ProjectName: "abc", - Description: "test project", - }}}, + mg: &slsv1alpha1.Project{ + ObjectMeta: metav1.ObjectMeta{ + Name: "abc", + Annotations: map[string]string{meta.AnnotationKeyExternalName: "abc", + }, + }, + Spec: slsv1alpha1.ProjectSpec{ForProvider: slsv1alpha1.ProjectParameters{ + Description: "test project", + }}}, want: want{ o: managed.ExternalObservation{}, err: errors.New("unknown error"), }, }, - "Success": { - reason: "Observing an Project bucket successfully should return an ExternalObservation and nil error", + "SLSProjectSuccessfullyFound": { + reason: "Observing an SLS project successfully should return an ExternalObservation and nil error", mg: validCR, want: want{ o: managed.ExternalObservation{ @@ -174,7 +188,7 @@ func TestCreate(t *testing.T) { }, }, "Success": { - reason: "Creating an Project bucket successfully", + reason: "Creating an SLS project successfully", mg: validCR, want: want{ o: managed.ExternalCreation{ @@ -222,7 +236,7 @@ func TestUpdate(t *testing.T) { }, }, "Success": { - reason: "Creating an Project bucket successfully", + reason: "Creating an SLS project successfully", mg: validCR, want: want{ o: managed.ExternalUpdate{}, @@ -267,7 +281,7 @@ func TestDelete(t *testing.T) { }, }, "Success": { - reason: "Creating an Project bucket successfully", + reason: "Creating an SLS project successfully", mg: validCR, want: want{ err: nil,