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 433ba49caa20745fd6ada768ba41419bdd06f561 Author: Michal Vavřík <[email protected]> AuthorDate: Thu Oct 1 13:53:51 2026 +0200 address review and resolve merge conflicts Signed-off-by: Michal Vavřík <[email protected]> --- 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 | 84 --------------------- pkg/apis/duck/knative/apis/duck_types.go | 15 ++-- .../duck/knative/apis/zz_generated.deepcopy.go | 61 ++------------- pkg/apis/duck/knative/eventing/v1/duck_types.go | 27 ------- pkg/apis/duck/knative/eventing/v1/register.go | 2 - .../knative/eventing/v1/zz_generated.deepcopy.go | 74 ------------------- pkg/apis/duck/knative/messaging/v1/duck_types.go | 26 ------- pkg/apis/duck/knative/messaging/v1/register.go | 2 - .../knative/messaging/v1/zz_generated.deepcopy.go | 74 ------------------- pkg/apis/duck/knative/serving/v1/duck_types.go | 2 +- pkg/controller/integration/monitor_knative.go | 14 +++- pkg/controller/integration/monitor_knative_test.go | 38 +++++++--- pkg/controller/integration/predicate_test.go | 11 ++- pkg/trait/knative_test.go | 86 +++++++++------------- pkg/util/knative/knative_test.go | 45 ++++++----- pkg/util/kubernetes/conditions.go | 4 +- 19 files changed, 117 insertions(+), 453 deletions(-) diff --git a/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go b/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go index 739912370..5466a9cb0 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 ( - v1 "k8s.io/api/core/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 af1a8a1dc..07e39cd5e 100644 --- a/pkg/apis/camel/v1/zz_generated.deepcopy.go +++ b/pkg/apis/camel/v1/zz_generated.deepcopy.go @@ -6,7 +6,6 @@ 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 450aba305..27d57d72a 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 ( - v1 "k8s.io/api/core/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 deleted file mode 100644 index c3875a547..000000000 --- a/pkg/apis/duck/knative/apis/condition_types.go +++ /dev/null @@ -1,84 +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 ( - corev1 "k8s.io/api/core/v1" -) - -// Conditions is the schema for the conditions portion of the payload. -type Conditions []Condition - -// ConditionType is a camel-cased condition type. -type ConditionType string - -// ConditionReady specifies that the resource is ready. -const ConditionReady ConditionType = "Ready" - -// Condition defines a readiness condition for a Knative resource. -type Condition struct { - // Type of condition. - Type ConditionType `json:"type"` - - // Status of the condition, one of True, False, Unknown. - Status corev1.ConditionStatus `json:"status"` - - // The reason for the condition's last transition. - // +optional - Reason string `json:"reason,omitempty"` - - // A human readable message indicating details about the transition. - // +optional - Message string `json:"message,omitempty"` -} - -// IsTrue is true if the condition is True. -func (c *Condition) IsTrue() bool { - if c == nil { - return false - } - - return c.Status == corev1.ConditionTrue -} - -// IsFalse is true if the condition is False. -func (c *Condition) IsFalse() bool { - if c == nil { - return false - } - - return c.Status == corev1.ConditionFalse -} - -// GetReason returns the reason of the condition, or an empty string for a nil condition. -func (c *Condition) GetReason() string { - if c == nil { - return "" - } - - return c.Reason -} - -// GetMessage returns the message of the condition, or an empty string for a nil condition. -func (c *Condition) GetMessage() string { - if c == nil { - return "" - } - - return c.Message -} diff --git a/pkg/apis/duck/knative/apis/duck_types.go b/pkg/apis/duck/knative/apis/duck_types.go index 291a53c78..3bdbe2e68 100644 --- a/pkg/apis/duck/knative/apis/duck_types.go +++ b/pkg/apis/duck/knative/apis/duck_types.go @@ -17,18 +17,17 @@ limitations under the License. package apis +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + // Status is the common status of the Knative resources. type Status struct { // Conditions the latest available observations of a resource's current state. + // The Knative conditions are read as Kubernetes API conditions, as they share + // the fields Camel K uses (type, status, reason and message). // +optional - Conditions Conditions `json:"conditions,omitempty"` -} - -// AddressStatus is the status of an addressable resource. -type AddressStatus struct { - // Address is a single Addressable address. - // +optional - Address *Addressable `json:"address,omitempty"` + Conditions []metav1.Condition `json:"conditions,omitempty"` } // Addressable is a destination for message delivery. diff --git a/pkg/apis/duck/knative/apis/zz_generated.deepcopy.go b/pkg/apis/duck/knative/apis/zz_generated.deepcopy.go index 114ecba4f..23905df76 100644 --- a/pkg/apis/duck/knative/apis/zz_generated.deepcopy.go +++ b/pkg/apis/duck/knative/apis/zz_generated.deepcopy.go @@ -5,29 +5,10 @@ package apis import ( + "k8s.io/apimachinery/pkg/apis/meta/v1" "net/url" ) -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *AddressStatus) DeepCopyInto(out *AddressStatus) { - *out = *in - if in.Address != nil { - in, out := &in.Address, &out.Address - *out = new(Addressable) - (*in).DeepCopyInto(*out) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AddressStatus. -func (in *AddressStatus) DeepCopy() *AddressStatus { - if in == nil { - return nil - } - out := new(AddressStatus) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Addressable) DeepCopyInto(out *Addressable) { *out = *in @@ -64,40 +45,6 @@ func (in *BindingSpec) DeepCopy() *BindingSpec { return out } -// 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 -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Condition. -func (in *Condition) DeepCopy() *Condition { - if in == nil { - return nil - } - out := new(Condition) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in Conditions) DeepCopyInto(out *Conditions) { - { - in := &in - *out = make(Conditions, len(*in)) - copy(*out, *in) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Conditions. -func (in Conditions) DeepCopy() Conditions { - if in == nil { - return nil - } - out := new(Conditions) - in.DeepCopyInto(out) - return *out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Destination) DeepCopyInto(out *Destination) { *out = *in @@ -174,8 +121,10 @@ func (in *Status) DeepCopyInto(out *Status) { *out = *in if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions - *out = make(Conditions, len(*in)) - copy(*out, *in) + *out = make([]v1.Condition, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } } diff --git a/pkg/apis/duck/knative/eventing/v1/duck_types.go b/pkg/apis/duck/knative/eventing/v1/duck_types.go index 35e9610e4..91dc8463c 100644 --- a/pkg/apis/duck/knative/eventing/v1/duck_types.go +++ b/pkg/apis/duck/knative/eventing/v1/duck_types.go @@ -63,30 +63,3 @@ type TriggerList struct { Items []Trigger `json:"items"` } - -// +kubebuilder:object:root=true - -// Broker is a partial schema of the Knative Eventing Broker resource: a pool of -// events that are consumable using Triggers. -type Broker struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Status BrokerStatus `json:"status,omitempty"` -} - -// BrokerStatus represents the current state of a Broker. -type BrokerStatus struct { - // AddressStatus is the part where the Broker fulfills the Addressable contract. - apis.AddressStatus `json:",inline"` -} - -// +kubebuilder:object:root=true - -// BrokerList contains a list of Broker. -type BrokerList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - - Items []Broker `json:"items"` -} diff --git a/pkg/apis/duck/knative/eventing/v1/register.go b/pkg/apis/duck/knative/eventing/v1/register.go index 51213722b..fabf95bea 100644 --- a/pkg/apis/duck/knative/eventing/v1/register.go +++ b/pkg/apis/duck/knative/eventing/v1/register.go @@ -44,8 +44,6 @@ func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, &Trigger{}, &TriggerList{}, - &Broker{}, - &BrokerList{}, ) metav1.AddToGroupVersion(scheme, SchemeGroupVersion) 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 9493d4d9e..e51997e00 100644 --- a/pkg/apis/duck/knative/eventing/v1/zz_generated.deepcopy.go +++ b/pkg/apis/duck/knative/eventing/v1/zz_generated.deepcopy.go @@ -8,80 +8,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" ) -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Broker) DeepCopyInto(out *Broker) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Status.DeepCopyInto(&out.Status) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Broker. -func (in *Broker) DeepCopy() *Broker { - if in == nil { - return nil - } - out := new(Broker) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Broker) 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 *BrokerList) DeepCopyInto(out *BrokerList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Broker, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BrokerList. -func (in *BrokerList) DeepCopy() *BrokerList { - if in == nil { - return nil - } - out := new(BrokerList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *BrokerList) 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 *BrokerStatus) DeepCopyInto(out *BrokerStatus) { - *out = *in - in.AddressStatus.DeepCopyInto(&out.AddressStatus) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BrokerStatus. -func (in *BrokerStatus) DeepCopy() *BrokerStatus { - if in == nil { - return nil - } - out := new(BrokerStatus) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Trigger) DeepCopyInto(out *Trigger) { *out = *in diff --git a/pkg/apis/duck/knative/messaging/v1/duck_types.go b/pkg/apis/duck/knative/messaging/v1/duck_types.go index f6f0add9d..41d821898 100644 --- a/pkg/apis/duck/knative/messaging/v1/duck_types.go +++ b/pkg/apis/duck/knative/messaging/v1/duck_types.go @@ -53,29 +53,3 @@ type SubscriptionList struct { Items []Subscription `json:"items"` } - -// +kubebuilder:object:root=true - -// Channel is a partial schema of the Knative Eventing Channel resource. -type Channel struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Status ChannelStatus `json:"status,omitempty"` -} - -// ChannelStatus represents the current state of a Channel. -type ChannelStatus struct { - // AddressStatus is the part where the Channel fulfills the Addressable contract. - apis.AddressStatus `json:",inline"` -} - -// +kubebuilder:object:root=true - -// ChannelList contains a list of Channel. -type ChannelList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - - Items []Channel `json:"items"` -} diff --git a/pkg/apis/duck/knative/messaging/v1/register.go b/pkg/apis/duck/knative/messaging/v1/register.go index edcfd6b70..d7823ec7f 100644 --- a/pkg/apis/duck/knative/messaging/v1/register.go +++ b/pkg/apis/duck/knative/messaging/v1/register.go @@ -44,8 +44,6 @@ func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, &Subscription{}, &SubscriptionList{}, - &Channel{}, - &ChannelList{}, ) metav1.AddToGroupVersion(scheme, SchemeGroupVersion) 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 f0f1181e1..52c068dc0 100644 --- a/pkg/apis/duck/knative/messaging/v1/zz_generated.deepcopy.go +++ b/pkg/apis/duck/knative/messaging/v1/zz_generated.deepcopy.go @@ -9,80 +9,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" ) -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Channel) DeepCopyInto(out *Channel) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Status.DeepCopyInto(&out.Status) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Channel. -func (in *Channel) DeepCopy() *Channel { - if in == nil { - return nil - } - out := new(Channel) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Channel) 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 *ChannelList) DeepCopyInto(out *ChannelList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Channel, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelList. -func (in *ChannelList) DeepCopy() *ChannelList { - if in == nil { - return nil - } - out := new(ChannelList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ChannelList) 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 *ChannelStatus) DeepCopyInto(out *ChannelStatus) { - *out = *in - in.AddressStatus.DeepCopyInto(&out.AddressStatus) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelStatus. -func (in *ChannelStatus) DeepCopy() *ChannelStatus { - if in == nil { - return nil - } - out := new(ChannelStatus) - 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 diff --git a/pkg/apis/duck/knative/serving/v1/duck_types.go b/pkg/apis/duck/knative/serving/v1/duck_types.go index 7e4794af5..db8994aeb 100644 --- a/pkg/apis/duck/knative/serving/v1/duck_types.go +++ b/pkg/apis/duck/knative/serving/v1/duck_types.go @@ -25,7 +25,7 @@ import ( ) // ServiceConditionReady is set when the service is configured and has available backends ready to receive traffic. -const ServiceConditionReady = apis.ConditionReady +const ServiceConditionReady = "Ready" // +kubebuilder:object:root=true diff --git a/pkg/controller/integration/monitor_knative.go b/pkg/controller/integration/monitor_knative.go index d516801c8..949969f5b 100644 --- a/pkg/controller/integration/monitor_knative.go +++ b/pkg/controller/integration/monitor_knative.go @@ -21,6 +21,7 @@ import ( "context" corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" servingv1 "github.com/apache/camel-k/v2/pkg/apis/duck/knative/serving/v1" @@ -36,8 +37,8 @@ var _ controller = &knativeServiceController{} func (c *knativeServiceController) checkReadyCondition(ctx context.Context) (bool, error) { // Check the KnativeService conditions - if ready := kubernetes.GetKnativeServiceCondition(*c.obj, servingv1.ServiceConditionReady); ready.IsFalse() && - ready.GetReason() == "RevisionFailed" { + if ready := kubernetes.GetKnativeServiceCondition(*c.obj, servingv1.ServiceConditionReady); ready != nil && + ready.Status == metav1.ConditionFalse && ready.Reason == "RevisionFailed" { c.integration.Status.Phase = v1.IntegrationPhaseError c.integration.SetReadyConditionError(ready.Message) @@ -49,14 +50,19 @@ func (c *knativeServiceController) checkReadyCondition(ctx context.Context) (boo func (c *knativeServiceController) updateReadyCondition(readyPods int32) bool { ready := kubernetes.GetKnativeServiceCondition(*c.obj, servingv1.ServiceConditionReady) - if ready.IsTrue() { + if ready == nil { + c.integration.SetReadyCondition(corev1.ConditionFalse, "", "") + + return false + } + if ready.Status == metav1.ConditionTrue { c.integration.SetReadyCondition(corev1.ConditionTrue, v1.IntegrationConditionKnativeServiceReadyReason, "") return true } c.integration.SetReadyCondition(corev1.ConditionFalse, - ready.GetReason(), ready.GetMessage()) + ready.Reason, ready.Message) return false } diff --git a/pkg/controller/integration/monitor_knative_test.go b/pkg/controller/integration/monitor_knative_test.go index 3604d5498..7e87047a9 100644 --- a/pkg/controller/integration/monitor_knative_test.go +++ b/pkg/controller/integration/monitor_knative_test.go @@ -30,11 +30,10 @@ import ( "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" servingv1 "github.com/apache/camel-k/v2/pkg/apis/duck/knative/serving/v1" ) -func newKnativeServiceController(ready *apis.Condition) *knativeServiceController { +func newKnativeServiceController(ready *metav1.Condition) *knativeServiceController { svc := &servingv1.Service{ ObjectMeta: metav1.ObjectMeta{ Namespace: "ns", @@ -42,7 +41,7 @@ func newKnativeServiceController(ready *apis.Condition) *knativeServiceControlle }, } if ready != nil { - svc.Status.Conditions = apis.Conditions{*ready} + svc.Status.Conditions = []metav1.Condition{*ready} } return &knativeServiceController{ @@ -60,9 +59,9 @@ func newKnativeServiceController(ready *apis.Condition) *knativeServiceControlle } func TestKnativeServiceControllerReady(t *testing.T) { - c := newKnativeServiceController(&apis.Condition{ + c := newKnativeServiceController(&metav1.Condition{ Type: servingv1.ServiceConditionReady, - Status: corev1.ConditionTrue, + Status: metav1.ConditionTrue, }) done, err := c.checkReadyCondition(context.TODO()) @@ -78,9 +77,9 @@ func TestKnativeServiceControllerReady(t *testing.T) { } func TestKnativeServiceControllerRevisionFailed(t *testing.T) { - c := newKnativeServiceController(&apis.Condition{ + c := newKnativeServiceController(&metav1.Condition{ Type: servingv1.ServiceConditionReady, - Status: corev1.ConditionFalse, + Status: metav1.ConditionFalse, Reason: "RevisionFailed", Message: "revision failed", }) @@ -96,9 +95,9 @@ func TestKnativeServiceControllerRevisionFailed(t *testing.T) { } func TestKnativeServiceControllerNotReady(t *testing.T) { - c := newKnativeServiceController(&apis.Condition{ + c := newKnativeServiceController(&metav1.Condition{ Type: servingv1.ServiceConditionReady, - Status: corev1.ConditionFalse, + Status: metav1.ConditionFalse, Reason: "Deploying", Message: "still deploying", }) @@ -116,6 +115,27 @@ func TestKnativeServiceControllerNotReady(t *testing.T) { assert.Equal(t, "still deploying", cond.Message) } +func TestKnativeServiceControllerUnknown(t *testing.T) { + c := newKnativeServiceController(&metav1.Condition{ + Type: servingv1.ServiceConditionReady, + Status: metav1.ConditionUnknown, + Reason: "RevisionMissing", + Message: "waiting for the revision", + }) + + done, err := c.checkReadyCondition(context.TODO()) + require.NoError(t, err) + assert.False(t, done) + assert.Equal(t, v1.IntegrationPhaseRunning, c.integration.Status.Phase) + + assert.False(t, c.updateReadyCondition(0)) + cond := c.integration.Status.GetCondition(v1.IntegrationConditionReady) + require.NotNil(t, cond) + assert.Equal(t, corev1.ConditionFalse, cond.Status) + assert.Equal(t, "RevisionMissing", cond.Reason) + assert.Equal(t, "waiting for the revision", cond.Message) +} + func TestKnativeServiceControllerMissingCondition(t *testing.T) { c := newKnativeServiceController(nil) diff --git a/pkg/controller/integration/predicate_test.go b/pkg/controller/integration/predicate_test.go index 47384ea6e..70f59958f 100644 --- a/pkg/controller/integration/predicate_test.go +++ b/pkg/controller/integration/predicate_test.go @@ -23,7 +23,6 @@ import ( "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" @@ -31,7 +30,7 @@ import ( 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 { +func newKnativeServiceWithStatus(t *testing.T, url string, ready metav1.ConditionStatus) *servingv1.Service { t.Helper() parsed, err := apis.ParseURL(url) require.NoError(t, err) @@ -43,7 +42,7 @@ func newKnativeServiceWithStatus(t *testing.T, url string, ready corev1.Conditio }, Status: servingv1.ServiceStatus{ Status: apis.Status{ - Conditions: apis.Conditions{ + Conditions: []metav1.Condition{ {Type: servingv1.ServiceConditionReady, Status: ready}, }, }, @@ -60,16 +59,16 @@ func TestStatusChangedPredicateKnativeService(t *testing.T) { // 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) + old := newKnativeServiceWithStatus(t, "http://user:[email protected]", metav1.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) + changedURL := newKnativeServiceWithStatus(t, "http://user:[email protected]/other", metav1.ConditionTrue) assert.True(t, p.Update(event.UpdateEvent{ObjectOld: old, ObjectNew: changedURL})) - notReady := newKnativeServiceWithStatus(t, "http://user:[email protected]", corev1.ConditionFalse) + notReady := newKnativeServiceWithStatus(t, "http://user:[email protected]", metav1.ConditionFalse) assert.True(t, p.Update(event.UpdateEvent{ObjectOld: old, ObjectNew: notReady})) assert.False(t, p.Update(event.UpdateEvent{ObjectOld: nil, ObjectNew: same})) diff --git a/pkg/trait/knative_test.go b/pkg/trait/knative_test.go index 33b6d0004..7526b5a09 100644 --- a/pkg/trait/knative_test.go +++ b/pkg/trait/knative_test.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" "k8s.io/utils/ptr" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" @@ -1307,14 +1308,6 @@ func NewFakeEnvironmentForKitWithoutCatalog(t *testing.T) Environment { } 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 @@ -1323,42 +1316,35 @@ func newFakeClient(namespace string) (client.Client, error) { if err != nil { return nil, err } - brokerURL, err := apis.ParseURL("http://broker-default.host/") - if err != nil { - return nil, err - } + // The Channel and Broker resources are only read as unstructured objects return internal.NewFakeClient( - &messaging.Channel{ - TypeMeta: metav1.TypeMeta{ - Kind: "Channel", - APIVersion: messaging.SchemeGroupVersion.String(), - }, - ObjectMeta: metav1.ObjectMeta{ - Namespace: namespace, - Name: "channel-source-1", - }, - Status: messaging.ChannelStatus{ - AddressStatus: apis.AddressStatus{ - Address: &apis.Addressable{ - URL: channelSourceURL, + &unstructured.Unstructured{ + Object: map[string]any{ + "apiVersion": messaging.SchemeGroupVersion.String(), + "kind": "Channel", + "metadata": map[string]any{ + "namespace": namespace, + "name": "channel-source-1", + }, + "status": map[string]any{ + "address": map[string]any{ + "url": "http://channel-source-1.host/", }, }, }, }, - &messaging.Channel{ - TypeMeta: metav1.TypeMeta{ - Kind: "Channel", - APIVersion: messaging.SchemeGroupVersion.String(), - }, - ObjectMeta: metav1.ObjectMeta{ - Namespace: namespace, - Name: "channel-sink-1", - }, - Status: messaging.ChannelStatus{ - AddressStatus: apis.AddressStatus{ - Address: &apis.Addressable{ - URL: channelSinkURL, + &unstructured.Unstructured{ + Object: map[string]any{ + "apiVersion": messaging.SchemeGroupVersion.String(), + "kind": "Channel", + "metadata": map[string]any{ + "namespace": namespace, + "name": "channel-sink-1", + }, + "status": map[string]any{ + "address": map[string]any{ + "url": "http://channel-sink-1.host/", }, }, }, @@ -1397,19 +1383,17 @@ func newFakeClient(namespace string) (client.Client, error) { }, }, }, - &eventing.Broker{ - TypeMeta: metav1.TypeMeta{ - APIVersion: eventing.SchemeGroupVersion.String(), - Kind: "Broker", - }, - ObjectMeta: metav1.ObjectMeta{ - Namespace: namespace, - Name: "default", - }, - Status: eventing.BrokerStatus{ - AddressStatus: apis.AddressStatus{ - Address: &apis.Addressable{ - URL: brokerURL, + &unstructured.Unstructured{ + Object: map[string]any{ + "apiVersion": eventing.SchemeGroupVersion.String(), + "kind": "Broker", + "metadata": map[string]any{ + "namespace": namespace, + "name": "default", + }, + "status": map[string]any{ + "address": map[string]any{ + "url": "http://broker-default.host/", }, }, }, diff --git a/pkg/util/knative/knative_test.go b/pkg/util/knative/knative_test.go index c6dee9761..18db2a14a 100644 --- a/pkg/util/knative/knative_test.go +++ b/pkg/util/knative/knative_test.go @@ -28,8 +28,8 @@ import ( corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "github.com/apache/camel-k/v2/pkg/apis/duck/knative/apis" eventing "github.com/apache/camel-k/v2/pkg/apis/duck/knative/eventing/v1" "github.com/apache/camel-k/v2/pkg/internal" ) @@ -125,34 +125,31 @@ func TestCreateKnativeServiceTrigger(t *testing.T) { } func TestGetSinkURL(t *testing.T) { - brokerURL, err := apis.ParseURL("http://broker-ingress.knative-eventing.svc.cluster.local/my-ns/default") - require.NoError(t, err) + // The Broker resources are only read as unstructured objects client, err := internal.NewFakeClient( - &eventing.Broker{ - TypeMeta: metav1.TypeMeta{ - Kind: "Broker", - APIVersion: eventing.SchemeGroupVersion.String(), - }, - ObjectMeta: metav1.ObjectMeta{ - Namespace: "my-ns", - Name: "default", - }, - Status: eventing.BrokerStatus{ - AddressStatus: apis.AddressStatus{ - Address: &apis.Addressable{ - URL: brokerURL, + &unstructured.Unstructured{ + Object: map[string]any{ + "apiVersion": eventing.SchemeGroupVersion.String(), + "kind": "Broker", + "metadata": map[string]any{ + "namespace": "my-ns", + "name": "default", + }, + "status": map[string]any{ + "address": map[string]any{ + "url": "http://broker-ingress.knative-eventing.svc.cluster.local/my-ns/default", }, }, }, }, - &eventing.Broker{ - TypeMeta: metav1.TypeMeta{ - Kind: "Broker", - APIVersion: eventing.SchemeGroupVersion.String(), - }, - ObjectMeta: metav1.ObjectMeta{ - Namespace: "my-ns", - Name: "not-ready", + &unstructured.Unstructured{ + Object: map[string]any{ + "apiVersion": eventing.SchemeGroupVersion.String(), + "kind": "Broker", + "metadata": map[string]any{ + "namespace": "my-ns", + "name": "not-ready", + }, }, }, &corev1.Service{ diff --git a/pkg/util/kubernetes/conditions.go b/pkg/util/kubernetes/conditions.go index 9d8a7ae5e..f587d63c4 100644 --- a/pkg/util/kubernetes/conditions.go +++ b/pkg/util/kubernetes/conditions.go @@ -21,8 +21,8 @@ import ( appsv1 "k8s.io/api/apps/v1" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - knative "github.com/apache/camel-k/v2/pkg/apis/duck/knative/apis" servingv1 "github.com/apache/camel-k/v2/pkg/apis/duck/knative/serving/v1" ) @@ -48,7 +48,7 @@ func GetDeploymentCondition(deployment appsv1.Deployment, conditionType appsv1.D return nil } -func GetKnativeServiceCondition(service servingv1.Service, conditionType knative.ConditionType) *knative.Condition { +func GetKnativeServiceCondition(service servingv1.Service, conditionType string) *metav1.Condition { for i := range service.Status.Conditions { condition := service.Status.Conditions[i] if condition.Type == conditionType {
