diff --git a/pkg/resources/constants.go b/pkg/resources/constants.go index c117fe98..4a79991a 100644 --- a/pkg/resources/constants.go +++ b/pkg/resources/constants.go @@ -25,6 +25,8 @@ const ( SecretsDir = "/etc/secrets/" // ConfigMapsDir is the the directory to mount volumes from ConfigMaps ConfigMapsDir = "/etc/configmaps/" + // StatefuleSetTemplateLabelsEnvVarName is the name of the envvar containg label/value map for pods created from the statefulset's template + StatefuleSetTemplateLabelsEnvVarName string = "STATEFULSET_TEMPLATE_LABELS" ) var ( @@ -35,7 +37,7 @@ var ( // JBossHome is read from the env var JBOSS_HOME or, in case of a Bootable JAR, from JBOSS_BOOTABLE_HOME func JBossHome(bootable bool) string { if bootable { - return os.Getenv("JBOSS_BOOTABLE_HOME") + return os.Getenv("JBOSS_BOOTABLE_HOME") } return os.Getenv("JBOSS_HOME") } @@ -43,7 +45,7 @@ func JBossHome(bootable bool) string { // JBossHome is read from the env var JBOSS_HOME or, in case of a Bootable JAR, from JBOSS_BOOTABLE_DATA_DIR func JBossHomeDataDir(bootable bool) string { if bootable { - return os.Getenv("JBOSS_BOOTABLE_DATA_DIR") + return os.Getenv("JBOSS_BOOTABLE_DATA_DIR") } return os.Getenv("JBOSS_HOME") } diff --git a/pkg/resources/statefulsets/statefulset.go b/pkg/resources/statefulsets/statefulset.go index 1c2a0206..14fb75be 100644 --- a/pkg/resources/statefulsets/statefulset.go +++ b/pkg/resources/statefulsets/statefulset.go @@ -1,6 +1,7 @@ package statefulsets import ( + "encoding/json" "os" "path" @@ -48,6 +49,7 @@ func NewStatefulSet(w *wildflyv1alpha1.WildFlyServer, labels map[string]string, labelsForActiveWildflyPod := wildflyutil.CopyMap(labels) labelsForActiveWildflyPod[resources.MarkerOperatedByHeadless] = resources.MarkerServiceActive labelsForActiveWildflyPod[resources.MarkerOperatedByLoadbalancer] = resources.MarkerServiceActive + applyLabels(resources.StatefuleSetTemplateLabelsEnvVarName, labelsForActiveWildflyPod) wildflyImageTypeAnnotation := resources.ImageTypeGeneric if w.Spec.BootableJar { @@ -193,7 +195,7 @@ func NewStatefulSet(w *wildflyv1alpha1.WildFlyServer, labels map[string]string, }) volumeMounts = append(volumeMounts, corev1.VolumeMount{ Name: "standalone-config-volume", - MountPath: path.Join(resources.JBossHome(w.Spec.BootableJar),"standalone/configuration/standalone.xml"), + MountPath: path.Join(resources.JBossHome(w.Spec.BootableJar), "standalone/configuration/standalone.xml"), SubPath: "standalone.xml", }) } @@ -340,7 +342,7 @@ func envArgsForBootableJAR(defaultDataDir string) []corev1.EnvVar { return []corev1.EnvVar{ { Name: "JAVA_ARGS", - Value: "-Djboss.server.data.dir="+path.Join(resources.JBossHomeDataDir(true), defaultDataDir) + " --install-dir=" + resources.JBossHome(true), + Value: "-Djboss.server.data.dir=" + path.Join(resources.JBossHomeDataDir(true), defaultDataDir) + " --install-dir=" + resources.JBossHome(true), }, { Name: "JBOSS_HOME", @@ -348,3 +350,19 @@ func envArgsForBootableJAR(defaultDataDir string) []corev1.EnvVar { }, } } + +func applyLabels(envvar string, labels map[string]string) { + labelsFromEnv := os.Getenv(envvar) + if labelsFromEnv == "" { + return + } + var labelMap map[string]string + if err := json.Unmarshal([]byte(labelsFromEnv), &labelMap); err != nil { + return + } + if len(labelMap) > 0 { + for name, value := range labelMap { + labels[name] = value + } + } +}