Skip to content

Commit 994feb4

Browse files
authored
Add support for using envFrom to load environment variables into Coherence Pods (#626)
1 parent abbbebb commit 994feb4

16 files changed

+259
-36
lines changed

.github/workflows/coherence-matrix.yaml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ jobs:
3535
matrixName:
3636
- "15.1.1-0-SNAPSHOT"
3737
- "15.1.1-0-SNAPSHOT-Graal"
38-
- "23.03"
39-
- "23.03-Graal"
38+
- "23.09"
39+
- "23.09-Graal"
4040
- "22.06"
4141
- "14.1.1-2206-SNAPSHOT"
4242
- "14.1.1-0-SNAPSHOT"
@@ -57,27 +57,27 @@ jobs:
5757
javaVersion: 17
5858
baseImage: "gcr.io/distroless/java17-debian11"
5959

60-
- matrixName: "23.03"
61-
coherenceVersion: "23.03.1"
62-
coherenceImage: "ghcr.io/oracle/coherence-ce:23.03.1"
60+
- matrixName: "23.09"
61+
coherenceVersion: "23.09"
62+
coherenceImage: "ghcr.io/oracle/coherence-ce:23.09"
6363
javaVersion: 17
6464
baseImage: "gcr.io/distroless/java17-debian11"
6565

66-
- matrixName: "23.03-Graal"
67-
coherenceVersion: "23.03.1"
68-
coherenceImage: "ghcr.io/oracle/coherence-ce:23.03.1-graal"
66+
- matrixName: "23.09-Graal"
67+
coherenceVersion: "23.09"
68+
coherenceImage: "ghcr.io/oracle/coherence-ce:23.09-graal"
6969
javaVersion: 17
7070
baseImage: "gcr.io/distroless/java17-debian11"
7171

7272
- matrixName: "22.06"
73-
coherenceVersion: "22.06.5"
74-
coherenceImage: "ghcr.io/oracle/coherence-ce:22.06.5"
73+
coherenceVersion: "22.06.6"
74+
coherenceImage: "ghcr.io/oracle/coherence-ce:22.06.6"
7575
javaVersion: 11
7676
baseImage: "gcr.io/distroless/java11-debian11"
7777

7878
- matrixName: "14.1.1-2206-SNAPSHOT"
79-
coherenceVersion: "14.1.1-2206-6-SNAPSHOT"
80-
coherenceImage: "iad.ocir.io/odx-stateservice/test/coherence:14.1.1-2206-6-SNAPSHOT"
79+
coherenceVersion: "14.1.1-2206-7-SNAPSHOT"
80+
coherenceImage: "iad.ocir.io/odx-stateservice/test/coherence:14.1.1-2206-7-SNAPSHOT"
8181
javaVersion: 11
8282
baseImage: "gcr.io/distroless/java11-debian11"
8383

@@ -88,9 +88,9 @@ jobs:
8888
baseImage: "gcr.io/distroless/java11-debian11"
8989

9090
- matrixName: "14.1.1-0"
91-
coherenceVersion: "14.1.1-0-14"
91+
coherenceVersion: "14.1.1-0-15"
9292
javaVersion: 8
93-
coherenceImage: "ghcr.io/oracle/coherence-ce:14.1.1-0-14"
93+
coherenceImage: "ghcr.io/oracle/coherence-ce:14.1.1-0-15"
9494
baseImage: "gcr.io/distroless/java11-debian11"
9595

9696
- matrixName: "14.1.1.0.0"
@@ -106,8 +106,8 @@ jobs:
106106
baseImage: "gcr.io/distroless/java11-debian11"
107107

108108
- matrixName: "12.2.1-4-SNAPSHOT"
109-
coherenceVersion: "12.2.1-4-19-SNAPSHOT"
110-
coherenceImage: "iad.ocir.io/odx-stateservice/test/coherence:12.2.1-4-19-SNAPSHOT"
109+
coherenceVersion: "12.2.1-4-20-SNAPSHOT"
110+
coherenceImage: "iad.ocir.io/odx-stateservice/test/coherence:12.2.1-4-20-SNAPSHOT"
111111
javaVersion: 8
112112
baseImage: "gcr.io/distroless/java11-debian11"
113113

.github/workflows/compatibility-tests.yaml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,40 @@ jobs:
3737
fail-fast: false
3838
matrix:
3939
compatibilityVersion:
40+
- 3.3.0
4041
- 3.2.11
4142
- 3.2.10
4243
- 3.2.9
4344
- 3.2.7
4445
- 3.2.6
4546
- 3.2.5
4647
include:
48+
- compatibilityVersion: 3.3.0
49+
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.6"
50+
compatibilitySelector: control-plane=coherence
51+
k8s: kindest/node:v1.27.3@sha256:3966ac761ae0136263ffdb6cfd4db23ef8a83cba8a463690e98317add2c9ba72
4752
- compatibilityVersion: 3.2.11
48-
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.3"
53+
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.6"
4954
compatibilitySelector: control-plane=coherence
50-
k8s: kindest/node:v1.26.3@sha256:61b92f38dff6ccc29969e7aa154d34e38b89443af1a2c14e6cfbd2df6419c66f
55+
k8s: kindest/node:v1.26.6@sha256:6e2d8b28a5b601defe327b98bd1c2d1930b49e5d8c512e1895099e4504007adb
5156
- compatibilityVersion: 3.2.10
52-
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.3"
57+
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.6"
5358
compatibilitySelector: control-plane=coherence
54-
k8s: kindest/node:v1.26.3@sha256:61b92f38dff6ccc29969e7aa154d34e38b89443af1a2c14e6cfbd2df6419c66f
59+
k8s: kindest/node:v1.26.6@sha256:6e2d8b28a5b601defe327b98bd1c2d1930b49e5d8c512e1895099e4504007adb
5560
- compatibilityVersion: 3.2.9
56-
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.3"
61+
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.6"
5762
compatibilitySelector: control-plane=coherence
5863
k8s: kindest/node:v1.24.12@sha256:1e12918b8bc3d4253bc08f640a231bb0d3b2c5a9b28aa3f2ca1aee93e1e8db16
5964
- compatibilityVersion: 3.2.7
60-
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.3"
65+
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.6"
6166
compatibilitySelector: control-plane=coherence
6267
k8s: kindest/node:v1.24.12@sha256:1e12918b8bc3d4253bc08f640a231bb0d3b2c5a9b28aa3f2ca1aee93e1e8db16
6368
- compatibilityVersion: 3.2.6
64-
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.3"
69+
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.6"
6570
compatibilitySelector: control-plane=coherence
6671
k8s: kindest/node:v1.24.12@sha256:1e12918b8bc3d4253bc08f640a231bb0d3b2c5a9b28aa3f2ca1aee93e1e8db16
6772
- compatibilityVersion: 3.2.5
68-
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.3"
73+
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.6"
6974
compatibilitySelector: control-plane=coherence
7075
k8s: kindest/node:v1.24.12@sha256:1e12918b8bc3d4253bc08f640a231bb0d3b2c5a9b28aa3f2ca1aee93e1e8db16
7176

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ VERSION ?= 3.3.1
1919
MVN_VERSION ?= $(VERSION)
2020

2121
# The version number to be replaced by this release
22-
PREV_VERSION ?= 3.2.11
22+
PREV_VERSION ?= 3.3.0
2323

2424
# The operator version to use to run certification tests against
2525
CERTIFICATION_VERSION ?= $(VERSION)
2626

2727
# The previous Operator version used to run the compatibility tests.
28-
COMPATIBLE_VERSION ?= 3.2.11
28+
COMPATIBLE_VERSION ?= 3.3.0
2929
# The selector to use to find Operator Pods of the COMPATIBLE_VERSION (do not put in double quotes!!)
3030
COMPATIBLE_SELECTOR = control-plane=coherence
3131

@@ -42,7 +42,7 @@ COHERENCE_VERSION ?= 21.12.5
4242
# The default Coherence image the Operator will run if no image is specified
4343
COHERENCE_IMAGE_REGISTRY ?= ghcr.io/oracle
4444
COHERENCE_IMAGE_NAME ?= coherence-ce
45-
COHERENCE_IMAGE_TAG ?= 22.06.5
45+
COHERENCE_IMAGE_TAG ?= 22.06.6
4646
COHERENCE_IMAGE ?= $(COHERENCE_IMAGE_REGISTRY)/$(COHERENCE_IMAGE_NAME):$(COHERENCE_IMAGE_TAG)
4747
# The Java version that tests will be compiled to.
4848
# This should match the version required by the COHERENCE_IMAGE version

api/v1/coherencejobresource_types.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ func (in *CoherenceJob) IsForceExit() bool {
6262
return in.Spec.ForceExit != nil && *in.Spec.ForceExit
6363
}
6464

65+
func (in *CoherenceJob) GetEnvVarFrom() []corev1.EnvFromSource {
66+
if in == nil {
67+
return make([]corev1.EnvFromSource, 0)
68+
}
69+
return in.Spec.EnvFrom
70+
}
71+
6572
// GetSpec returns this resource's CoherenceResourceSpec
6673
func (in *CoherenceJob) GetSpec() *CoherenceResourceSpec {
6774
return &in.Spec.CoherenceResourceSpec
@@ -384,6 +391,14 @@ type CoherenceJobResourceSpec struct {
384391
// ForceExit is a flag to indicate whether the Operator should call System.exit to forcefully exit the process
385392
// when the configured main class completes execution.
386393
ForceExit *bool `json:"forceExit,omitempty"`
394+
// List of sources to populate environment variables in the container.
395+
// The keys defined within a source must be a C_IDENTIFIER. All invalid keys
396+
// will be reported as an event when the container is starting. When a key exists in multiple
397+
// sources, the value associated with the last source will take precedence.
398+
// Values defined by an Env with a duplicate key will take precedence.
399+
// Cannot be updated.
400+
// +optional
401+
EnvFrom []corev1.EnvFromSource `json:"envFrom,omitempty"`
387402
}
388403

389404
// GetRestartPolicy returns the name of the application image to use

api/v1/coherenceresource.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package v1
88

99
import (
10+
corev1 "k8s.io/api/core/v1"
1011
"k8s.io/apimachinery/pkg/runtime"
1112
"k8s.io/apimachinery/pkg/types"
1213
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -87,4 +88,6 @@ type CoherenceResource interface {
8788
GetAPIVersion() string
8889
// IsForceExit is a flag to determine whether the Operator calls System.exit when the main class finishes.
8990
IsForceExit() bool
91+
// GetEnvVarFrom returns the array of EnvVarSource configurations
92+
GetEnvVarFrom() []corev1.EnvFromSource
9093
}

api/v1/coherenceresource_types.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ func (in *Coherence) IsForceExit() bool {
179179
return false
180180
}
181181

182+
func (in *Coherence) GetEnvVarFrom() []corev1.EnvFromSource {
183+
if in == nil {
184+
return make([]corev1.EnvFromSource, 0)
185+
}
186+
return in.Spec.EnvFrom
187+
}
188+
182189
// FindFullyQualifiedPortServiceNames returns a map of the exposed ports of this resource mapped to their Service's
183190
// fully qualified domain name.
184191
func (in *Coherence) FindFullyQualifiedPortServiceNames() map[string]string {
@@ -416,6 +423,14 @@ type CoherenceStatefulSetResourceSpec struct {
416423
// Actions to execute once all the Pods are ready after an initial deployment
417424
// +optional
418425
Actions []Action `json:"actions,omitempty"`
426+
// List of sources to populate environment variables in the container.
427+
// The keys defined within a source must be a C_IDENTIFIER. All invalid keys
428+
// will be reported as an event when the container is starting. When a key exists in multiple
429+
// sources, the value associated with the last source will take precedence.
430+
// Values defined by an Env with a duplicate key will take precedence.
431+
// Cannot be updated.
432+
// +optional
433+
EnvFrom []corev1.EnvFromSource `json:"envFrom,omitempty"`
419434
}
420435

421436
// CreateStatefulSetResource creates the deployment's StatefulSet resource.

api/v1/coherenceresourcespec_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,8 @@ func (in *CoherenceResourceSpec) CreateCoherenceContainer(deployment CoherenceRe
725725
VolumeMounts: vm,
726726
}
727727

728+
c.EnvFrom = deployment.GetEnvVarFrom()
729+
728730
if in.ImagePullPolicy != nil {
729731
c.ImagePullPolicy = *in.ImagePullPolicy
730732
}

api/v1/common_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,37 @@ func addEnvVarsToContainer(c *corev1.Container, envVars ...corev1.EnvVar) {
600600
}
601601
}
602602

603+
func addEnvVarsFrom(sts *appsv1.StatefulSet, containerName string, envVars ...corev1.EnvFromSource) {
604+
if sts != nil {
605+
addEnvVarsFromToPodSpec(&sts.Spec.Template, containerName, envVars...)
606+
}
607+
}
608+
609+
func addEnvVarsFromToJob(job *batchv1.Job, containerName string, envVars ...corev1.EnvFromSource) {
610+
if job != nil {
611+
addEnvVarsFromToPodSpec(&job.Spec.Template, containerName, envVars...)
612+
}
613+
}
614+
615+
func addEnvVarsFromToPodSpec(template *corev1.PodTemplateSpec, containerName string, envVars ...corev1.EnvFromSource) {
616+
for i, c := range template.Spec.InitContainers {
617+
if c.Name == containerName {
618+
addEnvVarsFromToContainer(&c, envVars...)
619+
template.Spec.InitContainers[i] = c
620+
}
621+
}
622+
for i, c := range template.Spec.Containers {
623+
if c.Name == containerName {
624+
addEnvVarsFromToContainer(&c, envVars...)
625+
template.Spec.Containers[i] = c
626+
}
627+
}
628+
}
629+
630+
func addEnvVarsFromToContainer(c *corev1.Container, envVars ...corev1.EnvFromSource) {
631+
c.EnvFrom = append(c.EnvFrom, envVars...)
632+
}
633+
603634
func addPorts(sts *appsv1.StatefulSet, containerName string, ports ...corev1.ContainerPort) {
604635
if sts != nil {
605636
addPortsToPodSpec(&sts.Spec.Template, containerName, ports...)

api/v1/create_job_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package v1_test
88

99
import (
1010
coh "github.com/oracle/coherence-operator/api/v1"
11+
corev1 "k8s.io/api/core/v1"
1112
"k8s.io/utils/pointer"
1213
"testing"
1314
)
@@ -103,3 +104,35 @@ func TestCreateJobWithReplicasAndSyncedCompletionsOverride(t *testing.T) {
103104
// assert that the Job is as expected
104105
assertJobCreation(t, deployment, expected)
105106
}
107+
108+
func TestCreateJobWithEnvVarsFrom(t *testing.T) {
109+
cm := corev1.ConfigMapEnvSource{
110+
LocalObjectReference: corev1.LocalObjectReference{
111+
Name: "test-vars",
112+
},
113+
Optional: pointer.Bool(true),
114+
}
115+
116+
var from []corev1.EnvFromSource
117+
from = append(from, corev1.EnvFromSource{
118+
Prefix: "foo",
119+
ConfigMapRef: &cm,
120+
})
121+
122+
spec := coh.CoherenceJobResourceSpec{
123+
CoherenceResourceSpec: coh.CoherenceResourceSpec{
124+
Env: []corev1.EnvVar{},
125+
},
126+
EnvFrom: from,
127+
}
128+
129+
// Create the test deployment
130+
deployment := createTestCoherenceJobDeployment(spec)
131+
// Create expected StatefulSet
132+
expected := createMinimalExpectedJob(deployment)
133+
134+
addEnvVarsFromToJob(expected, coh.ContainerNameCoherence, from...)
135+
136+
// assert that the StatefulSet is as expected
137+
assertJobCreation(t, deployment, expected)
138+
}

api/v1/create_statefulset_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,38 @@ func TestCreateStatefulSetWithEmptyEnvVars(t *testing.T) {
128128
assertStatefulSetCreation(t, deployment, stsExpected)
129129
}
130130

131+
func TestCreateStatefulSetWithEnvVarsFrom(t *testing.T) {
132+
cm := corev1.ConfigMapEnvSource{
133+
LocalObjectReference: corev1.LocalObjectReference{
134+
Name: "test-vars",
135+
},
136+
Optional: pointer.Bool(true),
137+
}
138+
139+
var from []corev1.EnvFromSource
140+
from = append(from, corev1.EnvFromSource{
141+
Prefix: "foo",
142+
ConfigMapRef: &cm,
143+
})
144+
145+
spec := coh.CoherenceStatefulSetResourceSpec{
146+
CoherenceResourceSpec: coh.CoherenceResourceSpec{
147+
Env: []corev1.EnvVar{},
148+
},
149+
EnvFrom: from,
150+
}
151+
152+
// Create the test deployment
153+
deployment := createTestCoherenceDeployment(spec)
154+
// Create expected StatefulSet
155+
stsExpected := createMinimalExpectedStatefulSet(deployment)
156+
157+
addEnvVarsFrom(stsExpected, coh.ContainerNameCoherence, from...)
158+
159+
// assert that the StatefulSet is as expected
160+
assertStatefulSetCreation(t, deployment, stsExpected)
161+
}
162+
131163
func TestCreateStatefulSetWithHealthPort(t *testing.T) {
132164
// create a spec with a custom health port
133165
spec := coh.CoherenceResourceSpec{

0 commit comments

Comments
 (0)