From fdd2a5227fe2daffdb0413d113238589c89ae98d Mon Sep 17 00:00:00 2001 From: Luca Burgazzoli Date: Wed, 9 Dec 2020 13:44:57 +0100 Subject: [PATCH] chore(api): make Endpoint.Properties a pointer so it can be omitted --- addons/strimzi/strimzi_test.go | 7 ++++--- e2e/support/test_support.go | 6 +++--- pkg/apis/camel/v1alpha1/kamelet_binding_types.go | 2 +- pkg/apis/camel/v1alpha1/kamelet_binding_types_support.go | 5 ++++- pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go | 6 +++++- pkg/util/bindings/bindings_test.go | 4 ++-- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/addons/strimzi/strimzi_test.go b/addons/strimzi/strimzi_test.go index 13fd4ed2bf..540db88acb 100644 --- a/addons/strimzi/strimzi_test.go +++ b/addons/strimzi/strimzi_test.go @@ -20,6 +20,8 @@ package strimzi import ( "context" "encoding/json" + "testing" + "github.com/apache/camel-k/addons/strimzi/duck/v1beta1" "github.com/apache/camel-k/addons/strimzi/duck/v1beta1/client/internalclientset/fake" camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1" @@ -29,7 +31,6 @@ import ( "github.com/stretchr/testify/assert" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "testing" ) func TestStrimziDirect(t *testing.T) { @@ -122,12 +123,12 @@ func TestStrimziLookup(t *testing.T) { assert.Nil(t, binding.Traits) } -func asEndpointProperties(props map[string]string) v1alpha1.EndpointProperties { +func asEndpointProperties(props map[string]string) *v1alpha1.EndpointProperties { serialized, err := json.Marshal(props) if err != nil { panic(err) } - return v1alpha1.EndpointProperties{ + return &v1alpha1.EndpointProperties{ RawMessage: serialized, } } diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go index e57260202c..3a55ff40ce 100644 --- a/e2e/support/test_support.go +++ b/e2e/support/test_support.go @@ -56,7 +56,7 @@ import ( routev1 "github.com/openshift/api/route/v1" "github.com/apache/camel-k/e2e/support/util" - "github.com/apache/camel-k/pkg/apis/camel/v1" + v1 "github.com/apache/camel-k/pkg/apis/camel/v1" "github.com/apache/camel-k/pkg/client" "github.com/apache/camel-k/pkg/cmd" "github.com/apache/camel-k/pkg/install" @@ -968,12 +968,12 @@ func asFlow(source map[string]interface{}) *v1.Flow { } } -func asEndpointProperties(props map[string]string) v1alpha1.EndpointProperties { +func asEndpointProperties(props map[string]string) *v1alpha1.EndpointProperties { bytes, err := json.Marshal(props) if err != nil { panic(err) } - return v1alpha1.EndpointProperties{ + return &v1alpha1.EndpointProperties{ RawMessage: bytes, } } diff --git a/pkg/apis/camel/v1alpha1/kamelet_binding_types.go b/pkg/apis/camel/v1alpha1/kamelet_binding_types.go index c39c34dfb6..d4d7ac15cf 100644 --- a/pkg/apis/camel/v1alpha1/kamelet_binding_types.go +++ b/pkg/apis/camel/v1alpha1/kamelet_binding_types.go @@ -41,7 +41,7 @@ type Endpoint struct { // URI can alternatively be used to specify the (Camel) endpoint explicitly URI *string `json:"uri,omitempty"` // Properties are a key value representation of endpoint properties - Properties EndpointProperties `json:"properties,omitempty"` + Properties *EndpointProperties `json:"properties,omitempty"` } type EndpointType string diff --git a/pkg/apis/camel/v1alpha1/kamelet_binding_types_support.go b/pkg/apis/camel/v1alpha1/kamelet_binding_types_support.go index d470dc609e..b5891777e2 100644 --- a/pkg/apis/camel/v1alpha1/kamelet_binding_types_support.go +++ b/pkg/apis/camel/v1alpha1/kamelet_binding_types_support.go @@ -141,7 +141,10 @@ func (in *KameletBindingStatus) RemoveCondition(condType KameletBindingCondition } // GetPropertyMap returns the EndpointProperties as map -func (p EndpointProperties) GetPropertyMap() (map[string]string, error) { +func (p *EndpointProperties) GetPropertyMap() (map[string]string, error) { + if p == nil { + return nil, nil + } if len(p.RawMessage) == 0 { return nil, nil } diff --git a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go index 627e6806d8..4f57f13ba9 100644 --- a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go @@ -39,7 +39,11 @@ func (in *Endpoint) DeepCopyInto(out *Endpoint) { *out = new(string) **out = **in } - in.Properties.DeepCopyInto(&out.Properties) + if in.Properties != nil { + in, out := &in.Properties, &out.Properties + *out = new(EndpointProperties) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Endpoint. diff --git a/pkg/util/bindings/bindings_test.go b/pkg/util/bindings/bindings_test.go index 2648d07617..72e8ce5bba 100644 --- a/pkg/util/bindings/bindings_test.go +++ b/pkg/util/bindings/bindings_test.go @@ -196,12 +196,12 @@ func TestBindings(t *testing.T) { } } -func asEndpointProperties(props map[string]string) v1alpha1.EndpointProperties { +func asEndpointProperties(props map[string]string) *v1alpha1.EndpointProperties { serialized, err := json.Marshal(props) if err != nil { panic(err) } - return v1alpha1.EndpointProperties{ + return &v1alpha1.EndpointProperties{ RawMessage: serialized, } }