Skip to content

Commit

Permalink
Merge branch 'master' into 1.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
tchughesiv committed Mar 26, 2019
2 parents 4921c45 + 7f0eb08 commit a306c5a
Show file tree
Hide file tree
Showing 12 changed files with 466 additions and 46 deletions.
376 changes: 347 additions & 29 deletions config/envs/rhdm-authoring-ha.yaml

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions config/envs/rhdm-authoring.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/envs/rhdm-production-immutable.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
console:
omit: true
## KIE smartrouter BEGIN
smartRouter:
omit: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ spec:
resources:
- kind: DeploymentConfig
version: apps.openshift.io/v1
- kind: StatefulSet
version: apps/v1
- kind: Secret
version: v1
- kind: PersistentVolumeClaim
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ spec:
resources:
- kind: DeploymentConfig
version: apps.openshift.io/v1
- kind: StatefulSet
version: apps/v1
- kind: Secret
version: v1
- kind: PersistentVolumeClaim
Expand Down
2 changes: 2 additions & 0 deletions deploy/catalog_resources/redhat/catalog-source.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ items:
resources:
- kind: DeploymentConfig
version: apps.openshift.io/v1
- kind: StatefulSet
version: apps/v1
- kind: Secret
version: v1
- kind: PersistentVolumeClaim
Expand Down
6 changes: 4 additions & 2 deletions pkg/apis/app/v1/kieapp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"`
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/app/v1/zz_generated.deepcopy.go

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

1 change: 1 addition & 0 deletions pkg/controller/kieapp/defaults/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
91 changes: 76 additions & 15 deletions pkg/controller/kieapp/defaults/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand All @@ -217,15 +219,52 @@ 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
}
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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -424,7 +477,7 @@ func findDeploymentTriggerPolicy(object appsv1.DeploymentTriggerPolicy, slice []
}
}
}
return -1, appsv1.DeploymentTriggerPolicy{}
return -1, oappsv1.DeploymentTriggerPolicy{}
}

// findBuildTriggerPolicy Finds a buildTrigger by Type
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/kieapp/kieapp_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/kieapp/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down

0 comments on commit a306c5a

Please sign in to comment.