Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code clean-up #1481

Merged
merged 4 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/controller/integration/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
9 changes: 2 additions & 7 deletions pkg/trait/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions pkg/trait/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/trait/deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 2 additions & 17 deletions pkg/trait/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
// +camel-k:trait=deployment
type deploymentTrait struct {
BaseTrait `property:",squash"`
deployer deployerTrait
}

var _ ControllerStrategySelector = &deploymentTrait{}
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion pkg/trait/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/trait/knative_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pkg/trait/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/trait/trait_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -223,7 +221,7 @@ const (
ControllerStrategyKnativeService ControllerStrategy = "knative-service"
ControllerStrategyCronJob ControllerStrategy = "cron-job"

DefaultControllerStrategy ControllerStrategy = ControllerStrategyDeployment
DefaultControllerStrategy = ControllerStrategyDeployment
)

// GetTrait --
Expand Down Expand Up @@ -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 {
Expand Down