From 044d23b871df28c3849b20ce8e63155bc8c543af Mon Sep 17 00:00:00 2001 From: tchughesiv Date: Mon, 25 Mar 2019 14:11:59 -0500 Subject: [PATCH 1/3] [KIECLOUD-154] omit console from rhdm production-immutable env Signed-off-by: tchughesiv --- config/envs/rhdm-production-immutable.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/envs/rhdm-production-immutable.yaml b/config/envs/rhdm-production-immutable.yaml index b7d7cad58..9f75ae02d 100644 --- a/config/envs/rhdm-production-immutable.yaml +++ b/config/envs/rhdm-production-immutable.yaml @@ -1,3 +1,5 @@ +console: + omit: true ## KIE smartrouter BEGIN smartRouter: omit: true From 9fa630e9e1d22cdcc1d500525d99bf9222dce505 Mon Sep 17 00:00:00 2001 From: tchughesiv Date: Mon, 25 Mar 2019 14:25:25 -0500 Subject: [PATCH 2/3] [KIECLOUD-152] remove ping vars from rhdm authoring console Signed-off-by: tchughesiv --- config/envs/rhdm-authoring.yaml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/config/envs/rhdm-authoring.yaml b/config/envs/rhdm-authoring.yaml index 186fc3691..9ea04d610 100644 --- a/config/envs/rhdm-authoring.yaml +++ b/config/envs/rhdm-authoring.yaml @@ -9,6 +9,23 @@ console: spec: containers: - name: "[[.ApplicationName]]-[[.Console.Name]]" + env: + - name: MAVEN_MIRROR_URL + value: "" + - name: MAVEN_REPO_ID + value: "" + - name: MAVEN_REPO_URL + value: "" + - name: MAVEN_REPO_USERNAME + value: "" + - name: MAVEN_REPO_PASSWORD + value: "" + - name: JGROUPS_PING_PROTOCOL + value: "" + - name: OPENSHIFT_DNS_PING_SERVICE_NAME + value: "" + - name: OPENSHIFT_DNS_PING_SERVICE_PORT + value: "" ports: - name: git-ssh containerPort: 8001 From 70f2c1989f5cc950b652cc370ad00f6a0658129d Mon Sep 17 00:00:00 2001 From: tchughesiv Date: Mon, 25 Mar 2019 14:50:40 -0500 Subject: [PATCH 3/3] [KIECLOUD-155] rhdm authoring-ha fixes Signed-off-by: tchughesiv --- config/envs/rhdm-authoring-ha.yaml | 376 ++++++++++++++++-- ...operator.v1.0.0.clusterserviceversion.yaml | 2 + ...operator.v1.0.0.clusterserviceversion.yaml | 2 + .../redhat/catalog-source.yaml | 2 + pkg/apis/app/v1/kieapp_types.go | 6 +- pkg/apis/app/v1/zz_generated.deepcopy.go | 8 + .../kieapp/defaults/defaults_test.go | 1 + pkg/controller/kieapp/defaults/merge.go | 91 ++++- pkg/controller/kieapp/kieapp_controller.go | 4 + pkg/controller/kieapp/watch.go | 1 + 10 files changed, 447 insertions(+), 46 deletions(-) diff --git a/config/envs/rhdm-authoring-ha.yaml b/config/envs/rhdm-authoring-ha.yaml index 62c9f1df8..6a3283216 100644 --- a/config/envs/rhdm-authoring-ha.yaml +++ b/config/envs/rhdm-authoring-ha.yaml @@ -58,7 +58,119 @@ smartRouter: ## KIE smartrouter END # ES/AMQ BEGIN others: - - persistentVolumeClaims: + - roles: + - metadata: + name: "[[.ApplicationName]]-amq-role" + labels: + app: "[[.ApplicationName]]" + application: "[[.ApplicationName]]" + rules: + - apiGroups: + - "" + resources: + - endpoints + verbs: + - create + - delete + - deletecollection + - get + - list + - patch + - update + - watch + - apiGroups: + - "" + resources: + - namespaces + verbs: + - get + - list + + - metadata: + name: "[[.ApplicationName]]-amq-scaledown-controller-role" + labels: + app: "[[.ApplicationName]]" + application: "[[.ApplicationName]]" + rules: + - apiGroups: + - apps + resources: + - statefulsets + verbs: + - get + - list + - watch + - apiGroups: + - "" + resources: + - pods + verbs: + - get + - list + - watch + - create + - delete + - patch + - update + - apiGroups: + - "" + resources: + - persistentvolumeclaims + verbs: + - get + - list + - watch + - delete + - apiGroups: + - "" + resources: + - events + verbs: + - get + - list + - watch + + rolebindings: + - metadata: + name: "[[.ApplicationName]]-amq-scaledown-controller-openshift-rb" + labels: + app: "[[.ApplicationName]]" + application: "[[.ApplicationName]]" + subjects: + - kind: ServiceAccount + name: "[[.ApplicationName]]-amq-scaledown-controller-sa" + roleRef: + kind: Role + name: "[[.ApplicationName]]-amq-scaledown-controller-role" + apiGroup: rbac.authorization.k8s.io + + - metadata: + name: "[[.ApplicationName]]-amq-rb" + labels: + app: "[[.ApplicationName]]" + application: "[[.ApplicationName]]" + subjects: + - kind: ServiceAccount + name: "[[.ApplicationName]]-amq-sa" + roleRef: + kind: Role + name: "[[.ApplicationName]]-amq-role" + apiGroup: rbac.authorization.k8s.io + + serviceaccounts: + - metadata: + labels: + app: "[[.ApplicationName]]" + application: "[[.ApplicationName]]" + name: "[[.ApplicationName]]-amq-sa" + + - metadata: + labels: + app: "[[.ApplicationName]]" + application: "[[.ApplicationName]]" + name: "[[.ApplicationName]]-amq-scaledown-controller-sa" + + persistentVolumeClaims: - metadata: name: "[[.ApplicationName]]-[[.Constants.Product]]index-claim" labels: @@ -139,17 +251,172 @@ others: labels: app: "[[.ApplicationName]]" application: "[[.ApplicationName]]" - name: "[[.ApplicationName]]-amq" + service: "[[.ApplicationName]]-amq-scaledown-controller" + name: "[[.ApplicationName]]-amq-scaledown-controller" + annotations: + deployment.kubernetes.io/revision: "1" + template.alpha.openshift.io/wait-for-ready: "true" spec: replicas: 1 selector: - deploymentConfig: "[[.ApplicationName]]-amq" + deploymentConfig: "[[.ApplicationName]]-amq-scaledown-controller" strategy: rollingParams: maxSurge: 0 type: Rolling template: metadata: + labels: + app: "[[.ApplicationName]]" + application: "[[.ApplicationName]]" + deploymentConfig: "[[.ApplicationName]]-amq-scaledown-controller" + name: "[[.ApplicationName]]-amq-scaledown-controller" + spec: + serviceAccountName: "[[.ApplicationName]]-amq-scaledown-controller-sa" + containers: + - args: + - --localOnly + - --v + - "3" + image: "amq-broker-72-scaledown-controller-openshift" + imagePullPolicy: IfNotPresent + name: "[[.ApplicationName]]-amq" + terminationGracePeriodSeconds: 30 + triggers: + - imageChangeParams: + automatic: true + containerNames: + - "[[.ApplicationName]]-amq" + from: + kind: ImageStreamTag + namespace: "openshift" + name: "amq-broker-72-scaledown-controller-openshift:0.4" + type: ImageChange + - type: ConfigChange + + statefulsets: + - metadata: + annotations: + alpha.image.policy.openshift.io/resolve-names: "*" + statefulsets.kubernetes.io/drainer-pod-template: | + { + "metadata": { + "labels": { + "app": "[[.ApplicationName]]", + "application": "[[.ApplicationName]]" + }, + "name": "[[.ApplicationName]]-amq-drainer-pod" + }, + "spec": { + "serviceAccount": "[[.ApplicationName]]-amq-sa", + "serviceAccountName": "[[.ApplicationName]]-amq-sa", + "terminationGracePeriodSeconds": 5, + "containers": [ + { + "env": [ + { + "name": "AMQ_EXTRA_ARGS", + "value": "--no-autotune" + }, + { + "name": "AMQ_USER", + "value": "jmsBrokserUser" + }, + { + "name": "AMQ_PASSWORD", + "value": "[[.AdminPassword]]" + }, + { + "name": "AMQ_ROLE", + "value": "admin" + }, + { + "name": "AMQ_NAME", + "value": "broker" + }, + { + "name": "AMQ_TRANSPORTS", + "value": "openwire" + }, + { + "name": "AMQ_QUEUES", + "value": "" + }, + { + "name": "AMQ_GLOBAL_MAX_SIZE", + "value": "100 gb" + }, + { + "name": "AMQ_ALLOW_ANONYMOUS", + "value": "" + }, + { + "name": "AMQ_DATA_DIR", + "value": "/opt/amq/data" + }, + { + "name": "AMQ_DATA_DIR_LOGGING", + "value": "true" + }, + { + "name": "AMQ_CLUSTERED", + "value": "true" + }, + { + "name": "AMQ_REPLICAS", + "value": "2" + }, + { + "name": "AMQ_CLUSTER_USER", + "value": "jmsBrokserUser" + }, + { + "name": "AMQ_CLUSTER_PASSWORD", + "value": "[[.AdminPassword]]" + }, + { + "name": "POD_NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace" + } + } + }, + { + "name": "OPENSHIFT_DNS_PING_SERVICE_PORT", + "value": "8888" + } + ], + "image": "amq-broker-72-openshift:1.1", + "name": "[[.ApplicationName]]-amq", + "command": ["/bin/sh", "-c", "echo \"Starting the drainer\" ; /opt/amq/bin/drain.sh; echo \"Drain completed! Exit code $?\""], + "volumeMounts": [ + { + "name": "[[.ApplicationName]]-amq-pvol", + "mountPath": "/opt/amq/data" + } + ] + } + ] + } + } + creationTimestamp: null + generation: 3 + labels: + app: "[[.ApplicationName]]" + application: "[[.ApplicationName]]" + name: "[[.ApplicationName]]-amq" + spec: + podManagementPolicy: OrderedReady + replicas: 2 + revisionHistoryLimit: 10 + selector: + matchLabels: + app: "[[.ApplicationName]]" + serviceName: "[[.ApplicationName]]-amq-tcp" + template: + metadata: + creationTimestamp: null labels: app: "[[.ApplicationName]]" application: "[[.ApplicationName]]" @@ -170,20 +437,32 @@ others: value: "openwire" - name: AMQ_GLOBAL_MAX_SIZE value: "100 gb" - image: "amq-broker-72-openshift" - imagePullPolicy: Always - readinessProbe: - exec: - command: - - "/bin/bash" - - "-c" - - "/opt/amq/bin/readinessProbe.sh" - lifecycle: - preStop: - exec: - command: - - /opt/amq/bin/shutdownHook.sh - name: "[[.ApplicationName]]-amq" + - name: AMQ_REQUIRE_LOGIN + - name: AMQ_DATA_DIR + value: /opt/amq/data + - name: AMQ_DATA_DIR_LOGGING + value: "true" + - name: AMQ_CLUSTERED + value: "true" + - name: AMQ_REPLICAS + value: "0" + - name: AMQ_CLUSTER_USER + value: "jmsBrokserUser" + - name: AMQ_CLUSTER_PASSWORD + value: "[[.AdminPassword]]" + - name: OPENSHIFT_DNS_PING_SERVICE_NAME + value: "[[.ApplicationName]]-amq-ping" + - name: AMQ_EXTRA_ARGS + - name: AMQ_ANYCAST_PREFIX + - name: AMQ_MULTICAST_PREFIX + - name: POD_NAMESPACE + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.namespace + image: "amq-broker-72-openshift:1.1" + imagePullPolicy: IfNotPresent + name: broker-amq ports: - containerPort: 8161 name: jolokia @@ -200,21 +479,43 @@ others: - containerPort: 61616 name: artemis protocol: TCP + readinessProbe: + exec: + command: + - /bin/bash + - -c + - /opt/amq/bin/readinessProbe.sh + failureThreshold: 3 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 + resources: {} + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + volumeMounts: + - mountPath: /opt/amq/data + name: "[[.ApplicationName]]-amq-pvol" + dnsPolicy: ClusterFirst + restartPolicy: Always + schedulerName: default-scheduler + securityContext: {} terminationGracePeriodSeconds: 60 - triggers: - - imageChangeParams: - automatic: true - containerNames: - - "[[.ApplicationName]]-amq" - from: - kind: ImageStreamTag - namespace: "openshift" - name: "amq-broker-72-openshift:1.0" - type: ImageChange - - type: ConfigChange + updateStrategy: + type: OnDelete + volumeClaimTemplates: + - metadata: + creationTimestamp: null + name: "[[.ApplicationName]]-amq-pvol" + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi services: - spec: + clusterIP: None ports: - port: 61616 targetPort: 61616 @@ -229,6 +530,23 @@ others: annotations: description: The broker's OpenWire port. + - spec: + clusterIP: None + ports: + - port: 8888 + protocol: TCP + targetPort: 8888 + selector: + deploymentConfig: "[[.ApplicationName]]-amq" + metadata: + name: "[[.ApplicationName]]-amq-ping" + annotations: + description: The JGroups ping port for clustering. + service.alpha.kubernetes.io/tolerate-unready-endpoints: "true" + labels: + app: "[[.ApplicationName]]" + application: "[[.ApplicationName]]" + - spec: ports: - name: rest @@ -263,4 +581,4 @@ others: name: "[[.ApplicationName]]-[[.Constants.Product]]index" port: targetPort: rest -## ES/AMQ END + ## ES/AMQ END diff --git a/deploy/catalog_resources/community/kiecloud-operator.v1.0.0.clusterserviceversion.yaml b/deploy/catalog_resources/community/kiecloud-operator.v1.0.0.clusterserviceversion.yaml index 6c0452f31..58c4cb4f2 100644 --- a/deploy/catalog_resources/community/kiecloud-operator.v1.0.0.clusterserviceversion.yaml +++ b/deploy/catalog_resources/community/kiecloud-operator.v1.0.0.clusterserviceversion.yaml @@ -69,6 +69,8 @@ spec: resources: - kind: DeploymentConfig version: apps.openshift.io/v1 + - kind: StatefulSet + version: apps/v1 - kind: Secret version: v1 - kind: PersistentVolumeClaim diff --git a/deploy/catalog_resources/redhat/businessautomation-operator.v1.0.0.clusterserviceversion.yaml b/deploy/catalog_resources/redhat/businessautomation-operator.v1.0.0.clusterserviceversion.yaml index b43bac406..70878c535 100644 --- a/deploy/catalog_resources/redhat/businessautomation-operator.v1.0.0.clusterserviceversion.yaml +++ b/deploy/catalog_resources/redhat/businessautomation-operator.v1.0.0.clusterserviceversion.yaml @@ -69,6 +69,8 @@ spec: resources: - kind: DeploymentConfig version: apps.openshift.io/v1 + - kind: StatefulSet + version: apps/v1 - kind: Secret version: v1 - kind: PersistentVolumeClaim diff --git a/deploy/catalog_resources/redhat/catalog-source.yaml b/deploy/catalog_resources/redhat/catalog-source.yaml index a3a6292e1..56103bbd5 100644 --- a/deploy/catalog_resources/redhat/catalog-source.yaml +++ b/deploy/catalog_resources/redhat/catalog-source.yaml @@ -79,6 +79,8 @@ items: resources: - kind: DeploymentConfig version: apps.openshift.io/v1 + - kind: StatefulSet + version: apps/v1 - kind: Secret version: v1 - kind: PersistentVolumeClaim diff --git a/pkg/apis/app/v1/kieapp_types.go b/pkg/apis/app/v1/kieapp_types.go index ac73e132e..1c574b442 100644 --- a/pkg/apis/app/v1/kieapp_types.go +++ b/pkg/apis/app/v1/kieapp_types.go @@ -3,11 +3,12 @@ package v1 import ( "context" - appsv1 "github.com/openshift/api/apps/v1" + oappsv1 "github.com/openshift/api/apps/v1" buildv1 "github.com/openshift/api/build/v1" oimagev1 "github.com/openshift/api/image/v1" routev1 "github.com/openshift/api/route/v1" imagev1 "github.com/openshift/client-go/image/clientset/versioned/typed/image/v1" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -145,7 +146,8 @@ type CustomObject struct { Secrets []corev1.Secret `json:"secrets,omitempty"` Roles []rbacv1.Role `json:"roles,omitempty"` RoleBindings []rbacv1.RoleBinding `json:"roleBindings,omitempty"` - DeploymentConfigs []appsv1.DeploymentConfig `json:"deploymentConfigs,omitempty"` + DeploymentConfigs []oappsv1.DeploymentConfig `json:"deploymentConfigs,omitempty"` + StatefulSets []appsv1.StatefulSet `json:"statefulSets,omitempty"` BuildConfigs []buildv1.BuildConfig `json:"buildConfigs,omitempty"` ImageStreams []oimagev1.ImageStream `json:"imageStreams,omitempty"` Services []corev1.Service `json:"services,omitempty"` diff --git a/pkg/apis/app/v1/zz_generated.deepcopy.go b/pkg/apis/app/v1/zz_generated.deepcopy.go index fdad149ed..bb125558f 100644 --- a/pkg/apis/app/v1/zz_generated.deepcopy.go +++ b/pkg/apis/app/v1/zz_generated.deepcopy.go @@ -25,6 +25,7 @@ import ( buildv1 "github.com/openshift/api/build/v1" imagev1 "github.com/openshift/api/image/v1" routev1 "github.com/openshift/api/route/v1" + apiappsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" runtime "k8s.io/apimachinery/pkg/runtime" @@ -178,6 +179,13 @@ func (in *CustomObject) DeepCopyInto(out *CustomObject) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.StatefulSets != nil { + in, out := &in.StatefulSets, &out.StatefulSets + *out = make([]apiappsv1.StatefulSet, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } if in.BuildConfigs != nil { in, out := &in.BuildConfigs, &out.BuildConfigs *out = make([]buildv1.BuildConfig, len(*in)) diff --git a/pkg/controller/kieapp/defaults/defaults_test.go b/pkg/controller/kieapp/defaults/defaults_test.go index 6ded996fe..aa6be4724 100644 --- a/pkg/controller/kieapp/defaults/defaults_test.go +++ b/pkg/controller/kieapp/defaults/defaults_test.go @@ -209,6 +209,7 @@ func TestRhdmAuthoringHAEnvironment(t *testing.T) { assert.Nil(t, err, "Error getting prod environment") assert.Equal(t, "test-rhdmcentr", env.Console.DeploymentConfigs[0].ObjectMeta.Name) + assert.Equal(t, "test-amq", env.Others[0].StatefulSets[0].ObjectMeta.Name) assert.Equal(t, fmt.Sprintf("rhdm%s-decisioncentral-openshift", cr.Spec.CommonConfig.Version), env.Console.DeploymentConfigs[0].Spec.Template.Spec.Containers[0].Image) for i := 0; i < len(env.Servers); i++ { assert.Equal(t, "DEVELOPMENT", getEnvVariable(env.Servers[i].DeploymentConfigs[0].Spec.Template.Spec.Containers[0], "KIE_SERVER_MODE")) diff --git a/pkg/controller/kieapp/defaults/merge.go b/pkg/controller/kieapp/defaults/merge.go index 91da39e40..013cb8ac3 100644 --- a/pkg/controller/kieapp/defaults/merge.go +++ b/pkg/controller/kieapp/defaults/merge.go @@ -7,11 +7,12 @@ import ( "github.com/imdario/mergo" v1 "github.com/kiegroup/kie-cloud-operator/pkg/apis/app/v1" "github.com/kiegroup/kie-cloud-operator/pkg/controller/kieapp/shared" - appsv1 "github.com/openshift/api/apps/v1" + oappsv1 "github.com/openshift/api/apps/v1" buildv1 "github.com/openshift/api/build/v1" oimagev1 "github.com/openshift/api/image/v1" routev1 "github.com/openshift/api/route/v1" "github.com/pkg/errors" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" ) @@ -61,6 +62,7 @@ func mergeCustomObject(baseline v1.CustomObject, overwrite v1.CustomObject) v1.C object.Roles = mergeRoles(baseline.Roles, overwrite.Roles) object.RoleBindings = mergeRoleBindings(baseline.RoleBindings, overwrite.RoleBindings) object.DeploymentConfigs = mergeDeploymentConfigs(baseline.DeploymentConfigs, overwrite.DeploymentConfigs) + object.StatefulSets = mergeStatefulSets(baseline.StatefulSets, overwrite.StatefulSets) object.ImageStreams = mergeImageStreams(baseline.ImageStreams, overwrite.ImageStreams) object.BuildConfigs = mergeBuildConfigs(baseline.BuildConfigs, overwrite.BuildConfigs) object.Services = mergeServices(baseline.Services, overwrite.Services) @@ -198,7 +200,7 @@ func getRoleBindingReferenceSlice(objects []rbacv1.RoleBinding) []v1.OpenShiftOb return slice } -func mergeDeploymentConfigs(baseline []appsv1.DeploymentConfig, overwrite []appsv1.DeploymentConfig) []appsv1.DeploymentConfig { +func mergeDeploymentConfigs(baseline []oappsv1.DeploymentConfig, overwrite []oappsv1.DeploymentConfig) []oappsv1.DeploymentConfig { if len(overwrite) == 0 { return baseline } @@ -217,7 +219,7 @@ func mergeDeploymentConfigs(baseline []appsv1.DeploymentConfig, overwrite []apps log.Error("Error merging interfaces. ", err) return nil } - mergedSpec, err := mergeSpec(baselineItem.Spec, overwriteItem.Spec) + mergedSpec, err := mergeDCSpec(baselineItem.Spec, overwriteItem.Spec) if err != nil { log.Error("Error merging DeploymentConfig Specs. ", err) return nil @@ -225,7 +227,44 @@ func mergeDeploymentConfigs(baseline []appsv1.DeploymentConfig, overwrite []apps overwriteItem.Spec = mergedSpec } } - slice := make([]appsv1.DeploymentConfig, combinedSize(baselineRefs, overwriteRefs)) + slice := make([]oappsv1.DeploymentConfig, combinedSize(baselineRefs, overwriteRefs)) + err := mergeObjects(baselineRefs, overwriteRefs, slice) + if err != nil { + log.Error("Error merging objects. ", err) + return nil + } + return slice + +} + +func mergeStatefulSets(baseline []appsv1.StatefulSet, overwrite []appsv1.StatefulSet) []appsv1.StatefulSet { + if len(overwrite) == 0 { + return baseline + } + if len(baseline) == 0 { + return overwrite + } + baselineRefs := getStatefulSetReferenceSlice(baseline) + overwriteRefs := getStatefulSetReferenceSlice(overwrite) + for overwriteIndex := range overwrite { + overwriteItem := &overwrite[overwriteIndex] + baselineIndex, _ := findOpenShiftObject(overwriteItem, baselineRefs) + if baselineIndex >= 0 { + baselineItem := baseline[baselineIndex] + err := mergo.Merge(&overwriteItem.ObjectMeta, baselineItem.ObjectMeta) + if err != nil { + log.Error("Error merging interfaces. ", err) + return nil + } + mergedSpec, err := mergeStatefulSpec(baselineItem.Spec, overwriteItem.Spec) + if err != nil { + log.Error("Error merging DeploymentConfig Specs. ", err) + return nil + } + overwriteItem.Spec = mergedSpec + } + } + slice := make([]appsv1.StatefulSet, combinedSize(baselineRefs, overwriteRefs)) err := mergeObjects(baselineRefs, overwriteRefs, slice) if err != nil { log.Error("Error merging objects. ", err) @@ -297,22 +336,36 @@ func mergeBuildConfigs(baseline, overwrite []buildv1.BuildConfig) []buildv1.Buil return slice } -func mergeSpec(baseline appsv1.DeploymentConfigSpec, overwrite appsv1.DeploymentConfigSpec) (appsv1.DeploymentConfigSpec, error) { +func mergeDCSpec(baseline oappsv1.DeploymentConfigSpec, overwrite oappsv1.DeploymentConfigSpec) (oappsv1.DeploymentConfigSpec, error) { mergedTemplate, err := mergeTemplate(baseline.Template, overwrite.Template) if err != nil { - return appsv1.DeploymentConfigSpec{}, err + return oappsv1.DeploymentConfigSpec{}, err } overwrite.Template = mergedTemplate mergedTriggers, err := mergeTriggers(baseline.Triggers, overwrite.Triggers) if err != nil { - return appsv1.DeploymentConfigSpec{}, err + return oappsv1.DeploymentConfigSpec{}, err } overwrite.Triggers = mergedTriggers err = mergo.Merge(&baseline, overwrite, mergo.WithOverride) if err != nil { - return appsv1.DeploymentConfigSpec{}, nil + return oappsv1.DeploymentConfigSpec{}, nil + } + return baseline, nil +} + +func mergeStatefulSpec(baseline appsv1.StatefulSetSpec, overwrite appsv1.StatefulSetSpec) (appsv1.StatefulSetSpec, error) { + mergedTemplate, err := mergeTemplate(&baseline.Template, &overwrite.Template) + if err != nil { + return appsv1.StatefulSetSpec{}, err + } + overwrite.Template = *mergedTemplate + + err = mergo.Merge(&baseline, overwrite, mergo.WithOverride) + if err != nil { + return appsv1.StatefulSetSpec{}, nil } return baseline, nil } @@ -354,8 +407,8 @@ func mergeTemplate(baseline *corev1.PodTemplateSpec, overwrite *corev1.PodTempla return baseline, nil } -func mergeTriggers(baseline appsv1.DeploymentTriggerPolicies, overwrite appsv1.DeploymentTriggerPolicies) (appsv1.DeploymentTriggerPolicies, error) { - var mergedTriggers []appsv1.DeploymentTriggerPolicy +func mergeTriggers(baseline oappsv1.DeploymentTriggerPolicies, overwrite oappsv1.DeploymentTriggerPolicies) (oappsv1.DeploymentTriggerPolicies, error) { + var mergedTriggers []oappsv1.DeploymentTriggerPolicy for baselineIndex, baselineItem := range baseline { idx, found := findDeploymentTriggerPolicy(baselineItem, overwrite) if idx == -1 { @@ -411,11 +464,11 @@ func mergeBuildTriggers(baseline []buildv1.BuildTriggerPolicy, overwrite []build // findDeploymentTriggerPolicy Finds a deploymentTrigger by Type. In case type == ImageChange // the match will be returned if both are not empty -func findDeploymentTriggerPolicy(object appsv1.DeploymentTriggerPolicy, slice []appsv1.DeploymentTriggerPolicy) (int, appsv1.DeploymentTriggerPolicy) { - emptyImageChangeParams := &appsv1.DeploymentTriggerImageChangeParams{} +func findDeploymentTriggerPolicy(object oappsv1.DeploymentTriggerPolicy, slice []oappsv1.DeploymentTriggerPolicy) (int, oappsv1.DeploymentTriggerPolicy) { + emptyImageChangeParams := &oappsv1.DeploymentTriggerImageChangeParams{} for index, candidate := range slice { if candidate.Type == object.Type { - if object.Type == appsv1.DeploymentTriggerOnImageChange { + if object.Type == oappsv1.DeploymentTriggerOnImageChange { if !cmp.Equal(object.ImageChangeParams, emptyImageChangeParams) && !cmp.Equal(candidate.ImageChangeParams, emptyImageChangeParams) { return index, candidate } @@ -424,7 +477,7 @@ func findDeploymentTriggerPolicy(object appsv1.DeploymentTriggerPolicy, slice [] } } } - return -1, appsv1.DeploymentTriggerPolicy{} + return -1, oappsv1.DeploymentTriggerPolicy{} } // findBuildTriggerPolicy Finds a buildTrigger by Type @@ -584,7 +637,15 @@ func findVolumeMount(object corev1.VolumeMount, slice []corev1.VolumeMount) (int return -1, corev1.VolumeMount{} } -func getDeploymentConfigReferenceSlice(objects []appsv1.DeploymentConfig) []v1.OpenShiftObject { +func getDeploymentConfigReferenceSlice(objects []oappsv1.DeploymentConfig) []v1.OpenShiftObject { + slice := make([]v1.OpenShiftObject, len(objects)) + for index := range objects { + slice[index] = &objects[index] + } + return slice +} + +func getStatefulSetReferenceSlice(objects []appsv1.StatefulSet) []v1.OpenShiftObject { slice := make([]v1.OpenShiftObject, len(objects)) for index := range objects { slice[index] = &objects[index] diff --git a/pkg/controller/kieapp/kieapp_controller.go b/pkg/controller/kieapp/kieapp_controller.go index 74f500a6d..9b1321ba4 100644 --- a/pkg/controller/kieapp/kieapp_controller.go +++ b/pkg/controller/kieapp/kieapp_controller.go @@ -554,6 +554,10 @@ func (reconciler *Reconciler) CreateCustomObjects(object v1.CustomObject, cr *v1 object.Services[index].SetGroupVersionKind(corev1.SchemeGroupVersion.WithKind("Service")) allObjects = append(allObjects, &object.Services[index]) } + for index := range object.StatefulSets { + object.StatefulSets[index].SetGroupVersionKind(appsv1.SchemeGroupVersion.WithKind("StatefulSet")) + allObjects = append(allObjects, &object.StatefulSets[index]) + } for index := range object.Routes { object.Routes[index].SetGroupVersionKind(routev1.SchemeGroupVersion.WithKind("Route")) allObjects = append(allObjects, &object.Routes[index]) diff --git a/pkg/controller/kieapp/watch.go b/pkg/controller/kieapp/watch.go index c11aa2c6c..0920bfb9b 100644 --- a/pkg/controller/kieapp/watch.go +++ b/pkg/controller/kieapp/watch.go @@ -54,6 +54,7 @@ func Add(mgr manager.Manager, reconciler reconcile.Reconciler) error { watchOwnedObjects = []runtime.Object{ &oappsv1.DeploymentConfig{}, + &appsv1.StatefulSet{}, &corev1.PersistentVolumeClaim{}, &rbacv1.RoleBinding{}, &rbacv1.Role{},