Repository: apache/camel-k
Pull request #1481 (2020-06-03 09:01:48)

Code clean-up
**Release Note**
```release-note
NONE
```



Patch:
diff --git a/pkg/controller/integration/monitor.go b/pkg/controller/integration/monitor.go
index 344c694c8..4cea23e0f 100644
--- a/pkg/controller/integration/monitor.go
+++ b/pkg/controller/integration/monitor.go
@@ -27,6 +27,7 @@ import (
 	"github.com/apache/camel-k/pkg/trait"
 	"github.com/apache/camel-k/pkg/util/defaults"
 	"github.com/apache/camel-k/pkg/util/digest"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
 )
 
 // NewMonitorAction creates a new monitoring action for an integration
@@ -91,6 +92,9 @@ func (action *monitorAction) Handle(ctx context.Context, integration *v1.Integra
 		}
 	}
 
+	// Mirror ready condition from the sub resource (e.g.ReplicaSet, Deployment, CronJob, ...) to the integration
+	kubernetes.MirrorReadyCondition(ctx, action.client, integration)
+
 	return integration, nil
 }
 
diff --git a/pkg/trait/cron.go b/pkg/trait/cron.go
index 853e68220..3f740b1d6 100644
--- a/pkg/trait/cron.go
+++ b/pkg/trait/cron.go
@@ -75,8 +75,7 @@ type cronTrait struct {
 	//
 	// It's required that all periodic consumers have the same period and it can be expressed as cron schedule (e.g. `1m` can be expressed as `0/1 * * * *`,
 	// while `35m` or `50s` cannot).
-	Auto     *bool `property:"auto"`
-	deployer deployerTrait
+	Auto *bool `property:"auto"`
 }
 
 var _ ControllerStrategySelector = &cronTrait{}
@@ -180,10 +179,6 @@ func (t *cronTrait) Configure(e *Environment) (bool, error) {
 			}
 		}
 	}
-	dt := e.Catalog.GetTrait("deployer")
-	if dt != nil {
-		t.deployer = *dt.(*deployerTrait)
-	}
 
 	// Fallback strategy can be implemented in any other controller
 	if t.Fallback != nil && *t.Fallback {
@@ -199,7 +194,7 @@ func (t *cronTrait) Configure(e *Environment) (bool, error) {
 	}
 
 	// CronJob strategy requires common schedule
-	strategy, err := e.DetermineControllerStrategy(t.Ctx, t.Client)
+	strategy, err := e.DetermineControllerStrategy()
 	if err != nil {
 		e.Integration.Status.SetErrorCondition(
 			v1.IntegrationConditionCronJobAvailable,
diff --git a/pkg/trait/deployer.go b/pkg/trait/deployer.go
index da55a7e1b..836811055 100644
--- a/pkg/trait/deployer.go
+++ b/pkg/trait/deployer.go
@@ -110,12 +110,6 @@ func (t *deployerTrait) Apply(e *Environment) error {
 			}
 			return nil
 		})
-
-		// Mirror ready condition from the sub resource to the integration
-		e.PostActions = append(e.PostActions, func(e *Environment) error {
-			kubernetes.MirrorReadyCondition(t.Ctx, t.Client, e.Integration)
-			return nil
-		})
 	}
 
 	return nil
diff --git a/pkg/trait/deployment.go b/pkg/trait/deployment.go
index 088a72156..a56ec0688 100644
--- a/pkg/trait/deployment.go
+++ b/pkg/trait/deployment.go
@@ -33,7 +33,6 @@ import (
 // +camel-k:trait=deployment
 type deploymentTrait struct {
 	BaseTrait `property:",squash"`
-	deployer  deployerTrait
 }
 
 var _ ControllerStrategySelector = &deploymentTrait{}
@@ -64,7 +63,7 @@ func (t *deploymentTrait) Configure(e *Environment) (bool, error) {
 	//
 	// Don't deploy when a different strategy is needed (e.g. Knative, Cron)
 	//
-	strategy, err := e.DetermineControllerStrategy(t.Ctx, t.Client)
+	strategy, err := e.DetermineControllerStrategy()
 	if err != nil {
 		e.Integration.Status.SetErrorCondition(
 			v1.IntegrationConditionDeploymentAvailable,
@@ -85,15 +84,7 @@ func (t *deploymentTrait) Configure(e *Environment) (bool, error) {
 		return false, nil
 	}
 
-	enabled := e.IntegrationInPhase(v1.IntegrationPhaseDeploying)
-	if enabled {
-		dt := e.Catalog.GetTrait("deployer")
-		if dt != nil {
-			t.deployer = *dt.(*deployerTrait)
-		}
-	}
-
-	return enabled, nil
+	return e.IntegrationInPhase(v1.IntegrationPhaseDeploying), nil
 }
 
 func (t *deploymentTrait) SelectControllerStrategy(e *Environment) (*ControllerStrategy, error) {
@@ -146,12 +137,6 @@ func (t *deploymentTrait) IsPlatformTrait() bool {
 	return true
 }
 
-// **********************************
-//
-// Deployment
-//
-// **********************************
-
 func (t *deploymentTrait) getDeploymentFor(e *Environment) *appsv1.Deployment {
 	// create a copy to avoid sharing the underlying annotation map
 	annotations := make(map[string]string)
diff --git a/pkg/trait/knative_service.go b/pkg/trait/knative_service.go
index 8bbe95cd5..bea151337 100644
--- a/pkg/trait/knative_service.go
+++ b/pkg/trait/knative_service.go
@@ -121,7 +121,7 @@ func (t *knativeServiceTrait) Configure(e *Environment) (bool, error) {
 		return false, nil
 	}
 
-	strategy, err := e.DetermineControllerStrategy(t.Ctx, t.Client)
+	strategy, err := e.DetermineControllerStrategy()
 	if err != nil {
 		e.Integration.Status.SetErrorCondition(
 			v1.IntegrationConditionKnativeServiceAvailable,
diff --git a/pkg/trait/prometheus.go b/pkg/trait/prometheus.go
index 03b89f7c4..9beeb2cb7 100644
--- a/pkg/trait/prometheus.go
+++ b/pkg/trait/prometheus.go
@@ -123,7 +123,7 @@ func (t *prometheusTrait) Apply(e *Environment) (err error) {
 
 	// Configure the Prometheus container port
 	containerPort := t.getContainerPort()
-	controller, err := e.DetermineControllerStrategy(t.Ctx, t.Client)
+	controller, err := e.DetermineControllerStrategy()
 	if err != nil {
 		return err
 	}
diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go
index 457afcf0f..6352c7a77 100644
--- a/pkg/trait/trait_types.go
+++ b/pkg/trait/trait_types.go
@@ -28,8 +28,6 @@ import (
 	"github.com/apache/camel-k/pkg/util"
 	corev1 "k8s.io/api/core/v1"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
-	controller "sigs.k8s.io/controller-runtime/pkg/client"
-
 	"k8s.io/apimachinery/pkg/runtime"
 
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
@@ -223,7 +221,7 @@ const (
 	ControllerStrategyKnativeService ControllerStrategy = "knative-service"
 	ControllerStrategyCronJob        ControllerStrategy = "cron-job"
 
-	DefaultControllerStrategy ControllerStrategy = ControllerStrategyDeployment
+	DefaultControllerStrategy = ControllerStrategyDeployment
 )
 
 // GetTrait --
@@ -298,7 +296,7 @@ func (e *Environment) DetermineProfile() v1.TraitProfile {
 }
 
 // DetermineControllerStrategy determines the type of controller that should be used for the integration
-func (e *Environment) DetermineControllerStrategy(ctx context.Context, c controller.Reader) (ControllerStrategy, error) {
+func (e *Environment) DetermineControllerStrategy() (ControllerStrategy, error) {
 	defaultStrategy := DefaultControllerStrategy
 	for _, creator := range e.getControllerStrategyChoosers() {
 		if strategy, err := creator.SelectControllerStrategy(e); err != nil {


Test patch:
diff --git a/pkg/trait/deployer_test.go b/pkg/trait/deployer_test.go
index 7160f55d4..d5ffb9735 100644
--- a/pkg/trait/deployer_test.go
+++ b/pkg/trait/deployer_test.go
@@ -52,7 +52,7 @@ func TestApplyDeployerTraitDoesSucceed(t *testing.T) {
 	err := deployerTrait.Apply(environment)
 
 	assert.Nil(t, err)
-	assert.Len(t, environment.PostActions, 2)
+	assert.Len(t, environment.PostActions, 1)
 }
 
 func TestApplyDeployerTraitInInitializationPhaseDoesSucceed(t *testing.T) {
diff --git a/pkg/trait/deployment_test.go b/pkg/trait/deployment_test.go
index a20293f80..9798e723c 100644
--- a/pkg/trait/deployment_test.go
+++ b/pkg/trait/deployment_test.go
@@ -68,7 +68,6 @@ func TestConfigureDeploymentTraitDoesSucceed(t *testing.T) {
 
 	assert.Nil(t, err)
 	assert.True(t, configured)
-	assert.NotNil(t, deploymentTrait.deployer)
 }
 
 func TestConfigureDeploymentTraitWhileBuildingKitDoesNotSucceed(t *testing.T) {