Skip to content

Commit

Permalink
fix(api): deprecate .spec.integration Pipe
Browse files Browse the repository at this point in the history
Closes #4780
  • Loading branch information
squakez committed Oct 5, 2023
1 parent aee0c5f commit 719007c
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 3 deletions.
3 changes: 2 additions & 1 deletion config/crd/bases/camel.apache.org_pipes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/modules/ROOT/partials/apis/camel-k-crds.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]*
Expand Down
3 changes: 2 additions & 1 deletion helm/camel-k/crds/crd-pipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/camel/v1/pipe_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 --.
Expand Down
11 changes: 10 additions & 1 deletion pkg/controller/pipe/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/pipe/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions pkg/controller/pipe/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions resources/traits.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 719007c

Please sign in to comment.