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

Commit

Permalink
[KOGITO-165] - Kogito Runtime Services integration with Infinispan
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardozanini committed Nov 23, 2019
1 parent 87546e5 commit b9c0a02
Show file tree
Hide file tree
Showing 21 changed files with 619 additions and 194 deletions.
284 changes: 165 additions & 119 deletions README.md

Large diffs are not rendered by default.

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)
}
20 changes: 20 additions & 0 deletions deploy/crds/app.kiegroup.org_kogitoapps_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,26 @@ spec:
type: string
type: object
type: array
infra:
description: Infrastructure definition
properties:
installInfinispan:
description: 'By default Kogito Operator installs an Infinispan
instance in the namespace if the service needs persistence (''Auto'').
Set to ''Never'' to disable this behavior, e.g. if the service
will use another persistence mechanism. Set to ''Always'' to always
install Infinispan, even if the service won''t need persistence.
For Quarkus runtime, it sets QUARKUS_INFINISPAN_CLIENT_* environment
variables. For Spring Boot, these variables start with SPRING_INFINISPAN_CLIENT_*.
More info: https://github.com/kiegroup/kogito-cloud-operator#infinispan-environment-variables.
Default to false, which means it installs Infinispan if the service
requires persistence.'
enum:
- Always
- Never
- Auto
type: string
type: object
replicas:
description: 'Number of replicas that the service will have deployed
in the cluster Default value: 1'
Expand Down
18 changes: 9 additions & 9 deletions deploy/examples/onboarding-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ spec:
uri: https://github.com/kiegroup/kogito-examples
contextDir: onboarding-example/onboarding
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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,26 @@ spec:
type: string
type: object
type: array
infra:
description: Infrastructure definition
properties:
installInfinispan:
description: 'By default Kogito Operator installs an Infinispan
instance in the namespace if the service needs persistence (''Auto'').
Set to ''Never'' to disable this behavior, e.g. if the service
will use another persistence mechanism. Set to ''Always'' to always
install Infinispan, even if the service won''t need persistence.
For Quarkus runtime, it sets QUARKUS_INFINISPAN_CLIENT_* environment
variables. For Spring Boot, these variables start with SPRING_INFINISPAN_CLIENT_*.
More info: https://github.com/kiegroup/kogito-cloud-operator#infinispan-environment-variables.
Default to false, which means it installs Infinispan if the service
requires persistence.'
enum:
- Always
- Never
- Auto
type: string
type: object
replicas:
description: 'Number of replicas that the service will have deployed
in the cluster Default value: 1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ spec:
path: route
x-descriptors:
- urn:alm:descriptor:org.w3:link
- description: Infinispan Installation Mode
displayName: Infinispan Installation Mode
path: infra.installInfinispan
- description: Conditions History
displayName: Conditions
path: conditions
Expand Down
31 changes: 30 additions & 1 deletion pkg/apis/app/v1alpha1/kogitoapp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ type KogitoAppSpec struct {
// Kubernetes Service configuration
// Default value: nil
Service KogitoAppServiceObject `json:"service,omitempty"`

// Infrastructure definition
Infra KogitoAppInfra `json:"infra,omitempty"`
}

// Resources Data to define Resources needed for each deployed pod
Expand Down Expand Up @@ -187,7 +190,31 @@ type KogitoAppStatus struct {
Builds Builds `json:"builds"`
}

// RuntimeType is the type of condition
// KogitoAppInfraInstallInfinispanType defines the Infinispan installation mode
type KogitoAppInfraInstallInfinispanType string

const (
// KogitoAppInfraInstallInfinispanAlways - Always installs Infinispan
KogitoAppInfraInstallInfinispanAlways KogitoAppInfraInstallInfinispanType = "Always"
// KogitoAppInfraInstallInfinispanNever - Never installs Infinispan
KogitoAppInfraInstallInfinispanNever KogitoAppInfraInstallInfinispanType = "Never"
// KogitoAppInfraInstallInfinispanAuto - The Operator will try to discover if the service needs persistence by scanning the runtime image metadata
KogitoAppInfraInstallInfinispanAuto KogitoAppInfraInstallInfinispanType = "Auto"
)

// KogitoAppInfra defines details regarding the Kogito Infrastructure to support the deployed Kogito Service
type KogitoAppInfra struct {
// By default Kogito Operator installs an Infinispan instance in the namespace if the service needs persistence ('Auto').
// Set to 'Never' to disable this behavior, e.g. if the service will use another persistence mechanism.
// Set to 'Always' to always install Infinispan, even if the service won't need persistence.
// For Quarkus runtime, it sets QUARKUS_INFINISPAN_CLIENT_* environment variables. For Spring Boot, these variables start with SPRING_INFINISPAN_CLIENT_*.
// More info: https://github.com/kiegroup/kogito-cloud-operator#infinispan-environment-variables.
// Default to false, which means it installs Infinispan if the service requires persistence.
// +kubebuilder:validation:Enum=Always;Never;Auto
InstallInfinispan KogitoAppInfraInstallInfinispanType `json:"installInfinispan,omitempty"`
}

// RuntimeType - type of condition
type RuntimeType string

const (
Expand Down Expand Up @@ -238,6 +265,8 @@ const (
BuildS2IFailedReason ReasonType = "BuildS2IFailedReason"
// BuildRuntimeFailedReason - Unable to build the runtime image
BuildRuntimeFailedReason ReasonType = "BuildRuntimeFailedReason"
// DeployKogitoInfraFailedReason - Unable to deploy Kogito Infra
DeployKogitoInfraFailedReason ReasonType = "DeployKogitoInfraFailedReason"
// UnknownReason - Unable to determine the error
UnknownReason ReasonType = "Unknown"
)
Expand Down
17 changes: 17 additions & 0 deletions pkg/apis/app/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion pkg/apis/app/v1alpha1/zz_generated.openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,12 +663,18 @@ func schema_pkg_apis_app_v1alpha1_KogitoAppSpec(ref common.ReferenceCallback) co
Ref: ref("github.com/kiegroup/kogito-cloud-operator/pkg/apis/app/v1alpha1.KogitoAppServiceObject"),
},
},
"infra": {
SchemaProps: spec.SchemaProps{
Description: "Infrastructure definition",
Ref: ref("github.com/kiegroup/kogito-cloud-operator/pkg/apis/app/v1alpha1.KogitoAppInfra"),
},
},
},
Required: []string{"build"},
},
},
Dependencies: []string{
"github.com/kiegroup/kogito-cloud-operator/pkg/apis/app/v1alpha1.Env", "github.com/kiegroup/kogito-cloud-operator/pkg/apis/app/v1alpha1.KogitoAppBuildObject", "github.com/kiegroup/kogito-cloud-operator/pkg/apis/app/v1alpha1.KogitoAppServiceObject", "github.com/kiegroup/kogito-cloud-operator/pkg/apis/app/v1alpha1.Resources"},
"github.com/kiegroup/kogito-cloud-operator/pkg/apis/app/v1alpha1.Env", "github.com/kiegroup/kogito-cloud-operator/pkg/apis/app/v1alpha1.KogitoAppBuildObject", "github.com/kiegroup/kogito-cloud-operator/pkg/apis/app/v1alpha1.KogitoAppInfra", "github.com/kiegroup/kogito-cloud-operator/pkg/apis/app/v1alpha1.KogitoAppServiceObject", "github.com/kiegroup/kogito-cloud-operator/pkg/apis/app/v1alpha1.Resources"},
}
}

Expand Down
43 changes: 43 additions & 0 deletions pkg/controller/kogitoapp/kogitoapp_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package kogitoapp
import (
"fmt"
"github.com/kiegroup/kogito-cloud-operator/pkg/infrastructure"
"github.com/openshift/api/image/docker10"
"reflect"
"time"

Expand Down Expand Up @@ -135,6 +136,10 @@ func (r *ReconcileKogitoApp) Reconcile(request reconcile.Request) (result reconc
instance.Spec.Runtime = v1alpha1.QuarkusRuntimeType
}

if &instance.Spec.Infra == nil || len(instance.Spec.Infra.InstallInfinispan) == 0 {
instance.Spec.Infra = v1alpha1.KogitoAppInfra{InstallInfinispan: v1alpha1.KogitoAppInfraInstallInfinispanAuto}
}

requeue, err := r.ensureKogitoImageStream(instance)
if err != nil {
return reconcile.Result{}, err
Expand Down Expand Up @@ -167,6 +172,18 @@ func (r *ReconcileKogitoApp) Reconcile(request reconcile.Request) (result reconc
return
}

requeue, err = r.ensureKogitoInfra(instance, kogitoResources.RuntimeImage, kogitoResources.DeploymentConfig)
if err != nil {
updateResourceResult.Err = err
updateResourceResult.ErrorReason = v1alpha1.DeployKogitoInfraFailedReason
return
}
if requeue {
result.Requeue = true
result.RequeueAfter = 5 * time.Second
return
}

deployedRes, err := kogitores.GetDeployedResources(instance, r.client)
if err != nil {
updateResourceResult.Err = err
Expand Down Expand Up @@ -377,3 +394,29 @@ func (r *ReconcileKogitoApp) ensureKogitoImageStream(instance *v1alpha1.KogitoAp
}
return false, nil
}

func (r *ReconcileKogitoApp) ensureKogitoInfra(instance *v1alpha1.KogitoApp, runtimeImage *docker10.DockerImage, requestedDeployment *oappsv1.DeploymentConfig) (requeue bool, err error) {
log.Debug("Verify if we need to deploy Infinispan")
if instance.Spec.Infra.InstallInfinispan == v1alpha1.KogitoAppInfraInstallInfinispanAlways ||
(instance.Spec.Infra.InstallInfinispan == v1alpha1.KogitoAppInfraInstallInfinispanAuto && resource.IsPersistenceEnabled(runtimeImage)) {
infra, created, ready, err := infrastructure.EnsureInfinispanWithKogitoInfra(instance.Namespace, r.client)
if err != nil {
return true, err
}
if created {
// since we just created a new Infra instance, let's wait for it to provision everything before proceeding
log.Debug("Returning to reconcile phase to give some time for the Infinispan Operator to deploy")
return true, nil
}
if ready {
if err := kogitores.SetInfinispanEnvVars(r.client, infra, instance, requestedDeployment); err != nil {
return true, err
}
log.Debug("KogitoInfra is ready, proceed!")
return false, nil
}
log.Debug("KogitoInfra is not ready, requeue")
return true, nil
}
return false, nil
}
Loading

0 comments on commit b9c0a02

Please sign in to comment.