You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2019/10/01 13:53:48 UTC

[camel-k] 05/08: Fix #952: add Knative 0.8.0 compatibility hack (refactor)

This is an automated email from the ASF dual-hosted git repository.

nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit ed724b80eb04ee1fb0abfc185a316f853c3360b3
Author: nferraro <ni...@gmail.com>
AuthorDate: Thu Sep 26 18:23:28 2019 +0200

    Fix #952: add Knative 0.8.0 compatibility hack (refactor)
---
 pkg/apis/knative08compat/knative08compat.go | 86 ++++++++++++++++++++++++++++-
 pkg/util/knative/knative.go                 | 10 +---
 2 files changed, 86 insertions(+), 10 deletions(-)

diff --git a/pkg/apis/knative08compat/knative08compat.go b/pkg/apis/knative08compat/knative08compat.go
index 7939754..a43a73f 100644
--- a/pkg/apis/knative08compat/knative08compat.go
+++ b/pkg/apis/knative08compat/knative08compat.go
@@ -1,6 +1,8 @@
 package knative08compat
 
 import (
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	"k8s.io/apimachinery/pkg/runtime"
 	"k8s.io/apimachinery/pkg/runtime/schema"
 	messaging "knative.dev/eventing/pkg/apis/messaging/v1alpha1"
 )
@@ -13,10 +15,90 @@ var CompatSchemeGroupVersion = schema.GroupVersion{
 
 // Subscription is a Knative 0.8 compatibility version for messaging.Subscription
 type Subscription struct {
-	messaging.Subscription
+	metav1.TypeMeta   `json:",inline"`
+	metav1.ObjectMeta `json:"metadata"`
+	Spec              messaging.SubscriptionSpec   `json:"spec"`
+	Status            messaging.SubscriptionStatus `json:"status,omitempty"`
 }
 
 // SubscriptionList is a Knative 0.8 compatibility version for messaging.SubscriptionList
 type SubscriptionList struct {
-	messaging.SubscriptionList
+	metav1.TypeMeta `json:",inline"`
+	metav1.ListMeta `json:"metadata"`
+	Items           []Subscription `json:"items"`
+}
+
+// FromMessagingSubscription creates a compat08 subscription from a messaging.Subscription
+func FromMessagingSubscription(s messaging.Subscription) *Subscription {
+	in := s.DeepCopy()
+	out := Subscription{
+		TypeMeta:   in.TypeMeta,
+		ObjectMeta: in.ObjectMeta,
+		Spec:       in.Spec,
+		Status:     in.Status,
+	}
+	// fix API group
+	out.TypeMeta.APIVersion = CompatSchemeGroupVersion.String()
+	return &out
+}
+
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *Subscription) DeepCopyInto(out *Subscription) {
+	*out = *in
+	out.TypeMeta = in.TypeMeta
+	in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
+	in.Spec.DeepCopyInto(&out.Spec)
+	in.Status.DeepCopyInto(&out.Status)
+	return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Subscription.
+func (in *Subscription) DeepCopy() *Subscription {
+	if in == nil {
+		return nil
+	}
+	out := new(Subscription)
+	in.DeepCopyInto(out)
+	return out
+}
+
+// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
+func (in *Subscription) DeepCopyObject() runtime.Object {
+	if c := in.DeepCopy(); c != nil {
+		return c
+	}
+	return nil
+}
+
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *SubscriptionList) DeepCopyInto(out *SubscriptionList) {
+	*out = *in
+	out.TypeMeta = in.TypeMeta
+	out.ListMeta = in.ListMeta
+	if in.Items != nil {
+		in, out := &in.Items, &out.Items
+		*out = make([]Subscription, len(*in))
+		for i := range *in {
+			(*in)[i].DeepCopyInto(&(*out)[i])
+		}
+	}
+	return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscriptionList.
+func (in *SubscriptionList) DeepCopy() *SubscriptionList {
+	if in == nil {
+		return nil
+	}
+	out := new(SubscriptionList)
+	in.DeepCopyInto(out)
+	return out
+}
+
+// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
+func (in *SubscriptionList) DeepCopyObject() runtime.Object {
+	if c := in.DeepCopy(); c != nil {
+		return c
+	}
+	return nil
 }
diff --git a/pkg/util/knative/knative.go b/pkg/util/knative/knative.go
index 874c108..bfa7343 100644
--- a/pkg/util/knative/knative.go
+++ b/pkg/util/knative/knative.go
@@ -72,13 +72,9 @@ func IsInstalled(ctx context.Context, c kubernetes.Interface) (bool, error) {
 
 // CreateSubscription ---
 func CreateSubscription(channelReference corev1.ObjectReference, serviceName string, compat08 bool) runtime.Object {
-	apiVersion := messaging.SchemeGroupVersion.String()
-	if compat08 {
-		apiVersion = knative08compat.CompatSchemeGroupVersion.String()
-	}
 	subs := messaging.Subscription{
 		TypeMeta: metav1.TypeMeta{
-			APIVersion: apiVersion,
+			APIVersion: messaging.SchemeGroupVersion.String(),
 			Kind:       "Subscription",
 		},
 		ObjectMeta: metav1.ObjectMeta{
@@ -102,9 +98,7 @@ func CreateSubscription(channelReference corev1.ObjectReference, serviceName str
 	}
 
 	if compat08 {
-		return &knative08compat.Subscription{
-			Subscription: subs,
-		}
+		return knative08compat.FromMessagingSubscription(subs)
 	}
 	return &subs
 }