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/12/09 14:13:49 UTC

[camel-k] 01/03: Fix #1112: remove Knative 0.8 compatibility mode

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 dc694504ec792a95fb8f97a9be6666f8348a8dd2
Author: Nicola Ferraro <ni...@gmail.com>
AuthorDate: Thu Dec 5 15:53:01 2019 +0100

    Fix #1112: remove Knative 0.8 compatibility mode
---
 docs/modules/ROOT/pages/traits/knative.adoc        |   5 -
 ...toscheme_knative_eventing_08_compat_v1alpha1.go |  43 --------
 pkg/apis/knative08compat/knative08compat.go        | 119 ---------------------
 pkg/trait/istio_test.go                            |   5 -
 pkg/trait/knative.go                               |  32 +-----
 pkg/trait/knative_service_test.go                  |   6 --
 pkg/util/knative/knative.go                        |   6 +-
 7 files changed, 2 insertions(+), 214 deletions(-)

diff --git a/docs/modules/ROOT/pages/traits/knative.adoc b/docs/modules/ROOT/pages/traits/knative.adoc
index f3b44a7..50d27e6 100755
--- a/docs/modules/ROOT/pages/traits/knative.adoc
+++ b/docs/modules/ROOT/pages/traits/knative.adoc
@@ -69,11 +69,6 @@ Can contain simple event types or full Camel URIs (to use a specific broker).
 that can be removed in a future version of Knative, filtering is enabled only when the integration is
 listening from more than 1 channel.
 
-| knative.knative-08-compat-mode
-| bool
-| The Knative 0.8 compatibility mode will check the installed version of Knative and
-use resource versions compatible with Knative 0.8 if found on the cluster.
-
 | knative.auto
 | bool
 | Enable automatic discovery of all trait properties.
diff --git a/pkg/apis/addtoscheme_knative_eventing_08_compat_v1alpha1.go b/pkg/apis/addtoscheme_knative_eventing_08_compat_v1alpha1.go
deleted file mode 100644
index 51734f4..0000000
--- a/pkg/apis/addtoscheme_knative_eventing_08_compat_v1alpha1.go
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one or more
-contributor license agreements.  See the NOTICE file distributed with
-this work for additional information regarding copyright ownership.
-The ASF licenses this file to You under the Apache License, Version 2.0
-(the "License"); you may not use this file except in compliance with
-the License.  You may obtain a copy of the License at
-
-   http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-package apis
-
-import (
-	"github.com/apache/camel-k/pkg/apis/knative08compat"
-	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
-	"k8s.io/apimachinery/pkg/runtime"
-)
-
-var (
-	compat08SchemeBuilder = runtime.NewSchemeBuilder(eventing08CompatKnownTypes)
-	compat08AddToScheme   = compat08SchemeBuilder.AddToScheme
-)
-
-func init() {
-	AddToSchemes = append(AddToSchemes, compat08AddToScheme)
-}
-
-// eventing08CompatKnownTypes Adds the list of known types to Scheme.
-func eventing08CompatKnownTypes(scheme *runtime.Scheme) error {
-	scheme.AddKnownTypes(knative08compat.CompatSchemeGroupVersion,
-		&knative08compat.Subscription{},
-		&knative08compat.SubscriptionList{},
-	)
-	metav1.AddToGroupVersion(scheme, knative08compat.CompatSchemeGroupVersion)
-	return nil
-}
diff --git a/pkg/apis/knative08compat/knative08compat.go b/pkg/apis/knative08compat/knative08compat.go
deleted file mode 100644
index 395aae3..0000000
--- a/pkg/apis/knative08compat/knative08compat.go
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one or more
-contributor license agreements.  See the NOTICE file distributed with
-this work for additional information regarding copyright ownership.
-The ASF licenses this file to You under the Apache License, Version 2.0
-(the "License"); you may not use this file except in compliance with
-the License.  You may obtain a copy of the License at
-
-   http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-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"
-)
-
-// CompatSchemeGroupVersion is the old group version used in Knative 0.8
-var CompatSchemeGroupVersion = schema.GroupVersion{
-	Group:   "eventing.knative.dev",
-	Version: "v1alpha1",
-}
-
-// Subscription is a Knative 0.8 compatibility version for messaging.Subscription
-type Subscription struct {
-	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 {
-	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)
-}
-
-// 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])
-		}
-	}
-}
-
-// 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/trait/istio_test.go b/pkg/trait/istio_test.go
index 3671420..6e2f9f4 100644
--- a/pkg/trait/istio_test.go
+++ b/pkg/trait/istio_test.go
@@ -50,11 +50,6 @@ func NewIstioTestEnv(t *testing.T, d *appsv1.Deployment, s *serving.Service, ena
 					"istio": {
 						Configuration: make(map[string]string),
 					},
-					"knative": {
-						Configuration: map[string]string{
-							"knative-08-compat-mode": "false", // disable it so it does not check resources in the cluster
-						},
-					},
 				},
 			},
 		},
diff --git a/pkg/trait/knative.go b/pkg/trait/knative.go
index 13f36ff..8e40db5 100644
--- a/pkg/trait/knative.go
+++ b/pkg/trait/knative.go
@@ -26,15 +26,11 @@ import (
 	"github.com/apache/camel-k/pkg/metadata"
 	"github.com/apache/camel-k/pkg/util/envvar"
 	knativeutil "github.com/apache/camel-k/pkg/util/knative"
-	"github.com/apache/camel-k/pkg/util/kubernetes"
 	"github.com/pkg/errors"
 	v1 "k8s.io/api/core/v1"
 	k8serrors "k8s.io/apimachinery/pkg/api/errors"
-	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	eventing "knative.dev/eventing/pkg/apis/eventing/v1alpha1"
-	messaging "knative.dev/eventing/pkg/apis/messaging/v1alpha1"
 	serving "knative.dev/serving/pkg/apis/serving/v1beta1"
-	k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
 )
 
 // The Knative trait automatically discovers addresses of Knative resources and inject them into the
@@ -71,9 +67,6 @@ type knativeTrait struct {
 	// that can be removed in a future version of Knative, filtering is enabled only when the integration is
 	// listening from more than 1 channel.
 	FilterSourceChannels *bool `property:"filter-source-channels"`
-	// The Knative 0.8 compatibility mode will check the installed version of Knative and
-	// use resource versions compatible with Knative 0.8 if found on the cluster.
-	Knative08CompatMode *bool `property:"knative-08-compat-mode"`
 	// Enable automatic discovery of all trait properties.
 	Auto *bool `property:"auto"`
 }
@@ -167,14 +160,6 @@ func (t *knativeTrait) Configure(e *Environment) (bool, error) {
 			filter := true
 			t.FilterSourceChannels = &filter
 		}
-
-		if t.Knative08CompatMode == nil {
-			compat, err := t.shouldUseKnative08CompatMode(e.Integration.Namespace)
-			if err != nil {
-				return false, err
-			}
-			t.Knative08CompatMode = &compat
-		}
 	}
 
 	return true, nil
@@ -258,8 +243,7 @@ func (t *knativeTrait) configureChannels(e *Environment, env *knativeapi.CamelEn
 }
 
 func (t *knativeTrait) createSubscription(e *Environment, ref *v1.ObjectReference) error {
-	compat := t.Knative08CompatMode != nil && *t.Knative08CompatMode
-	sub := knativeutil.CreateSubscription(*ref, e.Integration.Name, compat)
+	sub := knativeutil.CreateSubscription(*ref, e.Integration.Name)
 	e.Resources.Add(sub)
 	return nil
 }
@@ -429,17 +413,3 @@ func (t *knativeTrait) extractServices(names string, serviceType knativeapi.Came
 	}
 	return answer
 }
-
-func (t *knativeTrait) shouldUseKnative08CompatMode(namespace string) (bool, error) {
-	lst := messaging.SubscriptionList{
-		TypeMeta: metav1.TypeMeta{
-			Kind:       "Subscription",
-			APIVersion: messaging.SchemeGroupVersion.String(),
-		},
-	}
-	err := t.client.List(t.ctx, &lst, k8sclient.InNamespace(namespace))
-	if err != nil && kubernetes.IsUnknownAPIError(err) {
-		return true, nil
-	}
-	return false, err
-}
diff --git a/pkg/trait/knative_service_test.go b/pkg/trait/knative_service_test.go
index 661afb4..833f847 100644
--- a/pkg/trait/knative_service_test.go
+++ b/pkg/trait/knative_service_test.go
@@ -45,9 +45,6 @@ func TestKnativeService(t *testing.T) {
 	assert.Nil(t, err)
 
 	traitCatalog := NewCatalog(context.TODO(), nil)
-	knativeTrait := traitCatalog.GetTrait("knative").(*knativeTrait)
-	falze := false
-	knativeTrait.Knative08CompatMode = &falze
 
 	environment := Environment{
 		CamelCatalog: catalog,
@@ -187,9 +184,6 @@ func TestKnativeServiceWithCustomContainerName(t *testing.T) {
 	assert.Nil(t, err)
 
 	traitCatalog := NewCatalog(context.TODO(), nil)
-	knativeTrait := traitCatalog.GetTrait("knative").(*knativeTrait)
-	falze := false
-	knativeTrait.Knative08CompatMode = &falze
 
 	environment := Environment{
 		CamelCatalog: catalog,
diff --git a/pkg/util/knative/knative.go b/pkg/util/knative/knative.go
index 13e2704..5e4aabf 100644
--- a/pkg/util/knative/knative.go
+++ b/pkg/util/knative/knative.go
@@ -22,7 +22,6 @@ import (
 	"fmt"
 	"net/url"
 
-	"github.com/apache/camel-k/pkg/apis/knative08compat"
 	"github.com/apache/camel-k/pkg/client"
 	kubernetesutils "github.com/apache/camel-k/pkg/util/kubernetes"
 	"github.com/apache/camel-k/pkg/util/log"
@@ -71,7 +70,7 @@ func IsInstalled(ctx context.Context, c kubernetes.Interface) (bool, error) {
 }
 
 // CreateSubscription ---
-func CreateSubscription(channelReference corev1.ObjectReference, serviceName string, compat08 bool) runtime.Object {
+func CreateSubscription(channelReference corev1.ObjectReference, serviceName string) runtime.Object {
 	subs := messaging.Subscription{
 		TypeMeta: metav1.TypeMeta{
 			APIVersion: messaging.SchemeGroupVersion.String(),
@@ -97,9 +96,6 @@ func CreateSubscription(channelReference corev1.ObjectReference, serviceName str
 		},
 	}
 
-	if compat08 {
-		return knative08compat.FromMessagingSubscription(subs)
-	}
 	return &subs
 }