You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by GitBox <gi...@apache.org> on 2019/01/08 16:57:01 UTC

[GitHub] nicolaferraro closed pull request #319: Allow to customize contexts create at installation

nicolaferraro closed pull request #319: Allow to customize contexts create at installation
URL: https://github.com/apache/camel-k/pull/319
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/Gopkg.lock b/Gopkg.lock
index f9ea74a5..4ce6fa5e 100644
--- a/Gopkg.lock
+++ b/Gopkg.lock
@@ -1006,7 +1006,6 @@
     "pkg/client/apiutil",
     "pkg/client/config",
     "pkg/controller",
-    "pkg/controller/controllerutil",
     "pkg/event",
     "pkg/handler",
     "pkg/internal/controller",
@@ -1067,14 +1066,19 @@
     "k8s.io/apimachinery/pkg/api/errors",
     "k8s.io/apimachinery/pkg/apis/meta/v1",
     "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured",
+    "k8s.io/apimachinery/pkg/labels",
     "k8s.io/apimachinery/pkg/runtime",
     "k8s.io/apimachinery/pkg/runtime/schema",
+    "k8s.io/apimachinery/pkg/runtime/serializer",
     "k8s.io/apimachinery/pkg/runtime/serializer/json",
     "k8s.io/apimachinery/pkg/runtime/serializer/versioning",
-    "k8s.io/apimachinery/pkg/types",
     "k8s.io/apimachinery/pkg/util/intstr",
+    "k8s.io/apimachinery/pkg/util/json",
     "k8s.io/apimachinery/pkg/util/yaml",
     "k8s.io/apimachinery/pkg/watch",
+    "k8s.io/client-go/dynamic",
+    "k8s.io/client-go/kubernetes",
+    "k8s.io/client-go/kubernetes/scheme",
     "k8s.io/client-go/plugin/pkg/client/auth/gcp",
     "k8s.io/client-go/rest",
     "k8s.io/client-go/tools/clientcmd",
@@ -1091,7 +1095,6 @@
     "sigs.k8s.io/controller-runtime/pkg/client",
     "sigs.k8s.io/controller-runtime/pkg/client/config",
     "sigs.k8s.io/controller-runtime/pkg/controller",
-    "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil",
     "sigs.k8s.io/controller-runtime/pkg/handler",
     "sigs.k8s.io/controller-runtime/pkg/manager",
     "sigs.k8s.io/controller-runtime/pkg/reconcile",
diff --git a/pkg/apis/camel/v1alpha1/integrationplatform_types.go b/pkg/apis/camel/v1alpha1/integrationplatform_types.go
index d13ea637..7db0ae0f 100644
--- a/pkg/apis/camel/v1alpha1/integrationplatform_types.go
+++ b/pkg/apis/camel/v1alpha1/integrationplatform_types.go
@@ -8,9 +8,15 @@ import (
 
 // IntegrationPlatformSpec defines the desired state of IntegrationPlatform
 type IntegrationPlatformSpec struct {
-	Cluster IntegrationPlatformCluster   `json:"cluster,omitempty"`
-	Profile TraitProfile                 `json:"profile,omitempty"`
-	Build   IntegrationPlatformBuildSpec `json:"build,omitempty"`
+	Cluster   IntegrationPlatformCluster       `json:"cluster,omitempty"`
+	Profile   TraitProfile                     `json:"profile,omitempty"`
+	Build     IntegrationPlatformBuildSpec     `json:"build,omitempty"`
+	Resources IntegrationPlatformResourcesSpec `json:"resources,omitempty"`
+}
+
+// IntegrationPlatformResourcesSpec contains platform related resources
+type IntegrationPlatformResourcesSpec struct {
+	Contexts []string `json:"contexts,omitempty"`
 }
 
 // IntegrationPlatformStatus defines the observed state of IntegrationPlatform
diff --git a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
index f26f1086..38ebafe7 100644
--- a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
+++ b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
@@ -385,10 +385,32 @@ func (in *IntegrationPlatformList) DeepCopyObject() runtime.Object {
 	return nil
 }
 
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *IntegrationPlatformResourcesSpec) DeepCopyInto(out *IntegrationPlatformResourcesSpec) {
+	*out = *in
+	if in.Contexts != nil {
+		in, out := &in.Contexts, &out.Contexts
+		*out = make([]string, len(*in))
+		copy(*out, *in)
+	}
+	return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IntegrationPlatformResourcesSpec.
+func (in *IntegrationPlatformResourcesSpec) DeepCopy() *IntegrationPlatformResourcesSpec {
+	if in == nil {
+		return nil
+	}
+	out := new(IntegrationPlatformResourcesSpec)
+	in.DeepCopyInto(out)
+	return out
+}
+
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 func (in *IntegrationPlatformSpec) DeepCopyInto(out *IntegrationPlatformSpec) {
 	*out = *in
 	in.Build.DeepCopyInto(&out.Build)
+	in.Resources.DeepCopyInto(&out.Resources)
 	return
 }
 
diff --git a/pkg/cmd/completion_bash.go b/pkg/cmd/completion_bash.go
index 836b3912..115f18e3 100644
--- a/pkg/cmd/completion_bash.go
+++ b/pkg/cmd/completion_bash.go
@@ -23,6 +23,8 @@ import (
 	"os"
 	"strings"
 
+	"github.com/apache/camel-k/pkg/platform"
+
 	"github.com/apache/camel-k/pkg/trait"
 
 	"github.com/apache/camel-k/pkg/util/camel"
@@ -141,6 +143,12 @@ __kamel_kubectl_get_user_integrationcontexts() {
     fi
 }
 
+__kamel_kubectl_get_known_integrationcontexts() {
+    local type_list="` + strings.Join(platform.GetContextsNames(), " ") + `"
+    COMPREPLY=( $( compgen -W "${type_list}" -- "$cur") )
+    compopt -o nospace
+}
+
 __custom_func() {
     case ${last_command} in
         kamel_delete)
diff --git a/pkg/cmd/install.go b/pkg/cmd/install.go
index 342c4a94..f9bbff2c 100644
--- a/pkg/cmd/install.go
+++ b/pkg/cmd/install.go
@@ -30,26 +30,36 @@ import (
 )
 
 func newCmdInstall(rootCmdOptions *RootCmdOptions) *cobra.Command {
-	options := installCmdOptions{
+	impl := installCmdOptions{
 		RootCmdOptions: rootCmdOptions,
 	}
 	cmd := cobra.Command{
 		Use:   "install",
 		Short: "Install Camel K on a Kubernetes cluster",
 		Long:  `Installs Camel K on a Kubernetes or OpenShift cluster.`,
-		RunE:  options.install,
+		RunE:  impl.install,
 	}
 
-	cmd.Flags().BoolVar(&options.clusterSetupOnly, "cluster-setup", false, "Execute cluster-wide operations only (may require admin rights)")
-	cmd.Flags().BoolVar(&options.skipClusterSetup, "skip-cluster-setup", false, "Skip the cluster-setup phase")
-	cmd.Flags().BoolVar(&options.exampleSetup, "example", false, "Install example integration")
-	cmd.Flags().StringVar(&options.registry, "registry", "", "A Docker registry that can be used to publish images")
-	cmd.Flags().StringVarP(&options.outputFormat, "output", "o", "", "Output format. One of: json|yaml")
-	cmd.Flags().StringVar(&options.organization, "organization", "", "A organization on the Docker registry that can be used to publish images")
-	cmd.Flags().StringVar(&options.pushSecret, "push-secret", "", "A secret used to push images to the Docker registry")
-	cmd.Flags().StringSliceVar(&options.repositories, "repository", nil, "Add a maven repository")
-	cmd.Flags().StringSliceVarP(&options.properties, "property", "p", nil, "Add a camel property")
-	cmd.Flags().StringVar(&options.camelVersion, "camel-version", "", "Set the camel version")
+	cmd.Flags().BoolVar(&impl.clusterSetupOnly, "cluster-setup", false, "Execute cluster-wide operations only (may require admin rights)")
+	cmd.Flags().BoolVar(&impl.skipClusterSetup, "skip-cluster-setup", false, "Skip the cluster-setup phase")
+	cmd.Flags().BoolVar(&impl.exampleSetup, "example", false, "Install example integration")
+	cmd.Flags().StringVar(&impl.registry, "registry", "", "A Docker registry that can be used to publish images")
+	cmd.Flags().StringVarP(&impl.outputFormat, "output", "o", "", "Output format. One of: json|yaml")
+	cmd.Flags().StringVar(&impl.organization, "organization", "", "A organization on the Docker registry that can be used to publish images")
+	cmd.Flags().StringVar(&impl.pushSecret, "push-secret", "", "A secret used to push images to the Docker registry")
+	cmd.Flags().StringSliceVar(&impl.repositories, "repository", nil, "Add a maven repository")
+	cmd.Flags().StringSliceVarP(&impl.properties, "property", "p", nil, "Add a camel property")
+	cmd.Flags().StringVar(&impl.camelVersion, "camel-version", "", "Set the camel version")
+	cmd.Flags().StringSliceVar(&impl.contexts, "context", nil, "Add a camel context to build at startup, by default all known contexts are built")
+
+	// completion support
+	configureBashAnnotationForFlag(
+		&cmd,
+		"context",
+		map[string][]string{
+			cobra.BashCompCustom: {"__kamel_kubectl_get_known_integrationcontexts"},
+		},
+	)
 
 	return &cmd
 }
@@ -66,6 +76,7 @@ type installCmdOptions struct {
 	camelVersion     string
 	repositories     []string
 	properties       []string
+	contexts         []string
 }
 
 func (o *installCmdOptions) install(cmd *cobra.Command, args []string) error {
@@ -129,6 +140,8 @@ func (o *installCmdOptions) install(cmd *cobra.Command, args []string) error {
 			platform.Spec.Build.CamelVersion = o.camelVersion
 		}
 
+		platform.Spec.Resources.Contexts = o.contexts
+
 		err = install.RuntimeObjectOrCollect(o.Context, c, namespace, collection, platform)
 		if err != nil {
 			return err
diff --git a/pkg/controller/integrationplatform/create.go b/pkg/controller/integrationplatform/create.go
index 82cfcd34..fa203c2b 100644
--- a/pkg/controller/integrationplatform/create.go
+++ b/pkg/controller/integrationplatform/create.go
@@ -19,23 +19,16 @@ package integrationplatform
 
 import (
 	"context"
+	"fmt"
+	"strings"
 
 	"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
 	"github.com/apache/camel-k/pkg/install"
+	p "github.com/apache/camel-k/pkg/platform"
+
 	"github.com/sirupsen/logrus"
 )
 
-var resources = []string{
-	"platform-integration-context-jvm.yaml",
-	"platform-integration-context-groovy.yaml",
-	"platform-integration-context-kotlin.yaml",
-	"platform-integration-context-spring-boot.yaml",
-}
-
-var knativeResources = []string{
-	"platform-integration-context-knative.yaml",
-}
-
 // NewCreateAction returns a action that creates resources needed by the platform
 func NewCreateAction() Action {
 	return &createAction{}
@@ -54,18 +47,40 @@ func (action *createAction) CanHandle(platform *v1alpha1.IntegrationPlatform) bo
 }
 
 func (action *createAction) Handle(ctx context.Context, platform *v1alpha1.IntegrationPlatform) error {
-	logrus.Info("Installing platform resources")
-	err := install.Resources(ctx, action.client, platform.Namespace, resources...)
-	if err != nil {
-		return err
-	}
+	if l := len(platform.Spec.Resources.Contexts); l > 0 {
+		res := make([]string, 0, l)
+
+		for _, c := range platform.Spec.Resources.Contexts {
+			//
+			// Assuming that if the resource ends with a yaml extension, the full
+			// resource name is provided
+			//
+			if !strings.HasSuffix(c, ".yaml") && !strings.HasSuffix(c, ".yml") {
+				c = fmt.Sprintf("platform-integration-context-%s.yaml", c)
+			}
 
-	if platform.Spec.Profile == v1alpha1.TraitProfileKnative {
-		logrus.Info("Installing knative resources")
-		err := install.Resources(ctx, action.client, platform.Namespace, knativeResources...)
+			res = append(res, c)
+		}
+
+		logrus.Info("Installing custom platform resources")
+		err := install.Resources(ctx, action.client, platform.Namespace, res...)
 		if err != nil {
 			return err
 		}
+	} else {
+		logrus.Info("Installing default platform resources")
+		err := install.Resources(ctx, action.client, platform.Namespace, p.DefaultContexts...)
+		if err != nil {
+			return err
+		}
+
+		if platform.Spec.Profile == v1alpha1.TraitProfileKnative {
+			logrus.Info("Installing knative resources")
+			err := install.Resources(ctx, action.client, platform.Namespace, p.KnativeContexts...)
+			if err != nil {
+				return err
+			}
+		}
 	}
 
 	target := platform.DeepCopy()
diff --git a/pkg/platform/resources.go b/pkg/platform/resources.go
new file mode 100644
index 00000000..292776fb
--- /dev/null
+++ b/pkg/platform/resources.go
@@ -0,0 +1,53 @@
+/*
+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 platform
+
+import "strings"
+
+// DefaultContexts --
+var DefaultContexts = []string{
+	"platform-integration-context-jvm.yaml",
+	"platform-integration-context-groovy.yaml",
+	"platform-integration-context-kotlin.yaml",
+	"platform-integration-context-spring-boot.yaml",
+}
+
+// KnativeContexts --
+var KnativeContexts = []string{
+	"platform-integration-context-knative.yaml",
+}
+
+// GetContexts --
+func GetContexts() []string {
+	return append(DefaultContexts, KnativeContexts...)
+}
+
+// GetContextsNames --
+func GetContextsNames() []string {
+	ctxs := GetContexts()
+	names := make([]string, 0, len(ctxs))
+
+	for _, r := range ctxs {
+		r = strings.TrimPrefix(r, "platform-integration-context-")
+		r = strings.TrimSuffix(r, ".yaml")
+
+		names = append(names, r)
+	}
+
+	return names
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services