Repository: apache/camel-k
Pull request #1853 (2020-12-09 12:45:38)

chore(api): make Endpoint.Properties a pointer so it can be omitted
<!-- Description -->




<!--
Enter your extended release note in the below block. If the PR requires
additional action from users switching to the new release, include the string
"action required". If no release note is required, write "NONE". 

You can (optionally) mark this PR with labels "kind/bug" or "kind/feature" to make sure
the text is added to the right section of the release notes. 
-->

**Release Note**
```release-note
NONE
```


Patch:
diff --git a/pkg/apis/camel/v1alpha1/kamelet_binding_types.go b/pkg/apis/camel/v1alpha1/kamelet_binding_types.go
index c39c34dfb..d4d7ac15c 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 d470dc609..b5891777e 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 627e6806d..4f57f13ba 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.


Test patch:
diff --git a/addons/strimzi/strimzi_test.go b/addons/strimzi/strimzi_test.go
index 13fd4ed2b..540db88ac 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 e57260202..3a55ff40c 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/util/bindings/bindings_test.go b/pkg/util/bindings/bindings_test.go
index 2648d0761..72e8ce5bb 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,
 	}
 }