This is an automated email from the ASF dual-hosted git repository. nferraro pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit ce211433814eca6c6218ea0c8ef4840703cfd776 Author: nferraro <ni.ferr...@gmail.com> AuthorDate: Fri Sep 7 01:07:02 2018 +0200 Added kamel binary --- .gitignore | 3 +- Gopkg.lock | 14 +++++++++- build/Makefile | 9 ++++-- cmd/kamel/main.go | 36 ++++++++++++++++++++++++ pkg/cmd/cmd.go | 39 ++++++++++++++++++++++++++ pkg/cmd/config/config.go | 53 +++++++++++++++++++++++++++++++++++ pkg/cmd/run/run.go | 69 ++++++++++++++++++++++++++++++++++++++++++++++ pkg/cmd/version/version.go | 37 +++++++++++++++++++++++++ 8 files changed, 256 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 319e113..1b5f6d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Binary files -/camel-k +/operator +/kamel # We do not stage vendor directory /vendor diff --git a/Gopkg.lock b/Gopkg.lock index 08cdcda..8c9833a 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -135,6 +135,12 @@ version = "v0.3.6" [[projects]] + name = "github.com/inconshreveable/mousetrap" + packages = ["."] + revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75" + version = "v1.0" + +[[projects]] name = "github.com/json-iterator/go" packages = ["."] revision = "1624edc4454b8682399def8740d46db5e4362ba4" @@ -251,6 +257,12 @@ version = "v1.0.6" [[projects]] + name = "github.com/spf13/cobra" + packages = ["."] + revision = "ef82de70bb3f60c65fb8eebacbb2d122ef517385" + version = "v0.0.3" + +[[projects]] name = "github.com/spf13/pflag" packages = ["."] revision = "9a97c102cda95a86cec2345a6f09f55a939babf5" @@ -572,6 +584,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "fe3fc8a50615445124a1a85023b09a54b2aa9f0dfc077f6c4823b46ee4ba7ef1" + inputs-digest = "c389a066bf0697a6e8a5b618cb76954f299b9d346e69cc46dade09c1de436ce8" solver-name = "gps-cdcl" solver-version = 1 diff --git a/build/Makefile b/build/Makefile index 4d9c017..7be3aed 100644 --- a/build/Makefile +++ b/build/Makefile @@ -1,7 +1,12 @@ VERSION := $(shell ./build/get_version.sh) -install: - go build -o camel-k ./cmd/camel-k/*.go +build: build-operator build-kamel + +build-operator: + go build -o operator ./cmd/camel-k/*.go + +build-kamel: + go build -o kamel ./cmd/kamel/*.go images: operator-sdk build docker.io/apache/camel-k:$(VERSION) diff --git a/cmd/kamel/main.go b/cmd/kamel/main.go new file mode 100644 index 0000000..bc1c1bb --- /dev/null +++ b/cmd/kamel/main.go @@ -0,0 +1,36 @@ +/* +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 main + +import ( + _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" + "fmt" + "os" + "github.com/apache/camel-k/pkg/cmd" +) + +func main() { + + rootCmd := cmd.NewKamelCommand() + + if err := rootCmd.Execute(); err != nil { + fmt.Println(err) + os.Exit(1) + } + +} diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go new file mode 100644 index 0000000..dacf440 --- /dev/null +++ b/pkg/cmd/cmd.go @@ -0,0 +1,39 @@ +/* +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 cmd + +import ( + "github.com/spf13/cobra" + "github.com/apache/camel-k/pkg/cmd/version" + "github.com/apache/camel-k/pkg/cmd/run" +) + +func NewKamelCommand() *cobra.Command { + var rootCmd = cobra.Command{ + Use: "kamel", + Short: "Kamel is a awesome client tool for running Apache Camel integrations natively on Kubernetes", + Long: "Apache Camel K (a.k.a. Kamel) is a lightweight integration framework\nbuilt from Apache Camel that runs natively on Kubernetes and is\nspecifically designed for serverless and microservice architectures.", + + } + + var kubeconfig string + rootCmd.PersistentFlags().StringVar(&kubeconfig, "config", "", "Path to the config file to use for CLI requests") + + rootCmd.AddCommand(version.NewCmdVersion(), run.NewCmdRun()) + return &rootCmd +} \ No newline at end of file diff --git a/pkg/cmd/config/config.go b/pkg/cmd/config/config.go new file mode 100644 index 0000000..1e8583e --- /dev/null +++ b/pkg/cmd/config/config.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 config + +import ( + "path/filepath" + "k8s.io/client-go/tools/clientcmd" + "os" + "k8s.io/client-go/kubernetes" + "github.com/spf13/cobra" +) + +func NewKubeClient(cmd *cobra.Command) (*kubernetes.Clientset, error) { + kubeconfig := cmd.Flag("config").Value.String() + if kubeconfig == "" { + kubeconfig = filepath.Join(homeDir(), ".kube", "config") + } + + // use the current context in kubeconfig + config, err := clientcmd.BuildConfigFromFlags("", kubeconfig) + if err != nil { + return nil, err + } + + // create the clientset + clientset, err := kubernetes.NewForConfig(config) + if err != nil { + return nil, err + } + return clientset, nil +} + +func homeDir() string { + if h := os.Getenv("HOME"); h != "" { + return h + } + return os.Getenv("USERPROFILE") // windows +} diff --git a/pkg/cmd/run/run.go b/pkg/cmd/run/run.go new file mode 100644 index 0000000..6510635 --- /dev/null +++ b/pkg/cmd/run/run.go @@ -0,0 +1,69 @@ +/* +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 run + +import ( + "github.com/spf13/cobra" + "errors" + "strconv" + "os" + "github.com/apache/camel-k/pkg/cmd/config" + "fmt" +) + +type runCmdFlags struct { + language string +} + +func NewCmdRun() *cobra.Command { + flags := runCmdFlags{} + cmd := cobra.Command{ + Use: "run [file to run]", + Short: "Run a integration on Kubernetes", + Long: `Deploys and execute a integration pod on Kubernetes.`, + Args: validateArgs, + RunE: run, + } + + cmd.Flags().StringVarP(&flags.language, "language", "l", "", "Programming Language used to write the file") + + return &cmd +} + +func validateArgs(cmd *cobra.Command, args []string) error { + if len(args) != 1 { + return errors.New("accepts 1 arg, received " + strconv.Itoa(len(args))) + } + fileName := args[0] + if _, err := os.Stat(fileName); err != nil && os.IsNotExist(err) { + return errors.New("file " + fileName + " does not exist") + } else if err != nil { + return errors.New("error while accessing file " + fileName) + } + return nil +} + +func run(cmd *cobra.Command, args []string) error { + _, err := config.NewKubeClient(cmd) + if err != nil { + return err + } + + fmt.Println("Now something should run") + return nil +} diff --git a/pkg/cmd/version/version.go b/pkg/cmd/version/version.go new file mode 100644 index 0000000..5eadbfb --- /dev/null +++ b/pkg/cmd/version/version.go @@ -0,0 +1,37 @@ +/* +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 version + +import ( + "github.com/spf13/cobra" + "fmt" + rootVersion "github.com/apache/camel-k/version" +) + + +func NewCmdVersion() *cobra.Command { + return &cobra.Command{ + Use: "version", + Short: "Display client version", + Long: `Display Camel K client version.`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("Camel K Client " + rootVersion.Version) + }, + } +} +