This is an automated email from the ASF dual-hosted git repository. squakez pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 4bb27cc397c25d7a5f0b0059e985ca4af95430cc Author: Michal Vavřík <[email protected]> AuthorDate: Mon Sep 28 00:12:55 2026 +0200 address review comments Signed-off-by: Michal Vavřík <[email protected]> --- docs/antora.yml | 1 - docs/modules/ROOT/pages/concepts/dependencies.adoc | 5 +- e2e/support/util/dump.go | 6 +- pkg/apis/camel/v1/trait/zz_generated.deepcopy.go | 2 +- pkg/apis/camel/v1/zz_generated.deepcopy.go | 1 + .../duck/keda/v1alpha1/zz_generated.deepcopy.go | 2 +- pkg/apis/duck/knative/apis/condition_types.go | 11 --- pkg/apis/duck/knative/apis/condition_types_test.go | 44 ----------- pkg/apis/duck/knative/apis/duck_types.go | 16 ---- pkg/apis/duck/knative/apis/url_test.go | 66 ----------------- pkg/apis/duck/knative/apis/volatile_time.go | 46 ------------ pkg/apis/duck/knative/apis/volatile_time_test.go | 56 -------------- .../duck/knative/apis/zz_generated.deepcopy.go | 32 +------- pkg/apis/duck/knative/eventing/v1/duck_types.go | 23 +----- .../knative/eventing/v1/zz_generated.deepcopy.go | 63 +--------------- pkg/apis/duck/knative/messaging/v1/duck_types.go | 45 +---------- .../knative/messaging/v1/zz_generated.deepcopy.go | 86 ---------------------- pkg/apis/duck/knative/serving/v1/duck_types.go | 61 +-------------- .../knative/serving/v1/zz_generated.deepcopy.go | 81 -------------------- pkg/apis/duck/knative/sources/v1/duck_types.go | 8 +- .../knative/sources/v1/zz_generated.deepcopy.go | 17 ----- pkg/controller/integration/monitor_knative_test.go | 72 ++++++++++++++++++ pkg/controller/integration/predicate_test.go | 77 +++++++++++++++++++ pkg/trait/knative_test.go | 3 +- pkg/util/knative/knative_test.go | 9 +-- script/update_docs.sh | 7 -- 26 files changed, 173 insertions(+), 667 deletions(-) diff --git a/docs/antora.yml b/docs/antora.yml index 3f649ebea..96aeec53d 100644 --- a/docs/antora.yml +++ b/docs/antora.yml @@ -38,6 +38,5 @@ asciidoc: kustomize-version: 5.7.1 kubernetes-api-version: 0.37.0 operator-fwk-api-version: 0.45.0 - knative-api-version: 1.20.1 service-binding-op-version: "" prometheus-op-version: 0.94.1 diff --git a/docs/modules/ROOT/pages/concepts/dependencies.adoc b/docs/modules/ROOT/pages/concepts/dependencies.adoc index 0cf9b06f6..8ae2ceb2b 100644 --- a/docs/modules/ROOT/pages/concepts/dependencies.adoc +++ b/docs/modules/ROOT/pages/concepts/dependencies.adoc @@ -23,16 +23,15 @@ Below you can find a list of the main dependencies and APIs used by Camel K and [caption=] .Kubernetes and other dependencies -[width="100%",cols="4,2,2,2,2,2",options="header"] +[width="100%",cols="4,2,2,2,2",options="header"] |=== |Camel K Version |Kubernetes API |Operator Framework API -|Knative |Prometheus Operator |Kustomize version |=== //cannot use top level index.adoc as the page with the query is always omitted. -indexTable::[version="*",relative="running/running.adoc",cellformats="util.ckRef(pageComponentDisplayVersion, pageComponentVersion)|kubernetesApiVersion|operatorFwkApiVersion|knativeApiVersion|prometheusOpVersion|kustomizeVersion", requires={requires},transform=util.sortCompatibilityItems] +indexTable::[version="*",relative="running/running.adoc",cellformats="util.ckRef(pageComponentDisplayVersion, pageComponentVersion)|kubernetesApiVersion|operatorFwkApiVersion|prometheusOpVersion|kustomizeVersion", requires={requires},transform=util.sortCompatibilityItems] diff --git a/e2e/support/util/dump.go b/e2e/support/util/dump.go index c77b23bb0..142b705ba 100644 --- a/e2e/support/util/dump.go +++ b/e2e/support/util/dump.go @@ -28,6 +28,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ctrl "sigs.k8s.io/controller-runtime/pkg/client" @@ -156,7 +157,10 @@ func Dump(ctx context.Context, c client.Client, ns string, t *testing.T) error { } if installed, _ := knative.IsServingInstalled(c); installed { - var ksrvs servingv1.ServiceList + // List the Knative Services as unstructured objects, so that the dump carries + // the complete resources rather than the partial schema of the duck type. + var ksrvs unstructured.UnstructuredList + ksrvs.SetGroupVersionKind(servingv1.SchemeGroupVersion.WithKind("ServiceList")) err = c.List(ctx, &ksrvs) if err == nil { t.Logf("Found %d Knative services:\n", len(ksrvs.Items)) diff --git a/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go b/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go index 5466a9cb0..739912370 100644 --- a/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go +++ b/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go @@ -5,7 +5,7 @@ package trait import ( - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" networkingv1 "k8s.io/api/networking/v1" "k8s.io/apimachinery/pkg/util/intstr" ) diff --git a/pkg/apis/camel/v1/zz_generated.deepcopy.go b/pkg/apis/camel/v1/zz_generated.deepcopy.go index 07e39cd5e..af1a8a1dc 100644 --- a/pkg/apis/camel/v1/zz_generated.deepcopy.go +++ b/pkg/apis/camel/v1/zz_generated.deepcopy.go @@ -6,6 +6,7 @@ package v1 import ( "encoding/json" + "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/apis/duck/keda/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/duck/keda/v1alpha1/zz_generated.deepcopy.go index 27d57d72a..450aba305 100644 --- a/pkg/apis/duck/keda/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/duck/keda/v1alpha1/zz_generated.deepcopy.go @@ -5,7 +5,7 @@ package v1alpha1 import ( - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" ) diff --git a/pkg/apis/duck/knative/apis/condition_types.go b/pkg/apis/duck/knative/apis/condition_types.go index 0a3d1c549..c3875a547 100644 --- a/pkg/apis/duck/knative/apis/condition_types.go +++ b/pkg/apis/duck/knative/apis/condition_types.go @@ -30,9 +30,6 @@ type ConditionType string // ConditionReady specifies that the resource is ready. const ConditionReady ConditionType = "Ready" -// ConditionSeverity expresses the severity of a Condition Type failing. -type ConditionSeverity string - // Condition defines a readiness condition for a Knative resource. type Condition struct { // Type of condition. @@ -41,14 +38,6 @@ type Condition struct { // Status of the condition, one of True, False, Unknown. Status corev1.ConditionStatus `json:"status"` - // Severity with which to treat failures of this type of condition. - // +optional - Severity ConditionSeverity `json:"severity,omitempty"` - - // LastTransitionTime is the last time the condition transitioned from one status to another. - // +optional - LastTransitionTime VolatileTime `json:"lastTransitionTime,omitempty"` - // The reason for the condition's last transition. // +optional Reason string `json:"reason,omitempty"` diff --git a/pkg/apis/duck/knative/apis/condition_types_test.go b/pkg/apis/duck/knative/apis/condition_types_test.go deleted file mode 100644 index 9beea7cf4..000000000 --- a/pkg/apis/duck/knative/apis/condition_types_test.go +++ /dev/null @@ -1,44 +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 ( - "testing" - - "github.com/stretchr/testify/assert" - - corev1 "k8s.io/api/core/v1" -) - -func TestConditionAccessors(t *testing.T) { - var c *Condition - assert.False(t, c.IsTrue()) - assert.False(t, c.IsFalse()) - assert.Empty(t, c.GetReason()) - assert.Empty(t, c.GetMessage()) - - c = &Condition{Type: ConditionReady, Status: corev1.ConditionFalse, Reason: "RevisionFailed", Message: "revision failed"} - assert.False(t, c.IsTrue()) - assert.True(t, c.IsFalse()) - assert.Equal(t, "RevisionFailed", c.GetReason()) - assert.Equal(t, "revision failed", c.GetMessage()) - - c.Status = corev1.ConditionTrue - assert.True(t, c.IsTrue()) - assert.False(t, c.IsFalse()) -} diff --git a/pkg/apis/duck/knative/apis/duck_types.go b/pkg/apis/duck/knative/apis/duck_types.go index 0e54ffe5d..291a53c78 100644 --- a/pkg/apis/duck/knative/apis/duck_types.go +++ b/pkg/apis/duck/knative/apis/duck_types.go @@ -19,17 +19,9 @@ package apis // Status is the common status of the Knative resources. type Status struct { - // ObservedGeneration is the 'Generation' of the resource that was last processed by the controller. - // +optional - ObservedGeneration int64 `json:"observedGeneration,omitempty"` - // Conditions the latest available observations of a resource's current state. // +optional Conditions Conditions `json:"conditions,omitempty"` - - // Annotations is additional Status fields for the resource to save some additional state. - // +optional - Annotations map[string]string `json:"annotations,omitempty"` } // AddressStatus is the status of an addressable resource. @@ -61,10 +53,6 @@ type KReference struct { // Kind of the referent. Kind string `json:"kind"` - // Namespace of the referent. - // +optional - Namespace string `json:"namespace,omitempty"` - // Name of the referent. Name string `json:"name"` @@ -95,10 +83,6 @@ type Reference struct { // +optional Kind string `json:"kind,omitempty"` - // Namespace of the referent. - // +optional - Namespace string `json:"namespace,omitempty"` - // Name of the referent. // +optional Name string `json:"name,omitempty"` diff --git a/pkg/apis/duck/knative/apis/url_test.go b/pkg/apis/duck/knative/apis/url_test.go deleted file mode 100644 index b8d7ab7b0..000000000 --- a/pkg/apis/duck/knative/apis/url_test.go +++ /dev/null @@ -1,66 +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 ( - "encoding/json" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - "k8s.io/apimachinery/pkg/api/equality" -) - -func TestURLJSON(t *testing.T) { - u, err := ParseURL("http://my-service.my-ns.svc.cluster.local/path?query=1") - require.NoError(t, err) - - data, err := json.Marshal(u) - require.NoError(t, err) - assert.Equal(t, `"http://my-service.my-ns.svc.cluster.local/path?query=1"`, string(data)) - - var parsed URL - require.NoError(t, json.Unmarshal(data, &parsed)) - assert.Equal(t, *u, parsed) - assert.Equal(t, "my-service.my-ns.svc.cluster.local", parsed.Host) - assert.Equal(t, "/path", parsed.Path) - - require.NoError(t, json.Unmarshal([]byte(`""`), &parsed)) - assert.Equal(t, URL{}, parsed) - require.Error(t, json.Unmarshal([]byte(`"://invalid"`), &parsed)) -} - -func TestParseURLEmpty(t *testing.T) { - u, err := ParseURL("") - require.NoError(t, err) - assert.Nil(t, u) - assert.Empty(t, u.String()) -} - -func TestURLSemanticEquality(t *testing.T) { - a, err := ParseURL("http://my-host/a") - require.NoError(t, err) - b, err := ParseURL("http://my-host/a") - require.NoError(t, err) - c, err := ParseURL("http://my-host/c") - require.NoError(t, err) - - assert.True(t, equality.Semantic.DeepEqual(a, b)) - assert.False(t, equality.Semantic.DeepEqual(a, c)) -} diff --git a/pkg/apis/duck/knative/apis/volatile_time.go b/pkg/apis/duck/knative/apis/volatile_time.go deleted file mode 100644 index 09dc7adde..000000000 --- a/pkg/apis/duck/knative/apis/volatile_time.go +++ /dev/null @@ -1,46 +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 ( - "k8s.io/apimachinery/pkg/api/equality" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// VolatileTime wraps metav1.Time. Unlike metav1.Time, two VolatileTime values are always -// semantically equal, so that a change of a condition transition time alone is not -// considered a status change. -type VolatileTime struct { //nolint: recvcheck - Inner metav1.Time `json:",inline"` -} - -func init() { - _ = equality.Semantic.AddFunc(func(VolatileTime, VolatileTime) bool { - return true - }) -} - -// MarshalJSON implements json.Marshaler. -func (t VolatileTime) MarshalJSON() ([]byte, error) { - return t.Inner.MarshalJSON() -} - -// UnmarshalJSON implements json.Unmarshaler. -func (t *VolatileTime) UnmarshalJSON(b []byte) error { - return t.Inner.UnmarshalJSON(b) -} diff --git a/pkg/apis/duck/knative/apis/volatile_time_test.go b/pkg/apis/duck/knative/apis/volatile_time_test.go deleted file mode 100644 index e5f16c349..000000000 --- a/pkg/apis/duck/knative/apis/volatile_time_test.go +++ /dev/null @@ -1,56 +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 ( - "encoding/json" - "testing" - "time" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/equality" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func TestVolatileTimeJSON(t *testing.T) { - vt := VolatileTime{Inner: metav1.NewTime(time.Date(2026, 1, 2, 3, 4, 5, 0, time.UTC))} - - data, err := json.Marshal(vt) - require.NoError(t, err) - assert.Equal(t, `"2026-01-02T03:04:05Z"`, string(data)) - - var parsed VolatileTime - require.NoError(t, json.Unmarshal(data, &parsed)) - assert.True(t, vt.Inner.Equal(&parsed.Inner)) -} - -func TestVolatileTimeSemanticEquality(t *testing.T) { - t1 := VolatileTime{Inner: metav1.NewTime(time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC))} - t2 := VolatileTime{Inner: metav1.NewTime(time.Date(2026, 6, 1, 0, 0, 0, 0, time.UTC))} - assert.True(t, equality.Semantic.DeepEqual(t1, t2)) - - c1 := Condition{Type: ConditionReady, Status: corev1.ConditionTrue, LastTransitionTime: t1} - c2 := Condition{Type: ConditionReady, Status: corev1.ConditionTrue, LastTransitionTime: t2} - assert.True(t, equality.Semantic.DeepEqual(c1, c2)) - - c2.Status = corev1.ConditionFalse - assert.False(t, equality.Semantic.DeepEqual(c1, c2)) -} diff --git a/pkg/apis/duck/knative/apis/zz_generated.deepcopy.go b/pkg/apis/duck/knative/apis/zz_generated.deepcopy.go index 342c85f6d..114ecba4f 100644 --- a/pkg/apis/duck/knative/apis/zz_generated.deepcopy.go +++ b/pkg/apis/duck/knative/apis/zz_generated.deepcopy.go @@ -67,7 +67,6 @@ func (in *BindingSpec) DeepCopy() *BindingSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Condition) DeepCopyInto(out *Condition) { *out = *in - in.LastTransitionTime.DeepCopyInto(&out.LastTransitionTime) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Condition. @@ -85,9 +84,7 @@ func (in Conditions) DeepCopyInto(out *Conditions) { { in := &in *out = make(Conditions, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } + copy(*out, *in) } } @@ -178,16 +175,7 @@ func (in *Status) DeepCopyInto(out *Status) { if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions *out = make(Conditions, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.Annotations != nil { - in, out := &in.Annotations, &out.Annotations - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } + copy(*out, *in) } } @@ -220,19 +208,3 @@ func (in *URL) DeepCopy() *URL { in.DeepCopyInto(out) return out } - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *VolatileTime) DeepCopyInto(out *VolatileTime) { - *out = *in - in.Inner.DeepCopyInto(&out.Inner) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VolatileTime. -func (in *VolatileTime) DeepCopy() *VolatileTime { - if in == nil { - return nil - } - out := new(VolatileTime) - in.DeepCopyInto(out) - return out -} diff --git a/pkg/apis/duck/knative/eventing/v1/duck_types.go b/pkg/apis/duck/knative/eventing/v1/duck_types.go index bd455456a..35e9610e4 100644 --- a/pkg/apis/duck/knative/eventing/v1/duck_types.go +++ b/pkg/apis/duck/knative/eventing/v1/duck_types.go @@ -31,8 +31,7 @@ type Trigger struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec TriggerSpec `json:"spec,omitempty"` - Status TriggerStatus `json:"status,omitempty"` + Spec TriggerSpec `json:"spec,omitempty"` } // TriggerSpec defines the desired state of the Trigger. @@ -52,15 +51,7 @@ type TriggerSpec struct { type TriggerFilter struct { // Attributes filters events by exact match on event context attributes. // +optional - Attributes TriggerFilterAttributes `json:"attributes,omitempty"` -} - -// TriggerFilterAttributes is a map of context attribute names to values for filtering by equality. -type TriggerFilterAttributes map[string]string - -// TriggerStatus represents the current state of a Trigger. -type TriggerStatus struct { - apis.Status `json:",inline"` + Attributes map[string]string `json:"attributes,omitempty"` } // +kubebuilder:object:root=true @@ -81,21 +72,11 @@ type Broker struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec BrokerSpec `json:"spec,omitempty"` Status BrokerStatus `json:"status,omitempty"` } -// BrokerSpec defines the desired state of the Broker. -type BrokerSpec struct { - // Config is a KReference to the configuration that specifies configuration options for this Broker. - // +optional - Config *apis.KReference `json:"config,omitempty"` -} - // BrokerStatus represents the current state of a Broker. type BrokerStatus struct { - apis.Status `json:",inline"` - // AddressStatus is the part where the Broker fulfills the Addressable contract. apis.AddressStatus `json:",inline"` } diff --git a/pkg/apis/duck/knative/eventing/v1/zz_generated.deepcopy.go b/pkg/apis/duck/knative/eventing/v1/zz_generated.deepcopy.go index a848c09de..9493d4d9e 100644 --- a/pkg/apis/duck/knative/eventing/v1/zz_generated.deepcopy.go +++ b/pkg/apis/duck/knative/eventing/v1/zz_generated.deepcopy.go @@ -5,7 +5,6 @@ package v1 import ( - "github.com/apache/camel-k/v2/pkg/apis/duck/knative/apis" "k8s.io/apimachinery/pkg/runtime" ) @@ -14,7 +13,6 @@ func (in *Broker) DeepCopyInto(out *Broker) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) in.Status.DeepCopyInto(&out.Status) } @@ -68,30 +66,9 @@ func (in *BrokerList) DeepCopyObject() runtime.Object { return nil } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *BrokerSpec) DeepCopyInto(out *BrokerSpec) { - *out = *in - if in.Config != nil { - in, out := &in.Config, &out.Config - *out = new(apis.KReference) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BrokerSpec. -func (in *BrokerSpec) DeepCopy() *BrokerSpec { - if in == nil { - return nil - } - out := new(BrokerSpec) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *BrokerStatus) DeepCopyInto(out *BrokerStatus) { *out = *in - in.Status.DeepCopyInto(&out.Status) in.AddressStatus.DeepCopyInto(&out.AddressStatus) } @@ -111,7 +88,6 @@ func (in *Trigger) DeepCopyInto(out *Trigger) { 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 Trigger. @@ -137,7 +113,7 @@ func (in *TriggerFilter) DeepCopyInto(out *TriggerFilter) { *out = *in if in.Attributes != nil { in, out := &in.Attributes, &out.Attributes - *out = make(TriggerFilterAttributes, len(*in)) + *out = make(map[string]string, len(*in)) for key, val := range *in { (*out)[key] = val } @@ -154,27 +130,6 @@ func (in *TriggerFilter) DeepCopy() *TriggerFilter { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in TriggerFilterAttributes) DeepCopyInto(out *TriggerFilterAttributes) { - { - in := &in - *out = make(TriggerFilterAttributes, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TriggerFilterAttributes. -func (in TriggerFilterAttributes) DeepCopy() TriggerFilterAttributes { - if in == nil { - return nil - } - out := new(TriggerFilterAttributes) - in.DeepCopyInto(out) - return *out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TriggerList) DeepCopyInto(out *TriggerList) { *out = *in @@ -227,19 +182,3 @@ func (in *TriggerSpec) DeepCopy() *TriggerSpec { in.DeepCopyInto(out) return out } - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TriggerStatus) DeepCopyInto(out *TriggerStatus) { - *out = *in - in.Status.DeepCopyInto(&out.Status) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TriggerStatus. -func (in *TriggerStatus) DeepCopy() *TriggerStatus { - if in == nil { - return nil - } - out := new(TriggerStatus) - in.DeepCopyInto(out) - return out -} diff --git a/pkg/apis/duck/knative/messaging/v1/duck_types.go b/pkg/apis/duck/knative/messaging/v1/duck_types.go index 00626803a..f6f0add9d 100644 --- a/pkg/apis/duck/knative/messaging/v1/duck_types.go +++ b/pkg/apis/duck/knative/messaging/v1/duck_types.go @@ -29,10 +29,9 @@ import ( // routing the events received on a Channel to a Subscriber. type Subscription struct { metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata"` + metav1.ObjectMeta `json:"metadata,omitempty"` - Spec SubscriptionSpec `json:"spec"` - Status SubscriptionStatus `json:"status,omitempty"` + Spec SubscriptionSpec `json:"spec,omitempty"` } // SubscriptionSpec specifies the Channel for incoming events and the Subscriber processing them. @@ -43,29 +42,6 @@ type SubscriptionSpec struct { // Subscriber is reference to the function for processing events. // +optional Subscriber *apis.Destination `json:"subscriber,omitempty"` - - // Reply specifies how to handle events returned from the Subscriber target. - // +optional - Reply *apis.Destination `json:"reply,omitempty"` -} - -// SubscriptionStatus represents the current state of a Subscription. -type SubscriptionStatus struct { - apis.Status `json:",inline"` - - // PhysicalSubscription is the fully resolved values that this Subscription represents. - PhysicalSubscription SubscriptionStatusPhysicalSubscription `json:"physicalSubscription,omitempty"` -} - -// SubscriptionStatusPhysicalSubscription represents the fully resolved values for this Subscription. -type SubscriptionStatusPhysicalSubscription struct { - // SubscriberURI is the fully resolved URI for spec.subscriber. - // +optional - SubscriberURI *apis.URL `json:"subscriberUri,omitempty"` - - // ReplyURI is the fully resolved URI for the spec.reply. - // +optional - ReplyURI *apis.URL `json:"replyUri,omitempty"` } // +kubebuilder:object:root=true @@ -73,7 +49,7 @@ type SubscriptionStatusPhysicalSubscription struct { // SubscriptionList contains a list of Subscription. type SubscriptionList struct { metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata"` + metav1.ListMeta `json:"metadata,omitempty"` Items []Subscription `json:"items"` } @@ -85,26 +61,11 @@ type Channel struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec ChannelSpec `json:"spec,omitempty"` Status ChannelStatus `json:"status,omitempty"` } -// ChannelSpec holds the desired state of the Channel. -type ChannelSpec struct { - // ChannelTemplate specifies which Channel CRD to use to create the backing Channel. - // +optional - ChannelTemplate *ChannelTemplateSpec `json:"channelTemplate,omitempty"` -} - -// ChannelTemplateSpec identifies the underlying Channel implementation. -type ChannelTemplateSpec struct { - metav1.TypeMeta `json:",inline"` -} - // ChannelStatus represents the current state of a Channel. type ChannelStatus struct { - apis.Status `json:",inline"` - // AddressStatus is the part where the Channel fulfills the Addressable contract. apis.AddressStatus `json:",inline"` } diff --git a/pkg/apis/duck/knative/messaging/v1/zz_generated.deepcopy.go b/pkg/apis/duck/knative/messaging/v1/zz_generated.deepcopy.go index 636ae22d1..f0f1181e1 100644 --- a/pkg/apis/duck/knative/messaging/v1/zz_generated.deepcopy.go +++ b/pkg/apis/duck/knative/messaging/v1/zz_generated.deepcopy.go @@ -14,7 +14,6 @@ func (in *Channel) DeepCopyInto(out *Channel) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) in.Status.DeepCopyInto(&out.Status) } @@ -68,30 +67,9 @@ func (in *ChannelList) DeepCopyObject() runtime.Object { return nil } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ChannelSpec) DeepCopyInto(out *ChannelSpec) { - *out = *in - if in.ChannelTemplate != nil { - in, out := &in.ChannelTemplate, &out.ChannelTemplate - *out = new(ChannelTemplateSpec) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelSpec. -func (in *ChannelSpec) DeepCopy() *ChannelSpec { - if in == nil { - return nil - } - out := new(ChannelSpec) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ChannelStatus) DeepCopyInto(out *ChannelStatus) { *out = *in - in.Status.DeepCopyInto(&out.Status) in.AddressStatus.DeepCopyInto(&out.AddressStatus) } @@ -105,29 +83,12 @@ func (in *ChannelStatus) DeepCopy() *ChannelStatus { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ChannelTemplateSpec) DeepCopyInto(out *ChannelTemplateSpec) { - *out = *in - out.TypeMeta = in.TypeMeta -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelTemplateSpec. -func (in *ChannelTemplateSpec) DeepCopy() *ChannelTemplateSpec { - if in == nil { - return nil - } - out := new(ChannelTemplateSpec) - in.DeepCopyInto(out) - 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. @@ -189,11 +150,6 @@ func (in *SubscriptionSpec) DeepCopyInto(out *SubscriptionSpec) { *out = new(apis.Destination) (*in).DeepCopyInto(*out) } - if in.Reply != nil { - in, out := &in.Reply, &out.Reply - *out = new(apis.Destination) - (*in).DeepCopyInto(*out) - } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscriptionSpec. @@ -205,45 +161,3 @@ func (in *SubscriptionSpec) DeepCopy() *SubscriptionSpec { in.DeepCopyInto(out) return out } - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SubscriptionStatus) DeepCopyInto(out *SubscriptionStatus) { - *out = *in - in.Status.DeepCopyInto(&out.Status) - in.PhysicalSubscription.DeepCopyInto(&out.PhysicalSubscription) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscriptionStatus. -func (in *SubscriptionStatus) DeepCopy() *SubscriptionStatus { - if in == nil { - return nil - } - out := new(SubscriptionStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SubscriptionStatusPhysicalSubscription) DeepCopyInto(out *SubscriptionStatusPhysicalSubscription) { - *out = *in - if in.SubscriberURI != nil { - in, out := &in.SubscriberURI, &out.SubscriberURI - *out = new(apis.URL) - (*in).DeepCopyInto(*out) - } - if in.ReplyURI != nil { - in, out := &in.ReplyURI, &out.ReplyURI - *out = new(apis.URL) - (*in).DeepCopyInto(*out) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscriptionStatusPhysicalSubscription. -func (in *SubscriptionStatusPhysicalSubscription) DeepCopy() *SubscriptionStatusPhysicalSubscription { - if in == nil { - return nil - } - out := new(SubscriptionStatusPhysicalSubscription) - in.DeepCopyInto(out) - return out -} diff --git a/pkg/apis/duck/knative/serving/v1/duck_types.go b/pkg/apis/duck/knative/serving/v1/duck_types.go index 0e8371b24..7e4794af5 100644 --- a/pkg/apis/duck/knative/serving/v1/duck_types.go +++ b/pkg/apis/duck/knative/serving/v1/duck_types.go @@ -43,9 +43,6 @@ type Service struct { type ServiceSpec struct { // ConfigurationSpec holds the desired state of the Configuration. ConfigurationSpec `json:",inline"` - - // RouteSpec holds the desired state of the Route. - RouteSpec `json:",inline"` } // ConfigurationSpec holds the desired state of the Configuration. @@ -65,71 +62,19 @@ type RevisionTemplateSpec struct { type RevisionSpec struct { corev1.PodSpec `json:",inline"` - // ContainerConcurrency specifies the maximum allowed in-flight (concurrent) requests per container of the Revision. - // +optional - ContainerConcurrency *int64 `json:"containerConcurrency,omitempty"` - // TimeoutSeconds is the maximum duration in seconds that the request instance is allowed to respond to a request. // +optional TimeoutSeconds *int64 `json:"timeoutSeconds,omitempty"` } -// RouteSpec holds the desired state of the Route. -type RouteSpec struct { - // Traffic specifies how to distribute traffic over a collection of revisions and configurations. - // +optional - Traffic []TrafficTarget `json:"traffic,omitempty"` -} - -// TrafficTarget holds a single entry of the routing table for a Route. -type TrafficTarget struct { - // Tag is optionally used to expose a dedicated url for referencing this target exclusively. - // +optional - Tag string `json:"tag,omitempty"` - - // RevisionName of a specific revision to which to send this portion of traffic. - // +optional - RevisionName string `json:"revisionName,omitempty"` - - // ConfigurationName of a configuration to whose latest revision we will send this portion of traffic. - // +optional - ConfigurationName string `json:"configurationName,omitempty"` - - // LatestRevision indicates that the latest ready Revision of the Configuration should be used for this traffic target. - // +optional - LatestRevision *bool `json:"latestRevision,omitempty"` - - // Percent indicates the percent of traffic that is to be routed to this Revision or Configuration. - // +optional - Percent *int64 `json:"percent,omitempty"` - - // URL displays the URL for accessing named traffic targets. It is only present in the status. - // +optional - URL *apis.URL `json:"url,omitempty"` -} - // ServiceStatus represents the status of the Service resource. type ServiceStatus struct { apis.Status `json:",inline"` - // ConfigurationStatusFields represents the current Configuration. - ConfigurationStatusFields `json:",inline"` - // RouteStatusFields represents the current Route. RouteStatusFields `json:",inline"` } -// ConfigurationStatusFields holds the fields of the Configuration status. -type ConfigurationStatusFields struct { - // LatestReadyRevisionName holds the name of the latest Revision that has become ready. - // +optional - LatestReadyRevisionName string `json:"latestReadyRevisionName,omitempty"` - - // LatestCreatedRevisionName is the last revision that was created from this Configuration. - // +optional - LatestCreatedRevisionName string `json:"latestCreatedRevisionName,omitempty"` -} - // RouteStatusFields holds the fields of the Route status. type RouteStatusFields struct { // URL holds the url that will distribute traffic over the provided traffic targets. @@ -139,10 +84,6 @@ type RouteStatusFields struct { // Address holds the information needed for a Route to be the target of an event. // +optional Address *apis.Addressable `json:"address,omitempty"` - - // Traffic holds the configured traffic distribution. - // +optional - Traffic []TrafficTarget `json:"traffic,omitempty"` } // +kubebuilder:object:root=true @@ -150,7 +91,7 @@ type RouteStatusFields struct { // ServiceList contains a list of Service. type ServiceList struct { metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata"` + metav1.ListMeta `json:"metadata,omitempty"` Items []Service `json:"items"` } diff --git a/pkg/apis/duck/knative/serving/v1/zz_generated.deepcopy.go b/pkg/apis/duck/knative/serving/v1/zz_generated.deepcopy.go index 0ccc5cdd4..a43f0d802 100644 --- a/pkg/apis/duck/knative/serving/v1/zz_generated.deepcopy.go +++ b/pkg/apis/duck/knative/serving/v1/zz_generated.deepcopy.go @@ -25,30 +25,10 @@ func (in *ConfigurationSpec) DeepCopy() *ConfigurationSpec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ConfigurationStatusFields) DeepCopyInto(out *ConfigurationStatusFields) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConfigurationStatusFields. -func (in *ConfigurationStatusFields) DeepCopy() *ConfigurationStatusFields { - if in == nil { - return nil - } - out := new(ConfigurationStatusFields) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RevisionSpec) DeepCopyInto(out *RevisionSpec) { *out = *in in.PodSpec.DeepCopyInto(&out.PodSpec) - if in.ContainerConcurrency != nil { - in, out := &in.ContainerConcurrency, &out.ContainerConcurrency - *out = new(int64) - **out = **in - } if in.TimeoutSeconds != nil { in, out := &in.TimeoutSeconds, &out.TimeoutSeconds *out = new(int64) @@ -83,28 +63,6 @@ func (in *RevisionTemplateSpec) DeepCopy() *RevisionTemplateSpec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *RouteSpec) DeepCopyInto(out *RouteSpec) { - *out = *in - if in.Traffic != nil { - in, out := &in.Traffic, &out.Traffic - *out = make([]TrafficTarget, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RouteSpec. -func (in *RouteSpec) DeepCopy() *RouteSpec { - if in == nil { - return nil - } - out := new(RouteSpec) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RouteStatusFields) DeepCopyInto(out *RouteStatusFields) { *out = *in @@ -118,13 +76,6 @@ func (in *RouteStatusFields) DeepCopyInto(out *RouteStatusFields) { *out = new(apis.Addressable) (*in).DeepCopyInto(*out) } - if in.Traffic != nil { - in, out := &in.Traffic, &out.Traffic - *out = make([]TrafficTarget, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RouteStatusFields. @@ -200,7 +151,6 @@ func (in *ServiceList) DeepCopyObject() runtime.Object { func (in *ServiceSpec) DeepCopyInto(out *ServiceSpec) { *out = *in in.ConfigurationSpec.DeepCopyInto(&out.ConfigurationSpec) - in.RouteSpec.DeepCopyInto(&out.RouteSpec) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceSpec. @@ -217,7 +167,6 @@ func (in *ServiceSpec) DeepCopy() *ServiceSpec { func (in *ServiceStatus) DeepCopyInto(out *ServiceStatus) { *out = *in in.Status.DeepCopyInto(&out.Status) - out.ConfigurationStatusFields = in.ConfigurationStatusFields in.RouteStatusFields.DeepCopyInto(&out.RouteStatusFields) } @@ -230,33 +179,3 @@ func (in *ServiceStatus) DeepCopy() *ServiceStatus { in.DeepCopyInto(out) return out } - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TrafficTarget) DeepCopyInto(out *TrafficTarget) { - *out = *in - if in.LatestRevision != nil { - in, out := &in.LatestRevision, &out.LatestRevision - *out = new(bool) - **out = **in - } - if in.Percent != nil { - in, out := &in.Percent, &out.Percent - *out = new(int64) - **out = **in - } - if in.URL != nil { - in, out := &in.URL, &out.URL - *out = new(apis.URL) - (*in).DeepCopyInto(*out) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TrafficTarget. -func (in *TrafficTarget) DeepCopy() *TrafficTarget { - if in == nil { - return nil - } - out := new(TrafficTarget) - in.DeepCopyInto(out) - return out -} diff --git a/pkg/apis/duck/knative/sources/v1/duck_types.go b/pkg/apis/duck/knative/sources/v1/duck_types.go index 6a8cf0ee0..e6a5c46f3 100644 --- a/pkg/apis/duck/knative/sources/v1/duck_types.go +++ b/pkg/apis/duck/knative/sources/v1/duck_types.go @@ -31,8 +31,7 @@ type SinkBinding struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec SinkBindingSpec `json:"spec"` - Status SinkBindingStatus `json:"status"` + Spec SinkBindingSpec `json:"spec,omitempty"` } // SinkBindingSpec holds the desired state of the SinkBinding. @@ -44,11 +43,6 @@ type SinkBindingSpec struct { apis.BindingSpec `json:",inline"` } -// SinkBindingStatus communicates the observed state of the SinkBinding. -type SinkBindingStatus struct { - apis.Status `json:",inline"` -} - // +kubebuilder:object:root=true // SinkBindingList contains a list of SinkBinding. diff --git a/pkg/apis/duck/knative/sources/v1/zz_generated.deepcopy.go b/pkg/apis/duck/knative/sources/v1/zz_generated.deepcopy.go index a4c77c568..478719126 100644 --- a/pkg/apis/duck/knative/sources/v1/zz_generated.deepcopy.go +++ b/pkg/apis/duck/knative/sources/v1/zz_generated.deepcopy.go @@ -14,7 +14,6 @@ func (in *SinkBinding) DeepCopyInto(out *SinkBinding) { 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 SinkBinding. @@ -83,19 +82,3 @@ func (in *SinkBindingSpec) DeepCopy() *SinkBindingSpec { in.DeepCopyInto(out) return out } - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SinkBindingStatus) DeepCopyInto(out *SinkBindingStatus) { - *out = *in - in.Status.DeepCopyInto(&out.Status) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SinkBindingStatus. -func (in *SinkBindingStatus) DeepCopy() *SinkBindingStatus { - if in == nil { - return nil - } - out := new(SinkBindingStatus) - in.DeepCopyInto(out) - return out -} diff --git a/pkg/controller/integration/monitor_knative_test.go b/pkg/controller/integration/monitor_knative_test.go index a1190d441..3604d5498 100644 --- a/pkg/controller/integration/monitor_knative_test.go +++ b/pkg/controller/integration/monitor_knative_test.go @@ -19,6 +19,7 @@ package integration import ( "context" + "encoding/json" "testing" "github.com/stretchr/testify/assert" @@ -26,6 +27,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/utils/ptr" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" "github.com/apache/camel-k/v2/pkg/apis/duck/knative/apis" @@ -127,3 +129,73 @@ func TestKnativeServiceControllerMissingCondition(t *testing.T) { require.NotNil(t, cond) assert.Equal(t, corev1.ConditionFalse, cond.Status) } + +// knativeServicePayload mimics a Knative Serving Service as returned by the API server: +// it carries a number of fields the duck type does not model, which must be ignored. +const knativeServicePayload = `{ + "apiVersion": "serving.knative.dev/v1", + "kind": "Service", + "metadata": {"name": "my-ksvc", "namespace": "ns", "generation": 2}, + "spec": { + "template": { + "metadata": {"labels": {"camel.apache.org/integration": "my-it"}}, + "spec": { + "containerConcurrency": 0, + "containers": [{"name": "integration", "image": "my-image"}], + "enableServiceLinks": false, + "timeoutSeconds": 300 + } + }, + "traffic": [{"latestRevision": true, "percent": 100}] + }, + "status": { + "address": {"url": "http://my-ksvc.ns.svc.cluster.local"}, + "conditions": [ + {"lastTransitionTime": "2026-01-02T03:04:05Z", "status": "True", "type": "ConfigurationsReady"}, + {"lastTransitionTime": "2026-01-02T03:04:05Z", "status": "False", "type": "Ready", + "reason": "RevisionFailed", "message": "Revision \"my-ksvc-00001\" failed with message: Container failed."}, + {"lastTransitionTime": "2026-01-02T03:04:05Z", "status": "False", "type": "RoutesReady", + "reason": "RevisionMissing", "message": "Configuration \"my-ksvc\" does not have any ready Revision.", "severity": "Info"} + ], + "latestCreatedRevisionName": "my-ksvc-00001", + "latestReadyRevisionName": "my-ksvc-00001", + "observedGeneration": 2, + "traffic": [{"latestRevision": true, "percent": 100, "revisionName": "my-ksvc-00001"}], + "url": "http://my-ksvc.ns.example.com" + } +}` + +func TestKnativeServiceControllerFromAPIServerPayload(t *testing.T) { + svc := &servingv1.Service{} + require.NoError(t, json.Unmarshal([]byte(knativeServicePayload), svc)) + + assert.Equal(t, "http://my-ksvc.ns.example.com", svc.Status.URL.String()) + require.NotNil(t, svc.Status.Address) + assert.Equal(t, "my-ksvc.ns.svc.cluster.local", svc.Status.Address.URL.Host) + assert.Equal(t, int64(300), ptr.Deref(svc.Spec.Template.Spec.TimeoutSeconds, 0)) + assert.Len(t, svc.Spec.Template.Spec.Containers, 1) + + c := &knativeServiceController{ + obj: svc, + integration: &v1.Integration{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "ns", + Name: "my-it", + }, + Status: v1.IntegrationStatus{ + Phase: v1.IntegrationPhaseRunning, + }, + }, + } + assert.True(t, c.hasTemplateIntegrationLabel()) + assert.Equal(t, "KnativeService/my-ksvc", c.getControllerName()) + + done, err := c.checkReadyCondition(context.TODO()) + require.NoError(t, err) + assert.True(t, done) + assert.Equal(t, v1.IntegrationPhaseError, c.integration.Status.Phase) + cond := c.integration.Status.GetCondition(v1.IntegrationConditionReady) + require.NotNil(t, cond) + assert.Equal(t, corev1.ConditionFalse, cond.Status) + assert.Contains(t, cond.Message, "my-ksvc-00001") +} diff --git a/pkg/controller/integration/predicate_test.go b/pkg/controller/integration/predicate_test.go new file mode 100644 index 000000000..47384ea6e --- /dev/null +++ b/pkg/controller/integration/predicate_test.go @@ -0,0 +1,77 @@ +/* +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 integration + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/controller-runtime/pkg/event" + + "github.com/apache/camel-k/v2/pkg/apis/duck/knative/apis" + servingv1 "github.com/apache/camel-k/v2/pkg/apis/duck/knative/serving/v1" +) + +func newKnativeServiceWithStatus(t *testing.T, url string, ready corev1.ConditionStatus) *servingv1.Service { + t.Helper() + parsed, err := apis.ParseURL(url) + require.NoError(t, err) + + return &servingv1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "ns", + Name: "my-ksvc", + }, + Status: servingv1.ServiceStatus{ + Status: apis.Status{ + Conditions: apis.Conditions{ + {Type: servingv1.ServiceConditionReady, Status: ready}, + }, + }, + RouteStatusFields: servingv1.RouteStatusFields{ + URL: parsed, + Address: &apis.Addressable{URL: parsed}, + }, + }, + } +} + +func TestStatusChangedPredicateKnativeService(t *testing.T) { + p := StatusChangedPredicate{} + + // A URL with user information makes url.URL carry an unexported *url.Userinfo: + // the semantic equality can only compare it through the URL equality function. + old := newKnativeServiceWithStatus(t, "http://user:[email protected]", corev1.ConditionTrue) + + same := old.DeepCopy() + same.Generation++ + assert.False(t, p.Update(event.UpdateEvent{ObjectOld: old, ObjectNew: same})) + + changedURL := newKnativeServiceWithStatus(t, "http://user:[email protected]/other", corev1.ConditionTrue) + assert.True(t, p.Update(event.UpdateEvent{ObjectOld: old, ObjectNew: changedURL})) + + notReady := newKnativeServiceWithStatus(t, "http://user:[email protected]", corev1.ConditionFalse) + assert.True(t, p.Update(event.UpdateEvent{ObjectOld: old, ObjectNew: notReady})) + + assert.False(t, p.Update(event.UpdateEvent{ObjectOld: nil, ObjectNew: same})) + assert.False(t, p.Update(event.UpdateEvent{ObjectOld: old, ObjectNew: nil})) +} diff --git a/pkg/trait/knative_test.go b/pkg/trait/knative_test.go index 553f087c5..33b6d0004 100644 --- a/pkg/trait/knative_test.go +++ b/pkg/trait/knative_test.go @@ -1406,7 +1406,6 @@ func newFakeClient(namespace string) (client.Client, error) { Namespace: namespace, Name: "default", }, - Spec: eventing.BrokerSpec{}, Status: eventing.BrokerStatus{ AddressStatus: apis.AddressStatus{ Address: &apis.Addressable{ @@ -1426,7 +1425,7 @@ func newFakeClient(namespace string) (client.Client, error) { }, Spec: eventing.TriggerSpec{ Filter: &eventing.TriggerFilter{ - Attributes: eventing.TriggerFilterAttributes{ + Attributes: map[string]string{ "type": "event-source-1", }, }, diff --git a/pkg/util/knative/knative_test.go b/pkg/util/knative/knative_test.go index 71047d683..c6dee9761 100644 --- a/pkg/util/knative/knative_test.go +++ b/pkg/util/knative/knative_test.go @@ -57,8 +57,7 @@ func TestCreateSinkBinding(t *testing.T) { "spec": { "sink": {"ref": {"kind": "Channel", "name": "my-channel", "apiVersion": "messaging.knative.dev/v1"}}, "subject": {"apiVersion": "apps/v1", "kind": "Deployment", "name": "my-source"} - }, - "status": {} + } }`, string(actual)) } @@ -88,8 +87,7 @@ func TestCreateSubscription(t *testing.T) { "ref": {"kind": "Service", "name": "my-service", "apiVersion": "serving.knative.dev/v1"}, "uri": "/channels/my-channel" } - }, - "status": {"physicalSubscription": {}} + } }`, string(actual)) } @@ -122,8 +120,7 @@ func TestCreateKnativeServiceTrigger(t *testing.T) { "ref": {"kind": "Service", "name": "my-service", "apiVersion": "serving.knative.dev/v1"}, "uri": "/events/evt.type" } - }, - "status": {} + } }`, string(actual)) } diff --git a/script/update_docs.sh b/script/update_docs.sh index 42d9f4987..086ae5f24 100755 --- a/script/update_docs.sh +++ b/script/update_docs.sh @@ -42,10 +42,3 @@ yq -i ".asciidoc.attributes.kubernetes-api-version = \"$KUBE_API_VERSION\"" $loc yq -i ".asciidoc.attributes.operator-fwk-api-version = \"$OPERATOR_FWK_API_VERSION\"" $location/../docs/antora.yml yq -i ".asciidoc.attributes.service-binding-op-version = \"$SERVICE_BINDING_OP_VERSION\"" $location/../docs/antora.yml yq -i ".asciidoc.attributes.prometheus-op-version = \"$PROMETHEUS_OP_VERSION\"" $location/../docs/antora.yml - -echo "Scraping information from e2e/knative/files/setup.sh" -KNATIVE_VERSION=$(grep '^KNATIVE_VERSION=' $location/../e2e/knative/files/setup.sh | sed 's/^.*=//') - -echo "Knative version: $KNATIVE_VERSION" - -yq -i ".asciidoc.attributes.knative-api-version = \"$KNATIVE_VERSION\"" $location/../docs/antora.yml
