Skip to content

Commit

Permalink
fix(trait):define the default trait name
Browse files Browse the repository at this point in the history
Make the default trait name not the same as the component name

Fixes crossplane#66

Signed-off-by: zhuhuijun <[email protected]>
  • Loading branch information
Ghostbaby committed Jul 7, 2020
1 parent 05cdd00 commit 6ff2b63
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 6 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ require (
github.com/rs/xid v1.2.1
github.com/stretchr/testify v1.4.0
golang.org/x/tools v0.0.0-20200630223951-c138986dd9b9 // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
k8s.io/api v0.18.5
k8s.io/apiextensions-apiserver v0.18.2
k8s.io/apimachinery v0.18.5
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,6 @@ gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qS
gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
gopkg.in/inf.v0 v0.9.0/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/v1alpha2/applicationconfiguration/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (r *components) renderComponent(ctx context.Context, acc v1alpha2.Applicati
}

func (r *components) renderTrait(ctx context.Context, ct v1alpha2.ComponentTrait, namespace, componentName string, ref *metav1.OwnerReference, dag *dependency.DAG) (*unstructured.Unstructured, *v1alpha2.TraitDefinition, error) {
traitName := util.GenTraitName(componentName, ct.DeepCopy(), nil)
traitName := util.GenTraitName(componentName, ct.DeepCopy(), new(int32))
t, err := r.trait.Render(ct.Trait.Raw)
if err != nil {
return nil, nil, errors.Wrapf(err, errFmtRenderTrait, traitName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func TestRenderComponents(t *testing.T) {
},
args: args{ac: ac},
want: want{
err: errors.Wrapf(errBoom, errFmtRenderTrait, util.GenTraitName(componentName, ac.Spec.Components[0].Traits[0].DeepCopy(), nil)),
err: errors.Wrapf(errBoom, errFmtRenderTrait, util.GenTraitName(componentName, ac.Spec.Components[0].Traits[0].DeepCopy(), new(int32))),
},
},
"Success": {
Expand Down Expand Up @@ -670,7 +670,7 @@ func TestRenderTraitWithoutMetadataName(t *testing.T) {
t.Run(name, func(t *testing.T) {
r := &components{tc.fields.client, nil, tc.fields.params, tc.fields.workload, tc.fields.trait}
got, _ := r.Render(tc.args.ctx, tc.args.ac)
if len(got) == 0 || len(got[0].Traits) == 0 || got[0].Traits[0].GetName() != util.GenTraitName(componentName, ac.Spec.Components[0].Traits[0].DeepCopy(), nil) {
if len(got) == 0 || len(got[0].Traits) == 0 || got[0].Traits[0].GetName() != util.GenTraitName(componentName, ac.Spec.Components[0].Traits[0].DeepCopy(), new(int32)) {
t.Errorf("\n%s\nr.Render(...): -want error, +got error:\n%s\n", tc.reason, "Trait name is NOT"+
"automatically set.")
}
Expand Down

0 comments on commit 6ff2b63

Please sign in to comment.