Skip to content

Commit

Permalink
[wildfly#114]Allow standaloneConfigMap point a configMap which contai…
Browse files Browse the repository at this point in the history
…ns all config files under wildfly/standalone/configuration directory
  • Loading branch information
jimma committed Oct 9, 2019
1 parent 18af904 commit 2537771
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 115 deletions.
11 changes: 1 addition & 10 deletions deploy/crds/wildfly_v1alpha1_wildflyserver_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,7 @@ spec:
if omitted)
type: boolean
standaloneConfigMap:
properties:
key:
description: Key of the config map whose value is the standalone
XML configuration file ("standalone.xml" if omitted)
type: string
name:
type: string
required:
- name
type: object
type: string
storage:
description: StorageSpec defines specific storage required for the server
own data directory. If omitted, an EmptyDir is used (that will not
Expand Down
12 changes: 2 additions & 10 deletions pkg/apis/wildfly/v1alpha1/wildflyserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ type WildFlyServerSpec struct {
// SessionAffinity defines if connections from the same client ip are passed to the same WildFlyServer instance/pod each time (false if omitted)
SessionAffinity bool `json:"sessionAffinity,omitempty"`
// DisableHTTPRoute disables the creation a route to the HTTP port of the application service (false if omitted)
DisableHTTPRoute bool `json:"disableHTTPRoute,omitempty"`
StandaloneConfigMap *StandaloneConfigMapSpec `json:"standaloneConfigMap,omitempty"`
DisableHTTPRoute bool `json:"disableHTTPRoute,omitempty"`
StandaloneConfigMap string `json:"standaloneConfigMap,omitempty"`
// StorageSpec defines specific storage required for the server own data directory. If omitted, an EmptyDir is used (that will not
// persist data across pod restart).
Storage *StorageSpec `json:"storage,omitempty"`
Expand All @@ -43,14 +43,6 @@ type WildFlyServerSpec struct {
ConfigMaps []string `json:"configMaps,omitempty"`
}

// StandaloneConfigMapSpec defines the desired configMap configuration to obtain the standalone configuration for WildFlyServer
// +k8s:openapi-gen=true
type StandaloneConfigMapSpec struct {
Name string `json:"name"`
// Key of the config map whose value is the standalone XML configuration file ("standalone.xml" if omitted)
Key string `json:"key,omitempty"`
}

// StorageSpec defines the desired storage for WildFlyServer
// +k8s:openapi-gen=true
type StorageSpec struct {
Expand Down
21 changes: 0 additions & 21 deletions pkg/apis/wildfly/v1alpha1/zz_generated.deepcopy.go

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

45 changes: 9 additions & 36 deletions pkg/apis/wildfly/v1alpha1/zz_generated.openapi.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !ignore_autogenerated
// +build !

// This file was autogenerated by openapi-gen. Do not edit it manually!

Expand All @@ -11,12 +11,11 @@ import (

func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition {
return map[string]common.OpenAPIDefinition{
"./pkg/apis/wildfly/v1alpha1.PodStatus": schema_pkg_apis_wildfly_v1alpha1_PodStatus(ref),
"./pkg/apis/wildfly/v1alpha1.StandaloneConfigMapSpec": schema_pkg_apis_wildfly_v1alpha1_StandaloneConfigMapSpec(ref),
"./pkg/apis/wildfly/v1alpha1.StorageSpec": schema_pkg_apis_wildfly_v1alpha1_StorageSpec(ref),
"./pkg/apis/wildfly/v1alpha1.WildFlyServer": schema_pkg_apis_wildfly_v1alpha1_WildFlyServer(ref),
"./pkg/apis/wildfly/v1alpha1.WildFlyServerSpec": schema_pkg_apis_wildfly_v1alpha1_WildFlyServerSpec(ref),
"./pkg/apis/wildfly/v1alpha1.WildFlyServerStatus": schema_pkg_apis_wildfly_v1alpha1_WildFlyServerStatus(ref),
"./pkg/apis/wildfly/v1alpha1.PodStatus": schema_pkg_apis_wildfly_v1alpha1_PodStatus(ref),
"./pkg/apis/wildfly/v1alpha1.StorageSpec": schema_pkg_apis_wildfly_v1alpha1_StorageSpec(ref),
"./pkg/apis/wildfly/v1alpha1.WildFlyServer": schema_pkg_apis_wildfly_v1alpha1_WildFlyServer(ref),
"./pkg/apis/wildfly/v1alpha1.WildFlyServerSpec": schema_pkg_apis_wildfly_v1alpha1_WildFlyServerSpec(ref),
"./pkg/apis/wildfly/v1alpha1.WildFlyServerStatus": schema_pkg_apis_wildfly_v1alpha1_WildFlyServerStatus(ref),
}
}

Expand Down Expand Up @@ -53,33 +52,6 @@ func schema_pkg_apis_wildfly_v1alpha1_PodStatus(ref common.ReferenceCallback) co
}
}

func schema_pkg_apis_wildfly_v1alpha1_StandaloneConfigMapSpec(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Description: "StandaloneConfigMapSpec defines the desired configMap configuration to obtain the standalone configuration for WildFlyServer",
Properties: map[string]spec.Schema{
"name": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Format: "",
},
},
"key": {
SchemaProps: spec.SchemaProps{
Description: "Key of the config map whose value is the standalone XML configuration file (\"standalone.xml\" if omitted)",
Type: []string{"string"},
Format: "",
},
},
},
Required: []string{"name"},
},
},
Dependencies: []string{},
}
}

func schema_pkg_apis_wildfly_v1alpha1_StorageSpec(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
Expand Down Expand Up @@ -184,7 +156,8 @@ func schema_pkg_apis_wildfly_v1alpha1_WildFlyServerSpec(ref common.ReferenceCall
},
"standaloneConfigMap": {
SchemaProps: spec.SchemaProps{
Ref: ref("./pkg/apis/wildfly/v1alpha1.StandaloneConfigMapSpec"),
Type: []string{"string"},
Format: "",
},
},
"storage": {
Expand Down Expand Up @@ -258,7 +231,7 @@ func schema_pkg_apis_wildfly_v1alpha1_WildFlyServerSpec(ref common.ReferenceCall
},
},
Dependencies: []string{
"./pkg/apis/wildfly/v1alpha1.StandaloneConfigMapSpec", "./pkg/apis/wildfly/v1alpha1.StorageSpec", "k8s.io/api/core/v1.EnvFromSource", "k8s.io/api/core/v1.EnvVar"},
"./pkg/apis/wildfly/v1alpha1.StorageSpec", "k8s.io/api/core/v1.EnvFromSource", "k8s.io/api/core/v1.EnvVar"},
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/wildflyserver/wildflyserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func (r *ReconcileWildFlyServer) checkStatefulSet(wildflyServer *wildflyv1alpha1
}

if !resources.IsCurrentGeneration(wildflyServer, foundStatefulSet) {
statefulSet := statefulsets.NewStatefulSet(wildflyServer, LabelsForWildFly(wildflyServer), desiredStatefulSetReplicaSize)
statefulSet := statefulsets.NewStatefulSet(wildflyServer, r.client, LabelsForWildFly(wildflyServer), desiredStatefulSetReplicaSize)
delete := false
// changes to VolumeClaimTemplates can not be updated and requires a delete/create of the statefulset
if len(statefulSet.Spec.VolumeClaimTemplates) > 0 {
Expand Down
81 changes: 51 additions & 30 deletions pkg/resources/statefulsets/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func GetOrCreateNewStatefulSet(w *wildflyv1alpha1.WildFlyServer, client client.C
statefulSet := &appsv1.StatefulSet{}
if err := resources.Get(w, types.NamespacedName{Name: w.Name, Namespace: w.Namespace}, client, statefulSet); err != nil {
if errors.IsNotFound(err) {
if err := resources.Create(w, client, scheme, NewStatefulSet(w, labels, desiredReplicaSize)); err != nil {
if err := resources.Create(w, client, scheme, NewStatefulSet(w, client, labels, desiredReplicaSize)); err != nil {
return nil, err
}
return nil, nil
Expand All @@ -40,7 +40,7 @@ func GetOrCreateNewStatefulSet(w *wildflyv1alpha1.WildFlyServer, client client.C
}

// NewStatefulSet retunrs a new statefulset
func NewStatefulSet(w *wildflyv1alpha1.WildFlyServer, labels map[string]string, desiredReplicaSize int32) *appsv1.StatefulSet {
func NewStatefulSet(w *wildflyv1alpha1.WildFlyServer, client client.Client, labels map[string]string, desiredReplicaSize int32) *appsv1.StatefulSet {
replicas := desiredReplicaSize
applicationImage := w.Spec.ApplicationImage
labesForActiveWildflyPod := wildflyutil.CopyMap(labels)
Expand Down Expand Up @@ -152,37 +152,38 @@ func NewStatefulSet(w *wildflyv1alpha1.WildFlyServer, labels map[string]string,
MountPath: resources.StandaloneServerDataDirPath,
})

// mount the volume to read the standalone XML configuration from a ConfigMap
standaloneConfigMap := w.Spec.StandaloneConfigMap
if standaloneConfigMap != nil {
configMapName := standaloneConfigMap.Name
configMapKey := standaloneConfigMap.Key
if configMapKey == "" {
configMapKey = "standalone.xml"
}
log.Info("Reading standalone configuration from configmap", "StandaloneConfigMap.Name", configMapName, "StandaloneConfigMap.Key", configMapKey)

volumes = append(volumes, corev1.Volume{
Name: "standalone-config-volume",
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: configMapName,
},
Items: []corev1.KeyToPath{
{
Key: configMapKey,
Path: "standalone.xml",
if len(standaloneConfigMap) > 0 {
log.Info("Store standalone configuration from configmap", standaloneConfigMap)
keyPath := []corev1.KeyToPath{}
keyPath, err := getKeyPath(w, client, keyPath)
if err != nil {
log.Error(err, "Failed to read key/path from configmap")
} else {
if len(keyPath) > 0 {
volumes = append(volumes, corev1.Volume{
Name: "standalone-config-volume",
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: standaloneConfigMap,
},
},
},
},
},
})
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: "standalone-config-volume",
MountPath: resources.JBossHome + "/standalone/configuration/standalone.xml",
SubPath: "standalone.xml",
})
})
for _, v := range keyPath {

volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: "standalone-config-volume",
MountPath: resources.JBossHome + "/standalone/configuration/" + v.Path,
SubPath: v.Path,
})
}
} else {
log.Info("Ignore this configmap and there is no configuration files found")
}
}

}

// mount volumes from secrets
Expand Down Expand Up @@ -302,3 +303,23 @@ func envForEJBRecovery(w *wildflyv1alpha1.WildFlyServer) []corev1.EnvVar {
},
}
}

func getKeyPath(w *wildflyv1alpha1.WildFlyServer, client client.Client, keypath []corev1.KeyToPath) ([]corev1.KeyToPath, error) {
config := &corev1.ConfigMap{}
err := resources.Get(w, types.NamespacedName{Name: w.Spec.StandaloneConfigMap, Namespace: w.Namespace}, client, config)
if err != nil {
return keypath, nil
}
for k := range config.Data {
//ConfigMapVolumeSource can be only accessed with 644 mode (https://github.com/kubernetes/kubernetes/issues/62099)
//Wildfly server writes back to logging.properites when it starts and filter out this file
if k != "logging.properties" {
keypath = append(keypath, corev1.KeyToPath{Key: k, Path: k})
}
}
for k := range config.BinaryData {
keypath = append(keypath, corev1.KeyToPath{Key: k, Path: k})
}
return keypath, nil

}
File renamed without changes.
File renamed without changes.
10 changes: 3 additions & 7 deletions test/framework/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

framework "github.com/operator-framework/operator-sdk/pkg/test"
wildflyv1alpha1 "github.com/wildfly/wildfly-operator/pkg/apis/wildfly/v1alpha1"
rbac "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -95,7 +94,7 @@ func wildflyClusterViewTest(t *testing.T, f *framework.Framework, ctx *framework
}

name := "clusterbench-" + unixEpoch()
standaloneConfigXML, err := ioutil.ReadFile("test/e2e/" + applicationTag + "/standalone-clustering-test.xml")
standaloneConfigXML, err := ioutil.ReadFile("test/e2e/" + applicationTag + "/standalone.xml")
if err != nil {
return err
}
Expand Down Expand Up @@ -127,13 +126,10 @@ func wildflyClusterViewTest(t *testing.T, f *framework.Framework, ctx *framework
}

// create config map for the standalone config
CreateStandaloneConfigMap(f, ctx, namespace, "clusterbench-configmap", "standalone-openshift.xml", standaloneConfigXML)
CreateStandaloneConfigMap(f, ctx, namespace, "clusterbench-configmap", "standalone.xml", standaloneConfigXML)
// create wildflyserver custom resource
wildflyServer := MakeBasicWildFlyServer(namespace, name, "quay.io/wildfly-quickstarts/clusterbench-ee7:"+applicationTag, 2)
wildflyServer.Spec.StandaloneConfigMap = &wildflyv1alpha1.StandaloneConfigMapSpec{
Name: "clusterbench-configmap",
Key: "standalone-openshift.xml",
}
wildflyServer.Spec.StandaloneConfigMap = "clusterbench-configmap"

err = CreateAndWaitUntilReady(f, ctx, t, wildflyServer)
if err != nil {
Expand Down

0 comments on commit 2537771

Please sign in to comment.