Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
onboarding example integration tests, kogito CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardozanini committed Nov 22, 2019
1 parent 2dc8e9b commit 535c8d1
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 39 deletions.
38 changes: 23 additions & 15 deletions cmd/kogito/command/deploy/deploy_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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{},
Expand Down
6 changes: 5 additions & 1 deletion cmd/kogito/command/deploy/deploy_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
18 changes: 9 additions & 9 deletions deploy/examples/onboarding-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ spec:
env:
# optional, but will improve your build time quite a lot
- name: MAVEN_MIRROR_URL
value: "<your maven url>"
value: "<http://yourmavenurl>"
service:
labels:
onboarding: process
env:
- name: NAMESPACE
value: "< your namespace >"
value: "<namespace_where_this_app_is_deployed>"

---
apiVersion: app.kiegroup.org/v1alpha1
Expand All @@ -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
Expand All @@ -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: "<http://yourmavenurl>"
service:
labels:
taxRate: process
vacationDays: process
paymentDate: process
taxes/rate: process
vacations/days: process
payments/date: process
42 changes: 28 additions & 14 deletions pkg/controller/kogitoapp/resource/deployment_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 535c8d1

Please sign in to comment.