Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
thegridman committed May 13, 2023
1 parent fd13dfa commit fb2c649
Show file tree
Hide file tree
Showing 16 changed files with 197 additions and 201 deletions.
30 changes: 15 additions & 15 deletions .github/workflows/compatibility-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,37 +47,37 @@ jobs:
- 3.1.5
include:
- compatibilityVersion: 3.2.11
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.4"
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.3"
compatibilitySelector: control-plane=coherence
k8s: kindest/node:v1.26.0@sha256:691e24bd2417609db7e589e1a479b902d2e209892a10ce375fab60a8407c7352
k8s: kindest/node:v1.26.3@sha256:61b92f38dff6ccc29969e7aa154d34e38b89443af1a2c14e6cfbd2df6419c66f
- compatibilityVersion: 3.2.10
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.4"
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.3"
compatibilitySelector: control-plane=coherence
k8s: kindest/node:v1.26.0@sha256:691e24bd2417609db7e589e1a479b902d2e209892a10ce375fab60a8407c7352
k8s: kindest/node:v1.26.3@sha256:61b92f38dff6ccc29969e7aa154d34e38b89443af1a2c14e6cfbd2df6419c66f
- compatibilityVersion: 3.2.9
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.4"
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.3"
compatibilitySelector: control-plane=coherence
k8s: kindest/node:v1.24.0@sha256:0866296e693efe1fed79d5e6c7af8df71fc73ae45e3679af05342239cdc5bc8e
k8s: kindest/node:v1.24.12@sha256:1e12918b8bc3d4253bc08f640a231bb0d3b2c5a9b28aa3f2ca1aee93e1e8db16
- compatibilityVersion: 3.2.8
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.4"
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.3"
compatibilitySelector: control-plane=coherence
k8s: kindest/node:v1.24.0@sha256:0866296e693efe1fed79d5e6c7af8df71fc73ae45e3679af05342239cdc5bc8e
k8s: kindest/node:v1.24.12@sha256:1e12918b8bc3d4253bc08f640a231bb0d3b2c5a9b28aa3f2ca1aee93e1e8db16
- compatibilityVersion: 3.2.7
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.4"
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.3"
compatibilitySelector: control-plane=coherence
k8s: kindest/node:v1.24.0@sha256:0866296e693efe1fed79d5e6c7af8df71fc73ae45e3679af05342239cdc5bc8e
k8s: kindest/node:v1.24.12@sha256:1e12918b8bc3d4253bc08f640a231bb0d3b2c5a9b28aa3f2ca1aee93e1e8db16
- compatibilityVersion: 3.2.6
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.4"
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.3"
compatibilitySelector: control-plane=coherence
k8s: kindest/node:v1.24.0@sha256:0866296e693efe1fed79d5e6c7af8df71fc73ae45e3679af05342239cdc5bc8e
k8s: kindest/node:v1.24.12@sha256:1e12918b8bc3d4253bc08f640a231bb0d3b2c5a9b28aa3f2ca1aee93e1e8db16
- compatibilityVersion: 3.2.5
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.4"
coherence-image: "ghcr.io/oracle/coherence-ce:22.06.3"
compatibilitySelector: control-plane=coherence
k8s: kindest/node:v1.24.0@sha256:0866296e693efe1fed79d5e6c7af8df71fc73ae45e3679af05342239cdc5bc8e
k8s: kindest/node:v1.24.12@sha256:1e12918b8bc3d4253bc08f640a231bb0d3b2c5a9b28aa3f2ca1aee93e1e8db16
- compatibilityVersion: 3.1.5
coherence-image: "ghcr.io/oracle/coherence-ce:21.12.4"
compatibilitySelector: control-plane=coherence
k8s: kindest/node:v1.21.1@sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6
k8s: kindest/node:v1.21.14@sha256:27ef72ea623ee879a25fe6f9982690a3e370c68286f4356bf643467c552a3888

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ COHERENCE_VERSION ?= 21.12.5
# The default Coherence image the Operator will run if no image is specified
COHERENCE_IMAGE_REGISTRY ?= ghcr.io/oracle
COHERENCE_IMAGE_NAME ?= coherence-ce
COHERENCE_IMAGE_TAG ?= 22.06.4
COHERENCE_IMAGE_TAG ?= 22.06.3
COHERENCE_IMAGE ?= $(COHERENCE_IMAGE_REGISTRY)/$(COHERENCE_IMAGE_NAME):$(COHERENCE_IMAGE_TAG)
# The Java version that tests will be compiled to.
# This should match the version required by the COHERENCE_IMAGE version
Expand Down
12 changes: 11 additions & 1 deletion api/v1/coherence_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ func (in *CoherenceSpec) UpdateStatefulSet(deployment *Coherence, sts *appsv1.St
}

// UpdatePodTemplateSpec applies Coherence settings to the PodTemplateSpec.
func (in *CoherenceSpec) UpdatePodTemplateSpec(podTemplate *corev1.PodTemplateSpec) {
func (in *CoherenceSpec) UpdatePodTemplateSpec(podTemplate *corev1.PodTemplateSpec, deployment CoherenceResource) {
// Get the Coherence container
c := EnsureContainerInPod(ContainerNameCoherence, podTemplate)
defer ReplaceContainerInPod(podTemplate, c)
Expand All @@ -455,6 +455,11 @@ func (in *CoherenceSpec) UpdatePodTemplateSpec(podTemplate *corev1.PodTemplateSp
// we're nil so disable management and metrics/
c.Env = append(c.Env, corev1.EnvVar{Name: EnvVarCohMgmtPrefix + EnvVarCohEnabledSuffix, Value: "false"},
corev1.EnvVar{Name: EnvVarCohMetricsPrefix + EnvVarCohEnabledSuffix, Value: "false"})

// StorageEnabled is obviously not set, so if this is a CoherenceJob default to false
if deployment.GetType() == CoherenceTypeJob {
c.Env = append(c.Env, corev1.EnvVar{Name: EnvVarCohStorage, Value: "false"})
}
return
}

Expand Down Expand Up @@ -482,6 +487,11 @@ func (in *CoherenceSpec) UpdatePodTemplateSpec(podTemplate *corev1.PodTemplateSp

if in.StorageEnabled != nil {
c.Env = append(c.Env, corev1.EnvVar{Name: EnvVarCohStorage, Value: BoolPtrToString(in.StorageEnabled)})
} else {
// StorageEnabled is nil, so if this is a CoherenceJob default to false
if deployment.GetType() == CoherenceTypeJob {
c.Env = append(c.Env, corev1.EnvVar{Name: EnvVarCohStorage, Value: "false"})
}
}

if in.SkipVersionCheck != nil {
Expand Down
10 changes: 5 additions & 5 deletions api/v1/coherencejobresource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ func (in *CoherenceJob) GetCoherenceClusterName() string {
if in == nil {
return ""
}

if in.Spec.Cluster == nil {
return in.Name
}
return *in.Spec.Cluster
return in.Spec.Cluster
}

func (in *CoherenceJob) GetAPIVersion() string {
Expand Down Expand Up @@ -272,6 +268,10 @@ func (in *CoherenceJob) IsBeforeVersion(version string) bool {
type CoherenceJobResourceSpec struct {
CoherenceResourceSpec `json:",inline"`

// The name of the Coherence cluster that this CoherenceJob resource belongs to.
// A CoherenceJob will typically be part of an existing cluster, so this field is required.
Cluster string `json:"cluster,omitempty"`

// Specifies the desired number of successfully finished pods the
// job should be run with. Setting to nil means that the success of any
// pod signals the success of all pods, and allows parallelism to have any positive
Expand Down
6 changes: 6 additions & 0 deletions api/v1/coherenceresource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,12 @@ func (in *Coherence) IsBeforeVersion(version string) bool {
// +k8s:openapi-gen=true
type CoherenceStatefulSetResourceSpec struct {
CoherenceResourceSpec `json:",inline"`
// The optional name of the Coherence cluster that this Coherence resource belongs to.
// If this value is set the Pods controlled by this Coherence resource will form a cluster
// with other Pods controlled by Coherence resources with the same cluster name.
// If not set the Coherence resource's name will be used as the cluster name.
// +optional
Cluster *string `json:"cluster,omitempty"`
// StatefulSetAnnotations are free-form yaml that will be added to the Coherence cluster
// `StatefulSet` as annotations.
// Any annotations should be placed BELOW this "annotations:" key, for example:
Expand Down
8 changes: 1 addition & 7 deletions api/v1/coherenceresourcespec_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ type CoherenceResourceSpec struct {
// +kubebuilder:validation:Minimum:=0
// +optional
Replicas *int32 `json:"replicas,omitempty"`
// The optional name of the Coherence cluster that this Coherence resource belongs to.
// If this value is set the Pods controlled by this Coherence resource will form a cluster
// with other Pods controlled by Coherence resources with the same cluster name.
// If not set the Coherence resource's name will be used as the cluster name.
// +optional
Cluster *string `json:"cluster,omitempty"`
// The name of the role that this deployment represents in a Coherence cluster.
// This value will be used to set the Coherence role property for all members of this role
// +optional
Expand Down Expand Up @@ -651,7 +645,7 @@ func (in *CoherenceResourceSpec) CreatePodTemplateSpec(deployment CoherenceResou
// Add any JVM settings
in.JVM.UpdatePodTemplate(&podTemplate)
// Add any Coherence settings
in.Coherence.UpdatePodTemplateSpec(&podTemplate)
in.Coherence.UpdatePodTemplateSpec(&podTemplate, deployment)

// Add any additional init-containers and any additional containers
in.ProcessSideCars(deployment, &podTemplate)
Expand Down
177 changes: 93 additions & 84 deletions api/v1/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,98 @@ func createMinimalExpectedPodSpec(deployment coh.CoherenceResource) corev1.PodTe
EmptyDir: &corev1.EmptyDirVolumeSource{},
}

envVars := []corev1.EnvVar{
{
Name: "COH_CLUSTER_NAME",
Value: deployment.GetName(),
},
{
Name: "COH_HEALTH_PORT",
Value: fmt.Sprintf("%d", spec.GetHealthPort()),
},
{
Name: "COH_MACHINE_NAME",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "spec.nodeName",
},
},
},
{
Name: "COH_MEMBER_NAME",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "metadata.name",
},
},
},
{
Name: "COH_METRICS_ENABLED",
Value: "false",
},
{
Name: "COH_MGMT_ENABLED",
Value: "false",
},
{
Name: "COH_POD_UID",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "metadata.uid",
},
},
},
{
Name: "COH_RACK_INFO_LOCATION",
Value: "http://$(OPERATOR_HOST)/rack/$(COH_MACHINE_NAME)",
},
{
Name: "COH_ROLE",
Value: deployment.GetRoleName(),
},
{
Name: "COH_SITE_INFO_LOCATION",
Value: "http://$(OPERATOR_HOST)/site/$(COH_MACHINE_NAME)",
},
{
Name: "COH_UTIL_DIR",
Value: coh.VolumeMountPathUtils,
},
{
Name: "COH_WKA",
Value: deployment.GetWKA(),
},
{
Name: "JVM_GC_LOGGING",
Value: "false",
},
{
Name: "JVM_USE_CONTAINER_LIMITS",
Value: "true",
},
{
Name: "OPERATOR_HOST",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{Name: coh.OperatorConfigName},
Key: coh.OperatorConfigKeyHost,
Optional: pointer.Bool(true),
},
},
},
{
Name: "OPERATOR_REQUEST_TIMEOUT",
Value: "120",
},
}

if deployment.GetType() == coh.CoherenceTypeJob {
envVars = append(envVars, corev1.EnvVar{
Name: "COH_STORAGE_ENABLED",
Value: "false",
})
}

// The Coherence Container
cohContainer := corev1.Container{
Name: coh.ContainerNameCoherence,
Expand Down Expand Up @@ -298,90 +390,7 @@ func createMinimalExpectedPodSpec(deployment coh.CoherenceResource) corev1.PodTe
ReadOnly: false,
},
},
Env: []corev1.EnvVar{
{
Name: "COH_CLUSTER_NAME",
Value: deployment.GetName(),
},
{
Name: "COH_HEALTH_PORT",
Value: fmt.Sprintf("%d", spec.GetHealthPort()),
},
{
Name: "COH_MACHINE_NAME",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "spec.nodeName",
},
},
},
{
Name: "COH_MEMBER_NAME",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "metadata.name",
},
},
},
{
Name: "COH_METRICS_ENABLED",
Value: "false",
},
{
Name: "COH_MGMT_ENABLED",
Value: "false",
},
{
Name: "COH_POD_UID",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "metadata.uid",
},
},
},
{
Name: "COH_RACK_INFO_LOCATION",
Value: "http://$(OPERATOR_HOST)/rack/$(COH_MACHINE_NAME)",
},
{
Name: "COH_ROLE",
Value: deployment.GetRoleName(),
},
{
Name: "COH_SITE_INFO_LOCATION",
Value: "http://$(OPERATOR_HOST)/site/$(COH_MACHINE_NAME)",
},
{
Name: "COH_UTIL_DIR",
Value: coh.VolumeMountPathUtils,
},
{
Name: "COH_WKA",
Value: deployment.GetWKA(),
},
{
Name: "JVM_GC_LOGGING",
Value: "false",
},
{
Name: "JVM_USE_CONTAINER_LIMITS",
Value: "true",
},
{
Name: "OPERATOR_HOST",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{Name: coh.OperatorConfigName},
Key: coh.OperatorConfigKeyHost,
Optional: pointer.Bool(true),
},
},
},
{
Name: "OPERATOR_REQUEST_TIMEOUT",
Value: "120",
},
},
Env: envVars,
}

if cohImage := spec.GetCoherenceImage(); cohImage != nil {
Expand Down
5 changes: 1 addition & 4 deletions api/v1/create_job_wka_services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/pointer"
"testing"
)

Expand Down Expand Up @@ -184,9 +183,7 @@ func TestCreateWKAServiceForJobWithClusterName(t *testing.T) {
Name: "test",
},
Spec: coh.CoherenceJobResourceSpec{
CoherenceResourceSpec: coh.CoherenceResourceSpec{
Cluster: pointer.String("test-cluster"),
},
Cluster: "test-cluster",
},
}

Expand Down
4 changes: 1 addition & 3 deletions api/v1/create_wka_services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,7 @@ func TestCreateWKAServiceForDeploymentWithClusterName(t *testing.T) {
Name: "test",
},
Spec: coh.CoherenceStatefulSetResourceSpec{
CoherenceResourceSpec: coh.CoherenceResourceSpec{
Cluster: pointer.String("test-cluster"),
},
Cluster: pointer.String("test-cluster"),
},
}

Expand Down
10 changes: 5 additions & 5 deletions api/v1/zz_generated.deepcopy.go

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

Loading

0 comments on commit fb2c649

Please sign in to comment.