Skip to content

Commit

Permalink
Remove spec.forprovider.name
Browse files Browse the repository at this point in the history
Signed-off-by: Zheng Xi Zhou <[email protected]>
  • Loading branch information
zzxwill committed Apr 5, 2021
1 parent 2b650c2 commit 9e6a108
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
1 change: 0 additions & 1 deletion apis/sls/v1alpha1/project_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
1 change: 0 additions & 1 deletion examples/sls/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ metadata:
namespace: default
spec:
forProvider:
name: sls-project-sample
description: provisioned by Crossplane
writeConnectionSecretToRef:
name: sls-endpoint
Expand Down
3 changes: 0 additions & 3 deletions package/crds/sls.alibaba.crossplane.io_projects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
50 changes: 32 additions & 18 deletions pkg/controller/sls/project_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 "":
Expand All @@ -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
}
Expand All @@ -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{},
Expand All @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9e6a108

Please sign in to comment.