Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Commit

Permalink
Change type of xxxDefinition.spec.extension to runtime.RawExtension (
Browse files Browse the repository at this point in the history
…#153)

* Change type of xxxDefinition.spec.extension to `runtime.RawExtension`

When listing xxxDefinitionList, it will hit the error
`Object 'Kind' is missing` if the type is
`unstructured.Unstructured`

Signed-off-by: zzxwill <[email protected]>

Co-authored-by: Sun Jianbo <[email protected]>
  • Loading branch information
zzxwill and wonderflow authored Jul 31, 2020
1 parent 68198b3 commit 16c4109
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
7 changes: 3 additions & 4 deletions apis/core/v1alpha2/core_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package v1alpha2
import (
runtimev1alpha1 "github.com/crossplane/crossplane-runtime/apis/core/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr"
)
Expand Down Expand Up @@ -52,7 +51,7 @@ type WorkloadDefinitionSpec struct {

// Extension is used for extension needs by OAM platform builders
// +optional
Extension *unstructured.Unstructured `json:"extension,omitempty"`
Extension *runtime.RawExtension `json:"extension,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down Expand Up @@ -101,7 +100,7 @@ type TraitDefinitionSpec struct {

// Extension is used for extension needs by OAM platform builders
// +optional
Extension *unstructured.Unstructured `json:"extension,omitempty"`
Extension *runtime.RawExtension `json:"extension,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down Expand Up @@ -142,7 +141,7 @@ type ScopeDefinitionSpec struct {

// Extension is used for extension needs by OAM platform builders
// +optional
Extension *unstructured.Unstructured `json:"extension,omitempty"`
Extension *runtime.RawExtension `json:"extension,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down
9 changes: 6 additions & 3 deletions apis/core/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions test/e2e-test/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package controllers_test

import (
"context"
"encoding/json"
"testing"

. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -45,9 +46,15 @@ import (
var k8sClient client.Client
var scheme = runtime.NewScheme()
var manualscalertrait v1alpha2.TraitDefinition
var extendedmanualscalertrait v1alpha2.TraitDefinition
var roleBindingName = "oam-role-binding"
var crd crdv1.CustomResourceDefinition

// A DefinitionExtension is an Object type for xxxDefinitin.spec.extension
type DefinitionExtension struct {
Alias string `json:"alias,omitempty"`
}

func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)

Expand Down Expand Up @@ -100,6 +107,30 @@ var _ = BeforeSuite(func(done Done) {
// For some reason, traitDefinition is created as a Cluster scope object
Expect(k8sClient.Create(context.Background(), &manualscalertrait)).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{}))
By("Created manual scalar trait definition")

// Create manual scaler trait definition with spec.extension field
definitionExtension := DefinitionExtension{
Alias: "ManualScaler",
}
in := new(runtime.RawExtension)
in.Raw, _ = json.Marshal(definitionExtension)

extendedmanualscalertrait = v1alpha2.TraitDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: "manualscalertraits-extended.core.oam.dev",
Labels: map[string]string{"trait": "manualscalertrait"},
},
Spec: v1alpha2.TraitDefinitionSpec{
WorkloadRefPath: "spec.workloadRef",
Reference: v1alpha2.DefinitionReference{
Name: "manualscalertraits-extended.core.oam.dev",
},
Extension: in,
},
}
Expect(k8sClient.Create(context.Background(), &extendedmanualscalertrait)).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{}))
By("Created extended manualscalertraits.core.oam.dev")

adminRoleBinding := rbac.ClusterRoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: roleBindingName,
Expand Down Expand Up @@ -178,6 +209,7 @@ var _ = AfterSuite(func() {
},
}
Expect(k8sClient.Delete(context.Background(), &manualscalertrait)).Should(BeNil())
Expect(k8sClient.Delete(context.Background(), &extendedmanualscalertrait)).Should(BeNil())
By("Deleted the manual scalertrait definition")
crd = crdv1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit 16c4109

Please sign in to comment.