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 20eed1a42e8f59ee59dee203dd714a8243bd2ed1 Author: Nicola Ferraro <ni.ferr...@gmail.com> AuthorDate: Thu Dec 5 17:28:21 2019 +0100 Fix #1112: switch to serving.knative.dev/v1 --- pkg/apis/addtoscheme_knative_serving_v1alpha1.go | 2 +- pkg/trait/classpath_test.go | 5 ++-- pkg/trait/container.go | 2 +- pkg/trait/istio_test.go | 27 +++++++++--------- pkg/trait/knative.go | 2 +- pkg/trait/knative_service.go | 11 ++++---- pkg/trait/knative_service_test.go | 2 +- pkg/trait/knative_test.go | 36 ++++++++++++++++-------- pkg/trait/owner.go | 2 +- pkg/trait/probes_test.go | 11 ++++---- pkg/util/knative/apis.go | 6 ++-- pkg/util/knative/apis_test.go | 4 +-- pkg/util/knative/knative.go | 18 ++++++------ pkg/util/kubernetes/collection.go | 9 +++--- pkg/util/kubernetes/replace.go | 7 ++--- 15 files changed, 75 insertions(+), 69 deletions(-) diff --git a/pkg/apis/addtoscheme_knative_serving_v1alpha1.go b/pkg/apis/addtoscheme_knative_serving_v1alpha1.go index b96c913..f270608 100644 --- a/pkg/apis/addtoscheme_knative_serving_v1alpha1.go +++ b/pkg/apis/addtoscheme_knative_serving_v1alpha1.go @@ -18,7 +18,7 @@ limitations under the License. package apis import ( - serving "knative.dev/serving/pkg/apis/serving/v1beta1" + serving "knative.dev/serving/pkg/apis/serving/v1" ) func init() { diff --git a/pkg/trait/classpath_test.go b/pkg/trait/classpath_test.go index 125d75e..20d62dc 100644 --- a/pkg/trait/classpath_test.go +++ b/pkg/trait/classpath_test.go @@ -26,8 +26,7 @@ import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - servingv1 "knative.dev/serving/pkg/apis/serving/v1" - serving "knative.dev/serving/pkg/apis/serving/v1beta1" + serving "knative.dev/serving/pkg/apis/serving/v1" "github.com/apache/camel-k/pkg/apis/camel/v1alpha1" "github.com/apache/camel-k/pkg/util/kubernetes" @@ -148,7 +147,7 @@ func TestApplyClasspathTraitWithKNativeResource(t *testing.T) { trait, environment := createNominalClasspathTest() s := serving.Service{} - s.Spec.ConfigurationSpec.Template = servingv1.RevisionTemplateSpec{} + s.Spec.ConfigurationSpec.Template = serving.RevisionTemplateSpec{} s.Spec.ConfigurationSpec.Template.Spec.Containers = []corev1.Container{ { Name: defaultContainerName, diff --git a/pkg/trait/container.go b/pkg/trait/container.go index 6bd3ae6..558e109 100644 --- a/pkg/trait/container.go +++ b/pkg/trait/container.go @@ -27,7 +27,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/intstr" - serving "knative.dev/serving/pkg/apis/serving/v1beta1" + serving "knative.dev/serving/pkg/apis/serving/v1" ) const ( diff --git a/pkg/trait/istio_test.go b/pkg/trait/istio_test.go index 6e2f9f4..b68d374 100644 --- a/pkg/trait/istio_test.go +++ b/pkg/trait/istio_test.go @@ -26,8 +26,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - servingv1 "knative.dev/serving/pkg/apis/serving/v1" - serving "knative.dev/serving/pkg/apis/serving/v1beta1" + serving "knative.dev/serving/pkg/apis/serving/v1" "github.com/apache/camel-k/pkg/apis/camel/v1alpha1" "github.com/apache/camel-k/pkg/util/camel" @@ -75,9 +74,9 @@ func NewIstioTestEnv(t *testing.T, d *appsv1.Deployment, s *serving.Service, ena func TestIstioInject(t *testing.T) { s := serving.Service{ - Spec: servingv1.ServiceSpec{ - ConfigurationSpec: servingv1.ConfigurationSpec{ - Template: servingv1.RevisionTemplateSpec{}, + Spec: serving.ServiceSpec{ + ConfigurationSpec: serving.ConfigurationSpec{ + Template: serving.RevisionTemplateSpec{}, }, }, } @@ -97,9 +96,9 @@ func TestIstioInject(t *testing.T) { func TestIstioForcedInjectTrue(t *testing.T) { s := serving.Service{ - Spec: servingv1.ServiceSpec{ - ConfigurationSpec: servingv1.ConfigurationSpec{ - Template: servingv1.RevisionTemplateSpec{}, + Spec: serving.ServiceSpec{ + ConfigurationSpec: serving.ConfigurationSpec{ + Template: serving.RevisionTemplateSpec{}, }, }, } @@ -121,9 +120,9 @@ func TestIstioForcedInjectTrue(t *testing.T) { func TestIstioForcedInjectFalse(t *testing.T) { s := serving.Service{ - Spec: servingv1.ServiceSpec{ - ConfigurationSpec: servingv1.ConfigurationSpec{ - Template: servingv1.RevisionTemplateSpec{}, + Spec: serving.ServiceSpec{ + ConfigurationSpec: serving.ConfigurationSpec{ + Template: serving.RevisionTemplateSpec{}, }, }, } @@ -145,9 +144,9 @@ func TestIstioForcedInjectFalse(t *testing.T) { func TestIstioDisabled(t *testing.T) { s := serving.Service{ - Spec: servingv1.ServiceSpec{ - ConfigurationSpec: servingv1.ConfigurationSpec{ - Template: servingv1.RevisionTemplateSpec{}, + Spec: serving.ServiceSpec{ + ConfigurationSpec: serving.ConfigurationSpec{ + Template: serving.RevisionTemplateSpec{}, }, }, } diff --git a/pkg/trait/knative.go b/pkg/trait/knative.go index 8e40db5..1256136 100644 --- a/pkg/trait/knative.go +++ b/pkg/trait/knative.go @@ -30,7 +30,7 @@ import ( v1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" eventing "knative.dev/eventing/pkg/apis/eventing/v1alpha1" - serving "knative.dev/serving/pkg/apis/serving/v1beta1" + serving "knative.dev/serving/pkg/apis/serving/v1" ) // The Knative trait automatically discovers addresses of Knative resources and inject them into the diff --git a/pkg/trait/knative_service.go b/pkg/trait/knative_service.go index b57f76f..f8d5d25 100644 --- a/pkg/trait/knative_service.go +++ b/pkg/trait/knative_service.go @@ -23,8 +23,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - servingv1 "knative.dev/serving/pkg/apis/serving/v1" - serving "knative.dev/serving/pkg/apis/serving/v1beta1" + serving "knative.dev/serving/pkg/apis/serving/v1" "github.com/apache/camel-k/pkg/apis/camel/v1alpha1" "github.com/apache/camel-k/pkg/metadata" @@ -280,14 +279,14 @@ func (t *knativeServiceTrait) getServiceFor(e *Environment) *serving.Service { Labels: labels, Annotations: e.Integration.Annotations, }, - Spec: servingv1.ServiceSpec{ - ConfigurationSpec: servingv1.ConfigurationSpec{ - Template: servingv1.RevisionTemplateSpec{ + Spec: serving.ServiceSpec{ + ConfigurationSpec: serving.ConfigurationSpec{ + Template: serving.RevisionTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: labels, Annotations: annotations, }, - Spec: servingv1.RevisionSpec{ + Spec: serving.RevisionSpec{ PodSpec: corev1.PodSpec{ ServiceAccountName: e.Integration.Spec.ServiceAccountName, }, diff --git a/pkg/trait/knative_service_test.go b/pkg/trait/knative_service_test.go index 833f847..faad1b2 100644 --- a/pkg/trait/knative_service_test.go +++ b/pkg/trait/knative_service_test.go @@ -26,7 +26,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - serving "knative.dev/serving/pkg/apis/serving/v1beta1" + serving "knative.dev/serving/pkg/apis/serving/v1" "github.com/apache/camel-k/pkg/apis/camel/v1alpha1" "github.com/apache/camel-k/pkg/util/camel" diff --git a/pkg/trait/knative_test.go b/pkg/trait/knative_test.go index 13038e5..3596188 100644 --- a/pkg/trait/knative_test.go +++ b/pkg/trait/knative_test.go @@ -31,8 +31,8 @@ import ( "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" duckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1" - servingv1 "knative.dev/serving/pkg/apis/serving/v1" - serving "knative.dev/serving/pkg/apis/serving/v1beta1" + duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" + serving "knative.dev/serving/pkg/apis/serving/v1" "github.com/apache/camel-k/pkg/apis/camel/v1alpha1" knativeapi "github.com/apache/camel-k/pkg/apis/camel/v1alpha1/knative" @@ -130,14 +130,14 @@ func TestKnativeEnvConfigurationFromTrait(t *testing.T) { assert.NotNil(t, cSink1) assert.Equal(t, "channel-sink-1.host", cSink1.Host) - eSource1 := ne.FindService("endpoint-source-1", knativeapi.CamelEndpointKindSource, knativeapi.CamelServiceTypeEndpoint, "serving.knative.dev/v1beta1", "Service") + eSource1 := ne.FindService("endpoint-source-1", knativeapi.CamelEndpointKindSource, knativeapi.CamelServiceTypeEndpoint, "serving.knative.dev/v1", "Service") assert.NotNil(t, eSource1) assert.Equal(t, "0.0.0.0", eSource1.Host) - eSink1 := ne.FindService("endpoint-sink-1", knativeapi.CamelEndpointKindSink, knativeapi.CamelServiceTypeEndpoint, "serving.knative.dev/v1beta1", "Service") + eSink1 := ne.FindService("endpoint-sink-1", knativeapi.CamelEndpointKindSink, knativeapi.CamelServiceTypeEndpoint, "serving.knative.dev/v1", "Service") assert.NotNil(t, eSink1) assert.Equal(t, "endpoint-sink-1.host", eSink1.Host) - eSink2 := ne.FindService("endpoint-sink-2", knativeapi.CamelEndpointKindSink, knativeapi.CamelServiceTypeEndpoint, "serving.knative.dev/v1beta1", "Service") + eSink2 := ne.FindService("endpoint-sink-2", knativeapi.CamelEndpointKindSink, knativeapi.CamelServiceTypeEndpoint, "serving.knative.dev/v1", "Service") assert.NotNil(t, eSink2) assert.Equal(t, "endpoint-sink-2.host", eSink2.Host) } @@ -232,13 +232,21 @@ func TestKnativeEnvConfigurationFromSource(t *testing.T) { err = ne.Deserialize(kc.Value) assert.Nil(t, err) - source := ne.FindService("s3fileMover1", knativeapi.CamelEndpointKindSource, knativeapi.CamelServiceTypeEndpoint, "serving.knative.dev/v1beta1", "Service") + source := ne.FindService("s3fileMover1", knativeapi.CamelEndpointKindSource, knativeapi.CamelServiceTypeEndpoint, "serving.knative.dev/v1", "Service") assert.NotNil(t, source) assert.Equal(t, "0.0.0.0", source.Host) assert.Equal(t, 8080, source.Port) } func NewFakeClient(namespace string) (client.Client, error) { + channelSourceURL, err := apis.ParseURL("http://channel-source-1.host/") + if err != nil { + return nil, err + } + channelSinkURL, err := apis.ParseURL("http://channel-sink-1.host/") + if err != nil { + return nil, err + } sink1URL, err := apis.ParseURL("http://endpoint-sink-1.host/") if err != nil { return nil, err @@ -260,7 +268,9 @@ func NewFakeClient(namespace string) (client.Client, error) { Status: messaging.ChannelStatus{ AddressStatus: duckv1alpha1.AddressStatus{ Address: &duckv1alpha1.Addressable{ - Hostname: "channel-source-1.host", + Addressable: duckv1beta1.Addressable{ + URL: channelSourceURL, + }, }, }, }, @@ -277,7 +287,9 @@ func NewFakeClient(namespace string) (client.Client, error) { Status: messaging.ChannelStatus{ AddressStatus: duckv1alpha1.AddressStatus{ Address: &duckv1alpha1.Addressable{ - Hostname: "channel-sink-1.host", + Addressable: duckv1beta1.Addressable{ + URL: channelSinkURL, + }, }, }, }, @@ -291,8 +303,8 @@ func NewFakeClient(namespace string) (client.Client, error) { Namespace: namespace, Name: "endpoint-sink-1", }, - Status: servingv1.ServiceStatus{ - RouteStatusFields: servingv1.RouteStatusFields{ + Status: serving.ServiceStatus{ + RouteStatusFields: serving.RouteStatusFields{ Address: &duckv1.Addressable{ URL: sink1URL, @@ -309,8 +321,8 @@ func NewFakeClient(namespace string) (client.Client, error) { Namespace: namespace, Name: "endpoint-sink-2", }, - Status: servingv1.ServiceStatus{ - RouteStatusFields: servingv1.RouteStatusFields{ + Status: serving.ServiceStatus{ + RouteStatusFields: serving.RouteStatusFields{ Address: &duckv1.Addressable{ URL: sink2URL, }, diff --git a/pkg/trait/owner.go b/pkg/trait/owner.go index 3b1ff11..784a650 100644 --- a/pkg/trait/owner.go +++ b/pkg/trait/owner.go @@ -24,7 +24,7 @@ import ( appsv1 "k8s.io/api/apps/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - serving "knative.dev/serving/pkg/apis/serving/v1beta1" + serving "knative.dev/serving/pkg/apis/serving/v1" ) // The Owner trait ensures that all created resources belong to the integration being created diff --git a/pkg/trait/probes_test.go b/pkg/trait/probes_test.go index e2d1b09..69ab235 100644 --- a/pkg/trait/probes_test.go +++ b/pkg/trait/probes_test.go @@ -27,8 +27,7 @@ import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" - servingv1 "knative.dev/serving/pkg/apis/serving/v1" - serving "knative.dev/serving/pkg/apis/serving/v1beta1" + serving "knative.dev/serving/pkg/apis/serving/v1" ) func TestProbesDeps(t *testing.T) { @@ -101,10 +100,10 @@ func TestProbesOnDeployment(t *testing.T) { func TestProbesOnKnativeService(t *testing.T) { target := serving.Service{ - Spec: servingv1.ServiceSpec{ - ConfigurationSpec: servingv1.ConfigurationSpec{ - Template: servingv1.RevisionTemplateSpec{ - Spec: servingv1.RevisionSpec{ + Spec: serving.ServiceSpec{ + ConfigurationSpec: serving.ConfigurationSpec{ + Template: serving.RevisionTemplateSpec{ + Spec: serving.RevisionSpec{ PodSpec: corev1.PodSpec{ Containers: []corev1.Container{ { diff --git a/pkg/util/knative/apis.go b/pkg/util/knative/apis.go index bb80509..43708bc 100644 --- a/pkg/util/knative/apis.go +++ b/pkg/util/knative/apis.go @@ -59,17 +59,17 @@ var ( { Kind: "Service", Group: "serving.knative.dev", - Version: "v1beta1", + Version: "v1", }, { Kind: "Service", Group: "serving.knative.dev", - Version: "v1alpha1", + Version: "v1beta1", }, { Kind: "Service", Group: "serving.knative.dev", - Version: "v1", + Version: "v1alpha1", }, } diff --git a/pkg/util/knative/apis_test.go b/pkg/util/knative/apis_test.go index ab573b9..9078273 100644 --- a/pkg/util/knative/apis_test.go +++ b/pkg/util/knative/apis_test.go @@ -32,7 +32,7 @@ func TestAPIs(t *testing.T) { checkValidRefs(t, refs) assert.Equal(t, v1.ObjectReference{ Kind: "Service", - APIVersion: "serving.knative.dev/v1beta1", + APIVersion: "serving.knative.dev/v1", Name: "ciao", }, refs[0]) @@ -75,7 +75,7 @@ func TestAPIs(t *testing.T) { checkValidRefs(t, refs) assert.Equal(t, v1.ObjectReference{ Kind: "Service", - APIVersion: "serving.knative.dev/v1beta1", + APIVersion: "serving.knative.dev/v1", Name: "ciao", }, refs[0]) diff --git a/pkg/util/knative/knative.go b/pkg/util/knative/knative.go index 8c24d3d..003912b 100644 --- a/pkg/util/knative/knative.go +++ b/pkg/util/knative/knative.go @@ -38,9 +38,9 @@ import ( eventing "knative.dev/eventing/pkg/apis/eventing/v1alpha1" messaging "knative.dev/eventing/pkg/apis/messaging/v1alpha1" "knative.dev/pkg/apis/duck" - duckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1" + duckv1 "knative.dev/pkg/apis/duck/v1" apisv1alpha1 "knative.dev/pkg/apis/v1alpha1" - serving "knative.dev/serving/pkg/apis/serving/v1beta1" + serving "knative.dev/serving/pkg/apis/serving/v1" ) // IsEnabledInNamespace returns true if we can list some basic knative objects in the given namespace @@ -176,23 +176,23 @@ func GetSinkURI(ctx context.Context, c client.Client, sink *corev1.ObjectReferen objIdentifier := fmt.Sprintf("\"%s/%s\" (%s)", u.GetNamespace(), u.GetName(), u.GroupVersionKind()) // Special case v1/Service to allow it be addressable - if u.GroupVersionKind().Kind == "Service" && u.GroupVersionKind().Version == "v1" { + if u.GroupVersionKind().Kind == "Service" && u.GroupVersionKind().Group == "" && u.GroupVersionKind().Version == "v1" { return fmt.Sprintf("http://%s.%s.svc/", u.GetName(), u.GetNamespace()), nil } - t := duckv1alpha1.AddressableType{} + t := duckv1.AddressableType{} err = duck.FromUnstructured(u, &t) if err != nil { return "", fmt.Errorf("failed to deserialize sink %s: %v", objIdentifier, err) } - if t.Status.Address == nil { - return "", fmt.Errorf("sink %s does not contain address", objIdentifier) + if t.Status.Address == nil || t.Status.Address.URL == nil { + return "", fmt.Errorf("sink %s does not contain address or URL", objIdentifier) } - url := t.Status.Address.GetURL() - if url.Host == "" { + addressURL := t.Status.Address.URL + if addressURL.Host == "" { return "", fmt.Errorf("sink %s contains an empty hostname", objIdentifier) } - return url.String(), nil + return addressURL.String(), nil } diff --git a/pkg/util/kubernetes/collection.go b/pkg/util/kubernetes/collection.go index 20a2c25..d825a78 100644 --- a/pkg/util/kubernetes/collection.go +++ b/pkg/util/kubernetes/collection.go @@ -25,8 +25,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" eventing "knative.dev/eventing/pkg/apis/eventing/v1alpha1" - servingv1 "knative.dev/serving/pkg/apis/serving/v1" - serving "knative.dev/serving/pkg/apis/serving/v1beta1" + serving "knative.dev/serving/pkg/apis/serving/v1" ) // A Collection is a container of Kubernetes resources @@ -298,7 +297,7 @@ func (c *Collection) VisitContainer(visitor func(container *corev1.Container)) { visitor(cntref) } }) - c.VisitKnativeConfigurationSpec(func(cs *servingv1.ConfigurationSpec) { + c.VisitKnativeConfigurationSpec(func(cs *serving.ConfigurationSpec) { for id := range cs.Template.Spec.Containers { cntref := &cs.Template.Spec.Containers[id] visitor(cntref) @@ -311,13 +310,13 @@ func (c *Collection) VisitPodSpec(visitor func(container *corev1.PodSpec)) { c.VisitDeployment(func(d *appsv1.Deployment) { visitor(&d.Spec.Template.Spec) }) - c.VisitKnativeConfigurationSpec(func(cs *servingv1.ConfigurationSpec) { + c.VisitKnativeConfigurationSpec(func(cs *serving.ConfigurationSpec) { visitor(&cs.Template.Spec.PodSpec) }) } // VisitKnativeConfigurationSpec executes the visitor function on all knative ConfigurationSpec inside serving Services -func (c *Collection) VisitKnativeConfigurationSpec(visitor func(container *servingv1.ConfigurationSpec)) { +func (c *Collection) VisitKnativeConfigurationSpec(visitor func(container *serving.ConfigurationSpec)) { c.VisitKnativeService(func(s *serving.Service) { visitor(&s.Spec.ConfigurationSpec) }) diff --git a/pkg/util/kubernetes/replace.go b/pkg/util/kubernetes/replace.go index 7a25ab3..c0c417a 100644 --- a/pkg/util/kubernetes/replace.go +++ b/pkg/util/kubernetes/replace.go @@ -28,8 +28,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" messaging "knative.dev/eventing/pkg/apis/messaging/v1alpha1" - servingv1 "knative.dev/serving/pkg/apis/serving/v1" - serving "knative.dev/serving/pkg/apis/serving/v1beta1" + serving "knative.dev/serving/pkg/apis/serving/v1" k8sclient "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -121,8 +120,8 @@ func mapRequiredKnativeServiceV1Beta1Data(from runtime.Object, to runtime.Object } func mapRequiredKnativeServiceV1Data(from runtime.Object, to runtime.Object) { - if fromC, ok := from.(*servingv1.Service); ok { - if toC, ok := to.(*servingv1.Service); ok { + if fromC, ok := from.(*serving.Service); ok { + if toC, ok := to.(*serving.Service); ok { if toC.ObjectMeta.Annotations == nil { toC.ObjectMeta.Annotations = make(map[string]string) }