From 719007cc05eddc15002e1d3e6b512fef147195a4 Mon Sep 17 00:00:00 2001 From: Pasquale Congiusti Date: Thu, 5 Oct 2023 15:56:59 +0200 Subject: [PATCH] fix(api): deprecate .spec.integration Pipe Closes #4780 --- config/crd/bases/camel.apache.org_pipes.yaml | 3 ++- .../modules/ROOT/partials/apis/camel-k-crds.adoc | 1 + helm/camel-k/crds/crd-pipe.yaml | 3 ++- pkg/apis/camel/v1/pipe_types.go | 3 +++ pkg/controller/pipe/initialize.go | 11 ++++++++++- pkg/controller/pipe/integration.go | 1 + pkg/controller/pipe/monitor.go | 9 +++++++++ resources/traits.yaml | 16 ++++++++++++++++ 8 files changed, 44 insertions(+), 3 deletions(-) diff --git a/config/crd/bases/camel.apache.org_pipes.yaml b/config/crd/bases/camel.apache.org_pipes.yaml index 5bf2d8ff01..c8c5b8ea8e 100644 --- a/config/crd/bases/camel.apache.org_pipes.yaml +++ b/config/crd/bases/camel.apache.org_pipes.yaml @@ -74,7 +74,8 @@ spec: x-kubernetes-preserve-unknown-fields: true integration: description: Integration is an optional integration used to specify - custom parameters + custom parameters Deprecated don't use this. Use trait annotations + if you need to change any cluster configuration. properties: configuration: description: 'Deprecated: Use camel trait (camel.properties) to diff --git a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc index 39fe3ed4c2..a9070f7c78 100644 --- a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc +++ b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc @@ -4218,6 +4218,7 @@ PipeSpec defines the binding between a source and a sink. It can include custom Integration is an optional integration used to specify custom parameters +Deprecated don't use this. Use trait annotations if you need to change any cluster configuration. |`source` + *xref:#_camel_apache_org_v1_Endpoint[Endpoint]* diff --git a/helm/camel-k/crds/crd-pipe.yaml b/helm/camel-k/crds/crd-pipe.yaml index 5bf2d8ff01..c8c5b8ea8e 100644 --- a/helm/camel-k/crds/crd-pipe.yaml +++ b/helm/camel-k/crds/crd-pipe.yaml @@ -74,7 +74,8 @@ spec: x-kubernetes-preserve-unknown-fields: true integration: description: Integration is an optional integration used to specify - custom parameters + custom parameters Deprecated don't use this. Use trait annotations + if you need to change any cluster configuration. properties: configuration: description: 'Deprecated: Use camel trait (camel.properties) to diff --git a/pkg/apis/camel/v1/pipe_types.go b/pkg/apis/camel/v1/pipe_types.go index 369e8626f0..74bf55626c 100644 --- a/pkg/apis/camel/v1/pipe_types.go +++ b/pkg/apis/camel/v1/pipe_types.go @@ -46,6 +46,7 @@ type Pipe struct { // PipeSpec defines the binding between a source and a sink. It can include custom parameters and additional intermediate steps and error handling. type PipeSpec struct { // Integration is an optional integration used to specify custom parameters + // Deprecated don't use this. Use trait annotations if you need to change any cluster configuration. Integration *IntegrationSpec `json:"integration,omitempty"` // Source is the starting point of the integration defined by this Pipe Source Endpoint `json:"source,omitempty"` @@ -132,6 +133,8 @@ const ( PipeConditionReady PipeConditionType = "Ready" // PipeIntegrationConditionError is used to report the error on the generated Integration. PipeIntegrationConditionError PipeConditionType = "IntegrationError" + // PipeIntegrationDeprecationNotice is used to report the usage of a deprecated resource. + PipeIntegrationDeprecationNotice PipeConditionType = "DeprecationNotice" ) // PipePhase --. diff --git a/pkg/controller/pipe/initialize.go b/pkg/controller/pipe/initialize.go index 35b5c56f08..4cec1faf4c 100644 --- a/pkg/controller/pipe/initialize.go +++ b/pkg/controller/pipe/initialize.go @@ -54,6 +54,15 @@ func (action *initializeAction) CanHandle(binding *v1.Pipe) bool { func (action *initializeAction) Handle(ctx context.Context, binding *v1.Pipe) (*v1.Pipe, error) { action.L.Info("Initializing Pipe") + if binding.Spec.Integration != nil { + action.L.Infof("Pipe %s is using deprecated .spec.integration parameter. Please, update and use annotation traits instead", binding.Name) + binding.Status.SetCondition( + v1.PipeIntegrationDeprecationNotice, + corev1.ConditionTrue, + ".spec.integration parameter is deprecated", + ".spec.integration parameter is deprecated. Use annotation traits instead", + ) + } it, err := CreateIntegrationFor(ctx, action.client, binding) if err != nil { binding.Status.Phase = v1.PipePhaseError @@ -63,7 +72,7 @@ func (action *initializeAction) Handle(ctx context.Context, binding *v1.Pipe) (* } if _, err := kubernetes.ReplaceResource(ctx, action.client, it); err != nil { - return nil, fmt.Errorf("could not create integration forPipe: %w", err) + return nil, fmt.Errorf("could not create integration for Pipe: %w", err) } // propagate Kamelet icon (best effort) diff --git a/pkg/controller/pipe/integration.go b/pkg/controller/pipe/integration.go index 9d21e1c412..cf25f0722f 100644 --- a/pkg/controller/pipe/integration.go +++ b/pkg/controller/pipe/integration.go @@ -75,6 +75,7 @@ func CreateIntegrationFor(ctx context.Context, c client.Client, binding *v1.Pipe it.GetLabels()[kubernetes.CamelCreatorLabelKind] = binding.Kind it.GetLabels()[kubernetes.CamelCreatorLabelName] = binding.Name + // Deprecated // start from the integration spec defined in the binding if binding.Spec.Integration != nil { it.Spec = *binding.Spec.Integration.DeepCopy() diff --git a/pkg/controller/pipe/monitor.go b/pkg/controller/pipe/monitor.go index a2bff2456d..292add27aa 100644 --- a/pkg/controller/pipe/monitor.go +++ b/pkg/controller/pipe/monitor.go @@ -82,6 +82,15 @@ func (action *monitorAction) Handle(ctx context.Context, binding *v1.Pipe) (*v1. // Check if the integration needs to be changed expected, err := CreateIntegrationFor(ctx, action.client, binding) + if binding.Spec.Integration != nil { + action.L.Infof("Pipe %s is using deprecated .spec.integration parameter. Please, update and use annotation traits instead", binding.Name) + binding.Status.SetCondition( + v1.PipeIntegrationDeprecationNotice, + corev1.ConditionTrue, + ".spec.integration parameter is deprecated", + ".spec.integration parameter is deprecated. Use annotation traits instead", + ) + } if err != nil { binding.Status.Phase = v1.PipePhaseError binding.Status.SetErrorCondition(v1.PipeIntegrationConditionError, diff --git a/resources/traits.yaml b/resources/traits.yaml index 8a0e7c5865..d2d95bed76 100755 --- a/resources/traits.yaml +++ b/resources/traits.yaml @@ -1,3 +1,19 @@ +# --------------------------------------------------------------------------- +# 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. +# --------------------------------------------------------------------------- traits: - name: 3scale platform: false