You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2019/09/30 08:54:08 UTC

[camel-k] branch master updated: fix: Merge all binaries into a single one

This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/master by this push:
     new 8f17be6  fix: Merge all binaries into a single one
8f17be6 is described below

commit 8f17be6249226ac10b377e796c0ec88968b8b984
Author: James Netherton <ja...@gmail.com>
AuthorDate: Mon Sep 30 07:08:39 2019 +0100

    fix: Merge all binaries into a single one
    
    fixes #945
---
 assets/json-schema/IntegrationKit.json             |  5 +--
 build/Dockerfile                                   |  2 -
 cmd/kamel/main.go                                  |  2 +
 ...k.v1.0.0-m2-SNAPSHOT.clusterserviceversion.yaml |  3 +-
 deploy/operator-deployment.yaml                    |  3 +-
 deploy/resources.go                                |  3 +-
 cmd/kamel/main.go => pkg/cmd/builder.go            | 47 ++++++++++------------
 cmd/builder/main.go => pkg/cmd/builder/builder.go  | 11 +++--
 cmd/kamel/main.go => pkg/cmd/operator.go           | 46 +++++++++------------
 .../main.go => pkg/cmd/operator/operator.go        |  7 ++--
 pkg/cmd/root.go                                    |  4 +-
 pkg/controller/build/schedule_pod.go               |  7 +++-
 script/Makefile                                    | 18 +++------
 script/travis_build.sh                             |  2 -
 14 files changed, 71 insertions(+), 89 deletions(-)

diff --git a/assets/json-schema/IntegrationKit.json b/assets/json-schema/IntegrationKit.json
index ec5970f..94c94f1 100644
--- a/assets/json-schema/IntegrationKit.json
+++ b/assets/json-schema/IntegrationKit.json
@@ -302,9 +302,6 @@
         "platform": {
           "type": "string"
         },
-        "publicImage": {
-          "type": "string"
-        },
         "runtimeVersion": {
           "type": "string"
         },
@@ -444,4 +441,4 @@
       "type": "object"
     }
   }
-}
\ No newline at end of file
+}
diff --git a/build/Dockerfile b/build/Dockerfile
index 6ded515..c0601a6 100644
--- a/build/Dockerfile
+++ b/build/Dockerfile
@@ -23,6 +23,4 @@ RUN chgrp -R 0 /tmp/artifacts/m2 \
 
 USER 1000
 
-ADD build/_output/bin/camel-k /usr/local/bin/camel-k
-ADD build/_output/bin/builder /usr/local/bin/camel-k-builder
 ADD build/_output/bin/kamel /usr/local/bin/kamel
diff --git a/cmd/kamel/main.go b/cmd/kamel/main.go
index 72ac1c2..6713497 100644
--- a/cmd/kamel/main.go
+++ b/cmd/kamel/main.go
@@ -24,6 +24,8 @@ import (
 	"os"
 	"time"
 
+	_ "github.com/apache/camel-k/pkg/builder/kaniko"
+	_ "github.com/apache/camel-k/pkg/builder/s2i"
 	"github.com/apache/camel-k/pkg/cmd"
 
 	_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
diff --git a/deploy/olm-catalog/camel-k/1.0.0-M2-SNAPSHOT/camel-k.v1.0.0-m2-SNAPSHOT.clusterserviceversion.yaml b/deploy/olm-catalog/camel-k/1.0.0-M2-SNAPSHOT/camel-k.v1.0.0-m2-SNAPSHOT.clusterserviceversion.yaml
index 4339dd0..d0ea287 100644
--- a/deploy/olm-catalog/camel-k/1.0.0-M2-SNAPSHOT/camel-k.v1.0.0-m2-SNAPSHOT.clusterserviceversion.yaml
+++ b/deploy/olm-catalog/camel-k/1.0.0-M2-SNAPSHOT/camel-k.v1.0.0-m2-SNAPSHOT.clusterserviceversion.yaml
@@ -150,7 +150,8 @@ spec:
             spec:
               containers:
               - command:
-                - camel-k
+                - kamel
+                - operator
                 env:
                 - name: WATCH_NAMESPACE
                   valueFrom:
diff --git a/deploy/operator-deployment.yaml b/deploy/operator-deployment.yaml
index 01c593c..6b69b29 100644
--- a/deploy/operator-deployment.yaml
+++ b/deploy/operator-deployment.yaml
@@ -41,7 +41,8 @@ spec:
         - name: camel-k-operator
           image: docker.io/apache/camel-k:1.0.0-M2-SNAPSHOT
           command:
-          - camel-k
+          - kamel
+          - operator
           imagePullPolicy: IfNotPresent
           env:
             - name: WATCH_NAMESPACE
diff --git a/deploy/resources.go b/deploy/resources.go
index 2999ace..1346f1d 100644
--- a/deploy/resources.go
+++ b/deploy/resources.go
@@ -2764,7 +2764,8 @@ spec:
         - name: camel-k-operator
           image: docker.io/apache/camel-k:1.0.0-M2-SNAPSHOT
           command:
-          - camel-k
+          - kamel
+          - operator
           imagePullPolicy: IfNotPresent
           env:
             - name: WATCH_NAMESPACE
diff --git a/cmd/kamel/main.go b/pkg/cmd/builder.go
similarity index 55%
copy from cmd/kamel/main.go
copy to pkg/cmd/builder.go
index 72ac1c2..9534cf8 100644
--- a/cmd/kamel/main.go
+++ b/pkg/cmd/builder.go
@@ -15,39 +15,34 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-package main
+package cmd
 
 import (
-	"context"
-	"fmt"
-	"math/rand"
-	"os"
-	"time"
-
-	"github.com/apache/camel-k/pkg/cmd"
-
-	_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
+	"github.com/apache/camel-k/pkg/cmd/builder"
+	"github.com/spf13/cobra"
 )
 
-func main() {
-	rand.Seed(time.Now().UTC().UnixNano())
-
-	ctx, cancel := context.WithCancel(context.Background())
-
-	// Cancel ctx as soon as main returns
-	defer cancel()
+func newCmdBuilder(rootCmdOptions *RootCmdOptions) *cobra.Command {
+	impl := builderCmdOptions{
+		RootCmdOptions: rootCmdOptions,
+	}
+	cmd := cobra.Command{
+		Use:   "builder",
+		Short: "Run the Camel K builder",
+		Long:  `Run the Camel K builder`,
+		Run:   impl.run,
+	}
 
-	rootCmd, err := cmd.NewKamelCommand(ctx)
-	exitOnError(err)
+	cmd.Flags().StringVar(&impl.BuildName, "build-name", "", "The name of the build resource")
 
-	err = rootCmd.Execute()
-	exitOnError(err)
+	return &cmd
 }
 
-func exitOnError(err error) {
-	if err != nil {
-		fmt.Println("Error:", err)
+type builderCmdOptions struct {
+	*RootCmdOptions
+	BuildName string
+}
 
-		os.Exit(1)
-	}
+func (o *builderCmdOptions) run(_ *cobra.Command, _ []string) {
+	builder.Run(o.Namespace, o.BuildName)
 }
diff --git a/cmd/builder/main.go b/pkg/cmd/builder/builder.go
similarity index 93%
rename from cmd/builder/main.go
rename to pkg/cmd/builder/builder.go
index e526aed..e21aa6c 100644
--- a/cmd/builder/main.go
+++ b/pkg/cmd/builder/builder.go
@@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-package main
+package builder
 
 import (
 	"fmt"
@@ -31,8 +31,6 @@ 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/client"
 	util "github.com/apache/camel-k/pkg/controller/build"
 	"github.com/apache/camel-k/pkg/util/cancellable"
@@ -48,7 +46,8 @@ func printVersion() {
 	log.Info(fmt.Sprintf("Camel K Version: %v", defaults.Version))
 }
 
-func main() {
+// Run creates a build resource in the specified namespace
+func Run(namespace string, buildName string) {
 	logf.SetLogger(logf.ZapLogger(false))
 
 	rand.Seed(time.Now().UTC().UnixNano())
@@ -61,8 +60,8 @@ func main() {
 
 	build := &v1alpha1.Build{
 		ObjectMeta: metav1.ObjectMeta{
-			Namespace: os.Args[1],
-			Name:      os.Args[2],
+			Namespace: namespace,
+			Name:      buildName,
 		},
 	}
 
diff --git a/cmd/kamel/main.go b/pkg/cmd/operator.go
similarity index 60%
copy from cmd/kamel/main.go
copy to pkg/cmd/operator.go
index 72ac1c2..22a0300 100644
--- a/cmd/kamel/main.go
+++ b/pkg/cmd/operator.go
@@ -15,39 +15,31 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-package main
+package cmd
 
 import (
-	"context"
-	"fmt"
-	"math/rand"
-	"os"
-	"time"
-
-	"github.com/apache/camel-k/pkg/cmd"
-
-	_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
+	"github.com/apache/camel-k/pkg/cmd/operator"
+	"github.com/spf13/cobra"
 )
 
-func main() {
-	rand.Seed(time.Now().UTC().UnixNano())
-
-	ctx, cancel := context.WithCancel(context.Background())
-
-	// Cancel ctx as soon as main returns
-	defer cancel()
-
-	rootCmd, err := cmd.NewKamelCommand(ctx)
-	exitOnError(err)
+func newCmdOperator(rootCmdOptions *RootCmdOptions) *cobra.Command {
+	impl := operatorCmdOptions{
+		RootCmdOptions: rootCmdOptions,
+	}
+	cmd := cobra.Command{
+		Use:   "operator",
+		Short: "Run the Camel K operator",
+		Long:  `Run the Camel K operator`,
+		Run:   impl.run,
+	}
 
-	err = rootCmd.Execute()
-	exitOnError(err)
+	return &cmd
 }
 
-func exitOnError(err error) {
-	if err != nil {
-		fmt.Println("Error:", err)
+type operatorCmdOptions struct {
+	*RootCmdOptions
+}
 
-		os.Exit(1)
-	}
+func (o *operatorCmdOptions) run(_ *cobra.Command, _ []string) {
+	operator.Run()
 }
diff --git a/cmd/manager/main.go b/pkg/cmd/operator/operator.go
similarity index 97%
rename from cmd/manager/main.go
rename to pkg/cmd/operator/operator.go
index ee3ccb3..2ef1ad3 100644
--- a/cmd/manager/main.go
+++ b/pkg/cmd/operator/operator.go
@@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-package main
+package operator
 
 import (
 	"context"
@@ -37,8 +37,6 @@ import (
 	"sigs.k8s.io/controller-runtime/pkg/manager"
 	logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
 	"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
-
-	_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
 )
 
 var log = logf.Log.WithName("cmd")
@@ -52,7 +50,8 @@ func printVersion() {
 	log.Info(fmt.Sprintf("Camel K Git Commit: %v", GitCommit))
 }
 
-func main() {
+// Run starts the Camel K operator
+func Run() {
 	rand.Seed(time.Now().UTC().UnixNano())
 
 	flag.Parse()
diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go
index d1dbffc..c5b9168 100644
--- a/pkg/cmd/root.go
+++ b/pkg/cmd/root.go
@@ -26,7 +26,7 @@ import (
 	"github.com/spf13/cobra"
 )
 
-const kamelCommandLongDescription = `Apache Camel K is a lightweight integration platform, born on Kubernetes, with serverless 
+const kamelCommandLongDescription = `Apache Camel K is a lightweight integration platform, born on Kubernetes, with serverless
 superpowers.
 `
 
@@ -65,6 +65,8 @@ func NewKamelCommand(ctx context.Context) (*cobra.Command, error) {
 	cmd.AddCommand(newCmdReset(&options))
 	cmd.AddCommand(newCmdDescribe(&options))
 	cmd.AddCommand(newCmdRebuild(&options))
+	cmd.AddCommand(newCmdOperator(&options))
+	cmd.AddCommand(newCmdBuilder(&options))
 
 	return &cmd, nil
 }
diff --git a/pkg/controller/build/schedule_pod.go b/pkg/controller/build/schedule_pod.go
index 2b719b1..282f91c 100644
--- a/pkg/controller/build/schedule_pod.go
+++ b/pkg/controller/build/schedule_pod.go
@@ -137,9 +137,12 @@ func newBuildPod(build *v1alpha1.Build, operatorImage string) *corev1.Pod {
 					Name:            "builder",
 					Image:           builderImage,
 					ImagePullPolicy: "IfNotPresent",
-					Args: []string{
-						"camel-k-builder",
+					Command: []string{
+						"kamel",
+						"builder",
+						"--namespace",
 						build.Namespace,
+						"--build-name",
 						build.Name,
 					},
 				},
diff --git a/script/Makefile b/script/Makefile
index 0d043ae..476d544 100644
--- a/script/Makefile
+++ b/script/Makefile
@@ -38,7 +38,7 @@ STAGING_IMAGE_NAME := docker.io/camelk/camel-k
 # or "download" them from Apache Snapshots and Maven Central
 PACKAGE_ARTIFACTS_STRATEGY := copy
 
-GOLDFLAGS += -X main.GitCommit=$(GIT_COMMIT)
+GOLDFLAGS += -X github.com/apache/camel-k/pkg/cmd/operator.GitCommit=$(GIT_COMMIT)
 GOFLAGS = -ldflags "$(GOLDFLAGS)" -gcflags=-trimpath=$(GO_PATH) -asmflags=-trimpath=$(GO_PATH)
 
 define LICENSE_HEADER
@@ -48,9 +48,9 @@ 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.
@@ -99,7 +99,7 @@ codegen:
 generate:
 	operator-sdk generate k8s
 
-build: build-operator build-kamel build-builder build-compile-integration-tests
+build: build-kamel build-compile-integration-tests
 
 test: build
 	go test ./...
@@ -110,15 +110,9 @@ test-integration: build
 test-knative: build
 	go test -timeout 30m -v ./e2e/... -tags=knative
 
-build-operator:
-	go build $(GOFLAGS) -o camel-k ./cmd/manager/*.go
-
 build-kamel:
 	go build $(GOFLAGS) -o kamel ./cmd/kamel/*.go
 
-build-builder:
-	env GOOS=linux go build -o builder ./cmd/builder/*.go
-
 build-resources:
 	./script/build_catalog.sh $(CAMEL_VERSION) $(RUNTIME_VERSION)
 	./script/embed_resources.sh deploy
@@ -131,7 +125,7 @@ build-compile-integration-tests:
 	go test -c -tags="integration knative" ./e2e/*.go
 
 clean:
-	# go clean fails if modules support are turned on as it tries to 
+	# go clean fails if modules support are turned on as it tries to
 	# resolve modules, if module support is turned off, it does not
 	# care about modules and simply deletes bits.
 	#
@@ -209,4 +203,4 @@ install-minikube:
 release-notes:
 	./script/gen_release_notes.sh $(LAST_RELEASED_VERSION) $(VERSION)
 
-.PHONY: build build-operator build-kamel build-resources build-builder build-olm unsnapshot-olm dep codegen images images-dec images-push images-push-staging test check test-integration clean release cross-compile package-examples set-version git-tag release-notes
+.PHONY: build build-kamel build-resources build-olm unsnapshot-olm dep codegen images images-dec images-push images-push-staging test check test-integration clean release cross-compile package-examples set-version git-tag release-notes
diff --git a/script/travis_build.sh b/script/travis_build.sh
index 215613e..d8cc6b0 100755
--- a/script/travis_build.sh
+++ b/script/travis_build.sh
@@ -70,8 +70,6 @@ make PACKAGE_ARTIFACTS_STRATEGY=download package-artifacts
 
 echo "Copying binary file to docker dir"
 mkdir -p ./build/_output/bin
-cp ./camel-k ./build/_output/bin/
-cp ./builder ./build/_output/bin/
 cp ./kamel ./build/_output/bin/
 
 echo "Building the images"