This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit aecb231de18c7cc519c9d6fd6f57aae588d698e7
Author: Antonin Stefanutti <[email protected]>
AuthorDate: Fri Aug 27 11:15:51 2021 +0200

    chore(trait): Remove trait context and the InjectContext interface
---
 addons/master/master.go                    |  4 ++--
 addons/tracing/tracing.go                  |  2 +-
 cmd/util/doc-gen/generators/traitdocgen.go | 12 ++---------
 pkg/cmd/completion_bash.go                 |  9 +++-----
 pkg/cmd/kit_create.go                      |  2 +-
 pkg/cmd/run.go                             |  2 +-
 pkg/cmd/run_test.go                        |  2 +-
 pkg/cmd/trait_help.go                      |  4 ++--
 pkg/controller/integration/build_kit.go    |  2 +-
 pkg/trait/builder.go                       |  2 +-
 pkg/trait/builder_test.go                  |  6 +++---
 pkg/trait/camel.go                         |  6 +++---
 pkg/trait/camel_test.go                    |  2 +-
 pkg/trait/container_test.go                | 16 +++++++-------
 pkg/trait/cron.go                          |  2 +-
 pkg/trait/cron_test.go                     | 21 +++++++++---------
 pkg/trait/dependencies.go                  |  2 +-
 pkg/trait/deployer.go                      |  8 +++----
 pkg/trait/deployer_test.go                 |  3 +--
 pkg/trait/deployment_test.go               |  3 +--
 pkg/trait/environment_test.go              |  9 ++++----
 pkg/trait/gc_test.go                       |  3 +--
 pkg/trait/ingress_test.go                  |  3 +--
 pkg/trait/jolokia_test.go                  |  3 +--
 pkg/trait/jvm.go                           |  2 +-
 pkg/trait/jvm_test.go                      |  4 +---
 pkg/trait/kamelets.go                      |  8 +++----
 pkg/trait/kamelets_test.go                 |  4 +---
 pkg/trait/knative.go                       | 16 +++++++-------
 pkg/trait/knative_service.go               |  4 ++--
 pkg/trait/knative_service_test.go          |  7 +++---
 pkg/trait/knative_test.go                  | 15 ++++++-------
 pkg/trait/logging_test.go                  |  6 +++---
 pkg/trait/openapi.go                       | 10 ++++-----
 pkg/trait/platform.go                      |  2 +-
 pkg/trait/prometheus_test.go               |  3 +--
 pkg/trait/pull_secret.go                   |  4 ++--
 pkg/trait/pull_secret_test.go              |  4 ++--
 pkg/trait/route_test.go                    |  3 +--
 pkg/trait/service.go                       |  2 +-
 pkg/trait/service_binding.go               |  2 +-
 pkg/trait/service_test.go                  | 11 +++++-----
 pkg/trait/trait.go                         |  4 ++--
 pkg/trait/trait_catalog.go                 |  6 +-----
 pkg/trait/trait_configure_test.go          | 17 ++++++++-------
 pkg/trait/trait_test.go                    |  5 ++---
 pkg/trait/trait_types.go                   | 34 +++++++++++++-----------------
 pkg/util/maven/maven_command.go            |  7 ++----
 48 files changed, 135 insertions(+), 173 deletions(-)

diff --git a/addons/master/master.go b/addons/master/master.go
index 5bcdd19..119cf85 100644
--- a/addons/master/master.go
+++ b/addons/master/master.go
@@ -95,7 +95,7 @@ func (t *masterTrait) Configure(e *trait.Environment) (bool, 
error) {
 
        if t.Auto == nil || *t.Auto {
                // Check if the master component has been used
-               sources, err := kubernetes.ResolveIntegrationSources(t.Ctx, 
t.Client, e.Integration, e.Resources)
+               sources, err := kubernetes.ResolveIntegrationSources(e.Ctx, 
t.Client, e.Integration, e.Resources)
                if err != nil {
                        return false, err
                }
@@ -237,7 +237,7 @@ func (t *masterTrait) Apply(e *trait.Environment) error {
 }
 
 func (t *masterTrait) canUseLeases(e *trait.Environment) (bool, error) {
-       return kubernetes.CheckPermission(t.Ctx, t.Client, 
"coordination.k8s.io", "leases", e.Integration.Namespace, "", "create")
+       return kubernetes.CheckPermission(e.Ctx, t.Client, 
"coordination.k8s.io", "leases", e.Integration.Namespace, "", "create")
 }
 
 func findAdditionalDependencies(e *trait.Environment, meta 
metadata.IntegrationMetadata) (dependencies []string) {
diff --git a/addons/tracing/tracing.go b/addons/tracing/tracing.go
index 8c01fba..705d492 100644
--- a/addons/tracing/tracing.go
+++ b/addons/tracing/tracing.go
@@ -83,7 +83,7 @@ func (t *tracingTrait) Configure(e *trait.Environment) (bool, 
error) {
        if trait.IsNilOrTrue(t.Auto) {
                if t.Endpoint == "" {
                        for _, locator := range discovery.TracingLocators {
-                               endpoint, err := locator.FindEndpoint(e.C, 
t.Client, t.L, e)
+                               endpoint, err := locator.FindEndpoint(e.Ctx, 
t.Client, t.L, e)
                                if err != nil {
                                        return false, err
                                }
diff --git a/cmd/util/doc-gen/generators/traitdocgen.go 
b/cmd/util/doc-gen/generators/traitdocgen.go
index e99022c..a7623ea 100644
--- a/cmd/util/doc-gen/generators/traitdocgen.go
+++ b/cmd/util/doc-gen/generators/traitdocgen.go
@@ -18,7 +18,6 @@ limitations under the License.
 package generators
 
 import (
-       "context"
        "fmt"
        "io"
        "io/ioutil"
@@ -64,7 +63,6 @@ type traitDocGen struct {
        generatedTraitFiles []string
 }
 
-// NewTraitDocGen --
 func NewTraitDocGen(arguments *args.GeneratorArgs) generator.Generator {
        return &traitDocGen{
                DefaultGen: generator.DefaultGen{},
@@ -304,19 +302,13 @@ func writeFile(file *os.File, content []string) error {
 }
 
 func isPlatformTrait(traitID string) bool {
-       ctx, cancel := context.WithCancel(context.Background())
-       defer cancel()
-
-       catalog := trait.NewCatalog(ctx, nil)
+       catalog := trait.NewCatalog(nil)
        t := catalog.GetTrait(traitID)
        return t.IsPlatformTrait()
 }
 
 func determineProfiles(traitID string) (profiles []string) {
-       ctx, cancel := context.WithCancel(context.Background())
-       defer cancel()
-
-       catalog := trait.NewCatalog(ctx, nil)
+       catalog := trait.NewCatalog(nil)
        for _, p := range v1.AllTraitProfiles {
                traits := catalog.TraitsForProfile(p)
                for _, t := range traits {
diff --git a/pkg/cmd/completion_bash.go b/pkg/cmd/completion_bash.go
index 7da2b7b..17c04a4 100644
--- a/pkg/cmd/completion_bash.go
+++ b/pkg/cmd/completion_bash.go
@@ -18,18 +18,15 @@ limitations under the License.
 package cmd
 
 import (
-       "context"
        "fmt"
        "strings"
 
-       v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+       "github.com/spf13/cobra"
 
+       v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
        "github.com/apache/camel-k/pkg/platform"
-
        "github.com/apache/camel-k/pkg/trait"
-
        "github.com/apache/camel-k/pkg/util/camel"
-       "github.com/spf13/cobra"
 )
 
 // ******************************
@@ -74,7 +71,7 @@ __kamel_dependency_type() {
 }
 
 __kamel_traits() {
-    local type_list="` + strings.Join(trait.NewCatalog(context.TODO(), 
nil).ComputeTraitsProperties(), " ") + `"
+    local type_list="` + 
strings.Join(trait.NewCatalog(nil).ComputeTraitsProperties(), " ") + `"
     COMPREPLY=( $( compgen -W "${type_list}" -- "$cur") )
     compopt -o nospace
 }
diff --git a/pkg/cmd/kit_create.go b/pkg/cmd/kit_create.go
index ebf547f..7d0544d 100644
--- a/pkg/cmd/kit_create.go
+++ b/pkg/cmd/kit_create.go
@@ -88,7 +88,7 @@ func (command *kitCreateCommandOptions) run(_ *cobra.Command, 
args []string) err
                return err
        }
 
-       catalog := trait.NewCatalog(command.Context, c)
+       catalog := trait.NewCatalog(c)
        tp := catalog.ComputeTraitsProperties()
        for _, t := range command.Traits {
                kv := strings.SplitN(t, "=", 2)
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 8cb1ebf..239259b 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -276,7 +276,7 @@ func (o *runCmdOptions) run(cmd *cobra.Command, args 
[]string) error {
                return err
        }
 
-       catalog := trait.NewCatalog(o.Context, c)
+       catalog := trait.NewCatalog(c)
        tp := catalog.ComputeTraitsProperties()
        for _, t := range o.Traits {
                kv := strings.SplitN(t, "=", 2)
diff --git a/pkg/cmd/run_test.go b/pkg/cmd/run_test.go
index 6da2bf0..bfe9ea6 100644
--- a/pkg/cmd/run_test.go
+++ b/pkg/cmd/run_test.go
@@ -366,7 +366,7 @@ func TestConfigureTraits(t *testing.T) {
        if err != nil {
                t.Error(err)
        }
-       catalog := trait.NewCatalog(runCmdOptions.Context, client)
+       catalog := trait.NewCatalog(client)
 
        traits, err := configureTraits(runCmdOptions.Traits, catalog)
 
diff --git a/pkg/cmd/trait_help.go b/pkg/cmd/trait_help.go
index 2af58c3..1834e10 100644
--- a/pkg/cmd/trait_help.go
+++ b/pkg/cmd/trait_help.go
@@ -29,8 +29,8 @@ import (
        "github.com/spf13/cobra"
        "gopkg.in/yaml.v2"
 
-       "github.com/apache/camel-k/pkg/resources"
        v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+       "github.com/apache/camel-k/pkg/resources"
        "github.com/apache/camel-k/pkg/trait"
        "github.com/apache/camel-k/pkg/util/indentedwriter"
 )
@@ -99,7 +99,7 @@ func (command *traitHelpCommandOptions) validate(args 
[]string) error {
 
 func (command *traitHelpCommandOptions) run(cmd *cobra.Command, args []string) 
error {
        var traitDescriptions []*traitDescription
-       var catalog = trait.NewCatalog(command.Context, nil)
+       var catalog = trait.NewCatalog(nil)
 
        var traitMetaData = &traitMetaData{}
        err := yaml.Unmarshal(resources.Resource("/traits.yaml"), traitMetaData)
diff --git a/pkg/controller/integration/build_kit.go 
b/pkg/controller/integration/build_kit.go
index 4568f4f..8740cb0 100644
--- a/pkg/controller/integration/build_kit.go
+++ b/pkg/controller/integration/build_kit.go
@@ -246,7 +246,7 @@ func (action *buildKitAction) kitMatches(k1 
*v1.IntegrationKit, k2 *v1.Integrati
 
 // hasMatchingTraits compares the traits defined on the v1.Integration with 
those defined on the v1.IntegrationKit
 func (action *buildKitAction) hasMatchingTraits(integration *v1.Integration, 
kit *v1.IntegrationKit) (bool, error) {
-       catalog := trait.NewCatalog(context.TODO(), action.client)
+       catalog := trait.NewCatalog(action.client)
 
        traitCount := 0
        for name, itTrait := range integration.Spec.Traits {
diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go
index 7343981..7a78a25 100644
--- a/pkg/trait/builder.go
+++ b/pkg/trait/builder.go
@@ -71,7 +71,7 @@ func (t *builderTrait) Apply(e *Environment) error {
                e.IntegrationKit.Status.Phase = v1.IntegrationKitPhaseError
                
e.IntegrationKit.Status.SetCondition("IntegrationKitPropertiesFormatValid", 
corev1.ConditionFalse,
                        "IntegrationKitPropertiesFormatValid", fmt.Sprintf("One 
or more properties where not formatted as expected: %s", err.Error()))
-               if err := e.Client.Status().Update(e.C, e.IntegrationKit); err 
!= nil {
+               if err := e.Client.Status().Update(e.Ctx, e.IntegrationKit); 
err != nil {
                        return err
                }
                return nil
diff --git a/pkg/trait/builder_test.go b/pkg/trait/builder_test.go
index 2c79bd6..5093409 100644
--- a/pkg/trait/builder_test.go
+++ b/pkg/trait/builder_test.go
@@ -108,9 +108,9 @@ func createBuilderTestEnv(cluster 
v1.IntegrationPlatformCluster, strategy v1.Int
 
        kanikoCache := false
        res := &Environment{
-               C:            context.TODO(),
+               Ctx:          context.TODO(),
                CamelCatalog: c,
-               Catalog:      NewCatalog(context.TODO(), nil),
+               Catalog:      NewCatalog(nil),
                Integration: &v1.Integration{
                        ObjectMeta: metav1.ObjectMeta{
                                Name:      "test",
@@ -148,7 +148,7 @@ func createBuilderTestEnv(cluster 
v1.IntegrationPlatformCluster, strategy v1.Int
 }
 
 func NewBuilderTestCatalog() *Catalog {
-       return NewCatalog(context.TODO(), nil)
+       return NewCatalog(nil)
 }
 
 func TestMavenPropertyBuilderTrait(t *testing.T) {
diff --git a/pkg/trait/camel.go b/pkg/trait/camel.go
index e02c78b..47a66f2 100644
--- a/pkg/trait/camel.go
+++ b/pkg/trait/camel.go
@@ -87,7 +87,7 @@ func (t *camelTrait) loadOrCreateCatalog(e *Environment, 
runtimeVersion string)
                Provider: v1.RuntimeProviderQuarkus,
        }
 
-       catalog, err := camel.LoadCatalog(e.C, e.Client, ns, runtime)
+       catalog, err := camel.LoadCatalog(e.Ctx, e.Client, ns, runtime)
        if err != nil {
                return err
        }
@@ -97,7 +97,7 @@ func (t *camelTrait) loadOrCreateCatalog(e *Environment, 
runtimeVersion string)
                // the required versions (camel and runtime) are not expressed 
as
                // semver constraints
                if exactVersionRegexp.MatchString(runtimeVersion) {
-                       ctx, cancel := context.WithTimeout(e.C, 
e.Platform.Status.Build.GetTimeout().Duration)
+                       ctx, cancel := context.WithTimeout(e.Ctx, 
e.Platform.Status.Build.GetTimeout().Duration)
                        defer cancel()
                        catalog, err = camel.GenerateCatalog(ctx, e.Client, ns, 
e.Platform.Status.Build.Maven, runtime, []maven.Dependency{})
                        if err != nil {
@@ -114,7 +114,7 @@ func (t *camelTrait) loadOrCreateCatalog(e *Environment, 
runtimeVersion string)
                        cx.Labels["camel.apache.org/runtime.provider"] = 
string(runtime.Provider)
                        cx.Labels["camel.apache.org/catalog.generated"] = True
 
-                       err = e.Client.Create(e.C, &cx)
+                       err = e.Client.Create(e.Ctx, &cx)
                        if err != nil {
                                return errors.Wrapf(err, "unable to create 
catalog runtime=%s, provider=%s, name=%s",
                                        runtime.Version,
diff --git a/pkg/trait/camel_test.go b/pkg/trait/camel_test.go
index 7b017fa..2932660 100644
--- a/pkg/trait/camel_test.go
+++ b/pkg/trait/camel_test.go
@@ -84,7 +84,7 @@ func createNominalCamelTest() (*camelTrait, *Environment) {
                        },
                },
                Catalog: NewEnvironmentTestCatalog(),
-               C:       context.TODO(),
+               Ctx:     context.TODO(),
                Client:  client,
                Integration: &v1.Integration{
                        ObjectMeta: metav1.ObjectMeta{
diff --git a/pkg/trait/container_test.go b/pkg/trait/container_test.go
index cf21d68..5a77015 100644
--- a/pkg/trait/container_test.go
+++ b/pkg/trait/container_test.go
@@ -41,7 +41,7 @@ func TestContainerWithDefaults(t *testing.T) {
        catalog, err := camel.DefaultCatalog()
        assert.Nil(t, err)
 
-       traitCatalog := NewCatalog(context.TODO(), nil)
+       traitCatalog := NewCatalog(nil)
 
        environment := Environment{
                CamelCatalog: catalog,
@@ -96,7 +96,7 @@ func TestContainerWithCustomName(t *testing.T) {
        catalog, err := camel.DefaultCatalog()
        assert.Nil(t, err)
 
-       traitCatalog := NewCatalog(context.TODO(), nil)
+       traitCatalog := NewCatalog(nil)
 
        environment := Environment{
                CamelCatalog: catalog,
@@ -159,10 +159,10 @@ func TestContainerWithCustomImage(t *testing.T) {
        assert.Nil(t, err)
 
        client, _ := test.NewFakeClient()
-       traitCatalog := NewCatalog(context.TODO(), nil)
+       traitCatalog := NewCatalog(nil)
 
        environment := Environment{
-               C:            context.TODO(),
+               Ctx:          context.TODO(),
                Client:       client,
                CamelCatalog: catalog,
                Catalog:      traitCatalog,
@@ -230,10 +230,10 @@ func TestContainerWithCustomImageAndIntegrationKit(t 
*testing.T) {
        assert.Nil(t, err)
 
        client, _ := test.NewFakeClient()
-       traitCatalog := NewCatalog(context.TODO(), nil)
+       traitCatalog := NewCatalog(nil)
 
        environment := Environment{
-               C:            context.TODO(),
+               Ctx:          context.TODO(),
                Client:       client,
                CamelCatalog: catalog,
                Catalog:      traitCatalog,
@@ -284,10 +284,10 @@ func 
TestContainerWithCustomImageAndDeprecatedIntegrationKit(t *testing.T) {
        assert.Nil(t, err)
 
        client, _ := test.NewFakeClient()
-       traitCatalog := NewCatalog(context.TODO(), nil)
+       traitCatalog := NewCatalog(nil)
 
        environment := Environment{
-               C:            context.TODO(),
+               Ctx:          context.TODO(),
                Client:       client,
                CamelCatalog: catalog,
                Catalog:      traitCatalog,
diff --git a/pkg/trait/cron.go b/pkg/trait/cron.go
index 45a325e..191fcaa 100644
--- a/pkg/trait/cron.go
+++ b/pkg/trait/cron.go
@@ -382,7 +382,7 @@ func (t *cronTrait) getGlobalCron(e *Environment) 
(*cronInfo, error) {
 func (t *cronTrait) getSourcesFromURIs(e *Environment) ([]string, error) {
        var sources []v1.SourceSpec
        var err error
-       if sources, err = kubernetes.ResolveIntegrationSources(t.Ctx, t.Client, 
e.Integration, e.Resources); err != nil {
+       if sources, err = kubernetes.ResolveIntegrationSources(e.Ctx, t.Client, 
e.Integration, e.Resources); err != nil {
                return nil, err
        }
        meta := metadata.ExtractAll(e.CamelCatalog, sources)
diff --git a/pkg/trait/cron_test.go b/pkg/trait/cron_test.go
index 0c8353a..a52bdfd 100644
--- a/pkg/trait/cron_test.go
+++ b/pkg/trait/cron_test.go
@@ -18,7 +18,6 @@ limitations under the License.
 package trait
 
 import (
-       "context"
        "strings"
        "testing"
 
@@ -31,7 +30,7 @@ import (
        v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
        "github.com/apache/camel-k/pkg/util"
        "github.com/apache/camel-k/pkg/util/camel"
-       k8sutils "github.com/apache/camel-k/pkg/util/kubernetes"
+       "github.com/apache/camel-k/pkg/util/kubernetes"
        "github.com/apache/camel-k/pkg/util/test"
 )
 
@@ -224,7 +223,7 @@ func TestCronDeps(t *testing.T) {
        catalog, err := camel.DefaultCatalog()
        assert.Nil(t, err)
 
-       traitCatalog := NewCatalog(context.TODO(), nil)
+       traitCatalog := NewCatalog(nil)
 
        environment := Environment{
                CamelCatalog: catalog,
@@ -269,14 +268,14 @@ func TestCronDeps(t *testing.T) {
                },
                EnvVars:        make([]corev1.EnvVar, 0),
                ExecutedTraits: make([]Trait, 0),
-               Resources:      k8sutils.NewCollection(),
+               Resources:      kubernetes.NewCollection(),
        }
        environment.Platform.ResyncStatusFullConfig()
 
        c, err := NewFakeClient("ns")
        assert.Nil(t, err)
 
-       tc := NewCatalog(context.TODO(), c)
+       tc := NewCatalog(c)
 
        err = tc.apply(&environment)
 
@@ -294,7 +293,7 @@ func TestCronDepsFallback(t *testing.T) {
        catalog, err := camel.DefaultCatalog()
        assert.Nil(t, err)
 
-       traitCatalog := NewCatalog(context.TODO(), nil)
+       traitCatalog := NewCatalog(nil)
 
        environment := Environment{
                CamelCatalog: catalog,
@@ -343,14 +342,14 @@ func TestCronDepsFallback(t *testing.T) {
                },
                EnvVars:        make([]corev1.EnvVar, 0),
                ExecutedTraits: make([]Trait, 0),
-               Resources:      k8sutils.NewCollection(),
+               Resources:      kubernetes.NewCollection(),
        }
        environment.Platform.ResyncStatusFullConfig()
 
        c, err := NewFakeClient("ns")
        assert.Nil(t, err)
 
-       tc := NewCatalog(context.TODO(), c)
+       tc := NewCatalog(c)
 
        err = tc.apply(&environment)
 
@@ -369,7 +368,7 @@ func TestCronWithQuarkus(t *testing.T) {
        catalog, err := camel.DefaultCatalog()
        assert.Nil(t, err)
 
-       traitCatalog := NewCatalog(context.TODO(), nil)
+       traitCatalog := NewCatalog(nil)
 
        environment := Environment{
                CamelCatalog: catalog,
@@ -418,14 +417,14 @@ func TestCronWithQuarkus(t *testing.T) {
                },
                EnvVars:        make([]corev1.EnvVar, 0),
                ExecutedTraits: make([]Trait, 0),
-               Resources:      k8sutils.NewCollection(),
+               Resources:      kubernetes.NewCollection(),
        }
        environment.Platform.ResyncStatusFullConfig()
 
        c, err := NewFakeClient("ns")
        assert.Nil(t, err)
 
-       tc := NewCatalog(context.TODO(), c)
+       tc := NewCatalog(c)
 
        err = tc.apply(&environment)
 
diff --git a/pkg/trait/dependencies.go b/pkg/trait/dependencies.go
index b5fd7a9..2a5623d 100644
--- a/pkg/trait/dependencies.go
+++ b/pkg/trait/dependencies.go
@@ -64,7 +64,7 @@ func (t *dependenciesTrait) Apply(e *Environment) error {
                dependencies.Add(d.GetDependencyID())
        }
 
-       sources, err := kubernetes.ResolveIntegrationSources(e.C, e.Client, 
e.Integration, e.Resources)
+       sources, err := kubernetes.ResolveIntegrationSources(e.Ctx, e.Client, 
e.Integration, e.Resources)
        if err != nil {
                return err
        }
diff --git a/pkg/trait/deployer.go b/pkg/trait/deployer.go
index 9e49374..dcc71eb 100644
--- a/pkg/trait/deployer.go
+++ b/pkg/trait/deployer.go
@@ -101,7 +101,7 @@ func (t *deployerTrait) serverSideApply(env *Environment, 
resource ctrl.Object)
        if err != nil {
                return err
        }
-       err = env.Client.Patch(env.C, target, ctrl.Apply, ctrl.ForceOwnership, 
ctrl.FieldOwner("camel-k-operator"))
+       err = env.Client.Patch(env.Ctx, target, ctrl.Apply, 
ctrl.ForceOwnership, ctrl.FieldOwner("camel-k-operator"))
        if err != nil {
                return errors.Wrapf(err, "error during apply resource: %v", 
resource)
        }
@@ -109,7 +109,7 @@ func (t *deployerTrait) serverSideApply(env *Environment, 
resource ctrl.Object)
 }
 
 func (t *deployerTrait) clientSideApply(env *Environment, resource 
ctrl.Object) error {
-       err := env.Client.Create(env.C, resource)
+       err := env.Client.Create(env.Ctx, resource)
        if err == nil {
                return nil
        } else if !k8serrors.IsAlreadyExists(err) {
@@ -119,7 +119,7 @@ func (t *deployerTrait) clientSideApply(env *Environment, 
resource ctrl.Object)
        object.SetNamespace(resource.GetNamespace())
        object.SetName(resource.GetName())
        object.SetGroupVersionKind(resource.GetObjectKind().GroupVersionKind())
-       err = env.Client.Get(env.C, ctrl.ObjectKeyFromObject(object), object)
+       err = env.Client.Get(env.Ctx, ctrl.ObjectKeyFromObject(object), object)
        if err != nil {
                return err
        }
@@ -130,7 +130,7 @@ func (t *deployerTrait) clientSideApply(env *Environment, 
resource ctrl.Object)
                // Avoid triggering a patch request for nothing
                return nil
        }
-       err = env.Client.Patch(env.C, resource, 
ctrl.RawPatch(types.MergePatchType, p))
+       err = env.Client.Patch(env.Ctx, resource, 
ctrl.RawPatch(types.MergePatchType, p))
        if err != nil {
                return errors.Wrapf(err, "error during patch resource: %v", 
resource)
        }
diff --git a/pkg/trait/deployer_test.go b/pkg/trait/deployer_test.go
index 939dcb0..6b43c2b 100644
--- a/pkg/trait/deployer_test.go
+++ b/pkg/trait/deployer_test.go
@@ -18,7 +18,6 @@ limitations under the License.
 package trait
 
 import (
-       "context"
        "testing"
 
        v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
@@ -69,7 +68,7 @@ func createNominalDeployerTest() (*deployerTrait, 
*Environment) {
        trait := newDeployerTrait().(*deployerTrait)
 
        environment := &Environment{
-               Catalog: NewCatalog(context.TODO(), nil),
+               Catalog: NewCatalog(nil),
                Integration: &v1.Integration{
                        ObjectMeta: metav1.ObjectMeta{
                                Name: "integration-name",
diff --git a/pkg/trait/deployment_test.go b/pkg/trait/deployment_test.go
index f4fdd7a..de571ca 100644
--- a/pkg/trait/deployment_test.go
+++ b/pkg/trait/deployment_test.go
@@ -18,7 +18,6 @@ limitations under the License.
 package trait
 
 import (
-       "context"
        "testing"
 
        v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
@@ -176,7 +175,7 @@ func createNominalDeploymentTest() (*deploymentTrait, 
*Environment) {
        replicas := int32(3)
 
        environment := &Environment{
-               Catalog: NewCatalog(context.TODO(), nil),
+               Catalog: NewCatalog(nil),
                Integration: &v1.Integration{
                        ObjectMeta: metav1.ObjectMeta{
                                Name: "integration-name",
diff --git a/pkg/trait/environment_test.go b/pkg/trait/environment_test.go
index ad0d3be..61426f1 100644
--- a/pkg/trait/environment_test.go
+++ b/pkg/trait/environment_test.go
@@ -18,7 +18,6 @@ limitations under the License.
 package trait
 
 import (
-       "context"
        "testing"
 
        "github.com/stretchr/testify/assert"
@@ -39,7 +38,7 @@ func TestDefaultEnvironment(t *testing.T) {
 
        env := Environment{
                CamelCatalog: catalog,
-               Catalog:      NewCatalog(context.TODO(), nil),
+               Catalog:      NewCatalog(nil),
                Integration: &v1.Integration{
                        Status: v1.IntegrationStatus{
                                Phase: v1.IntegrationPhaseDeploying,
@@ -110,7 +109,7 @@ func TestEnabledContainerMetaDataEnvVars(t *testing.T) {
 
        env := Environment{
                CamelCatalog: c,
-               Catalog:      NewCatalog(context.TODO(), nil),
+               Catalog:      NewCatalog(nil),
                Integration: &v1.Integration{
                        Status: v1.IntegrationStatus{
                                Phase: v1.IntegrationPhaseDeploying,
@@ -176,7 +175,7 @@ func TestDisabledContainerMetaDataEnvVars(t *testing.T) {
 
        env := Environment{
                CamelCatalog: c,
-               Catalog:      NewCatalog(context.TODO(), nil),
+               Catalog:      NewCatalog(nil),
                Integration: &v1.Integration{
                        Status: v1.IntegrationStatus{
                                Phase: v1.IntegrationPhaseDeploying,
@@ -237,5 +236,5 @@ func TestDisabledContainerMetaDataEnvVars(t *testing.T) {
 }
 
 func NewEnvironmentTestCatalog() *Catalog {
-       return NewCatalog(context.TODO(), nil)
+       return NewCatalog(nil)
 }
diff --git a/pkg/trait/gc_test.go b/pkg/trait/gc_test.go
index ac650c5..c261770 100644
--- a/pkg/trait/gc_test.go
+++ b/pkg/trait/gc_test.go
@@ -18,7 +18,6 @@ limitations under the License.
 package trait
 
 import (
-       "context"
        "testing"
 
        v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
@@ -71,7 +70,7 @@ func createNominalGarbageCollectorTest() 
(*garbageCollectorTrait, *Environment)
        trait.Enabled = BoolP(true)
 
        environment := &Environment{
-               Catalog: NewCatalog(context.TODO(), nil),
+               Catalog: NewCatalog(nil),
                Integration: &v1.Integration{
                        ObjectMeta: metav1.ObjectMeta{
                                Name: "integration-name",
diff --git a/pkg/trait/ingress_test.go b/pkg/trait/ingress_test.go
index a0fb217..84c3a06 100644
--- a/pkg/trait/ingress_test.go
+++ b/pkg/trait/ingress_test.go
@@ -18,7 +18,6 @@ limitations under the License.
 package trait
 
 import (
-       "context"
        "testing"
 
        "github.com/stretchr/testify/assert"
@@ -160,7 +159,7 @@ func createNominalIngressTest() (*ingressTrait, 
*Environment) {
        trait.Host = "hostname"
 
        environment := &Environment{
-               Catalog: NewCatalog(context.TODO(), nil),
+               Catalog: NewCatalog(nil),
                Integration: &v1.Integration{
                        ObjectMeta: metav1.ObjectMeta{
                                Name: "integration-name",
diff --git a/pkg/trait/jolokia_test.go b/pkg/trait/jolokia_test.go
index 0551d6f..e7a2802 100644
--- a/pkg/trait/jolokia_test.go
+++ b/pkg/trait/jolokia_test.go
@@ -18,7 +18,6 @@ limitations under the License.
 package trait
 
 import (
-       "context"
        "testing"
 
        "github.com/stretchr/testify/assert"
@@ -271,7 +270,7 @@ func createNominalJolokiaTest() (*jolokiaTrait, 
*Environment) {
        trait.Enabled = BoolP(true)
 
        environment := &Environment{
-               Catalog: NewCatalog(context.TODO(), nil),
+               Catalog: NewCatalog(nil),
                Integration: &v1.Integration{
                        Status: v1.IntegrationStatus{
                                Phase: v1.IntegrationPhaseDeploying,
diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index 4633494..8d17bcc 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -92,7 +92,7 @@ func (t *jvmTrait) Apply(e *Environment) error {
                name := e.Integration.Status.IntegrationKit.Name
                ns := e.Integration.GetIntegrationKitNamespace(e.Platform)
                k := v1.NewIntegrationKit(ns, name)
-               if err := t.Client.Get(t.Ctx, ctrl.ObjectKeyFromObject(k), k); 
err != nil {
+               if err := t.Client.Get(e.Ctx, ctrl.ObjectKeyFromObject(k), k); 
err != nil {
                        return errors.Wrapf(err, "unable to find integration 
kit %s/%s, %s", ns, name, err)
                }
                kit = k
diff --git a/pkg/trait/jvm_test.go b/pkg/trait/jvm_test.go
index 4c24a18..a6360a7 100644
--- a/pkg/trait/jvm_test.go
+++ b/pkg/trait/jvm_test.go
@@ -18,7 +18,6 @@ limitations under the License.
 package trait
 
 import (
-       "context"
        "fmt"
        "sort"
        "strings"
@@ -258,11 +257,10 @@ func createNominalJvmTest(kitType string) (*jvmTrait, 
*Environment) {
        trait := newJvmTrait().(*jvmTrait)
        trait.Enabled = BoolP(true)
        trait.PrintCommand = BoolP(false)
-       trait.Ctx = context.TODO()
        trait.Client = client
 
        environment := &Environment{
-               Catalog:      NewCatalog(context.TODO(), nil),
+               Catalog:      NewCatalog(nil),
                CamelCatalog: catalog,
                Integration: &v1.Integration{
                        Status: v1.IntegrationStatus{
diff --git a/pkg/trait/kamelets.go b/pkg/trait/kamelets.go
index 6b0b2a8..cee7ac3 100644
--- a/pkg/trait/kamelets.go
+++ b/pkg/trait/kamelets.go
@@ -99,7 +99,7 @@ func (t *kameletsTrait) Configure(e *Environment) (bool, 
error) {
        if IsNilOrTrue(t.Auto) {
                var kamelets []string
                if t.List == "" {
-                       sources, err := 
kubernetes.ResolveIntegrationSources(e.C, e.Client, e.Integration, e.Resources)
+                       sources, err := 
kubernetes.ResolveIntegrationSources(e.Ctx, e.Client, e.Integration, 
e.Resources)
                        if err != nil {
                                return false, err
                        }
@@ -142,7 +142,7 @@ func (t *kameletsTrait) Apply(e *Environment) error {
 }
 
 func (t *kameletsTrait) collectKamelets(e *Environment) 
(map[string]*v1alpha1.Kamelet, error) {
-       repo, err := repository.NewForPlatform(e.C, e.Client, e.Platform, 
e.Integration.Namespace, platform.GetOperatorNamespace())
+       repo, err := repository.NewForPlatform(e.Ctx, e.Client, e.Platform, 
e.Integration.Namespace, platform.GetOperatorNamespace())
        if err != nil {
                return nil, err
        }
@@ -152,7 +152,7 @@ func (t *kameletsTrait) collectKamelets(e *Environment) 
(map[string]*v1alpha1.Ka
        availableKamelets := make([]string, 0)
 
        for _, key := range t.getKameletKeys() {
-               kamelet, err := repo.Get(e.C, key)
+               kamelet, err := repo.Get(e.Ctx, key)
                if err != nil {
                        return nil, err
                }
@@ -320,7 +320,7 @@ func (t *kameletsTrait) addConfigurationSecrets(e 
*Environment) error {
                if k.configurationID != "" {
                        options.LabelSelector = fmt.Sprintf("%s=%s,%s=%s", 
kameletLabel, k.kamelet, kameletConfigurationLabel, k.configurationID)
                }
-               secrets, err := 
t.Client.CoreV1().Secrets(e.Integration.Namespace).List(e.C, options)
+               secrets, err := 
t.Client.CoreV1().Secrets(e.Integration.Namespace).List(e.Ctx, options)
                if err != nil {
                        return err
                }
diff --git a/pkg/trait/kamelets_test.go b/pkg/trait/kamelets_test.go
index 1e34eae..8c87cd7 100644
--- a/pkg/trait/kamelets_test.go
+++ b/pkg/trait/kamelets_test.go
@@ -18,7 +18,6 @@ limitations under the License.
 package trait
 
 import (
-       "context"
        "encoding/json"
        "testing"
 
@@ -540,11 +539,10 @@ func createKameletsTestEnvironment(flow string, objects 
...runtime.Object) (*kam
 
        client, _ := test.NewFakeClient(objects...)
        trait := newKameletsTrait().(*kameletsTrait)
-       trait.Ctx = context.TODO()
        trait.Client = client
 
        environment := &Environment{
-               Catalog:      NewCatalog(context.TODO(), client),
+               Catalog:      NewCatalog(client),
                Client:       client,
                CamelCatalog: catalog,
                Integration: &v1.Integration{
diff --git a/pkg/trait/knative.go b/pkg/trait/knative.go
index a76ae57..fa6591e 100644
--- a/pkg/trait/knative.go
+++ b/pkg/trait/knative.go
@@ -115,7 +115,7 @@ func (t *knativeTrait) Configure(e *Environment) (bool, 
error) {
        if IsNilOrTrue(t.Auto) {
                if len(t.ChannelSources) == 0 {
                        items := make([]string, 0)
-                       sources, err := 
kubernetes.ResolveIntegrationSources(e.C, e.Client, e.Integration, e.Resources)
+                       sources, err := 
kubernetes.ResolveIntegrationSources(e.Ctx, e.Client, e.Integration, 
e.Resources)
                        if err != nil {
                                return false, err
                        }
@@ -128,7 +128,7 @@ func (t *knativeTrait) Configure(e *Environment) (bool, 
error) {
                }
                if len(t.ChannelSinks) == 0 {
                        items := make([]string, 0)
-                       sources, err := 
kubernetes.ResolveIntegrationSources(e.C, e.Client, e.Integration, e.Resources)
+                       sources, err := 
kubernetes.ResolveIntegrationSources(e.Ctx, e.Client, e.Integration, 
e.Resources)
                        if err != nil {
                                return false, err
                        }
@@ -141,7 +141,7 @@ func (t *knativeTrait) Configure(e *Environment) (bool, 
error) {
                }
                if len(t.EndpointSources) == 0 {
                        items := make([]string, 0)
-                       sources, err := 
kubernetes.ResolveIntegrationSources(e.C, e.Client, e.Integration, e.Resources)
+                       sources, err := 
kubernetes.ResolveIntegrationSources(e.Ctx, e.Client, e.Integration, 
e.Resources)
                        if err != nil {
                                return false, err
                        }
@@ -154,7 +154,7 @@ func (t *knativeTrait) Configure(e *Environment) (bool, 
error) {
                }
                if len(t.EndpointSinks) == 0 {
                        items := make([]string, 0)
-                       sources, err := 
kubernetes.ResolveIntegrationSources(e.C, e.Client, e.Integration, e.Resources)
+                       sources, err := 
kubernetes.ResolveIntegrationSources(e.Ctx, e.Client, e.Integration, 
e.Resources)
                        if err != nil {
                                return false, err
                        }
@@ -167,7 +167,7 @@ func (t *knativeTrait) Configure(e *Environment) (bool, 
error) {
                }
                if len(t.EventSources) == 0 {
                        items := make([]string, 0)
-                       sources, err := 
kubernetes.ResolveIntegrationSources(e.C, e.Client, e.Integration, e.Resources)
+                       sources, err := 
kubernetes.ResolveIntegrationSources(e.Ctx, e.Client, e.Integration, 
e.Resources)
                        if err != nil {
                                return false, err
                        }
@@ -180,7 +180,7 @@ func (t *knativeTrait) Configure(e *Environment) (bool, 
error) {
                }
                if len(t.EventSinks) == 0 {
                        items := make([]string, 0)
-                       sources, err := 
kubernetes.ResolveIntegrationSources(e.C, e.Client, e.Integration, e.Resources)
+                       sources, err := 
kubernetes.ResolveIntegrationSources(e.Ctx, e.Client, e.Integration, 
e.Resources)
                        if err != nil {
                                return false, err
                        }
@@ -574,7 +574,7 @@ func (t *knativeTrait) withServiceDo(
                if len(possibleRefs) == 1 {
                        actualRef = &possibleRefs[0]
                } else {
-                       actualRef, err = 
knativeutil.GetAddressableReference(t.Ctx, t.Client, possibleRefs, 
e.Integration.Namespace, ref.Name)
+                       actualRef, err = 
knativeutil.GetAddressableReference(e.Ctx, t.Client, possibleRefs, 
e.Integration.Namespace, ref.Name)
                        if err != nil && k8serrors.IsNotFound(err) {
                                return errors.Errorf("cannot find %s", 
serviceType.ResourceDescription(ref.Name))
                        } else if err != nil {
@@ -583,7 +583,7 @@ func (t *knativeTrait) withServiceDo(
                }
 
                urlProvider := func() (*url.URL, error) {
-                       targetURL, err := knativeutil.GetSinkURL(t.Ctx, 
t.Client, actualRef, e.Integration.Namespace)
+                       targetURL, err := knativeutil.GetSinkURL(e.Ctx, 
t.Client, actualRef, e.Integration.Namespace)
                        if err != nil {
                                return nil, errors.Wrapf(err, "cannot determine 
address of %s", serviceType.ResourceDescription(ref.Name))
                        }
diff --git a/pkg/trait/knative_service.go b/pkg/trait/knative_service.go
index a86e7bd..5bf9e5c 100644
--- a/pkg/trait/knative_service.go
+++ b/pkg/trait/knative_service.go
@@ -142,7 +142,7 @@ func (t *knativeServiceTrait) Configure(e *Environment) 
(bool, error) {
        if IsNilOrTrue(t.Auto) {
                // Check the right value for minScale, as not all services are 
allowed to scale down to 0
                if t.MinScale == nil {
-                       sources, err := 
kubernetes.ResolveIntegrationSources(t.Ctx, t.Client, e.Integration, 
e.Resources)
+                       sources, err := 
kubernetes.ResolveIntegrationSources(e.Ctx, t.Client, e.Integration, 
e.Resources)
                        if err != nil {
                                e.Integration.Status.SetErrorCondition(
                                        
v1.IntegrationConditionKnativeServiceAvailable,
@@ -247,7 +247,7 @@ func (t *knativeServiceTrait) SelectControllerStrategy(e 
*Environment) (*Control
 
        var sources []v1.SourceSpec
        var err error
-       if sources, err = kubernetes.ResolveIntegrationSources(t.Ctx, t.Client, 
e.Integration, e.Resources); err != nil {
+       if sources, err = kubernetes.ResolveIntegrationSources(e.Ctx, t.Client, 
e.Integration, e.Resources); err != nil {
                return nil, err
        }
 
diff --git a/pkg/trait/knative_service_test.go 
b/pkg/trait/knative_service_test.go
index 482cd89..333449b 100644
--- a/pkg/trait/knative_service_test.go
+++ b/pkg/trait/knative_service_test.go
@@ -18,7 +18,6 @@ limitations under the License.
 package trait
 
 import (
-       "context"
        "testing"
 
        "github.com/stretchr/testify/assert"
@@ -43,7 +42,7 @@ func TestKnativeService(t *testing.T) {
        catalog, err := camel.DefaultCatalog()
        assert.Nil(t, err)
 
-       traitCatalog := NewCatalog(context.TODO(), nil)
+       traitCatalog := NewCatalog(nil)
 
        compressedRoute, err := 
gzip.CompressBase64([]byte(`from("undertow:test").log("hello")`))
        assert.NoError(t, err)
@@ -184,7 +183,7 @@ func TestKnativeServiceWithCustomContainerName(t 
*testing.T) {
        catalog, err := camel.DefaultCatalog()
        assert.Nil(t, err)
 
-       traitCatalog := NewCatalog(context.TODO(), nil)
+       traitCatalog := NewCatalog(nil)
 
        environment := Environment{
                CamelCatalog: catalog,
@@ -259,7 +258,7 @@ func TestKnativeServiceWithResr(t *testing.T) {
        catalog, err := camel.DefaultCatalog()
        assert.Nil(t, err)
 
-       traitCatalog := NewCatalog(context.TODO(), nil)
+       traitCatalog := NewCatalog(nil)
 
        environment := Environment{
                CamelCatalog: catalog,
diff --git a/pkg/trait/knative_test.go b/pkg/trait/knative_test.go
index 65feefa..5c22c68 100644
--- a/pkg/trait/knative_test.go
+++ b/pkg/trait/knative_test.go
@@ -18,7 +18,6 @@ limitations under the License.
 package trait
 
 import (
-       "context"
        "testing"
 
        "github.com/stretchr/testify/assert"
@@ -46,7 +45,7 @@ func TestKnativeEnvConfigurationFromTrait(t *testing.T) {
        catalog, err := camel.DefaultCatalog()
        assert.Nil(t, err)
 
-       traitCatalog := NewCatalog(context.TODO(), nil)
+       traitCatalog := NewCatalog(nil)
 
        environment := Environment{
                CamelCatalog: catalog,
@@ -101,7 +100,7 @@ func TestKnativeEnvConfigurationFromTrait(t *testing.T) {
        c, err := NewFakeClient("ns")
        assert.Nil(t, err)
 
-       tc := NewCatalog(context.TODO(), c)
+       tc := NewCatalog(c)
 
        err = tc.configure(&environment)
        assert.Nil(t, err)
@@ -151,7 +150,7 @@ func TestKnativeEnvConfigurationFromSource(t *testing.T) {
        catalog, err := camel.DefaultCatalog()
        assert.Nil(t, err)
 
-       traitCatalog := NewCatalog(context.TODO(), nil)
+       traitCatalog := NewCatalog(nil)
 
        environment := Environment{
                CamelCatalog: catalog,
@@ -220,7 +219,7 @@ func TestKnativeEnvConfigurationFromSource(t *testing.T) {
        c, err := NewFakeClient("ns")
        assert.Nil(t, err)
 
-       tc := NewCatalog(context.TODO(), c)
+       tc := NewCatalog(c)
 
        err = tc.configure(&environment)
        assert.Nil(t, err)
@@ -288,7 +287,7 @@ func TestKnativePlatformHttpConfig(t *testing.T) {
                        c, err := NewFakeClient("ns")
                        assert.Nil(t, err)
 
-                       tc := NewCatalog(context.TODO(), c)
+                       tc := NewCatalog(c)
 
                        err = tc.configure(&environment)
                        assert.Nil(t, err)
@@ -335,7 +334,7 @@ func TestKnativePlatformHttpDependencies(t *testing.T) {
                        c, err := NewFakeClient("ns")
                        assert.Nil(t, err)
 
-                       tc := NewCatalog(context.TODO(), c)
+                       tc := NewCatalog(c)
 
                        err = tc.configure(&environment)
                        assert.Nil(t, err)
@@ -353,7 +352,7 @@ func NewFakeEnvironment(t *testing.T, source v1.SourceSpec) 
Environment {
        catalog, err := camel.DefaultCatalog()
        assert.Nil(t, err)
 
-       traitCatalog := NewCatalog(context.TODO(), nil)
+       traitCatalog := NewCatalog(nil)
 
        environment := Environment{
                CamelCatalog: catalog,
diff --git a/pkg/trait/logging_test.go b/pkg/trait/logging_test.go
index f5fc573..058dd42 100644
--- a/pkg/trait/logging_test.go
+++ b/pkg/trait/logging_test.go
@@ -39,9 +39,9 @@ func createLoggingTestEnv(t *testing.T, color bool, json 
bool, jsonPrettyPrint b
        }
 
        res := &Environment{
-               C:            context.TODO(),
+               Ctx:          context.TODO(),
                CamelCatalog: c,
-               Catalog:      NewCatalog(context.TODO(), nil),
+               Catalog:      NewCatalog(nil),
                Integration: &v1.Integration{
                        ObjectMeta: metav1.ObjectMeta{
                                Name:      "test",
@@ -89,7 +89,7 @@ func createDefaultLoggingTestEnv(t *testing.T) *Environment {
 }
 
 func NewLoggingTestCatalog() *Catalog {
-       return NewCatalog(context.TODO(), nil)
+       return NewCatalog(nil)
 }
 
 func TestEmptyLoggingTrait(t *testing.T) {
diff --git a/pkg/trait/openapi.go b/pkg/trait/openapi.go
index 11d63d2..f5dfc28 100644
--- a/pkg/trait/openapi.go
+++ b/pkg/trait/openapi.go
@@ -146,7 +146,7 @@ func (t *openAPITrait) generateOpenAPIConfigMap(e 
*Environment, resource v1.Reso
                Namespace: e.Integration.Namespace,
                Name:      generatedContentName,
        }
-       err := t.Client.Get(t.Ctx, key, &cm)
+       err := t.Client.Get(e.Ctx, key, &cm)
        if err != nil && k8serrors.IsNotFound(err) {
                return t.createNewOpenAPIConfigMap(e, resource, tmpDir, 
generatedContentName)
        } else if err != nil {
@@ -207,7 +207,7 @@ func (t *openAPITrait) createNewOpenAPIConfigMap(e 
*Environment, resource v1.Res
        mc.AddArgument("-Dopenapi.spec=" + in)
        mc.AddArgument("-Ddsl.out=" + out)
 
-       settings, err := kubernetes.ResolveValueSource(e.C, e.Client, 
e.Platform.Namespace, &e.Platform.Status.Build.Maven.Settings)
+       settings, err := kubernetes.ResolveValueSource(e.Ctx, e.Client, 
e.Platform.Namespace, &e.Platform.Status.Build.Maven.Settings)
        if err != nil {
                return err
        }
@@ -216,13 +216,13 @@ func (t *openAPITrait) createNewOpenAPIConfigMap(e 
*Environment, resource v1.Res
        }
 
        if e.Platform.Status.Build.Maven.CASecret != nil {
-               certData, err := kubernetes.GetSecretRefData(e.C, e.Client, 
e.Platform.Namespace, e.Platform.Status.Build.Maven.CASecret)
+               certData, err := kubernetes.GetSecretRefData(e.Ctx, e.Client, 
e.Platform.Namespace, e.Platform.Status.Build.Maven.CASecret)
                if err != nil {
                        return err
                }
                trustStoreName := "trust.jks"
                trustStorePass := jvm.NewKeystorePassword()
-               err = jvm.GenerateKeystore(e.C, tmpDir, trustStoreName, 
trustStorePass, certData)
+               err = jvm.GenerateKeystore(e.Ctx, tmpDir, trustStoreName, 
trustStorePass, certData)
                if err != nil {
                        return err
                }
@@ -232,7 +232,7 @@ func (t *openAPITrait) createNewOpenAPIConfigMap(e 
*Environment, resource v1.Res
                )
        }
 
-       ctx, cancel := context.WithTimeout(e.C, 
e.Platform.Status.Build.GetTimeout().Duration)
+       ctx, cancel := context.WithTimeout(e.Ctx, 
e.Platform.Status.Build.GetTimeout().Duration)
        defer cancel()
        err = project.Command(mc).Do(ctx)
        if err != nil {
diff --git a/pkg/trait/platform.go b/pkg/trait/platform.go
index 525d9cd..e91dea1 100644
--- a/pkg/trait/platform.go
+++ b/pkg/trait/platform.go
@@ -100,7 +100,7 @@ func (t *platformTrait) Apply(e *Environment) error {
 }
 
 func (t *platformTrait) getOrCreatePlatform(e *Environment) 
(*v1.IntegrationPlatform, error) {
-       pl, err := platform.GetOrFind(t.Ctx, t.Client, e.Integration.Namespace, 
e.Integration.Status.Platform, false)
+       pl, err := platform.GetOrFind(e.Ctx, t.Client, e.Integration.Namespace, 
e.Integration.Status.Platform, false)
        if err != nil && k8serrors.IsNotFound(err) {
                if IsTrue(t.CreateDefault) {
                        platformName := e.Integration.Status.Platform
diff --git a/pkg/trait/prometheus_test.go b/pkg/trait/prometheus_test.go
index fbf244b..fe8aa46 100644
--- a/pkg/trait/prometheus_test.go
+++ b/pkg/trait/prometheus_test.go
@@ -18,7 +18,6 @@ limitations under the License.
 package trait
 
 import (
-       "context"
        "testing"
 
        "github.com/stretchr/testify/assert"
@@ -124,7 +123,7 @@ func createNominalPrometheusTest() (*prometheusTrait, 
*Environment) {
        }
 
        environment := &Environment{
-               Catalog:      NewCatalog(context.TODO(), nil),
+               Catalog:      NewCatalog(nil),
                CamelCatalog: camelCatalog,
                Integration: &v1.Integration{
                        ObjectMeta: metav1.ObjectMeta{
diff --git a/pkg/trait/pull_secret.go b/pkg/trait/pull_secret.go
index 005cdae..20d4722 100644
--- a/pkg/trait/pull_secret.go
+++ b/pkg/trait/pull_secret.go
@@ -74,7 +74,7 @@ func (t *pullSecretTrait) Configure(e *Environment) (bool, 
error) {
                        if secret != "" {
                                key := client.ObjectKey{Namespace: 
e.Platform.Namespace, Name: secret}
                                obj := corev1.Secret{}
-                               if err := t.Client.Get(t.Ctx, key, &obj); err 
!= nil {
+                               if err := t.Client.Get(e.Ctx, key, &obj); err 
!= nil {
                                        return false, err
                                }
                                if obj.Type == 
corev1.SecretTypeDockerConfigJson {
@@ -122,7 +122,7 @@ func (t *pullSecretTrait) delegateImagePuller(e 
*Environment) error {
        // Applying the rolebinding directly because it's a resource in the 
operator namespace
        // (different from the integration namespace when delegation is 
enabled).
        rb := t.newImagePullerRoleBinding(e)
-       if err := kubernetes.ReplaceResource(e.C, e.Client, rb); err != nil {
+       if err := kubernetes.ReplaceResource(e.Ctx, e.Client, rb); err != nil {
                return errors.Wrap(err, "error during the creation of the 
system:image-puller delegating role binding")
        }
        return nil
diff --git a/pkg/trait/pull_secret_test.go b/pkg/trait/pull_secret_test.go
index 12cf6b6..afd0049 100644
--- a/pkg/trait/pull_secret_test.go
+++ b/pkg/trait/pull_secret_test.go
@@ -86,7 +86,7 @@ func TestPullSecretImagePullerDelegation(t *testing.T) {
                Namespace: "test",
                Name:      "camel-k-puller-test-default",
        }
-       err = e.Client.Get(e.C, roleBindingKey, &roleBinding)
+       err = e.Client.Get(e.Ctx, roleBindingKey, &roleBinding)
        assert.NoError(t, err)
        assert.Len(t, roleBinding.Subjects, 1)
 }
@@ -117,7 +117,7 @@ func getEnvironmentAndDeployment(t *testing.T) 
(*Environment, *appsv1.Deployment
        e.Resources = kubernetes.NewCollection(&deployment)
 
        var err error
-       e.C = context.TODO()
+       e.Ctx = context.TODO()
        e.Client, err = test.NewFakeClient(e.Integration, &deployment)
        assert.NoError(t, err)
 
diff --git a/pkg/trait/route_test.go b/pkg/trait/route_test.go
index 764fedc..ab7af5c 100644
--- a/pkg/trait/route_test.go
+++ b/pkg/trait/route_test.go
@@ -18,7 +18,6 @@ limitations under the License.
 package trait
 
 import (
-       "context"
        "testing"
 
        "github.com/rs/xid"
@@ -41,7 +40,7 @@ func createTestRouteEnvironment(t *testing.T, name string) 
*Environment {
 
        res := &Environment{
                CamelCatalog: catalog,
-               Catalog:      NewCatalog(context.TODO(), nil),
+               Catalog:      NewCatalog(nil),
                Integration: &v1.Integration{
                        ObjectMeta: metav1.ObjectMeta{
                                Name:      name,
diff --git a/pkg/trait/service.go b/pkg/trait/service.go
index dc710e7..d12d1c7 100644
--- a/pkg/trait/service.go
+++ b/pkg/trait/service.go
@@ -71,7 +71,7 @@ func (t *serviceTrait) Configure(e *Environment) (bool, 
error) {
        }
 
        if IsNilOrTrue(t.Auto) {
-               sources, err := kubernetes.ResolveIntegrationSources(t.Ctx, 
t.Client, e.Integration, e.Resources)
+               sources, err := kubernetes.ResolveIntegrationSources(e.Ctx, 
t.Client, e.Integration, e.Resources)
                if err != nil {
                        e.Integration.Status.SetCondition(
                                v1.IntegrationConditionServiceAvailable,
diff --git a/pkg/trait/service_binding.go b/pkg/trait/service_binding.go
index 5012050..7bb600c 100644
--- a/pkg/trait/service_binding.go
+++ b/pkg/trait/service_binding.go
@@ -172,7 +172,7 @@ func (t *serviceBindingTrait) getServiceBinding(e 
*Environment, name string) (sb
                Namespace: e.Integration.Namespace,
                Name:      name,
        }
-       return serviceBinding, t.Client.Get(t.Ctx, key, &serviceBinding)
+       return serviceBinding, t.Client.Get(e.Ctx, key, &serviceBinding)
 }
 
 func (t *serviceBindingTrait) parseProvisionedServices(e *Environment) 
([]sb.Service, error) {
diff --git a/pkg/trait/service_test.go b/pkg/trait/service_test.go
index e68f482..9258542 100644
--- a/pkg/trait/service_test.go
+++ b/pkg/trait/service_test.go
@@ -18,18 +18,17 @@ limitations under the License.
 package trait
 
 import (
-       "context"
        "testing"
 
        v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
        "github.com/apache/camel-k/pkg/util/camel"
        "github.com/apache/camel-k/pkg/util/gzip"
        "github.com/apache/camel-k/pkg/util/kubernetes"
+       "github.com/apache/camel-k/pkg/util/test"
        "github.com/stretchr/testify/assert"
        appsv1 "k8s.io/api/apps/v1"
        corev1 "k8s.io/api/core/v1"
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
-       "github.com/apache/camel-k/pkg/util/test"
 )
 
 const (
@@ -41,7 +40,7 @@ func TestServiceWithDefaults(t *testing.T) {
        catalog, err := camel.DefaultCatalog()
        assert.Nil(t, err)
 
-       traitCatalog := NewCatalog(context.TODO(), nil)
+       traitCatalog := NewCatalog(nil)
 
        compressedRoute, err := 
gzip.CompressBase64([]byte(`from("netty-http:test").log("hello")`))
        assert.NoError(t, err)
@@ -130,7 +129,7 @@ func TestService(t *testing.T) {
        catalog, err := camel.DefaultCatalog()
        assert.Nil(t, err)
 
-       traitCatalog := NewCatalog(context.TODO(), nil)
+       traitCatalog := NewCatalog(nil)
 
        compressedRoute, err := 
gzip.CompressBase64([]byte(`from("netty-http:test").log("hello")`))
        assert.NoError(t, err)
@@ -227,7 +226,7 @@ func TestServiceWithCustomContainerName(t *testing.T) {
        catalog, err := camel.DefaultCatalog()
        assert.Nil(t, err)
 
-       traitCatalog := NewCatalog(context.TODO(), nil)
+       traitCatalog := NewCatalog(nil)
 
        environment := Environment{
                CamelCatalog: catalog,
@@ -298,7 +297,7 @@ func TestServiceWithNodePort(t *testing.T) {
        catalog, err := camel.DefaultCatalog()
        assert.Nil(t, err)
 
-       traitCatalog := NewCatalog(context.TODO(), nil)
+       traitCatalog := NewCatalog(nil)
 
        compressedRoute, err := 
gzip.CompressBase64([]byte(`from("netty-http:test").log("hello")`))
        assert.NoError(t, err)
diff --git a/pkg/trait/trait.go b/pkg/trait/trait.go
index 35ea851..fe837f9 100644
--- a/pkg/trait/trait.go
+++ b/pkg/trait/trait.go
@@ -37,7 +37,7 @@ func Apply(ctx context.Context, c client.Client, integration 
*v1.Integration, ki
                return nil, err
        }
 
-       catalog := NewCatalog(ctx, c)
+       catalog := NewCatalog(c)
 
        // set the catalog
        environment.Catalog = catalog
@@ -84,7 +84,7 @@ func newEnvironment(ctx context.Context, c client.Client, 
integration *v1.Integr
        }
 
        env := Environment{
-               C:                     ctx,
+               Ctx:                   ctx,
                Platform:              pl,
                Client:                c,
                IntegrationKit:        kit,
diff --git a/pkg/trait/trait_catalog.go b/pkg/trait/trait_catalog.go
index 7c51102..f3c31c5 100644
--- a/pkg/trait/trait_catalog.go
+++ b/pkg/trait/trait_catalog.go
@@ -18,7 +18,6 @@ limitations under the License.
 package trait
 
 import (
-       "context"
        "reflect"
        "sort"
        "strings"
@@ -38,7 +37,7 @@ type Catalog struct {
 }
 
 // NewCatalog creates a new trait Catalog
-func NewCatalog(ctx context.Context, c client.Client) *Catalog {
+func NewCatalog(c client.Client) *Catalog {
        var traitList = make([]Trait, 0, len(FactoryList))
        for _, factory := range FactoryList {
                traitList = append(traitList, factory())
@@ -56,9 +55,6 @@ func NewCatalog(ctx context.Context, c client.Client) 
*Catalog {
        }
 
        for _, t := range catalog.allTraits() {
-               if ctx != nil {
-                       t.InjectContext(ctx)
-               }
                if c != nil {
                        t.InjectClient(c)
                }
diff --git a/pkg/trait/trait_configure_test.go 
b/pkg/trait/trait_configure_test.go
index b454885..34b9e3f 100644
--- a/pkg/trait/trait_configure_test.go
+++ b/pkg/trait/trait_configure_test.go
@@ -18,13 +18,14 @@ limitations under the License.
 package trait
 
 import (
-       "context"
        "testing"
 
-       v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
-       "github.com/apache/camel-k/pkg/util/test"
        "github.com/stretchr/testify/assert"
+
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+       v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+       "github.com/apache/camel-k/pkg/util/test"
 )
 
 func TestTraitConfigurationFromAnnotations(t *testing.T) {
@@ -47,7 +48,7 @@ func TestTraitConfigurationFromAnnotations(t *testing.T) {
                        },
                },
        }
-       c := NewCatalog(context.Background(), nil)
+       c := NewCatalog(nil)
        assert.NoError(t, c.configure(&env))
        assert.True(t, *c.GetTrait("cron").(*cronTrait).Fallback)
        assert.Equal(t, "annotated-policy", 
c.GetTrait("cron").(*cronTrait).ConcurrencyPolicy)
@@ -67,7 +68,7 @@ func TestFailOnWrongTraitAnnotations(t *testing.T) {
                        },
                },
        }
-       c := NewCatalog(context.Background(), nil)
+       c := NewCatalog(nil)
        assert.Error(t, c.configure(&env))
 }
 
@@ -121,7 +122,7 @@ func TestTraitConfigurationOverrideRulesFromAnnotations(t 
*testing.T) {
                        },
                },
        }
-       c := NewCatalog(context.Background(), nil)
+       c := NewCatalog(nil)
        assert.NoError(t, c.configure(&env))
        assert.Equal(t, "schedule2", c.GetTrait("cron").(*cronTrait).Schedule)
        assert.Equal(t, "cmp4", c.GetTrait("cron").(*cronTrait).Components)
@@ -142,7 +143,7 @@ func TestTraitListConfigurationFromAnnotations(t 
*testing.T) {
                        },
                },
        }
-       c := NewCatalog(context.Background(), nil)
+       c := NewCatalog(nil)
        assert.NoError(t, c.configure(&env))
        assert.Equal(t, []string{"opt1", "opt2"}, 
c.GetTrait("jolokia").(*jolokiaTrait).Options)
        assert.Equal(t, []string{"Binding:xxx"}, 
c.GetTrait("service-binding").(*serviceBindingTrait).ServiceBindings)
@@ -161,7 +162,7 @@ func TestTraitSplitConfiguration(t *testing.T) {
                        },
                },
        }
-       c := NewCatalog(context.Background(), nil)
+       c := NewCatalog(nil)
        assert.NoError(t, c.configure(&env))
        assert.Equal(t, []string{"opt1", "opt2"}, 
c.GetTrait("owner").(*ownerTrait).TargetLabels)
 }
diff --git a/pkg/trait/trait_test.go b/pkg/trait/trait_test.go
index 100056d..6eb0261 100644
--- a/pkg/trait/trait_test.go
+++ b/pkg/trait/trait_test.go
@@ -18,7 +18,6 @@ limitations under the License.
 package trait
 
 import (
-       "context"
        "path"
        "testing"
 
@@ -568,7 +567,7 @@ func createTestEnv(t *testing.T, cluster 
v1.IntegrationPlatformCluster, script s
 
        res := &Environment{
                CamelCatalog: catalog,
-               Catalog:      NewCatalog(context.TODO(), nil),
+               Catalog:      NewCatalog(nil),
                Integration: &v1.Integration{
                        ObjectMeta: metav1.ObjectMeta{
                                Name:      TestDeploymentName,
@@ -608,5 +607,5 @@ func createTestEnv(t *testing.T, cluster 
v1.IntegrationPlatformCluster, script s
 }
 
 func NewTraitTestCatalog() *Catalog {
-       return NewCatalog(context.TODO(), nil)
+       return NewCatalog(nil)
 }
diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go
index 2ab9296..50fcb1a 100644
--- a/pkg/trait/trait_types.go
+++ b/pkg/trait/trait_types.go
@@ -25,12 +25,13 @@ import (
        "strconv"
        "strings"
 
-       "github.com/apache/camel-k/pkg/util/property"
        "github.com/pkg/errors"
+
        appsv1 "k8s.io/api/apps/v1"
        "k8s.io/api/batch/v1beta1"
        corev1 "k8s.io/api/core/v1"
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
        serving "knative.dev/serving/pkg/apis/serving/v1"
 
        ctrl "sigs.k8s.io/controller-runtime/pkg/client"
@@ -42,11 +43,13 @@ import (
        "github.com/apache/camel-k/pkg/util/camel"
        "github.com/apache/camel-k/pkg/util/kubernetes"
        "github.com/apache/camel-k/pkg/util/log"
+       "github.com/apache/camel-k/pkg/util/property"
 )
 
-// True --
-const True = "true"
-const False = "false"
+const (
+       True  = "true"
+       False = "false"
+)
 
 var (
        basePath                  = "/etc/camel"
@@ -72,9 +75,6 @@ type Trait interface {
        Identifiable
        client.Injectable
 
-       // InjectContext to inject a context
-       InjectContext(context.Context)
-
        // Configure the trait
        Configure(environment *Environment) (bool, error)
 
@@ -131,11 +131,10 @@ func NewBaseTrait(id string, order int) BaseTrait {
 type BaseTrait struct {
        TraitID ID `json:"-"`
        // Can be used to enable or disable a trait. All traits share this 
common property.
-       Enabled        *bool           `property:"enabled" 
json:"enabled,omitempty"`
-       Client         client.Client   `json:"-"`
-       Ctx            context.Context `json:"-"`
-       ExecutionOrder int             `json:"-"`
-       L              log.Logger      `json:"-"`
+       Enabled        *bool         `property:"enabled" 
json:"enabled,omitempty"`
+       Client         client.Client `json:"-"`
+       ExecutionOrder int           `json:"-"`
+       L              log.Logger    `json:"-"`
 }
 
 // ID returns the identifier of the trait
@@ -148,11 +147,6 @@ func (trait *BaseTrait) InjectClient(c client.Client) {
        trait.Client = c
 }
 
-// InjectContext allows to inject a context into the trait
-func (trait *BaseTrait) InjectContext(ctx context.Context) {
-       trait.Ctx = ctx
-}
-
 // InfluencesKit determines if the trait has any influence on Integration Kits
 func (trait *BaseTrait) InfluencesKit() bool {
        return false
@@ -192,8 +186,10 @@ type Environment struct {
        CamelCatalog   *camel.RuntimeCatalog
        RuntimeVersion string
        Catalog        *Catalog
-       C              context.Context
-       Client         client.Client
+       // The Go standard context for the traits execution
+       Ctx context.Context
+       // The client to the API server
+       Client client.Client
        // The active Platform
        Platform *v1.IntegrationPlatform
        // The current Integration
diff --git a/pkg/util/maven/maven_command.go b/pkg/util/maven/maven_command.go
index bca1a97..2e49333 100644
--- a/pkg/util/maven/maven_command.go
+++ b/pkg/util/maven/maven_command.go
@@ -159,15 +159,12 @@ func NewContext(buildDir string) Context {
 }
 
 type Context struct {
-       Path string
-       // Project             Project
+       Path                string
        ExtraMavenOpts      []string
        SettingsContent     []byte
        AdditionalArguments []string
        AdditionalEntries   map[string]interface{}
-       // Timeout             time.Duration
-       LocalRepository string
-       // Stdout              io.Writer
+       LocalRepository     string
 }
 
 func (c *Context) AddEntry(id string, entry interface{}) {

Reply via email to