This is an automated email from the ASF dual-hosted git repository.
squakez pushed a commit to branch v3
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/v3 by this push:
new 05f3ea5ef feat(ctrl): drop support for annotation traits
05f3ea5ef is described below
commit 05f3ea5ef78deae551164e42a919be9a68fa8ef7
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Thu Oct 22 08:53:00 2026 +0200
feat(ctrl): drop support for annotation traits
Closes #5766
---
pkg/apis/camel/v1/common_types.go | 4 -
pkg/apis/camel/v1/integrationplatform_types.go | 2 +-
pkg/controller/build/build_pod.go | 11 +-
pkg/controller/build/build_pod_test.go | 8 +-
pkg/controller/build/monitor_pod.go | 2 +-
pkg/controller/integration/build_kit.go | 2 +-
.../integration/integration_controller.go | 6 +-
pkg/controller/integration/kits.go | 10 +-
pkg/controller/integration/kits_test.go | 17 +--
pkg/controller/integration/monitor.go | 24 ----
pkg/controller/integrationkit/monitor.go | 27 ----
pkg/controller/integrationplatform/monitor.go | 24 ----
pkg/controller/pipe/integration.go | 13 --
pkg/controller/pipe/integration_test.go | 93 -------------
pkg/controller/pipe/monitor.go | 27 +---
pkg/controller/pipe/monitor_test.go | 48 -------
pkg/controller/pipe/pipe_controller.go | 6 +-
pkg/platform/operator.go | 9 --
pkg/resources/resources_support.go | 7 -
pkg/resources/resources_test.go | 4 -
pkg/trait/builder.go | 14 +-
pkg/trait/container.go | 17 +--
pkg/trait/pull_secret.go | 10 +-
pkg/trait/security_context.go | 17 +--
pkg/trait/trait_configure.go | 109 +---------------
pkg/trait/trait_configure_test.go | 95 --------------
pkg/trait/util.go | 144 +++------------------
pkg/trait/util_test.go | 69 ++--------
pkg/util/digest/digest.go | 22 ----
pkg/util/digest/digest_test.go | 8 --
pkg/util/kubernetes/loader.go | 70 ----------
pkg/util/kubernetes/permission.go | 28 ----
pkg/util/resource/config.go | 12 --
33 files changed, 69 insertions(+), 890 deletions(-)
diff --git a/pkg/apis/camel/v1/common_types.go
b/pkg/apis/camel/v1/common_types.go
index 521641624..23ea14f7a 100644
--- a/pkg/apis/camel/v1/common_types.go
+++ b/pkg/apis/camel/v1/common_types.go
@@ -24,10 +24,6 @@ import (
)
const (
- // TraitAnnotationPrefix represents the prefix used for traits
annotations.
- //
- // Deprecated: use .spec.traits instead.
- TraitAnnotationPrefix = "trait.camel.apache.org/"
// OperatorIDAnnotation operator id annotation label.
//
// Deprecated: will be removed in the future.
diff --git a/pkg/apis/camel/v1/integrationplatform_types.go
b/pkg/apis/camel/v1/integrationplatform_types.go
index bbfc64694..87c738b92 100644
--- a/pkg/apis/camel/v1/integrationplatform_types.go
+++ b/pkg/apis/camel/v1/integrationplatform_types.go
@@ -114,7 +114,7 @@ const (
DeprecatedIntegrationPlatformClusterKubernetes
IntegrationPlatformCluster = "Kubernetes"
)
-// AllIntegrationPlatformClusters --.
+// DeprecatedAllIntegrationPlatformClusters --.
var DeprecatedAllIntegrationPlatformClusters = []IntegrationPlatformCluster{
DeprecatedIntegrationPlatformClusterOpenShift,
DeprecatedIntegrationPlatformClusterKubernetes,
}
diff --git a/pkg/controller/build/build_pod.go
b/pkg/controller/build/build_pod.go
index 22e6175c9..e76709fd1 100644
--- a/pkg/controller/build/build_pod.go
+++ b/pkg/controller/build/build_pod.go
@@ -27,7 +27,6 @@ import (
ctrl "sigs.k8s.io/controller-runtime/pkg/client"
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
- "github.com/apache/camel-k/v2/pkg/client"
"github.com/apache/camel-k/v2/pkg/platform"
"github.com/apache/camel-k/v2/pkg/util/kubernetes"
"github.com/apache/camel-k/v2/pkg/util/registry"
@@ -38,7 +37,7 @@ const (
builderVolume = "camel-k-builder"
)
-func newBuildPod(ctx context.Context, client client.Client, build *v1.Build)
*corev1.Pod {
+func newBuildPod(build *v1.Build) *corev1.Pod {
var ugfid int64 = 1001
podSecurityContext := &corev1.PodSecurityContext{
RunAsUser: &ugfid,
@@ -70,16 +69,16 @@ func newBuildPod(ctx context.Context, client client.Client,
build *v1.Build) *co
switch {
// Builder task
case task.Builder != nil:
- addBuildTaskToPod(ctx, client, build,
task.Builder.Name, "", pod)
+ addBuildTaskToPod(build, task.Builder.Name, "", pod)
// Custom task
case task.Custom != nil:
addCustomTaskToPod(build, task.Custom, pod)
// Package task
// It's a type of builder task, we can reuse the same type
case task.Package != nil:
- addBuildTaskToPod(ctx, client, build,
task.Package.Name, "", pod)
+ addBuildTaskToPod(build, task.Package.Name, "", pod)
case task.Jib != nil:
- addBuildTaskToPod(ctx, client, build, task.Jib.Name,
task.Jib.Registry.Secret, pod)
+ addBuildTaskToPod(build, task.Jib.Name,
task.Jib.Registry.Secret, pod)
}
}
@@ -160,7 +159,7 @@ func buildPodName(build *v1.Build) string {
return "camel-k-" + build.Name + "-builder"
}
-func addBuildTaskToPod(ctx context.Context, client client.Client, build
*v1.Build, taskName, registrySecretName string, pod *corev1.Pod) {
+func addBuildTaskToPod(build *v1.Build, taskName, registrySecretName string,
pod *corev1.Pod) {
if !hasVolume(pod, builderVolume) {
pod.Spec.Volumes = append(pod.Spec.Volumes,
// EmptyDir volume used to share the build state across
tasks
diff --git a/pkg/controller/build/build_pod_test.go
b/pkg/controller/build/build_pod_test.go
index ebab005e6..4d6ad83a9 100644
--- a/pkg/controller/build/build_pod_test.go
+++ b/pkg/controller/build/build_pod_test.go
@@ -18,21 +18,15 @@ limitations under the License.
package build
import (
- "context"
"testing"
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
- "github.com/apache/camel-k/v2/pkg/internal"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestNewBuildPodConfiguration(t *testing.T) {
- ctx := context.TODO()
- c, err := internal.NewFakeClient()
- require.NoError(t, err)
-
build := v1.Build{
ObjectMeta: metav1.ObjectMeta{
Name: "theBuildName",
@@ -55,7 +49,7 @@ func TestNewBuildPodConfiguration(t *testing.T) {
},
}
- pod := newBuildPod(ctx, c, &build)
+ pod := newBuildPod(&build)
assert.Equal(t, "Pod", pod.Kind)
assert.Equal(t, "theNamespace", pod.Namespace)
diff --git a/pkg/controller/build/monitor_pod.go
b/pkg/controller/build/monitor_pod.go
index b76f5c18b..be0b60d7b 100644
--- a/pkg/controller/build/monitor_pod.go
+++ b/pkg/controller/build/monitor_pod.go
@@ -71,7 +71,7 @@ func (action *monitorPodAction) Handle(ctx context.Context,
build *v1.Build) (*v
if pod == nil {
switch build.Status.Phase {
case v1.BuildPhasePending:
- pod = newBuildPod(ctx, action.client, build)
+ pod = newBuildPod(build)
if err = controllerutil.SetControllerReference(build,
pod, action.client.GetScheme()); err != nil {
return nil, err
}
diff --git a/pkg/controller/integration/build_kit.go
b/pkg/controller/integration/build_kit.go
index dea015e97..0965f2897 100644
--- a/pkg/controller/integration/build_kit.go
+++ b/pkg/controller/integration/build_kit.go
@@ -102,7 +102,7 @@ kits:
k := &existingKits[i]
action.L.Debug("Comparing existing kit with
environment", "env kit", kit.Name, "existing kit", k.Name)
- match, err := kitMatches(action.client, &kit, k)
+ match, err := kitMatches(&kit, k)
if err != nil {
err = fmt.Errorf("error occurred matches
integration kits with environment for integration %s/%s: %w",
integration.Namespace, integration.Name, err)
integration.Status.Phase =
v1.IntegrationPhaseError
diff --git a/pkg/controller/integration/integration_controller.go
b/pkg/controller/integration/integration_controller.go
index 85570d97f..86a8f8bab 100644
--- a/pkg/controller/integration/integration_controller.go
+++ b/pkg/controller/integration/integration_controller.go
@@ -91,7 +91,7 @@ func newReconciler(mgr manager.Manager, c client.Client)
reconcile.Reconciler {
)
}
-func integrationUpdateFunc(c client.Client, old *v1.Integration, it
*v1.Integration) bool {
+func integrationUpdateFunc(old *v1.Integration, it *v1.Integration) bool {
// Observe the time to first readiness metric
previous := old.Status.GetCondition(v1.IntegrationConditionReady)
next := it.Status.GetCondition(v1.IntegrationConditionReady)
@@ -110,7 +110,7 @@ func integrationUpdateFunc(c client.Client, old
*v1.Integration, it *v1.Integrat
updateIntegrationPhase(it.Name, string(it.Status.Phase))
// If traits have changed, the reconciliation loop must kick in as
// traits may have impact
- sameTraits, err := trait.IntegrationsHaveSameTraits(c, old, it)
+ sameTraits, err := trait.IntegrationsHaveSameTraits(old, it)
if err != nil {
Log.ForIntegration(it).Error(
err,
@@ -292,7 +292,7 @@ func add(mgr manager.Manager, c client.Client, r
reconcile.Reconciler) error {
return false
}
- return integrationUpdateFunc(c, old, it)
+ return integrationUpdateFunc(old, it)
},
DeleteFunc: func(e event.DeleteEvent) bool {
// Evaluates to false if the object has
been confirmed deleted
diff --git a/pkg/controller/integration/kits.go
b/pkg/controller/integration/kits.go
index 5dd9c929f..1775cee75 100644
--- a/pkg/controller/integration/kits.go
+++ b/pkg/controller/integration/kits.go
@@ -126,11 +126,11 @@ func integrationMatches(ctx context.Context, c
client.Client, integration *v1.In
return false, err
}
- itc, err := trait.NewSpecTraitsOptionsForIntegrationAndPlatform(c,
integration, itp, pl)
+ itc, err :=
trait.NewSpecTraitsOptionsForIntegrationAndPlatform(integration, itp, pl)
if err != nil {
return false, err
}
- ikc, err := trait.NewSpecTraitsOptionsForIntegrationKit(c, kit)
+ ikc, err := trait.NewSpecTraitsOptionsForIntegrationKit(kit)
if err != nil {
return false, err
}
@@ -179,7 +179,7 @@ func statusMatches(integration *v1.Integration, kit
*v1.IntegrationKit, ilog *lo
}
// kitMatches returns whether the kit matches with the existing target kit.
-func kitMatches(c client.Client, kit *v1.IntegrationKit, target
*v1.IntegrationKit) (bool, error) {
+func kitMatches(kit *v1.IntegrationKit, target *v1.IntegrationKit) (bool,
error) {
version := kit.Labels[kubernetes.CamelLabelRuntimeVersion]
if version != target.Status.RuntimeVersion {
return false, nil
@@ -189,11 +189,11 @@ func kitMatches(c client.Client, kit *v1.IntegrationKit,
target *v1.IntegrationK
}
// We cannot have yet the status set
- c1, err := trait.NewSpecTraitsOptionsForIntegrationKit(c, kit)
+ c1, err := trait.NewSpecTraitsOptionsForIntegrationKit(kit)
if err != nil {
return false, err
}
- c2, err := trait.NewSpecTraitsOptionsForIntegrationKit(c, target)
+ c2, err := trait.NewSpecTraitsOptionsForIntegrationKit(target)
if err != nil {
return false, err
}
diff --git a/pkg/controller/integration/kits_test.go
b/pkg/controller/integration/kits_test.go
index c7f44b43c..ed7d07e3c 100644
--- a/pkg/controller/integration/kits_test.go
+++ b/pkg/controller/integration/kits_test.go
@@ -25,7 +25,6 @@ import (
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait"
- "github.com/apache/camel-k/v2/pkg/client"
"github.com/apache/camel-k/v2/pkg/trait"
@@ -260,10 +259,7 @@ func TestHasMatchingTraits_KitNoTraitShouldNotBePicked(t
*testing.T) {
},
}
- c, err := internal.NewFakeClient(integration, kit)
- require.NoError(t, err)
-
- ok, err := integrationAndKitHaveSameTraits(c, integration, kit)
+ ok, err := integrationAndKitHaveSameTraits(integration, kit)
require.NoError(t, err)
assert.False(t, ok)
}
@@ -310,9 +306,8 @@ func TestHasMatchingTraits_KitSameTraitShouldBePicked(t
*testing.T) {
},
},
}
- c, err := internal.NewFakeClient(integration, kit)
- require.NoError(t, err)
- ok, err := integrationAndKitHaveSameTraits(c, integration, kit)
+
+ ok, err := integrationAndKitHaveSameTraits(integration, kit)
require.NoError(t, err)
assert.True(t, ok)
}
@@ -414,12 +409,12 @@ func TestHasNotMatchingSources(t *testing.T) {
assert.False(t, hsm2)
}
-func integrationAndKitHaveSameTraits(c client.Client, i1 *v1.Integration, i2
*v1.IntegrationKit) (bool, error) {
- itOpts, err := trait.NewSpecTraitsOptionsForIntegration(c, i1)
+func integrationAndKitHaveSameTraits(i1 *v1.Integration, i2
*v1.IntegrationKit) (bool, error) {
+ itOpts, err := trait.NewSpecTraitsOptionsForIntegration(i1)
if err != nil {
return false, err
}
- ikOpts, err := trait.NewSpecTraitsOptionsForIntegrationKit(c, i2)
+ ikOpts, err := trait.NewSpecTraitsOptionsForIntegrationKit(i2)
if err != nil {
return false, err
}
diff --git a/pkg/controller/integration/monitor.go
b/pkg/controller/integration/monitor.go
index 48f7ac63b..8fb4197fc 100644
--- a/pkg/controller/integration/monitor.go
+++ b/pkg/controller/integration/monitor.go
@@ -23,7 +23,6 @@ import (
"fmt"
"reflect"
"strconv"
- "strings"
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
@@ -137,33 +136,10 @@ func (action *monitorAction) Handle(ctx context.Context,
integration *v1.Integra
return integration, err
}
- action.checkTraitAnnotationsDeprecatedNotice(integration)
return action.monitorPods(ctx, environment, integration)
}
-// Deprecated: to be removed in future versions, when we won't support any
longer trait annotations into Integrations.
-func (action *monitorAction) checkTraitAnnotationsDeprecatedNotice(integration
*v1.Integration) {
- if integration.Annotations != nil {
- for k := range integration.Annotations {
- if strings.HasPrefix(k, v1.TraitAnnotationPrefix) {
- integration.Status.SetCondition(
-
v1.IntegrationConditionType("AnnotationTraitsDeprecated"),
- corev1.ConditionTrue,
- "DeprecationNotice",
- "Annotation traits configuration is
deprecated and will be removed soon. Use .spec.traits configuration instead.",
- )
- action.L.Infof(
- "WARN: annotation traits configuration
is deprecated and will be removed soon. Use .spec.traits configuration for %s
integration instead.",
- integration.Name,
- )
-
- return
- }
- }
- }
-}
-
func (action *monitorAction) monitorPods(ctx context.Context, environment
*trait.Environment, integration *v1.Integration) (*v1.Integration, error) {
controller, err := action.newController(environment, integration)
if err != nil {
diff --git a/pkg/controller/integrationkit/monitor.go
b/pkg/controller/integrationkit/monitor.go
index c75f9fd3f..45f6a487b 100644
--- a/pkg/controller/integrationkit/monitor.go
+++ b/pkg/controller/integrationkit/monitor.go
@@ -19,11 +19,9 @@ package integrationkit
import (
"context"
- "strings"
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
"github.com/apache/camel-k/v2/pkg/util/digest"
- corev1 "k8s.io/api/core/v1"
)
// NewMonitorAction creates a new monitoring handling action for the kit.
@@ -66,30 +64,5 @@ func (action *monitorAction) Handle(ctx context.Context, kit
*v1.IntegrationKit)
return kit, nil
}
- action.checkTraitAnnotationsDeprecatedNotice(kit)
-
return nil, nil
}
-
-// Deprecated: to be removed in future versions, when we won't support any
longer trait annotations into IntegrationKits.
-func (action *monitorAction)
checkTraitAnnotationsDeprecatedNotice(integrationKit *v1.IntegrationKit) {
- if integrationKit.Annotations != nil {
- for k := range integrationKit.Annotations {
- if strings.HasPrefix(k, v1.TraitAnnotationPrefix) {
- integrationKit.Status.SetCondition(
-
v1.IntegrationKitConditionType("AnnotationTraitsDeprecated"),
- corev1.ConditionTrue,
- "DeprecationNotice",
- "Annotation traits configuration is
deprecated and will be removed soon. Use .spec.traits configuration instead.",
- )
-
- action.L.Infof(
- "WARN: annotation traits configuration
is deprecated and will be removed soon. Use .spec.traits configuration for %s
integration kit instead.",
- integrationKit.Name,
- )
-
- return
- }
- }
- }
-}
diff --git a/pkg/controller/integrationplatform/monitor.go
b/pkg/controller/integrationplatform/monitor.go
index b51736666..250ce8ac8 100644
--- a/pkg/controller/integrationplatform/monitor.go
+++ b/pkg/controller/integrationplatform/monitor.go
@@ -20,7 +20,6 @@ package integrationplatform
import (
"context"
"fmt"
- "strings"
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
platformutil "github.com/apache/camel-k/v2/pkg/platform"
@@ -111,7 +110,6 @@ func (action *monitorAction) Handle(ctx context.Context,
platform *v1.Integratio
}
}
- action.checkTraitAnnotationsDeprecatedNotice(platform)
action.checkMavenSettings(platform)
action.checkKameletsCatalogRepoDeprecatedNotice(platform)
@@ -125,28 +123,6 @@ func (action *monitorAction) Handle(ctx context.Context,
platform *v1.Integratio
return platform, nil
}
-// Deprecated: to be removed in future versions, when we won't support any
longer trait annotations into IntegrationPlatforms.
-func (action *monitorAction) checkTraitAnnotationsDeprecatedNotice(platform
*v1.IntegrationPlatform) {
- if platform.Annotations != nil {
- for k := range platform.Annotations {
- if strings.HasPrefix(k, v1.TraitAnnotationPrefix) {
- platform.Status.SetCondition(
-
v1.IntegrationPlatformConditionType("AnnotationTraitsDeprecated"),
- corev1.ConditionTrue,
- "DeprecationNotice",
- "Annotation traits configuration is
deprecated and will be removed soon. Use .spec.traits configuration instead.",
- )
- action.L.Infof(
- "WARN: annotation traits configuration
is deprecated and will be removed soon. Use .spec.traits configuration for %s
platform instead.",
- platform.Name,
- )
-
- return
- }
- }
- }
-}
-
// Deprecated: to be removed in future versions, when we won't support any
longer Kamelets catalog into IntegrationPlatforms.
func (action *monitorAction) checkKameletsCatalogRepoDeprecatedNotice(platform
*v1.IntegrationPlatform) {
if platform.Status.Kamelet.Repositories != nil {
diff --git a/pkg/controller/pipe/integration.go
b/pkg/controller/pipe/integration.go
index 8c6bc31f4..d44991185 100644
--- a/pkg/controller/pipe/integration.go
+++ b/pkg/controller/pipe/integration.go
@@ -28,7 +28,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
- "github.com/apache/camel-k/v2/pkg/trait"
"github.com/apache/camel-k/v2/pkg/client"
"github.com/apache/camel-k/v2/pkg/platform"
@@ -52,13 +51,6 @@ func CreateIntegrationFor(ctx context.Context, c
client.Client, pipe *v1.Pipe) (
// avoid propagating the icon to the integration as it's heavyweight
and not needed
delete(annotations, v1.AnnotationIcon)
traits := pipe.Spec.Traits
- if traits == nil {
- var err error
- traits, err = extractAndDeleteTraits(c, annotations)
- if err != nil {
- return nil, fmt.Errorf("could not marshal trait
annotations %w", err)
- }
- }
it := v1.Integration{
Namespace: pipe.Namespace,
@@ -233,11 +225,6 @@ func CreateIntegrationFor(ctx context.Context, c
client.Client, pipe *v1.Pipe) (
return &it, nil
}
-// extractAndDeleteTraits will extract the annotation traits into v1.Traits
struct, removing from the value from the input map.
-func extractAndDeleteTraits(c client.Client, annotations map[string]string)
(*v1.Traits, error) {
- return trait.ExtractAndMaybeDeleteTraits(c, annotations, true)
-}
-
func configureBinding(integration *v1.Integration, bindings
...*bindings.Binding) error {
for _, b := range bindings {
if b == nil {
diff --git a/pkg/controller/pipe/integration_test.go
b/pkg/controller/pipe/integration_test.go
index 7dc50710f..97f8beefa 100644
--- a/pkg/controller/pipe/integration_test.go
+++ b/pkg/controller/pipe/integration_test.go
@@ -22,12 +22,10 @@ import (
"testing"
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
- "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait"
"github.com/apache/camel-k/v2/pkg/internal"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
- "k8s.io/utils/ptr"
)
func TestCreateIntegrationForPipe(t *testing.T) {
@@ -266,94 +264,3 @@ func expectedNominalRouteWithDataType(name string) string {
id: binding
`
}
-
-func TestExtractTraitAnnotations(t *testing.T) {
- client, err := internal.NewFakeClient()
- require.NoError(t, err)
- annotations := map[string]string{
- "my-personal-annotation":
"hello",
- v1.TraitAnnotationPrefix + "service.enabled":
"true",
- v1.TraitAnnotationPrefix + "container.image-pull-policy":
"Never",
- v1.TraitAnnotationPrefix + "camel.runtime-version":
"1.2.3",
- v1.TraitAnnotationPrefix + "camel.properties":
`["prop1=1", "prop2=2"]`,
- v1.TraitAnnotationPrefix + "environment.vars":
`["env1=1"]`,
- }
- traits, err := extractAndDeleteTraits(client, annotations)
- require.NoError(t, err)
- assert.Equal(t, ptr.To(true), traits.Service.Enabled)
- assert.Equal(t, corev1.PullNever, traits.Container.ImagePullPolicy)
- assert.Equal(t, "1.2.3", traits.Camel.RuntimeVersion)
- assert.Equal(t, []string{"prop1=1", "prop2=2"}, traits.Camel.Properties)
- assert.Equal(t, []string{"env1=1"}, traits.Environment.Vars)
- assert.Len(t, annotations, 1)
- assert.Empty(t, annotations[v1.TraitAnnotationPrefix+"service.enabled"])
- assert.Empty(t,
annotations[v1.TraitAnnotationPrefix+"container.image-pull-policy"])
- assert.Empty(t,
annotations[v1.TraitAnnotationPrefix+"camel.runtime-version"])
- assert.Empty(t,
annotations[v1.TraitAnnotationPrefix+"camel.properties"])
- assert.Empty(t,
annotations[v1.TraitAnnotationPrefix+"environment.vars"])
- assert.Equal(t, "hello", annotations["my-personal-annotation"])
-}
-
-func TestExtractTraitAnnotationsError(t *testing.T) {
- client, err := internal.NewFakeClient()
- require.NoError(t, err)
- annotations := map[string]string{
- "my-personal-annotation": "hello",
- v1.TraitAnnotationPrefix + "servicefake.bogus": "true",
- }
- traits, err := extractAndDeleteTraits(client, annotations)
- require.Error(t, err)
- assert.Equal(t, "trait servicefake does not exist in catalog",
err.Error())
- assert.Nil(t, traits)
- assert.Len(t, annotations, 2)
-}
-
-func TestExtractTraitAnnotationsEmpty(t *testing.T) {
- client, err := internal.NewFakeClient()
- require.NoError(t, err)
- annotations := map[string]string{
- "my-personal-annotation": "hello",
- }
- traits, err := extractAndDeleteTraits(client, annotations)
- require.NoError(t, err)
- assert.Nil(t, traits)
- assert.Len(t, annotations, 1)
-}
-
-func TestCreateIntegrationTraitsForPipeWithTraitAnnotations(t *testing.T) {
- client, err := internal.NewFakeClient()
- require.NoError(t, err)
-
- pipe := nominalPipe("my-pipe")
- pipe.Annotations[v1.TraitAnnotationPrefix+"service.enabled"] = "true"
-
- it, err := CreateIntegrationFor(context.TODO(), client, &pipe)
- require.NoError(t, err)
- assert.Equal(t, "my-pipe", it.Name)
- assert.Equal(t, "default", it.Namespace)
- assert.Equal(t, map[string]string{
- "my-annotation": "my-annotation-val",
- }, it.Annotations)
- assert.Equal(t, ptr.To(true), it.Spec.Traits.Service.Enabled)
-}
-
-func TestCreateIntegrationTraitsForPipeWithTraitSpec(t *testing.T) {
- client, err := internal.NewFakeClient()
- require.NoError(t, err)
-
- pipe := nominalPipe("my-pipe")
- pipe.Annotations[v1.TraitAnnotationPrefix+"service.enabled"] = "true"
- pipe.Spec.Traits = &v1.Traits{
- Affinity: &trait.AffinityTrait{
- PodAffinityLabels: []string{"my-test-affinity"},
- },
- }
-
- it, err := CreateIntegrationFor(context.TODO(), client, &pipe)
- require.NoError(t, err)
- assert.Equal(t, "my-pipe", it.Name)
- assert.Equal(t, "default", it.Namespace)
- // We don't allow both annotations based and spec based traits
- assert.Nil(t, it.Spec.Traits.Service)
- assert.Equal(t, []string{"my-test-affinity"},
it.Spec.Traits.Affinity.PodAffinityLabels)
-}
diff --git a/pkg/controller/pipe/monitor.go b/pkg/controller/pipe/monitor.go
index 53e29d77d..31f05806e 100644
--- a/pkg/controller/pipe/monitor.go
+++ b/pkg/controller/pipe/monitor.go
@@ -20,7 +20,6 @@ package pipe
import (
"context"
"fmt"
- "strings"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality"
@@ -73,7 +72,7 @@ func (action *monitorAction) Handle(ctx context.Context, pipe
*v1.Pipe) (*v1.Pip
integrationProfileChanged :=
kubernetes.GetIntegrationProfileResource(pipe) != "" &&
(kubernetes.GetIntegrationProfileResource(pipe) !=
kubernetes.GetIntegrationProfileResource(&it))
- sameTraits, err := trait.IntegrationAndPipeSameTraits(action.client,
&it, pipe)
+ sameTraits, err := trait.IntegrationAndPipeSameTraits(&it, pipe)
if err != nil {
return nil, err
}
@@ -162,8 +161,6 @@ func (action *monitorAction) Handle(ctx context.Context,
pipe *v1.Pipe) (*v1.Pip
target.Status.Replicas = it.Status.Replicas
target.Status.Selector = it.Status.Selector
- action.checkTraitAnnotationsDeprecatedNotice(target)
-
return target, nil
}
@@ -197,25 +194,3 @@ func setPipeReadyCondition(kb *v1.Pipe, it
*v1.Integration) {
)
}
}
-
-// Deprecated: to be removed in future versions, when we won't support any
longer trait annotations into Pipes.
-func (action *monitorAction) checkTraitAnnotationsDeprecatedNotice(pipe
*v1.Pipe) {
- if pipe.Annotations != nil {
- for k := range pipe.Annotations {
- if strings.HasPrefix(k, v1.TraitAnnotationPrefix) {
- pipe.Status.SetCondition(
-
v1.PipeConditionType("AnnotationTraitsDeprecated"),
- corev1.ConditionTrue,
- "DeprecationNotice",
- "Annotation traits configuration is
deprecated and will be removed soon. Use .spec.traits configuration instead.",
- )
- action.L.Infof(
- "WARN: annotation traits configuration
is deprecated and will be removed soon. Use .spec.traits configuration for %s
pipe instead.",
- pipe.Name,
- )
-
- return
- }
- }
- }
-}
diff --git a/pkg/controller/pipe/monitor_test.go
b/pkg/controller/pipe/monitor_test.go
index ba2269b2b..55d8677bb 100644
--- a/pkg/controller/pipe/monitor_test.go
+++ b/pkg/controller/pipe/monitor_test.go
@@ -329,54 +329,6 @@ func TestPipeIntegrationCreatingFromPipeCreatingPhase(t
*testing.T) {
assert.Equal(t, "Integration \"my-pipe\" is in \"Creating\" phase",
handledPipe.Status.GetCondition(v1.PipeConditionReady).Message)
}
-func TestPipeIntegrationPipeTraitAnnotations(t *testing.T) {
- pipe := &v1.Pipe{
- TypeMeta: metav1.TypeMeta{
- APIVersion: v1.SchemeGroupVersion.String(),
- Kind: v1.PipeKind,
- },
- ObjectMeta: metav1.ObjectMeta{
- Namespace: "ns",
- Name: "my-pipe",
- Annotations: map[string]string{
- v1.TraitAnnotationPrefix +
"camel.runtime-version": "1.2.3",
- },
- },
- Spec: v1.PipeSpec{
- Source: v1.Endpoint{
- URI: ptr.To("timer:tick"),
- },
- Sink: v1.Endpoint{
- URI: ptr.To("log:info"),
- },
- },
- Status: v1.PipeStatus{
- Phase: v1.PipePhaseCreating,
- },
- }
-
- c, err := internal.NewFakeClient(pipe)
- require.NoError(t, err)
- // We calculate the integration the same way it does the operator
- // as we don't expect it to change in this test.
- it, err := CreateIntegrationFor(context.TODO(), c, pipe)
- require.NoError(t, err)
- it.Status.Phase = v1.IntegrationPhaseBuildingKit
- c, err = internal.NewFakeClient(pipe, it)
- require.NoError(t, err)
-
- a := NewMonitorAction()
- a.InjectLogger(log.Log)
- a.InjectClient(c)
- assert.Equal(t, "monitor", a.Name())
- assert.True(t, a.CanHandle(pipe))
- handledPipe, err := a.Handle(context.TODO(), pipe)
- require.NoError(t, err)
- assert.Equal(t, v1.PipePhaseCreating, handledPipe.Status.Phase)
- assert.Equal(t, corev1.ConditionFalse,
handledPipe.Status.GetCondition(v1.PipeConditionReady).Status)
- assert.Equal(t, "Integration \"my-pipe\" is in \"Creating\" phase",
handledPipe.Status.GetCondition(v1.PipeConditionReady).Message)
-}
-
func TestPipeIntegrationBuildComplete(t *testing.T) {
pipe := &v1.Pipe{
TypeMeta: metav1.TypeMeta{
diff --git a/pkg/controller/pipe/pipe_controller.go
b/pkg/controller/pipe/pipe_controller.go
index b5891c5cf..958f36109 100644
--- a/pkg/controller/pipe/pipe_controller.go
+++ b/pkg/controller/pipe/pipe_controller.go
@@ -47,7 +47,7 @@ import (
// Add creates a new Pipe Controller and adds it to the Manager. The Manager
will set fields on the Controller
// and Start it when the Manager is Started.
func Add(ctx context.Context, mgr manager.Manager, c client.Client) error {
- return add(mgr, newReconciler(mgr, c), c)
+ return add(mgr, newReconciler(mgr, c))
}
func newReconciler(mgr manager.Manager, c client.Client) reconcile.Reconciler {
@@ -69,7 +69,7 @@ func newReconciler(mgr manager.Manager, c client.Client)
reconcile.Reconciler {
)
}
-func add(mgr manager.Manager, r reconcile.Reconciler, c client.Client) error {
+func add(mgr manager.Manager, r reconcile.Reconciler) error {
ctrl, err := controller.New("pipe-controller", mgr,
controller.Options{Reconciler: r})
if err != nil {
return err
@@ -85,7 +85,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler, c
client.Client) error {
UpdateFunc: func(e
event.TypedUpdateEvent[*v1.Pipe]) bool {
// If traits have changed, the
reconciliation loop must kick in as
// traits may have impact
- sameTraits, err :=
trait.PipesHaveSameTraits(c, e.ObjectOld, e.ObjectNew)
+ sameTraits, err :=
trait.PipesHaveSameTraits(e.ObjectOld, e.ObjectNew)
if err != nil {
Log.ForPipe(e.ObjectNew).Error(
err,
diff --git a/pkg/platform/operator.go b/pkg/platform/operator.go
index df2ef9c74..b52d993f5 100644
--- a/pkg/platform/operator.go
+++ b/pkg/platform/operator.go
@@ -61,15 +61,6 @@ func IsCurrentOperatorGlobal() bool {
return false
}
-// GetOperatorWatchNamespace returns the namespace the operator watches.
-func GetOperatorWatchNamespace() string {
- if namespace, envSet :=
os.LookupEnv(OperatorWatchNamespaceEnvVariable); envSet {
- return namespace
- }
-
- return ""
-}
-
// GetOperatorNamespace returns the namespace where the current operator is
located (if set).
func GetOperatorNamespace() string {
if podNamespace, envSet := os.LookupEnv(operatorNamespaceEnvVariable);
envSet {
diff --git a/pkg/resources/resources_support.go
b/pkg/resources/resources_support.go
index d2325037f..2cc69171b 100644
--- a/pkg/resources/resources_support.go
+++ b/pkg/resources/resources_support.go
@@ -53,13 +53,6 @@ func Resource(name string) ([]byte, error) {
return data, file.Close()
}
-// ResourceAsString returns the named resource content as string.
-func ResourceAsString(name string) (string, error) {
- data, err := Resource(name)
-
- return string(data), err
-}
-
// WithPrefix lists all file names that begins with the give path prefix
// If pathPrefix is a path of directories then be sure to end it with a '/'.
func WithPrefix(pathPrefix string) ([]string, error) {
diff --git a/pkg/resources/resources_test.go b/pkg/resources/resources_test.go
index 42bb9cd27..4ec7e9a35 100644
--- a/pkg/resources/resources_test.go
+++ b/pkg/resources/resources_test.go
@@ -83,16 +83,12 @@ func ErrorString(t *testing.T, path string, callable
func(path string) (string,
func TestGetResource(t *testing.T) {
NoErrorAndNotEmptyBytes(t,
"config/manager/operator-service-account.yaml", Resource)
NoErrorAndNotEmptyBytes(t,
"/config/manager/operator-service-account.yaml", Resource)
- NoErrorAndNotEmptyString(t,
"config/manager/operator-service-account.yaml", ResourceAsString)
- NoErrorAndNotEmptyString(t,
"/config/manager/operator-service-account.yaml", ResourceAsString)
NoErrorAndContains(t, "/config/manager",
"config/manager/operator-service-account.yaml", Resources)
}
func TestGetNoResource(t *testing.T) {
ErrorBytes(t, "config/manager/operator-service-account.json", Resource)
ErrorBytes(t, "/config/manager/operator-service-account.json", Resource)
- ErrorString(t, "config/manager/operator-service-account.json",
ResourceAsString)
- ErrorString(t, "/config/manager/operator-service-account.json",
ResourceAsString)
NoErrorAndNotContains(t, "/config/",
"config/manager/operator-service-account.json", Resources)
}
diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go
index 52e5760f5..9f28ca8a7 100644
--- a/pkg/trait/builder.go
+++ b/pkg/trait/builder.go
@@ -290,8 +290,7 @@ func (t *builderTrait) Apply(e *Environment) error {
pipelineTasks = append(pipelineTasks, v1.Task{Package: packageTask})
// Publishing task
- switch e.Platform.PublishStrategy {
- case v1.IntegrationPlatformBuildPublishStrategyJib:
+ if e.Platform.PublishStrategy ==
v1.IntegrationPlatformBuildPublishStrategyJib {
jibTask := v1.Task{Jib: &v1.JibTask{
Name: "jib",
Configuration: *taskConfOrDefault(tasksConf, "jib"),
@@ -329,17 +328,6 @@ func (t *builderTrait) Apply(e *Environment) error {
return nil
}
-func getTag(e *Environment) string {
- if e.IntegrationKit != nil {
- return e.IntegrationKit.ResourceVersion
- }
- if e.Integration != nil {
- return e.Integration.ResourceVersion
- }
-
- return ""
-}
-
// when this trait fails, we must report the failure into the related
IntegrationKit if it affects the success of the Build.
func failIntegrationKit(e *Environment, conditionType
v1.IntegrationKitConditionType, status corev1.ConditionStatus, reason, message
string) error {
if e.IntegrationKit != nil {
diff --git a/pkg/trait/container.go b/pkg/trait/container.go
index c5b081446..32817d46d 100644
--- a/pkg/trait/container.go
+++ b/pkg/trait/container.go
@@ -217,7 +217,7 @@ func (t *containerTrait) configureContainer(e *Environment)
error {
t.configureService(e, &container, knative)
}
t.configureCapabilities(e)
- err := t.setSecurityContext(e, &container)
+ err := t.setSecurityContext(&container)
if err != nil {
return err
}
@@ -340,7 +340,7 @@ func (t *containerTrait) configureCapabilities(e
*Environment) {
}
}
-func (t *containerTrait) setSecurityContext(e *Environment, container
*corev1.Container) error {
+func (t *containerTrait) setSecurityContext(container *corev1.Container) error
{
sc := corev1.SecurityContext{
RunAsNonRoot: t.getRunAsNonRoot(),
SeccompProfile: &corev1.SeccompProfile{
@@ -350,23 +350,18 @@ func (t *containerTrait) setSecurityContext(e
*Environment, container *corev1.Co
Capabilities: &corev1.Capabilities{Drop:
t.getCapabilitiesDrop(), Add: t.CapabilitiesAdd},
}
- runAsUser, err := t.getUser(e)
- if err != nil {
- return err
- }
-
- sc.RunAsUser = runAsUser
+ sc.RunAsUser = t.getUser()
container.SecurityContext = &sc
return nil
}
-func (t *containerTrait) getUser(e *Environment) (*int64, error) {
+func (t *containerTrait) getUser() *int64 {
if t.RunAsUser != nil {
- return t.RunAsUser, nil
+ return t.RunAsUser
}
- return nil, nil
+ return nil
}
func (t *containerTrait) isExpose() bool {
diff --git a/pkg/trait/pull_secret.go b/pkg/trait/pull_secret.go
index 25d324db6..d4de27ea3 100644
--- a/pkg/trait/pull_secret.go
+++ b/pkg/trait/pull_secret.go
@@ -50,7 +50,6 @@ func newPullSecretTrait() Trait {
func (t *pullSecretTrait) Configure(e *Environment) (bool, *TraitCondition,
error) {
var condition *TraitCondition
- var err error
if e.Integration == nil {
return false, condition, nil
}
@@ -62,10 +61,7 @@ func (t *pullSecretTrait) Configure(e *Environment) (bool,
*TraitCondition, erro
}
if ptr.Deref(t.Auto, true) {
- condition, err = t.autoConfigure(e)
- if err != nil {
- return false, condition, err
- }
+ condition = t.autoConfigure(e)
}
if t.SecretName != "" {
@@ -77,7 +73,7 @@ func (t *pullSecretTrait) Configure(e *Environment) (bool,
*TraitCondition, erro
return t.secretName != "" ||
ptr.Deref(t.deprecatedImagePullerDelegation, false), condition, nil
}
-func (t *pullSecretTrait) autoConfigure(e *Environment) (*TraitCondition,
error) {
+func (t *pullSecretTrait) autoConfigure(e *Environment) *TraitCondition {
var condition *TraitCondition
if t.SecretName == "" && e.Platform.Registry.Secret != "" {
@@ -94,7 +90,7 @@ func (t *pullSecretTrait) autoConfigure(e *Environment)
(*TraitCondition, error)
)
}
- return condition, nil
+ return condition
}
func (t *pullSecretTrait) Apply(e *Environment) error {
diff --git a/pkg/trait/security_context.go b/pkg/trait/security_context.go
index 28b0f4e30..a2da122d9 100644
--- a/pkg/trait/security_context.go
+++ b/pkg/trait/security_context.go
@@ -76,10 +76,10 @@ func (t *securityContextTrait) Apply(e *Environment) error {
return fmt.Errorf("could not find any integration deployment
for %v", e.Integration.Name)
}
- return t.setSecurityContext(e, podSpec)
+ return t.setSecurityContext(podSpec)
}
-func (t *securityContextTrait) setSecurityContext(e *Environment, podSpec
*corev1.PodSpec) error {
+func (t *securityContextTrait) setSecurityContext(podSpec *corev1.PodSpec)
error {
sc := corev1.PodSecurityContext{
RunAsNonRoot: t.getRunAsNonRoot(),
SeccompProfile: &corev1.SeccompProfile{
@@ -87,23 +87,18 @@ func (t *securityContextTrait) setSecurityContext(e
*Environment, podSpec *corev
},
}
- runAsUser, err := t.getUser(e)
- if err != nil {
- return err
- }
-
- sc.RunAsUser = runAsUser
+ sc.RunAsUser = t.getUser()
podSpec.SecurityContext = &sc
return nil
}
-func (t *securityContextTrait) getUser(e *Environment) (*int64, error) {
+func (t *securityContextTrait) getUser() *int64 {
if t.RunAsUser != nil {
- return t.RunAsUser, nil
+ return t.RunAsUser
}
- return new(defaults.DefaultPodRunAsUser), nil
+ return new(defaults.DefaultPodRunAsUser)
}
func (t *securityContextTrait) getRunAsNonRoot() *bool {
diff --git a/pkg/trait/trait_configure.go b/pkg/trait/trait_configure.go
index 73a9f8a9d..bb45c76db 100644
--- a/pkg/trait/trait_configure.go
+++ b/pkg/trait/trait_configure.go
@@ -19,16 +19,8 @@ package trait
import (
"encoding/json"
- "errors"
- "fmt"
- "reflect"
- "strings"
- "github.com/go-viper/mapstructure/v2"
-
- v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
"github.com/apache/camel-k/v2/pkg/platform"
- "github.com/apache/camel-k/v2/pkg/util"
)
// Configure reads trait configurations from environment and applies them to
catalog.
@@ -42,12 +34,8 @@ func (c *Catalog) Configure(env *Environment) error {
if err := c.configureTraits(env.IntegrationKit.Spec.Traits);
err != nil {
return err
}
- // Deprecated: to be removed in future version
- if err :=
c.configureTraitsFromAnnotations(env.IntegrationKit.Annotations); err != nil {
- return err
- }
}
- //nolint:nestif
+
if env.Integration != nil {
ip, err := platform.GetForResource(env.Ctx, env.Client,
env.Integration)
if ip != nil && err == nil {
@@ -59,10 +47,6 @@ func (c *Catalog) Configure(env *Environment) error {
if err := c.configureTraits(env.Integration.Spec.Traits); err
!= nil {
return err
}
- // Deprecated: to be removed in future version
- if err :=
c.configureTraitsFromAnnotations(env.Integration.Annotations); err != nil {
- return err
- }
}
return nil
@@ -106,94 +90,3 @@ func decodeTrait(in map[string]any, target Trait) error {
return json.Unmarshal(data, target)
}
-
-// Deprecated: to be removed in future versions.
-func (c *Catalog) configureTraitsFromAnnotations(annotations
map[string]string) error {
- options := make(map[string]map[string]any, len(annotations))
- for k, v := range annotations {
- if !strings.HasPrefix(k, v1.TraitAnnotationPrefix) {
- continue
- }
-
- configKey := strings.TrimPrefix(k, v1.TraitAnnotationPrefix)
- if !strings.Contains(configKey, ".") {
- return fmt.Errorf("wrong format for trait annotation
%q: missing trait ID", k)
- }
-
- parts := strings.SplitN(configKey, ".", 2)
- id := parts[0]
- prop := parts[1]
- if _, ok := options[id]; !ok {
- options[id] = make(map[string]any)
- }
-
- propParts := util.ConfigTreePropertySplit(prop)
- var current = options[id]
- if len(propParts) > 1 {
- c, err := util.NavigateConfigTree(current,
propParts[0:len(propParts)-1])
- if err != nil {
- return err
- }
- if cc, ok := c.(map[string]any); ok {
- current = cc
- } else {
- return errors.New(`invalid array specification:
to set an array value use the ["v1", "v2"] format`)
- }
- }
- current[prop] = v
- }
-
- return c.configureFromOptions(options)
-}
-
-// Deprecated: to be removed in future versions.
-func (c *Catalog) configureFromOptions(traits map[string]map[string]any) error
{
- for id, config := range traits {
- t := c.GetTrait(id)
- if t != nil {
- err := configureTrait(id, config, t)
- if err != nil {
- return err
- }
- }
- }
-
- return nil
-}
-
-// Deprecated: to be removed in future versions.
-func configureTrait(id string, config map[string]any, trait any) error {
- md := mapstructure.Metadata{}
-
- var valueConverter mapstructure.DecodeHookFuncKind = func(sourceKind
reflect.Kind, targetKind reflect.Kind, data any) (any, error) {
- // Allow JSON encoded arrays to set slices
- if sourceKind == reflect.String && targetKind == reflect.Slice {
- if v, ok := data.(string); ok && strings.HasPrefix(v,
"[") && strings.HasSuffix(v, "]") {
- var value any
- if err := json.Unmarshal([]byte(v), &value);
err != nil {
- return nil, fmt.Errorf("could not
decode JSON array for configuring trait property: %w", err)
- }
-
- return value, nil
- }
- }
-
- return data, nil
- }
-
- decoder, err := mapstructure.NewDecoder(
- &mapstructure.DecoderConfig{
- Metadata: &md,
- DecodeHook: valueConverter,
- WeaklyTypedInput: true,
- TagName: "property",
- Result: &trait,
- ErrorUnused: true,
- },
- )
- if err != nil {
- return fmt.Errorf("error while decoding trait configuration %q:
%w", id, err)
- }
-
- return decoder.Decode(config)
-}
diff --git a/pkg/trait/trait_configure_test.go
b/pkg/trait/trait_configure_test.go
index 35b2de12d..707e29d01 100644
--- a/pkg/trait/trait_configure_test.go
+++ b/pkg/trait/trait_configure_test.go
@@ -24,13 +24,11 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait"
"github.com/apache/camel-k/v2/pkg/internal"
- "github.com/apache/camel-k/v2/pkg/util/boolean"
)
func TestTraitConfiguration(t *testing.T) {
@@ -67,96 +65,3 @@ func TestTraitConfiguration(t *testing.T) {
assert.True(t, *service.Enabled)
assert.True(t, *service.Auto)
}
-
-func TestTraitConfigurationFromAnnotations(t *testing.T) {
- cl, err := internal.NewFakeClient()
- require.NoError(t, err)
- env := Environment{
- Ctx: context.Background(),
- Client: cl,
- Integration: &v1.Integration{
- ObjectMeta: metav1.ObjectMeta{
- Annotations: map[string]string{
- v1.TraitAnnotationPrefix +
"cron.concurrency-policy": "annotated-policy",
- v1.TraitAnnotationPrefix +
"environment.container-meta": boolean.TrueString,
- },
- },
- Spec: v1.IntegrationSpec{
- Traits: v1.Traits{
- Cron: &traitv1.CronTrait{
- Fallback: ptr.To(true),
- ConcurrencyPolicy: "mypolicy",
- },
- },
- },
- },
- }
- c := NewCatalog(nil)
- require.NoError(t, c.Configure(&env))
- ct, _ := c.GetTrait("cron").(*cronTrait)
- assert.True(t, *ct.Fallback)
- assert.Equal(t, "annotated-policy", ct.ConcurrencyPolicy)
- et, _ := c.GetTrait("environment").(*environmentTrait)
- assert.True(t, *et.ContainerMeta)
-}
-
-func TestFailOnWrongTraitAnnotations(t *testing.T) {
- cl, err := internal.NewFakeClient()
- require.NoError(t, err)
- env := Environment{
- Ctx: context.Background(),
- Client: cl,
- Integration: &v1.Integration{
- ObjectMeta: metav1.ObjectMeta{
- Annotations: map[string]string{
- v1.TraitAnnotationPrefix +
"cron.missing-property": "the-value",
- },
- },
- },
- }
- c := NewCatalog(nil)
- assert.Error(t, c.Configure(&env))
-}
-
-func TestTraitListConfigurationFromAnnotations(t *testing.T) {
- cl, err := internal.NewFakeClient()
- require.NoError(t, err)
- env := Environment{
- Ctx: context.Background(),
- Client: cl,
- Integration: &v1.Integration{
- ObjectMeta: metav1.ObjectMeta{
- Annotations: map[string]string{
- v1.TraitAnnotationPrefix +
"environment.vars": `["V1=a", "V2=b"]`,
- v1.TraitAnnotationPrefix +
"camel.runtime-version": "1.2.3",
- },
- },
- },
- }
- c := NewCatalog(nil)
- require.NoError(t, c.Configure(&env))
- et, _ := c.GetTrait("environment").(*environmentTrait)
- assert.Equal(t, []string{"V1=a", "V2=b"}, et.Vars)
- cml, _ := c.GetTrait("camel").(*camelTrait)
- assert.Equal(t, "1.2.3", cml.RuntimeVersion)
-}
-
-func TestTraitSplitConfiguration(t *testing.T) {
- cl, err := internal.NewFakeClient()
- require.NoError(t, err)
- env := Environment{
- Ctx: context.Background(),
- Client: cl,
- Integration: &v1.Integration{
- ObjectMeta: metav1.ObjectMeta{
- Annotations: map[string]string{
- v1.TraitAnnotationPrefix +
"owner.target-labels": "[\"opt1\", \"opt2\"]",
- },
- },
- },
- }
- c := NewCatalog(nil)
- require.NoError(t, c.Configure(&env))
- ot, _ := c.GetTrait("owner").(*ownerTrait)
- assert.Equal(t, []string{"opt1", "opt2"}, ot.TargetLabels)
-}
diff --git a/pkg/trait/util.go b/pkg/trait/util.go
index 2a7f36d4e..97cbe1873 100644
--- a/pkg/trait/util.go
+++ b/pkg/trait/util.go
@@ -22,7 +22,6 @@ import (
"encoding/json"
"errors"
"fmt"
- "maps"
"reflect"
"regexp"
"strings"
@@ -254,12 +253,12 @@ func Equals(i1 Options, i2 Options) bool {
}
// IntegrationsHaveSameTraits return if traits are the same.
-func IntegrationsHaveSameTraits(c client.Client, i1 *v1.Integration, i2
*v1.Integration) (bool, error) {
- c1, err := NewSpecTraitsOptionsForIntegration(c, i1)
+func IntegrationsHaveSameTraits(i1 *v1.Integration, i2 *v1.Integration) (bool,
error) {
+ c1, err := NewSpecTraitsOptionsForIntegration(i1)
if err != nil {
return false, err
}
- c2, err := NewSpecTraitsOptionsForIntegration(c, i2)
+ c2, err := NewSpecTraitsOptionsForIntegration(i2)
if err != nil {
return false, err
}
@@ -268,12 +267,12 @@ func IntegrationsHaveSameTraits(c client.Client, i1
*v1.Integration, i2 *v1.Inte
}
// PipesHaveSameTraits return if traits are the same.
-func PipesHaveSameTraits(c client.Client, i1 *v1.Pipe, i2 *v1.Pipe) (bool,
error) {
- c1, err := NewTraitsOptionsForPipe(c, i1)
+func PipesHaveSameTraits(i1 *v1.Pipe, i2 *v1.Pipe) (bool, error) {
+ c1, err := NewTraitsOptionsForPipe(i1)
if err != nil {
return false, err
}
- c2, err := NewTraitsOptionsForPipe(c, i2)
+ c2, err := NewTraitsOptionsForPipe(i2)
if err != nil {
return false, err
}
@@ -284,12 +283,12 @@ func PipesHaveSameTraits(c client.Client, i1 *v1.Pipe, i2
*v1.Pipe) (bool, error
// IntegrationAndPipeSameTraits return if traits are the same.
// The comparison is done for the subset of traits defines on the binding as
during the trait processing,
// some traits may be added to the Integration i.e. knative configuration in
case of sink binding.
-func IntegrationAndPipeSameTraits(c client.Client, i1 *v1.Integration, i2
*v1.Pipe) (bool, error) {
- itOpts, err := NewSpecTraitsOptionsForIntegration(c, i1)
+func IntegrationAndPipeSameTraits(i1 *v1.Integration, i2 *v1.Pipe) (bool,
error) {
+ itOpts, err := NewSpecTraitsOptionsForIntegration(i1)
if err != nil {
return false, err
}
- klbOpts, err := NewTraitsOptionsForPipe(c, i2)
+ klbOpts, err := NewTraitsOptionsForPipe(i2)
if err != nil {
return false, err
}
@@ -303,85 +302,10 @@ func IntegrationAndPipeSameTraits(c client.Client, i1
*v1.Integration, i2 *v1.Pi
return Equals(klbOpts, toCompare), nil
}
-// newTraitsOptions will merge the traits annotations with the traits spec
using the same format.
-func newTraitsOptions(c client.Client, opts Options, annotations
map[string]string) (Options, error) {
- annotationTraits, err := ExtractAndMaybeDeleteTraits(c, annotations,
false)
- if err != nil {
- return nil, err
- }
- if annotationTraits == nil {
- return opts, nil
- }
-
- m2, err := ToTraitMap(*annotationTraits)
- if err != nil {
- return nil, err
- }
-
- maps.Copy(opts, m2)
-
- return opts, nil
-}
-
-// ExtractAndMaybeDeleteTraits will extract the annotation traits into
v1.Traits struct, removing from the value from the input map.
-func ExtractAndMaybeDeleteTraits(c client.Client, annotations
map[string]string, del bool) (*v1.Traits, error) {
- // structure that will be marshalled into a v1.Traits as it was a kamel
run command
- catalog := NewCatalog(c)
- traitsPlainParams := []string{}
- for k, v := range annotations {
- //nolint:staticcheck
- if strings.HasPrefix(k, v1.TraitAnnotationPrefix) {
- key := strings.ReplaceAll(k, v1.TraitAnnotationPrefix,
"")
- traitID, _, _ := strings.Cut(key, ".")
- if err := ValidateTrait(catalog, traitID); err != nil {
- return nil, err
- }
- traitArrayParams := extractAsArray(v)
- for _, param := range traitArrayParams {
- traitsPlainParams = append(traitsPlainParams,
fmt.Sprintf("%s=%s", key, param))
- }
- if del {
- delete(annotations, k)
- }
- }
- }
- if len(traitsPlainParams) == 0 {
- return nil, nil
- }
- var traits v1.Traits
- if err := ConfigureTraits(traitsPlainParams, &traits, catalog); err !=
nil {
- return nil, err
- }
-
- return &traits, nil
-}
-
-// extractAsArray can detect if the value is an array representation as
["prop1=1", "prop2=2"] and
-// return an array with the values or with the single value passed as a
parameter.
-func extractAsArray(value string) []string {
- if strings.HasPrefix(value, "[") && strings.HasSuffix(value, "]") {
- var arrayValue []string
- data := value[1 : len(value)-1]
- vals := strings.SplitSeq(data, ",")
- for v := range vals {
- prop := strings.Trim(v, " ")
- if strings.HasPrefix(prop, `"`) &&
strings.HasSuffix(prop, `"`) {
- prop = prop[1 : len(prop)-1]
- }
- arrayValue = append(arrayValue, prop)
- }
-
- return arrayValue
- }
-
- return []string{value}
-}
-
// NewSpecTraitsOptionsForIntegrationAndPlatform will merge traits giving
priority to Integration, Profile and Platform respectively.
//
//nolint:staticcheck
-func NewSpecTraitsOptionsForIntegrationAndPlatform(
- c client.Client, i *v1.Integration, itp *v1.IntegrationProfile, pl
*v1.IntegrationPlatform) (Options, error) {
+func NewSpecTraitsOptionsForIntegrationAndPlatform(i *v1.Integration, itp
*v1.IntegrationProfile, pl *v1.IntegrationPlatform) (Options, error) {
mergedTraits := v1.Traits{}
itpTraits := v1.Traits{}
if pl != nil {
@@ -397,52 +321,18 @@ func NewSpecTraitsOptionsForIntegrationAndPlatform(
return nil, err
}
- options, err := ToTraitMap(mergedTraits)
- if err != nil {
- return nil, err
- }
-
- // Deprecated: to remove when we remove support for traits annotations.
- //
- // IMPORTANT: when we remove this we'll need to remove the
client.Client from the func,
- // which will bring to more cascade removal. It had to be introduced to
support the deprecated feature
- // in a properly manner (ie, comparing the spec.traits with annotations
in a proper way).
- return newTraitsOptions(c, options, i.Annotations)
+ return ToTraitMap(mergedTraits)
}
-func NewSpecTraitsOptionsForIntegration(c client.Client, i *v1.Integration)
(Options, error) {
- m1, err := ToTraitMap(i.Spec.Traits)
- if err != nil {
- return nil, err
- }
-
- // Deprecated: to remove when we remove support for traits annotations.
- //
- // IMPORTANT: when we remove this we'll need to remove the
client.Client from the func,
- // which will bring to more cascade removal. It had to be introduced to
support the deprecated feature
- // in a properly manner (ie, comparing the spec.traits with annotations
in a proper way).
- return newTraitsOptions(c, m1, i.Annotations)
-}
-
-func newTraitsOptionsForIntegrationKit(c client.Client, i *v1.IntegrationKit,
traits v1.IntegrationKitTraits) (Options, error) {
- m1, err := ToTraitMap(traits)
- if err != nil {
- return nil, err
- }
-
- // Deprecated: to remove when we remove support for traits annotations.
- //
- // IMPORTANT: when we remove this we'll need to remove the
client.Client from the func,
- // which will bring to more cascade removal. It had to be introduced to
support the deprecated feature
- // in a properly manner (ie, comparing the spec.traits with annotations
in a proper way).
- return newTraitsOptions(c, m1, i.Annotations)
+func NewSpecTraitsOptionsForIntegration(it *v1.Integration) (Options, error) {
+ return ToTraitMap(it.Spec.Traits)
}
-func NewSpecTraitsOptionsForIntegrationKit(c client.Client, i
*v1.IntegrationKit) (Options, error) {
- return newTraitsOptionsForIntegrationKit(c, i, i.Spec.Traits)
+func NewSpecTraitsOptionsForIntegrationKit(ik *v1.IntegrationKit) (Options,
error) {
+ return ToTraitMap(ik.Spec.Traits)
}
-func NewTraitsOptionsForPipe(c client.Client, pipe *v1.Pipe) (Options, error) {
+func NewTraitsOptionsForPipe(pipe *v1.Pipe) (Options, error) {
options := Options{}
if pipe.Spec.Traits != nil {
@@ -453,7 +343,7 @@ func NewTraitsOptionsForPipe(c client.Client, pipe
*v1.Pipe) (Options, error) {
}
}
- return newTraitsOptions(c, options, pipe.Annotations)
+ return options, nil
}
// HasMatchingTraits verifies if two traits options match.
diff --git a/pkg/trait/util_test.go b/pkg/trait/util_test.go
index 22375020d..b949394fc 100644
--- a/pkg/trait/util_test.go
+++ b/pkg/trait/util_test.go
@@ -20,13 +20,11 @@ package trait
import (
"testing"
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait"
- "github.com/apache/camel-k/v2/pkg/internal"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -137,53 +135,6 @@ func TestToTrait(t *testing.T) {
assert.Equal(t, expected, trait)
}
-func TestSameTraits(t *testing.T) {
- c, err := internal.NewFakeClient()
- require.NoError(t, err)
-
- t.Run("same traits with annotations only", func(t *testing.T) {
- oldKlb := &v1.Pipe{
- ObjectMeta: metav1.ObjectMeta{
- Annotations: map[string]string{
- v1.TraitAnnotationPrefix +
"container.image": "foo/bar:1",
- },
- },
- }
- newKlb := &v1.Pipe{
- ObjectMeta: metav1.ObjectMeta{
- Annotations: map[string]string{
- v1.TraitAnnotationPrefix +
"container.image": "foo/bar:1",
- },
- },
- }
-
- ok, err := PipesHaveSameTraits(c, oldKlb, newKlb)
- require.NoError(t, err)
- assert.True(t, ok)
- })
-
- t.Run("not same traits with annotations only", func(t *testing.T) {
- oldKlb := &v1.Pipe{
- ObjectMeta: metav1.ObjectMeta{
- Annotations: map[string]string{
- v1.TraitAnnotationPrefix +
"container.image": "foo/bar:1",
- },
- },
- }
- newKlb := &v1.Pipe{
- ObjectMeta: metav1.ObjectMeta{
- Annotations: map[string]string{
- v1.TraitAnnotationPrefix +
"container.image": "foo/bar:2",
- },
- },
- }
-
- ok, err := PipesHaveSameTraits(c, oldKlb, newKlb)
- require.NoError(t, err)
- assert.False(t, ok)
- })
-}
-
func TestHasMathchingTraitsEmpty(t *testing.T) {
opt1 := Options{
"builder": {},
@@ -232,9 +183,11 @@ func TestHasMathchingTraitsMissing(t *testing.T) {
func TestIntegrationAndPipeSameTraits(t *testing.T) {
pipe := &v1.Pipe{
- ObjectMeta: metav1.ObjectMeta{
- Annotations: map[string]string{
- v1.TraitAnnotationPrefix +
"camel.runtime-version": "1.2.3",
+ Spec: v1.PipeSpec{
+ Traits: &v1.Traits{
+ Camel: &traitv1.CamelTrait{
+ RuntimeVersion: "1.2.3",
+ },
},
},
}
@@ -248,10 +201,8 @@ func TestIntegrationAndPipeSameTraits(t *testing.T) {
},
},
}
- c, err := internal.NewFakeClient(pipe, integration)
- require.NoError(t, err)
- result, err := IntegrationAndPipeSameTraits(c, integration, pipe)
+ result, err := IntegrationAndPipeSameTraits(integration, pipe)
require.NoError(t, err)
assert.True(t, result)
}
@@ -275,9 +226,7 @@ func TestMergePlatformTraitsIntegrationPriority(t
*testing.T) {
},
}
- c, err := internal.NewFakeClient()
- require.NoError(t, err)
- mergedOptions, err := NewSpecTraitsOptionsForIntegrationAndPlatform(c,
integration, nil, nil)
+ mergedOptions, err :=
NewSpecTraitsOptionsForIntegrationAndPlatform(integration, nil, nil)
require.NoError(t, err)
assert.Equal(t, expectedOptions, mergedOptions)
}
@@ -309,9 +258,7 @@ func TestMergeIntegrationProfileTraits(t *testing.T) {
},
}
- c, err := internal.NewFakeClient()
- require.NoError(t, err)
- mergedOptions, err := NewSpecTraitsOptionsForIntegrationAndPlatform(c,
integration, profile, nil)
+ mergedOptions, err :=
NewSpecTraitsOptionsForIntegrationAndPlatform(integration, profile, nil)
require.NoError(t, err)
assert.Equal(t, expectedOptions, mergedOptions)
}
diff --git a/pkg/util/digest/digest.go b/pkg/util/digest/digest.go
index 54aeb56b3..6abe72787 100644
--- a/pkg/util/digest/digest.go
+++ b/pkg/util/digest/digest.go
@@ -29,7 +29,6 @@ import (
"path/filepath"
"sort"
"strconv"
- "strings"
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
"github.com/apache/camel-k/v2/pkg/util"
@@ -133,14 +132,6 @@ func ComputeForIntegration(integration *v1.Integration,
configmapVersions []stri
return "", err
}
- // Integration traits as annotations
- for _, k := range sortedTraitAnnotationsKeys(integration) {
- v := integration.Annotations[k]
- if _, err := fmt.Fprintf(hash, "%s=%v,", k, v); err != nil {
- return "", err
- }
- }
-
// Configmap versions
for _, cm := range configmapVersions {
if cm != "" {
@@ -307,19 +298,6 @@ func sortedTraitsMapKeys(m map[string]map[string]any)
[]string {
return res
}
-// Deprecated: to be removed in future versions.
-func sortedTraitAnnotationsKeys(it *v1.Integration) []string {
- res := make([]string, 0, len(it.Annotations))
- for k := range it.Annotations {
- if strings.HasPrefix(k, v1.TraitAnnotationPrefix) {
- res = append(res, k)
- }
- }
- sort.Strings(res)
-
- return res
-}
-
func ComputeSHA1(elem ...string) (string, error) {
file := filepath.Join(elem...)
diff --git a/pkg/util/digest/digest_test.go b/pkg/util/digest/digest_test.go
index 38a89ac33..882ec33fc 100644
--- a/pkg/util/digest/digest_test.go
+++ b/pkg/util/digest/digest_test.go
@@ -40,14 +40,6 @@ func TestDigestUsesAnnotations(t *testing.T) {
digest2, err := ComputeForIntegration(&it, nil, nil)
require.NoError(t, err)
assert.Equal(t, digest1, digest2)
-
- it.Annotations = map[string]string{
- "another.annotation": "hello",
- v1.TraitAnnotationPrefix + "cron.fallback": "true",
- }
- digest3, err := ComputeForIntegration(&it, nil, nil)
- require.NoError(t, err)
- assert.NotEqual(t, digest1, digest3)
}
func TestDigestSHA1FromTempFile(t *testing.T) {
diff --git a/pkg/util/kubernetes/loader.go b/pkg/util/kubernetes/loader.go
deleted file mode 100644
index f5712df62..000000000
--- a/pkg/util/kubernetes/loader.go
+++ /dev/null
@@ -1,70 +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 kubernetes
-
-import (
- "fmt"
-
- "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
- "k8s.io/apimachinery/pkg/runtime"
- "k8s.io/apimachinery/pkg/runtime/serializer"
- "k8s.io/apimachinery/pkg/util/yaml"
-
- ctrl "sigs.k8s.io/controller-runtime/pkg/client"
-)
-
-// LoadResourceFromYaml returns a Kubernetes resource from its serialized YAML
definition.
-func LoadResourceFromYaml(scheme *runtime.Scheme, data string) (ctrl.Object,
error) {
- source := []byte(data)
- jsonSource, err := yaml.ToJSON(source)
- if err != nil {
- return nil, err
- }
- u := unstructured.Unstructured{}
- err = u.UnmarshalJSON(jsonSource)
- if err != nil {
- return nil, err
- }
- ro, err := runtimeObjectFromUnstructured(scheme, &u)
- if err != nil {
- return nil, err
- }
- o, ok := ro.(ctrl.Object)
- if !ok {
- return nil, fmt.Errorf("type assertion failed: %v", ro)
- }
-
- return o, nil
-}
-
-func runtimeObjectFromUnstructured(scheme *runtime.Scheme, u
*unstructured.Unstructured) (runtime.Object, error) {
- gvk := u.GroupVersionKind()
- codecs := serializer.NewCodecFactory(scheme)
- decoder := codecs.UniversalDecoder(gvk.GroupVersion())
-
- b, err := u.MarshalJSON()
- if err != nil {
- return nil, fmt.Errorf("error running MarshalJSON on
unstructured object: %w", err)
- }
- ro, _, err := decoder.Decode(b, &gvk, nil)
- if err != nil {
- return nil, fmt.Errorf("failed to decode json data with
gvk(%v): %w", gvk.String(), err)
- }
-
- return ro, nil
-}
diff --git a/pkg/util/kubernetes/permission.go
b/pkg/util/kubernetes/permission.go
index 7e2870aec..bafd5624e 100644
--- a/pkg/util/kubernetes/permission.go
+++ b/pkg/util/kubernetes/permission.go
@@ -26,34 +26,6 @@ import (
"k8s.io/client-go/kubernetes"
)
-// CheckSelfPermission can be used to check if the current
user/service-account is allowed to execute a given operation
-// in the cluster.
-// E.g. checkPermission(client, olmv1alpha1.GroupName,
"clusterserviceversions", namespace, "camel-k", "get").
-func CheckSelfPermission(ctx context.Context, client kubernetes.Interface,
group, resource, namespace, name, verb string) (bool, error) {
- sarReview := &authorizationv1.SelfSubjectAccessReview{
- Spec: authorizationv1.SelfSubjectAccessReviewSpec{
- ResourceAttributes: &authorizationv1.ResourceAttributes{
- Group: group,
- Resource: resource,
- Namespace: namespace,
- Name: name,
- Verb: verb,
- },
- },
- }
-
- sar, err :=
client.AuthorizationV1().SelfSubjectAccessReviews().Create(ctx, sarReview,
metav1.CreateOptions{})
- if err != nil {
- if k8serrors.IsForbidden(err) {
- return false, nil
- }
-
- return false, err
- }
-
- return sar.Status.Allowed, nil
-}
-
// CheckServiceAccountPermission verify if a given Service Account can access
a given resource.
// Service Account must be provided as "system:serviceaccount:namespace:name"
format.
func CheckServiceAccountPermission(ctx context.Context, client
kubernetes.Interface, sa, group, resource, namespace, name, verb string) (bool,
error) {
diff --git a/pkg/util/resource/config.go b/pkg/util/resource/config.go
index 13ad080be..9a65f351b 100644
--- a/pkg/util/resource/config.go
+++ b/pkg/util/resource/config.go
@@ -20,7 +20,6 @@ package resource
import (
"fmt"
"regexp"
- "strings"
)
// Config represents a config option.
@@ -111,17 +110,6 @@ func newConfig(storageType StorageType, contentType
ContentType, value string) *
}
}
-// ParseFileValue will parse a file resource/config option to return the local
path and the
-// destination path expected.
-func ParseFileValue(value string) (string, string) {
- split := strings.SplitN(value, "@", 2)
- if len(split) == 2 {
- return split[0], split[1]
- }
-
- return value, ""
-}
-
func parseCMOrSecretValue(value string) (string, string, string) {
if !validResourceRegexp.MatchString(value) {
return value, "", ""