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 b35a9b305f094e06768bca8333114b05a587ff28 Author: Antonin Stefanutti <[email protected]> AuthorDate: Thu Aug 19 17:11:23 2021 +0200 chore(native): Simplify integration transition out of kit building phase --- pkg/controller/integration/build_kit.go | 5 +-- pkg/trait/deployer.go | 68 +++++++++++++-------------------- pkg/trait/deployer_test.go | 10 ----- 3 files changed, 27 insertions(+), 56 deletions(-) diff --git a/pkg/controller/integration/build_kit.go b/pkg/controller/integration/build_kit.go index fbb665a..348d3a5 100644 --- a/pkg/controller/integration/build_kit.go +++ b/pkg/controller/integration/build_kit.go @@ -92,12 +92,9 @@ func (action *buildKitAction) Handle(ctx context.Context, integration *v1.Integr if kit.Status.Phase == v1.IntegrationKitPhaseReady { integration.Status.Image = kit.Status.Image + integration.Status.Phase = v1.IntegrationPhaseDeploying integration.SetIntegrationKit(kit) - if _, err := trait.Apply(ctx, action.client, integration, kit); err != nil { - return nil, err - } - return integration, nil } diff --git a/pkg/trait/deployer.go b/pkg/trait/deployer.go index 609519c..9e49374 100644 --- a/pkg/trait/deployer.go +++ b/pkg/trait/deployer.go @@ -33,8 +33,8 @@ import ( "github.com/apache/camel-k/pkg/util/patch" ) -// The deployer trait can be used to explicitly select the kind of high level resource that -// will deploy the integration. +// The deployer trait is responsible for deploying the resources owned by the integration, and can be used +// to explicitly select the underlying controller that will manage the integration pods. // // +camel-k:trait=deployer type deployerTrait struct { @@ -59,55 +59,39 @@ func (t *deployerTrait) Configure(e *Environment) (bool, error) { v1.IntegrationPhaseWaitingForBindings, v1.IntegrationPhaseWaitingForPlatform, v1.IntegrationPhaseInitialization, - v1.IntegrationPhaseBuildingKit, v1.IntegrationPhaseDeploying, v1.IntegrationPhaseRunning, ), nil } func (t *deployerTrait) Apply(e *Environment) error { - switch e.Integration.Status.Phase { - - case v1.IntegrationPhaseBuildingKit: - if e.IntegrationKitInPhase(v1.IntegrationKitPhaseReady) { - e.PostProcessors = append(e.PostProcessors, func(environment *Environment) error { - // trigger integration deploy - e.Integration.Status.Phase = v1.IntegrationPhaseDeploying - return nil - }) - } - - case v1.IntegrationPhaseNone, v1.IntegrationPhaseInitialization, - v1.IntegrationPhaseWaitingForPlatform, v1.IntegrationPhaseWaitingForBindings, - v1.IntegrationPhaseDeploying, v1.IntegrationPhaseRunning: - // Register a post action that patches the resources generated by the traits - e.PostActions = append(e.PostActions, func(env *Environment) error { - for _, resource := range env.Resources.Items() { - // We assume that server-side apply is enabled by default. - // It is currently convoluted to check pro-actively whether server-side apply - // is enabled. This is possible to fetch the OpenAPI endpoint, which returns - // the entire server API document, then lookup the resource PATCH endpoint, and - // check its list of accepted MIME types. - // As a simpler solution, we fall back to client-side apply at the first - // 415 error, and assume server-side apply is not available globally. - if hasServerSideApply { - if err := t.serverSideApply(env, resource); err == nil { - continue - } else if isIncompatibleServerError(err) { - t.L.Info("Fallback to client-side apply to patch resources") - hasServerSideApply = false - } else { - // Keep server-side apply unless server is incompatible with it - return err - } - } - if err := t.clientSideApply(env, resource); err != nil { + // Register a post action that patches the resources generated by the traits + e.PostActions = append(e.PostActions, func(env *Environment) error { + for _, resource := range env.Resources.Items() { + // We assume that server-side apply is enabled by default. + // It is currently convoluted to check pro-actively whether server-side apply + // is enabled. This is possible to fetch the OpenAPI endpoint, which returns + // the entire server API document, then lookup the resource PATCH endpoint, and + // check its list of accepted MIME types. + // As a simpler solution, we fall back to client-side apply at the first + // 415 error, and assume server-side apply is not available globally. + if hasServerSideApply { + if err := t.serverSideApply(env, resource); err == nil { + continue + } else if isIncompatibleServerError(err) { + t.L.Info("Fallback to client-side apply to patch resources") + hasServerSideApply = false + } else { + // Keep server-side apply unless server is incompatible with it return err } } - return nil - }) - } + if err := t.clientSideApply(env, resource); err != nil { + return err + } + } + return nil + }) return nil } diff --git a/pkg/trait/deployer_test.go b/pkg/trait/deployer_test.go index c595f2c..939dcb0 100644 --- a/pkg/trait/deployer_test.go +++ b/pkg/trait/deployer_test.go @@ -65,16 +65,6 @@ func TestApplyDeployerTraitInInitializationPhaseDoesSucceed(t *testing.T) { assert.Len(t, environment.PostActions, 1) } -func TestApplyDeployerTraitInResolvingKitPhaseSkipPostActions(t *testing.T) { - deployerTrait, environment := createNominalDeployerTest() - environment.Integration.Status.Phase = v1.IntegrationPhaseBuildingKit - - err := deployerTrait.Apply(environment) - - assert.Nil(t, err) - assert.Len(t, environment.PostActions, 0) -} - func createNominalDeployerTest() (*deployerTrait, *Environment) { trait := newDeployerTrait().(*deployerTrait)
