From 2c2504204ae421c1f19fb0ed5f5cc88452731760 Mon Sep 17 00:00:00 2001 From: Dmitry Volodin Date: Mon, 17 Sep 2018 16:23:13 +0300 Subject: [PATCH] kamel install with example --- deploy/cr-example.yaml | 22 ++++++++++++++++++++++ deploy/cr.yaml | 22 ---------------------- deploy/resources.go | 35 +++++++++++++++++------------------ pkg/client/cmd/install.go | 9 +++++++++ pkg/install/operator.go | 7 +++++++ 5 files changed, 55 insertions(+), 40 deletions(-) create mode 100644 deploy/cr-example.yaml delete mode 100644 deploy/cr.yaml diff --git a/deploy/cr-example.yaml b/deploy/cr-example.yaml new file mode 100644 index 0000000000..c2851c757f --- /dev/null +++ b/deploy/cr-example.yaml @@ -0,0 +1,22 @@ +apiVersion: camel.apache.org/v1alpha1 +kind: Integration +metadata: + name: example +spec: + dependencies: + - camel:groovy + source: + content: |- + // This is Camel K Groovy example route + + rnd = new Random() + + from('timer:groovy?period=1s') + .routeId('groovy') + .setBody() + .constant('Hello Camel K!') + .process { + it.in.headers['RandomValue'] = rnd.nextInt() + } + .to('log:info?showHeaders=true') + name: routes.groovy \ No newline at end of file diff --git a/deploy/cr.yaml b/deploy/cr.yaml deleted file mode 100644 index ae0ee3734a..0000000000 --- a/deploy/cr.yaml +++ /dev/null @@ -1,22 +0,0 @@ -apiVersion: "camel.apache.org/v1alpha1" -kind: "Integration" -metadata: - name: "example" -spec: - replicas: 1 - source: - code: |- - package kamel; - - import org.apache.camel.builder.RouteBuilder; - - public class Routes extends RouteBuilder { - - @Override - public void configure() throws Exception { - from("timer:tick") - .setBody(constant("Hello World!!!")) - .to("log:info"); - } - - } diff --git a/deploy/resources.go b/deploy/resources.go index 189d4eff8f..188d3929b8 100644 --- a/deploy/resources.go +++ b/deploy/resources.go @@ -66,31 +66,30 @@ spec: version: v1alpha1 ` - Resources["cr.yaml"] = + Resources["cr-example.yaml"] = ` -apiVersion: "camel.apache.org/v1alpha1" -kind: "Integration" +apiVersion: camel.apache.org/v1alpha1 +kind: Integration metadata: - name: "example" + name: example spec: - replicas: 1 + dependencies: + - camel:groovy source: - code: |- - package kamel; + content: |- + // This is Camel K Groovy example route - import org.apache.camel.builder.RouteBuilder; + rnd = new Random() - public class Routes extends RouteBuilder { - - @Override - public void configure() throws Exception { - from("timer:tick") - .setBody(constant("Hello World!!!")) - .to("log:info"); + from('timer:groovy?period=1s') + .routeId('groovy') + .setBody() + .constant('Hello Camel K!') + .process { + it.in.headers['RandomValue'] = rnd.nextInt() } - - } - + .to('log:info?showHeaders=true') + name: routes.groovy ` Resources["operator-deployment.yaml"] = ` diff --git a/pkg/client/cmd/install.go b/pkg/client/cmd/install.go index 15a4de0f21..1667f6acd8 100644 --- a/pkg/client/cmd/install.go +++ b/pkg/client/cmd/install.go @@ -40,6 +40,7 @@ func NewCmdInstall(rootCmdOptions *RootCmdOptions) *cobra.Command { } cmd.Flags().BoolVar(&options.clusterSetupOnly, "cluster-setup", false, "Execute cluster-wide operations only (may require admin rights)") + cmd.Flags().BoolVar(&options.exampleSetup, "example", false, "Install example integration") cmd.ParseFlags(os.Args) return &cmd @@ -48,6 +49,7 @@ func NewCmdInstall(rootCmdOptions *RootCmdOptions) *cobra.Command { type installCmdOptions struct { *RootCmdOptions clusterSetupOnly bool + exampleSetup bool } func (o *installCmdOptions) install(cmd *cobra.Command, args []string) error { @@ -74,6 +76,13 @@ func (o *installCmdOptions) install(cmd *cobra.Command, args []string) error { return err } + if o.exampleSetup { + err = install.Example(namespace) + if err != nil { + return err + } + } + fmt.Println("Camel K installed in namespace", namespace) } diff --git a/pkg/install/operator.go b/pkg/install/operator.go index 528424a361..58aed65868 100644 --- a/pkg/install/operator.go +++ b/pkg/install/operator.go @@ -45,6 +45,13 @@ func PlatformContexts(namespace string) error { ) } +// Example -- +func Example(namespace string) error { + return installResources(namespace, + "cr-example.yaml", + ) +} + func installResources(namespace string, names ...string) error { for _, name := range names { if err := installResource(namespace, name); err != nil {