From 9f632ae4b46146853fa397f71b177ba6e955143c Mon Sep 17 00:00:00 2001 From: lburgazzoli Date: Tue, 14 May 2019 10:31:07 +0200 Subject: [PATCH] remove support for integration container image creation #650 --- pkg/apis/camel/v1alpha1/integration_types.go | 4 - pkg/controller/integration/build_image.go | 232 --------------- .../integration/integration_controller.go | 1 - pkg/trait/builder.go | 45 +-- pkg/trait/deployer.go | 5 +- pkg/trait/deployment.go | 23 +- pkg/trait/knative_service.go | 2 +- pkg/trait/knative_service_vol.go | 4 +- pkg/trait/knative_service_vol_test.go | 113 -------- pkg/trait/trait_test.go | 2 +- pkg/trait/trait_types.go | 271 +++++++++--------- 11 files changed, 150 insertions(+), 552 deletions(-) delete mode 100644 pkg/controller/integration/build_image.go diff --git a/pkg/apis/camel/v1alpha1/integration_types.go b/pkg/apis/camel/v1alpha1/integration_types.go index 2edd3d8851..7b6b5482a5 100644 --- a/pkg/apis/camel/v1alpha1/integration_types.go +++ b/pkg/apis/camel/v1alpha1/integration_types.go @@ -132,10 +132,6 @@ const ( IntegrationPhaseBuildingContext IntegrationPhase = "Building Context" // IntegrationPhaseResolvingContext -- IntegrationPhaseResolvingContext IntegrationPhase = "Resolving Context" - // IntegrationPhaseBuildImageSubmitted -- - IntegrationPhaseBuildImageSubmitted IntegrationPhase = "Build Image Submitted" - // IntegrationPhaseBuildImageRunning -- - IntegrationPhaseBuildImageRunning IntegrationPhase = "Build Image Running" // IntegrationPhaseDeploying -- IntegrationPhaseDeploying IntegrationPhase = "Deploying" // IntegrationPhaseRunning -- diff --git a/pkg/controller/integration/build_image.go b/pkg/controller/integration/build_image.go deleted file mode 100644 index 7c2a9de174..0000000000 --- a/pkg/controller/integration/build_image.go +++ /dev/null @@ -1,232 +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 integration - -import ( - "context" - "fmt" - - k8serrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - - "github.com/pkg/errors" - - "github.com/apache/camel-k/pkg/apis/camel/v1alpha1" - "github.com/apache/camel-k/pkg/builder" - "github.com/apache/camel-k/pkg/trait" - "github.com/apache/camel-k/pkg/util/digest" - "github.com/apache/camel-k/pkg/util/kubernetes" -) - -// NewBuildImageAction create an action that handles integration image build -func NewBuildImageAction() Action { - return &buildImageAction{} -} - -type buildImageAction struct { - baseAction -} - -func (action *buildImageAction) Name() string { - return "build-image" -} - -func (action *buildImageAction) CanHandle(integration *v1alpha1.Integration) bool { - return integration.Status.Phase == v1alpha1.IntegrationPhaseBuildImageSubmitted || - integration.Status.Phase == v1alpha1.IntegrationPhaseBuildImageRunning -} - -func (action *buildImageAction) Handle(ctx context.Context, integration *v1alpha1.Integration) error { - if integration.Status.Phase == v1alpha1.IntegrationPhaseBuildImageSubmitted { - return action.handleBuildImageSubmitted(ctx, integration) - } else if integration.Status.Phase == v1alpha1.IntegrationPhaseBuildImageRunning { - return action.handleBuildImageRunning(ctx, integration) - } - - return nil -} - -func (action *buildImageAction) handleBuildImageSubmitted(ctx context.Context, integration *v1alpha1.Integration) error { - // in this phase the integration need to be associated to a context whose image - // will be used as base image for the integration images - if integration.Status.Context == "" { - return fmt.Errorf("context is not set for integration: %s", integration.Name) - } - - // look-up the integration context associated to this integration, this is needed - // to determine the base image - ictx, err := kubernetes.GetIntegrationContext(ctx, action.client, integration.Status.Context, integration.Namespace) - if err != nil || ictx == nil { - return errors.Wrapf(err, "unable to find integration context %s, %s", integration.Status.Context, err) - } - - build := &v1alpha1.Build{} - err = action.client.Get(ctx, types.NamespacedName{Namespace: integration.Namespace, Name: integration.Name}, build) - if err != nil && !k8serrors.IsNotFound(err) { - return err - } - - if err != nil && k8serrors.IsNotFound(err) || - build.Status.Phase == v1alpha1.BuildPhaseError || - build.Status.Phase == v1alpha1.BuildPhaseInterrupted || - build.Status.Phase == v1alpha1.BuildPhaseSucceeded { - env, err := trait.Apply(ctx, action.client, integration, ictx) - if err != nil { - return err - } - if env.CamelCatalog == nil { - return errors.New("undefined camel catalog") - } - - // This build do not require to determine dependencies nor a project, the - // builder step do remove them - - build = &v1alpha1.Build{ - TypeMeta: metav1.TypeMeta{ - APIVersion: "camel.apache.org/v1alpha1", - Kind: "Build", - }, - ObjectMeta: metav1.ObjectMeta{ - Namespace: integration.Namespace, - Name: integration.Name, - }, - Spec: v1alpha1.BuildSpec{ - Meta: integration.ObjectMeta, - Image: ictx.Status.Image, - CamelVersion: env.CamelCatalog.Version, - RuntimeVersion: env.RuntimeVersion, - Platform: env.Platform.Spec, - Steps: builder.StepIDsFor(env.Steps...), - BuildDir: env.BuildDir, - }, - } - - // Inline source and resources so they are copied over the generated - // container image. For the time being, references are being resolved - // and their content serialized. We may want to resolve after the build - // is submitted, just before the build is run. - if err := action.inlineSources(ctx, integration, build, env); err != nil { - return err - } - if err := action.inlineResources(ctx, integration, build, env); err != nil { - return err - } - - // Set the integration context instance as the owner and controller - if err := controllerutil.SetControllerReference(integration, build, action.client.GetScheme()); err != nil { - return err - } - - err = action.client.Delete(ctx, build) - if err != nil && !k8serrors.IsNotFound(err) { - return errors.Wrap(err, "cannot delete build") - } - - err = action.client.Create(ctx, build) - if err != nil { - return errors.Wrap(err, "cannot create build") - } - } - - if build.Status.Phase == v1alpha1.BuildPhaseRunning { - target := integration.DeepCopy() - target.Status.Phase = v1alpha1.IntegrationPhaseBuildImageRunning - - action.L.Info("Integration state transition", "phase", target.Status.Phase) - - return action.client.Status().Update(ctx, target) - } - - return nil -} - -func (action *buildImageAction) handleBuildImageRunning(ctx context.Context, integration *v1alpha1.Integration) error { - build := &v1alpha1.Build{} - err := action.client.Get(ctx, types.NamespacedName{Namespace: integration.Namespace, Name: integration.Name}, build) - if err != nil { - return err - } - - switch build.Status.Phase { - - case v1alpha1.BuildPhaseRunning: - action.L.Info("Build running") - - case v1alpha1.BuildPhaseSucceeded: - target := integration.DeepCopy() - target.Status.Phase = v1alpha1.IntegrationPhaseDeploying - if build.Status.PublicImage != "" { - target.Status.Image = build.Status.PublicImage - } else { - target.Status.Image = build.Status.Image - } - - dgst, err := digest.ComputeForIntegration(target) - if err != nil { - return err - } - - target.Status.Digest = dgst - - action.L.Info("Integration state transition", "phase", target.Status.Phase) - - if err := action.client.Status().Update(ctx, target); err != nil { - return err - } - - case v1alpha1.BuildPhaseError, v1alpha1.BuildPhaseInterrupted: - target := integration.DeepCopy() - - // Let's copy the build failure to the integration status - target.Status.Failure = build.Status.Failure - target.Status.Phase = v1alpha1.IntegrationPhaseError - - action.L.Error(fmt.Errorf(build.Status.Error), "Integration state transition", "phase", target.Status.Phase) - - return action.client.Status().Update(ctx, target) - } - - return nil -} - -func (action *buildImageAction) inlineSources(ctx context.Context, integration *v1alpha1.Integration, build *v1alpha1.Build, e *trait.Environment) error { - sources, err := kubernetes.ResolveIntegrationSources(ctx, action.client, integration, e.Resources) - if err != nil { - return err - } - - build.Spec.Sources = make([]v1alpha1.SourceSpec, 0, len(sources)) - build.Spec.Sources = append(build.Spec.Sources, sources...) - - return nil -} - -func (action *buildImageAction) inlineResources(ctx context.Context, integration *v1alpha1.Integration, build *v1alpha1.Build, e *trait.Environment) error { - resources, err := kubernetes.ResolveIntegrationResources(ctx, action.client, integration, e.Resources) - if err != nil { - return err - } - - build.Spec.Resources = make([]v1alpha1.ResourceSpec, 0, len(resources)) - build.Spec.Resources = append(build.Spec.Resources, resources...) - - return nil -} diff --git a/pkg/controller/integration/integration_controller.go b/pkg/controller/integration/integration_controller.go index d42ba4a2e7..a9161b2376 100644 --- a/pkg/controller/integration/integration_controller.go +++ b/pkg/controller/integration/integration_controller.go @@ -131,7 +131,6 @@ func (r *ReconcileIntegration) Reconcile(request reconcile.Request) (reconcile.R integrationActionPool := []Action{ NewInitializeAction(), NewBuildContextAction(), - NewBuildImageAction(), NewDeployAction(), NewMonitorAction(), NewDeleteAction(), diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go index bdfaa48af2..f957841a31 100644 --- a/pkg/trait/builder.go +++ b/pkg/trait/builder.go @@ -19,7 +19,6 @@ package trait import ( "github.com/apache/camel-k/pkg/apis/camel/v1alpha1" - "github.com/apache/camel-k/pkg/builder" "github.com/apache/camel-k/pkg/builder/kaniko" "github.com/apache/camel-k/pkg/builder/s2i" "github.com/apache/camel-k/pkg/platform" @@ -41,46 +40,18 @@ func (t *builderTrait) Configure(e *Environment) (bool, error) { return false, nil } - if e.IntegrationContextInPhase(v1alpha1.IntegrationContextPhaseBuildSubmitted) { - return true, nil - } - - if e.InPhase(v1alpha1.IntegrationContextPhaseReady, v1alpha1.IntegrationPhaseBuildImageSubmitted) { - return true, nil - } - - return false, nil + return e.IntegrationContextInPhase(v1alpha1.IntegrationContextPhaseBuildSubmitted), nil } func (t *builderTrait) Apply(e *Environment) error { - if e.IntegrationContextInPhase(v1alpha1.IntegrationContextPhaseBuildSubmitted) { - if platform.SupportsS2iPublishStrategy(e.Platform) { - e.Steps = s2i.DefaultSteps - if e.DetermineProfile() == v1alpha1.TraitProfileKnative { - e.Steps = append(e.Steps, s2i.Steps.ReplaceHost) - } - } else if platform.SupportsKanikoPublishStrategy(e.Platform) { - e.Steps = kaniko.DefaultSteps - e.BuildDir = kaniko.BuildDir - } - } - - if e.InPhase(v1alpha1.IntegrationContextPhaseReady, v1alpha1.IntegrationPhaseBuildImageSubmitted) { - if platform.SupportsS2iPublishStrategy(e.Platform) { - e.Steps = []builder.Step{ - builder.Steps.StandardPackager, - s2i.Steps.Publisher, - } - if e.DetermineProfile() == v1alpha1.TraitProfileKnative { - e.Steps = append(e.Steps, s2i.Steps.ReplaceHost) - } - } else if platform.SupportsKanikoPublishStrategy(e.Platform) { - e.Steps = []builder.Step{ - builder.Steps.StandardPackager, - kaniko.Steps.Publisher, - } - e.BuildDir = kaniko.BuildDir + if platform.SupportsS2iPublishStrategy(e.Platform) { + e.Steps = s2i.DefaultSteps + if e.DetermineProfile() == v1alpha1.TraitProfileKnative { + e.Steps = append(e.Steps, s2i.Steps.ReplaceHost) } + } else if platform.SupportsKanikoPublishStrategy(e.Platform) { + e.Steps = kaniko.DefaultSteps + e.BuildDir = kaniko.BuildDir } return nil diff --git a/pkg/trait/deployer.go b/pkg/trait/deployer.go index 7e00c0918a..58ee8032de 100644 --- a/pkg/trait/deployer.go +++ b/pkg/trait/deployer.go @@ -18,9 +18,8 @@ limitations under the License. package trait type deployerTrait struct { - BaseTrait `property:",squash"` - ContainerImage bool `property:"container-image"` - Kind string `property:"kind"` + BaseTrait `property:",squash"` + Kind string `property:"kind"` } func newDeployerTrait() *deployerTrait { diff --git a/pkg/trait/deployment.go b/pkg/trait/deployment.go index 36e0b5856f..2ae00dbd76 100644 --- a/pkg/trait/deployment.go +++ b/pkg/trait/deployment.go @@ -74,25 +74,17 @@ func (t *deploymentTrait) Apply(e *Environment) error { if e.IntegrationContextInPhase(v1alpha1.IntegrationContextPhaseReady) && e.IntegrationInPhase(v1alpha1.IntegrationPhaseBuildingContext, v1alpha1.IntegrationPhaseResolvingContext) { - if t.deployer.ContainerImage { - e.PostProcessors = append(e.PostProcessors, func(environment *Environment) error { - // trigger container image build - e.Integration.Status.Phase = v1alpha1.IntegrationPhaseBuildImageSubmitted - return nil - }) - } else { - e.PostProcessors = append(e.PostProcessors, func(environment *Environment) error { - // trigger integration deploy - e.Integration.Status.Phase = v1alpha1.IntegrationPhaseDeploying - return nil - }) - } + e.PostProcessors = append(e.PostProcessors, func(environment *Environment) error { + // trigger integration deploy + e.Integration.Status.Phase = v1alpha1.IntegrationPhaseDeploying + return nil + }) return nil } if e.InPhase(v1alpha1.IntegrationContextPhaseReady, v1alpha1.IntegrationPhaseDeploying) { - e.Resources.AddAll(e.ComputeConfigMaps(t.deployer.ContainerImage)) + e.Resources.AddAll(e.ComputeConfigMaps()) e.Resources.Add(t.getDeploymentFor(e)) } @@ -106,7 +98,7 @@ func (t *deploymentTrait) Apply(e *Environment) error { // ********************************** func (t *deploymentTrait) getDeploymentFor(e *Environment) *appsv1.Deployment { - paths := e.ComputeSourcesURI(t.deployer.ContainerImage) + paths := e.ComputeSourcesURI() environment := make([]corev1.EnvVar, 0) // combine Environment of integration with platform, context, integration @@ -179,7 +171,6 @@ func (t *deploymentTrait) getDeploymentFor(e *Environment) *appsv1.Deployment { } e.ConfigureVolumesAndMounts( - t.deployer.ContainerImage, &deployment.Spec.Template.Spec.Volumes, &deployment.Spec.Template.Spec.Containers[0].VolumeMounts, ) diff --git a/pkg/trait/knative_service.go b/pkg/trait/knative_service.go index 454e0cf8b5..e5c6dee81d 100644 --- a/pkg/trait/knative_service.go +++ b/pkg/trait/knative_service.go @@ -115,7 +115,7 @@ func (t *knativeServiceTrait) Apply(e *Environment) error { return err } - maps := e.ComputeConfigMaps(t.deployer.ContainerImage) + maps := e.ComputeConfigMaps() e.Resources.Add(svc) e.Resources.AddAll(maps) diff --git a/pkg/trait/knative_service_vol.go b/pkg/trait/knative_service_vol.go index efe058dc4e..03c95bb81e 100644 --- a/pkg/trait/knative_service_vol.go +++ b/pkg/trait/knative_service_vol.go @@ -26,13 +26,11 @@ import ( func (t *knativeServiceTrait) bindToVolumes(e *Environment, service *serving.Service) { e.ConfigureVolumesAndMounts( - t.deployer.ContainerImage, &service.Spec.RunLatest.Configuration.RevisionTemplate.Spec.Volumes, &service.Spec.RunLatest.Configuration.RevisionTemplate.Spec.Container.VolumeMounts, ) - paths := e.ComputeSourcesURI(t.deployer.ContainerImage) - + paths := e.ComputeSourcesURI() environment := &service.Spec.RunLatest.Configuration.RevisionTemplate.Spec.Container.Env envvar.SetVal(environment, "CAMEL_K_ROUTES", strings.Join(paths, ",")) diff --git a/pkg/trait/knative_service_vol_test.go b/pkg/trait/knative_service_vol_test.go index 86ff6c12cb..81cf388ef4 100644 --- a/pkg/trait/knative_service_vol_test.go +++ b/pkg/trait/knative_service_vol_test.go @@ -173,116 +173,3 @@ func TestKnativeWithVolumeBinding(t *testing.T) { test.EnvVarHasValue(t, spec.Container.Env, "CAMEL_K_CONF", "/etc/camel/conf/application.properties") test.EnvVarHasValue(t, spec.Container.Env, "CAMEL_K_CONF_D", "/etc/camel/conf.d") } - -func TestKnativeWithVolumeBindingAndContainerImage(t *testing.T) { - catalog, err := test.DefaultCatalog() - assert.Nil(t, err) - - traitCatalog := NewCatalog(context.TODO(), nil) - - environment := Environment{ - CamelCatalog: catalog, - Catalog: traitCatalog, - Integration: &v1alpha1.Integration{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test", - Namespace: "ns", - }, - Status: v1alpha1.IntegrationStatus{ - Phase: v1alpha1.IntegrationPhaseDeploying, - }, - Spec: v1alpha1.IntegrationSpec{ - Profile: v1alpha1.TraitProfileKnative, - Sources: []v1alpha1.SourceSpec{ - { - DataSpec: v1alpha1.DataSpec{ - Name: "routes.js", - Content: `from("undertow:test").log("hello")`, - Compression: true, - }, - Language: v1alpha1.LanguageJavaScript, - }, - }, - Resources: []v1alpha1.ResourceSpec{ - { - DataSpec: v1alpha1.DataSpec{ - Name: "my-resource.txt", - Content: "", - Compression: false, - }, - Type: v1alpha1.ResourceTypeData, - }, - }, - Configuration: []v1alpha1.ConfigurationSpec{ - {Type: "configmap", Value: "my-cm"}, - {Type: "secret", Value: "my-secret"}, - }, - Traits: map[string]v1alpha1.TraitSpec{ - "deployer": { - Configuration: map[string]string{ - "container-image": "true", - }, - }, - "knative-service": { - Configuration: map[string]string{ - "configuration-type": "volume", - }, - }, - }, - }, - }, - IntegrationContext: &v1alpha1.IntegrationContext{ - Status: v1alpha1.IntegrationContextStatus{ - Phase: v1alpha1.IntegrationContextPhaseReady, - }, - }, - Platform: &v1alpha1.IntegrationPlatform{ - Spec: v1alpha1.IntegrationPlatformSpec{ - Cluster: v1alpha1.IntegrationPlatformClusterOpenShift, - Build: v1alpha1.IntegrationPlatformBuildSpec{ - PublishStrategy: v1alpha1.IntegrationPlatformBuildPublishStrategyS2I, - Registry: v1alpha1.IntegrationPlatformRegistrySpec{Address: "registry"}, - }, - }, - }, - EnvVars: make([]corev1.EnvVar, 0), - ExecutedTraits: make([]Trait, 0), - Resources: kubernetes.NewCollection(), - Classpath: strset.New(), - } - - err = traitCatalog.apply(&environment) - - assert.Nil(t, err) - assert.NotEmpty(t, environment.ExecutedTraits) - assert.NotNil(t, environment.GetTrait(ID("knative"))) - assert.NotNil(t, envvar.Get(environment.EnvVars, "CAMEL_KNATIVE_CONFIGURATION")) - assert.Equal(t, 2, environment.Resources.Size()) - - names := make([]string, 0) - environment.Resources.VisitConfigMap(func(cm *corev1.ConfigMap) { - names = append(names, cm.Name) - }) - - assert.Contains(t, names, "test-properties") - - s := environment.Resources.GetKnativeService(func(service *serving.Service) bool { - return service.Name == "test" - }) - - assert.NotNil(t, s) - - spec := s.Spec.RunLatest.Configuration.RevisionTemplate.Spec - - assert.Len(t, spec.Container.VolumeMounts, 3) - assert.Len(t, spec.Volumes, 3) - - test.HasVolume(t, spec.Volumes, "my-cm") - test.HasVolume(t, spec.Volumes, "my-secret") - test.HasVolume(t, spec.Volumes, "integration-properties") - - test.EnvVarExists(t, spec.Container.Env, "JAVA_CLASSPATH") - test.EnvVarHasValue(t, spec.Container.Env, "CAMEL_K_ROUTES", "file:/deployments/sources/routes.js?language=js&compression=true") - test.EnvVarHasValue(t, spec.Container.Env, "CAMEL_K_CONF", "/etc/camel/conf/application.properties") - test.EnvVarHasValue(t, spec.Container.Env, "CAMEL_K_CONF_D", "/etc/camel/conf.d") -} diff --git a/pkg/trait/trait_test.go b/pkg/trait/trait_test.go index 69a59cf030..0cb46a4205 100644 --- a/pkg/trait/trait_test.go +++ b/pkg/trait/trait_test.go @@ -282,7 +282,7 @@ func TestConfigureVolumesAndMounts(t *testing.T) { vols := make([]corev1.Volume, 0) mnts := make([]corev1.VolumeMount, 0) - env.ConfigureVolumesAndMounts(false, &vols, &mnts) + env.ConfigureVolumesAndMounts(&vols, &mnts) assert.Len(t, vols, 8) assert.Len(t, mnts, 8) diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go index a840df358c..e750fd7d1f 100644 --- a/pkg/trait/trait_types.go +++ b/pkg/trait/trait_types.go @@ -255,7 +255,7 @@ func (e *Environment) DetermineRuntimeVersion() string { } // ComputeConfigMaps -- -func (e *Environment) ComputeConfigMaps(container bool) []runtime.Object { +func (e *Environment) ComputeConfigMaps() []runtime.Object { sources := e.Integration.Sources() maps := make([]runtime.Object, 0, len(sources)+1) @@ -287,92 +287,84 @@ func (e *Environment) ComputeConfigMaps(container bool) []runtime.Object { }, ) - if !container { - for i, s := range sources { - if s.ContentRef != "" { - continue - } + for i, s := range sources { + if s.ContentRef != "" { + continue + } - cm := corev1.ConfigMap{ - TypeMeta: metav1.TypeMeta{ - Kind: "ConfigMap", - APIVersion: "v1", - }, - ObjectMeta: metav1.ObjectMeta{ - Name: fmt.Sprintf("%s-source-%03d", e.Integration.Name, i), - Namespace: e.Integration.Namespace, - Labels: map[string]string{ - "camel.apache.org/integration": e.Integration.Name, - }, - Annotations: map[string]string{ - "camel.apache.org/source.language": string(s.InferLanguage()), - "camel.apache.org/source.name": s.Name, - "camel.apache.org/source.compression": strconv.FormatBool(s.Compression), - }, + cm := corev1.ConfigMap{ + TypeMeta: metav1.TypeMeta{ + Kind: "ConfigMap", + APIVersion: "v1", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("%s-source-%03d", e.Integration.Name, i), + Namespace: e.Integration.Namespace, + Labels: map[string]string{ + "camel.apache.org/integration": e.Integration.Name, }, - Data: map[string]string{ - "content": s.Content, + Annotations: map[string]string{ + "camel.apache.org/source.language": string(s.InferLanguage()), + "camel.apache.org/source.name": s.Name, + "camel.apache.org/source.compression": strconv.FormatBool(s.Compression), }, - } + }, + Data: map[string]string{ + "content": s.Content, + }, + } + + maps = append(maps, &cm) + } - maps = append(maps, &cm) + for i, r := range e.Integration.Spec.Resources { + if r.Type != v1alpha1.ResourceTypeData { + continue + } + if r.ContentRef != "" { + continue } - for i, r := range e.Integration.Spec.Resources { - if r.Type != v1alpha1.ResourceTypeData { - continue - } - if r.ContentRef != "" { - continue - } - - cmKey := "content" - if r.ContentKey != "" { - cmKey = r.ContentKey - } - - cm := corev1.ConfigMap{ - TypeMeta: metav1.TypeMeta{ - Kind: "ConfigMap", - APIVersion: "v1", - }, - ObjectMeta: metav1.ObjectMeta{ - Name: fmt.Sprintf("%s-resource-%03d", e.Integration.Name, i), - Namespace: e.Integration.Namespace, - Labels: map[string]string{ - "camel.apache.org/integration": e.Integration.Name, - }, - Annotations: map[string]string{ - "camel.apache.org/resource.name": r.Name, - "camel.apache.org/resource.compression": strconv.FormatBool(r.Compression), - }, + cmKey := "content" + if r.ContentKey != "" { + cmKey = r.ContentKey + } + + cm := corev1.ConfigMap{ + TypeMeta: metav1.TypeMeta{ + Kind: "ConfigMap", + APIVersion: "v1", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("%s-resource-%03d", e.Integration.Name, i), + Namespace: e.Integration.Namespace, + Labels: map[string]string{ + "camel.apache.org/integration": e.Integration.Name, }, - Data: map[string]string{ - cmKey: r.Content, + Annotations: map[string]string{ + "camel.apache.org/resource.name": r.Name, + "camel.apache.org/resource.compression": strconv.FormatBool(r.Compression), }, - } - - maps = append(maps, &cm) + }, + Data: map[string]string{ + cmKey: r.Content, + }, } + + maps = append(maps, &cm) } return maps } // ComputeSourcesURI -- -func (e *Environment) ComputeSourcesURI(container bool) []string { +func (e *Environment) ComputeSourcesURI() []string { sources := e.Integration.Sources() paths := make([]string, 0, len(sources)) for i, s := range sources { root := "/etc/camel/sources" - - if container { - // assume sources are copied over the standard deployments folder - root = "/deployments/sources" - } else { - root = path.Join(root, fmt.Sprintf("i-source-%03d", i)) - } + root = path.Join(root, fmt.Sprintf("i-source-%03d", i)) srcName := strings.TrimPrefix(s.Name, "/") src := path.Join(root, srcName) @@ -397,90 +389,87 @@ func (e *Environment) ComputeSourcesURI(container bool) []string { } // ConfigureVolumesAndMounts -- -func (e *Environment) ConfigureVolumesAndMounts(container bool, vols *[]corev1.Volume, mnts *[]corev1.VolumeMount) { - - if !container { - - // - // Volumes :: Sources - // - - for i, s := range e.Integration.Sources() { - cmName := fmt.Sprintf("%s-source-%03d", e.Integration.Name, i) - refName := fmt.Sprintf("i-source-%03d", i) - resName := strings.TrimPrefix(s.Name, "/") - resPath := path.Join("/etc/camel/sources", refName) - - if s.ContentRef != "" { - cmName = s.ContentRef - } - - *vols = append(*vols, corev1.Volume{ - Name: refName, - VolumeSource: corev1.VolumeSource{ - ConfigMap: &corev1.ConfigMapVolumeSource{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: cmName, - }, - Items: []corev1.KeyToPath{ - { - Key: "content", - Path: resName, - }, +func (e *Environment) ConfigureVolumesAndMounts(vols *[]corev1.Volume, mnts *[]corev1.VolumeMount) { + + // + // Volumes :: Sources + // + + for i, s := range e.Integration.Sources() { + cmName := fmt.Sprintf("%s-source-%03d", e.Integration.Name, i) + refName := fmt.Sprintf("i-source-%03d", i) + resName := strings.TrimPrefix(s.Name, "/") + resPath := path.Join("/etc/camel/sources", refName) + + if s.ContentRef != "" { + cmName = s.ContentRef + } + + *vols = append(*vols, corev1.Volume{ + Name: refName, + VolumeSource: corev1.VolumeSource{ + ConfigMap: &corev1.ConfigMapVolumeSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: cmName, + }, + Items: []corev1.KeyToPath{ + { + Key: "content", + Path: resName, }, }, }, - }) + }, + }) + + *mnts = append(*mnts, corev1.VolumeMount{ + Name: refName, + MountPath: resPath, + }) + } - *mnts = append(*mnts, corev1.VolumeMount{ - Name: refName, - MountPath: resPath, - }) + for i, r := range e.Integration.Spec.Resources { + if r.Type != v1alpha1.ResourceTypeData { + continue } - for i, r := range e.Integration.Spec.Resources { - if r.Type != v1alpha1.ResourceTypeData { - continue - } - - cmName := fmt.Sprintf("%s-resource-%03d", e.Integration.Name, i) - refName := fmt.Sprintf("i-resource-%03d", i) - resName := strings.TrimPrefix(r.Name, "/") - cmKey := "content" - resPath := path.Join("/etc/camel/resources", refName) - - if r.ContentRef != "" { - cmName = r.ContentRef - } - if r.ContentKey != "" { - cmKey = r.ContentKey - } - if r.MountPath != "" { - resPath = r.MountPath - } - - *vols = append(*vols, corev1.Volume{ - Name: refName, - VolumeSource: corev1.VolumeSource{ - ConfigMap: &corev1.ConfigMapVolumeSource{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: cmName, - }, - Items: []corev1.KeyToPath{ - { - Key: cmKey, - Path: resName, - }, + cmName := fmt.Sprintf("%s-resource-%03d", e.Integration.Name, i) + refName := fmt.Sprintf("i-resource-%03d", i) + resName := strings.TrimPrefix(r.Name, "/") + cmKey := "content" + resPath := path.Join("/etc/camel/resources", refName) + + if r.ContentRef != "" { + cmName = r.ContentRef + } + if r.ContentKey != "" { + cmKey = r.ContentKey + } + if r.MountPath != "" { + resPath = r.MountPath + } + + *vols = append(*vols, corev1.Volume{ + Name: refName, + VolumeSource: corev1.VolumeSource{ + ConfigMap: &corev1.ConfigMapVolumeSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: cmName, + }, + Items: []corev1.KeyToPath{ + { + Key: cmKey, + Path: resName, }, }, }, - }) + }, + }) - *mnts = append(*mnts, corev1.VolumeMount{ - Name: refName, - MountPath: resPath, - }) - } + *mnts = append(*mnts, corev1.VolumeMount{ + Name: refName, + MountPath: resPath, + }) } //