From 535c8d1f53fe8fefb2a8cb79639b8c942caacd61 Mon Sep 17 00:00:00 2001 From: Ricardo Zanini Date: Fri, 22 Nov 2019 11:57:46 -0300 Subject: [PATCH] onboarding example integration tests, kogito CLI --- cmd/kogito/command/deploy/deploy_service.go | 38 ++++++++++------- .../command/deploy/deploy_service_test.go | 6 ++- deploy/examples/onboarding-example.yaml | 18 ++++---- .../kogitoapp/resource/deployment_config.go | 42 ++++++++++++------- 4 files changed, 65 insertions(+), 39 deletions(-) diff --git a/cmd/kogito/command/deploy/deploy_service.go b/cmd/kogito/command/deploy/deploy_service.go index 9a961968c..9324f35cb 100644 --- a/cmd/kogito/command/deploy/deploy_service.go +++ b/cmd/kogito/command/deploy/deploy_service.go @@ -29,28 +29,31 @@ import ( ) const ( - defaultDeployRuntime = string(v1alpha1.QuarkusRuntimeType) + defaultDeployRuntime = string(v1alpha1.QuarkusRuntimeType) + defaultInstallInfinispan = string(v1alpha1.KogitoAppInfraInstallInfinispanAuto) ) var ( - deployRuntimeValidEntries = []string{string(v1alpha1.QuarkusRuntimeType), string(v1alpha1.SpringbootRuntimeType)} + deployRuntimeValidEntries = []string{string(v1alpha1.QuarkusRuntimeType), string(v1alpha1.SpringbootRuntimeType)} + installInfinispanValidEntries = []string{string(v1alpha1.KogitoAppInfraInstallInfinispanAuto), string(v1alpha1.KogitoAppInfraInstallInfinispanNever), string(v1alpha1.KogitoAppInfraInstallInfinispanAlways)} ) type deployFlags struct { CommonFlags - name string - runtime string - serviceLabels []string - incrementalBuild bool - buildEnv []string - reference string - contextDir string - source string - imageS2I string - imageRuntime string - native bool - buildLimits []string - buildRequests []string + name string + runtime string + serviceLabels []string + incrementalBuild bool + buildEnv []string + reference string + contextDir string + source string + imageS2I string + imageRuntime string + native bool + buildLimits []string + buildRequests []string + installInfinispan string } type deployCommand struct { @@ -110,6 +113,9 @@ func (i *deployCommand) RegisterHook() { if !util.Contains(i.flags.runtime, deployRuntimeValidEntries) { return fmt.Errorf("runtime not valid. Valid runtimes are %s. Received %s", deployRuntimeValidEntries, i.flags.runtime) } + if !util.Contains(i.flags.installInfinispan, installInfinispanValidEntries) { + return fmt.Errorf("install-infinispan not valid. Valid entries are %s. Received %s", installInfinispanValidEntries, i.flags.installInfinispan) + } if err := CheckImageTag(i.flags.imageRuntime); err != nil { return err } @@ -139,6 +145,7 @@ func (i *deployCommand) InitHook() { i.command.Flags().StringSliceVar(&i.flags.buildRequests, "build-requests", nil, "Resource requests for the s2i build pod. Valid values are 'cpu' and 'memory'. For example 'cpu=1'. Can be set more than once.") i.command.Flags().StringVar(&i.flags.imageS2I, "image-s2i", "", "Image tag (namespace/name:tag) for using during the s2i build, e.g: openshift/kogito-quarkus-ubi8-s2i:latest") i.command.Flags().StringVar(&i.flags.imageRuntime, "image-runtime", "", "Image tag (namespace/name:tag) for using during service runtime, e.g: openshift/kogito-quarkus-ubi8:latest") + i.command.Flags().StringVar(&i.flags.installInfinispan, "install-infinispan", defaultInstallInfinispan, "Infinispan installation mode: \"Always\", \"Never\" or \"Auto\". \"Always\" will install Infinispan in the same namespace no matter what, \"Never\" won't install Infinispan even if the service requires it and \"Auto\" will install only if the service requires persistence.") } func (i *deployCommand) Exec(cmd *cobra.Command, args []string) error { @@ -200,6 +207,7 @@ func (i *deployCommand) Exec(cmd *cobra.Command, args []string) error { Limits: shared.FromStringArrayToControllerResourceMap(i.flags.Limits), Requests: shared.FromStringArrayToControllerResourceMap(i.flags.Requests), }, + Infra: v1alpha1.KogitoAppInfra{InstallInfinispan: v1alpha1.KogitoAppInfraInstallInfinispanType(i.flags.installInfinispan)}, }, Status: v1alpha1.KogitoAppStatus{ Conditions: []v1alpha1.Condition{}, diff --git a/cmd/kogito/command/deploy/deploy_service_test.go b/cmd/kogito/command/deploy/deploy_service_test.go index 8d8ee379c..fd1dd5ea8 100644 --- a/cmd/kogito/command/deploy/deploy_service_test.go +++ b/cmd/kogito/command/deploy/deploy_service_test.go @@ -49,7 +49,8 @@ func Test_DeployCmd_CustomDeployment(t *testing.T) { -v --context-dir drools-quarkus-example --project %s --image-s2i=myimage --image-runtime=myimage:0.2 --limits cpu=1 --limits memory=1Gi --requests cpu=1,memory=1Gi - --build-limits cpu=1 --build-limits memory=1Gi --build-requests cpu=1,memory=2Gi`, ns) + --build-limits cpu=1 --build-limits memory=1Gi --build-requests cpu=1,memory=2Gi + --install-infinispan Always`, ns) // Clean up after the command above cli = strings.Join(strings.Fields(cli), " ") ctx := test.SetupCliTest(cli, @@ -82,6 +83,7 @@ func Test_DeployCmd_CustomDeployment(t *testing.T) { assert.Equal(t, kogitoApp.Spec.Build.ImageS2I.ImageStreamName, "myimage") assert.Equal(t, kogitoApp.Spec.Build.ImageRuntime.ImageStreamName, "myimage") assert.Equal(t, kogitoApp.Spec.Build.ImageRuntime.ImageStreamTag, "0.2") + assert.Equal(t, v1alpha1.KogitoAppInfraInstallInfinispanAlways, kogitoApp.Spec.Infra.InstallInfinispan) } func Test_DeployCmd_CustomImage(t *testing.T) { @@ -111,4 +113,6 @@ func Test_DeployCmd_CustomImage(t *testing.T) { assert.Equal(t, "openshift", instance.Spec.Build.ImageRuntime.ImageStreamNamespace) assert.Equal(t, "myimage", instance.Spec.Build.ImageRuntime.ImageStreamName) assert.Equal(t, "0.2", instance.Spec.Build.ImageRuntime.ImageStreamTag) + + assert.Equal(t, v1alpha1.KogitoAppInfraInstallInfinispanAuto, instance.Spec.Infra.InstallInfinispan) } diff --git a/deploy/examples/onboarding-example.yaml b/deploy/examples/onboarding-example.yaml index 386046539..79d08b545 100644 --- a/deploy/examples/onboarding-example.yaml +++ b/deploy/examples/onboarding-example.yaml @@ -14,13 +14,13 @@ spec: env: # optional, but will improve your build time quite a lot - name: MAVEN_MIRROR_URL - value: "" + value: "" service: labels: onboarding: process env: - name: NAMESPACE - value: "< your namespace >" + value: "" --- apiVersion: app.kiegroup.org/v1alpha1 @@ -33,9 +33,9 @@ spec: uri: https://github.com/kiegroup/kogito-examples contextDir: onboarding-example/hr imageRuntime: - imageStreamTag: 0.5.0 + imageStreamTag: 0.6.0 imageS2I: - imageStreamTag: 0.5.0 + imageStreamTag: 0.6.0 env: # optional, but will improve your build time quite a lot - name: MAVEN_MIRROR_URL @@ -57,15 +57,15 @@ spec: uri: https://github.com/kiegroup/kogito-examples contextDir: onboarding-example/payroll imageRuntime: - imageStreamTag: 0.5.0 + imageStreamTag: 0.6.0 imageS2I: - imageStreamTag: 0.5.0 + imageStreamTag: 0.6.0 env: # optional, but will improve your build time quite a lot - name: MAVEN_MIRROR_URL value: "" service: labels: - taxRate: process - vacationDays: process - paymentDate: process + taxes/rate: process + vacations/days: process + payments/date: process diff --git a/pkg/controller/kogitoapp/resource/deployment_config.go b/pkg/controller/kogitoapp/resource/deployment_config.go index a6f2df45f..56dc02392 100644 --- a/pkg/controller/kogitoapp/resource/deployment_config.go +++ b/pkg/controller/kogitoapp/resource/deployment_config.go @@ -35,18 +35,32 @@ const ( // ServiceAccountName is the name of service account used by Kogito Services Runtimes ServiceAccountName = "kogito-service-viewer" + envVarInfinispanServerList = "SERVER_LIST" + envVarInfinispanUser = "USERNAME" + envVarInfinispanPassword = "PASSWORD" + envVarInfinispanSaslMechanism = "SASL_MECHANISM" + defaultInfinispanSaslMechanism = v1alpha1.SASLPlain +) + +var ( /* Infinispan variables for the KogitoInfra deployed infrastructure. - More info: https://quarkus.io/guides/infinispan-client#quarkus-infinispan-client_configuration + For Quarkus: https://quarkus.io/guides/infinispan-client#quarkus-infinispan-client_configuration + For Spring: https://github.com/infinispan/infinispan-spring-boot/blob/master/infinispan-spring-boot-starter-remote/src/test/resources/test-application.properties */ - envVarInfinispanQuarkus = "QUARKUS_" - envVarInfinispanSpring = "SPRING_" - envVarInfinispanServerList = "INFINISPAN_CLIENT_SERVER_LIST" - envVarInfinispanUser = "INFINISPAN_CLIENT_AUTH_USERNAME" - envVarInfinispanPassword = "INFINISPAN_CLIENT_AUTH_PASSWORD" - envVarInfinispanSaslMechanism = "INFINISPAN_CLIENT_SASL_MECHANISM" - defaultInfinispanSaslMechanism = v1alpha1.SASLPlain + envVarInfinispanQuarkus = map[string]string{ + envVarInfinispanServerList: "QUARKUS_INFINISPAN_CLIENT_SERVER_LIST", + envVarInfinispanUser: "QUARKUS_INFINISPAN_CLIENT_AUTH_USERNAME", + envVarInfinispanPassword: "QUARKUS_INFINISPAN_CLIENT_AUTH_PASSWORD", + envVarInfinispanSaslMechanism: "QUARKUS_INFINISPAN_CLIENT_SASL_MECHANISM", + } + envVarInfinispanSpring = map[string]string{ + envVarInfinispanServerList: "INFINISPAN_REMOTE_SERVER_LIST", + envVarInfinispanUser: "INFINISPAN_REMOTE_AUTH_USER_NAME", + envVarInfinispanPassword: "INFINISPAN_REMOTE_AUTH_PASSWORD", + envVarInfinispanSaslMechanism: "INFINISPAN_REMOTE_SASL_MECHANISM", + } ) // NewDeploymentConfig creates a new DeploymentConfig resource for the KogitoApp based on the BuildConfig runner image @@ -129,14 +143,14 @@ func SetInfinispanEnvVars(cli *client.Client, kogitoInfra *v1alpha1.KogitoInfra, // inject credentials to deploymentConfig container if len(dc.Spec.Template.Spec.Containers) > 0 { - prefix := envVarInfinispanQuarkus + vars := envVarInfinispanQuarkus if kogitoApp.Spec.Runtime == v1alpha1.SpringbootRuntimeType { - prefix = envVarInfinispanSpring + vars = envVarInfinispanSpring } - util.SetEnvVar(fmt.Sprintf("%s%s", prefix, envVarInfinispanServerList), uri, &dc.Spec.Template.Spec.Containers[0]) - util.SetEnvVar(fmt.Sprintf("%s%s", prefix, envVarInfinispanUser), user, &dc.Spec.Template.Spec.Containers[0]) - util.SetEnvVar(fmt.Sprintf("%s%s", prefix, envVarInfinispanPassword), password, &dc.Spec.Template.Spec.Containers[0]) - util.SetEnvVar(fmt.Sprintf("%s%s", prefix, envVarInfinispanSaslMechanism), string(defaultInfinispanSaslMechanism), &dc.Spec.Template.Spec.Containers[0]) + util.SetEnvVar(vars[envVarInfinispanServerList], uri, &dc.Spec.Template.Spec.Containers[0]) + util.SetEnvVar(vars[envVarInfinispanUser], user, &dc.Spec.Template.Spec.Containers[0]) + util.SetEnvVar(vars[envVarInfinispanPassword], password, &dc.Spec.Template.Spec.Containers[0]) + util.SetEnvVar(vars[envVarInfinispanSaslMechanism], string(defaultInfinispanSaslMechanism), &dc.Spec.Template.Spec.Containers[0]) } } return nil