Skip to content

Commit

Permalink
Fix broken hash
Browse files Browse the repository at this point in the history
  • Loading branch information
thegridman committed Oct 17, 2023
1 parent d5d7dda commit 4267d83
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 29 deletions.
15 changes: 15 additions & 0 deletions api/v1/coherencejobresource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ func (in *CoherenceJob) IsForceExit() bool {
return in.Spec.ForceExit != nil && *in.Spec.ForceExit
}

func (in *CoherenceJob) GetEnvVarFrom() []corev1.EnvFromSource {
if in == nil {
return make([]corev1.EnvFromSource, 0)
}
return in.Spec.EnvFrom
}

// GetSpec returns this resource's CoherenceResourceSpec
func (in *CoherenceJob) GetSpec() *CoherenceResourceSpec {
return &in.Spec.CoherenceResourceSpec
Expand Down Expand Up @@ -384,6 +391,14 @@ type CoherenceJobResourceSpec struct {
// ForceExit is a flag to indicate whether the Operator should call System.exit to forcefully exit the process
// when the configured main class completes execution.
ForceExit *bool `json:"forceExit,omitempty"`
// List of sources to populate environment variables in the container.
// The keys defined within a source must be a C_IDENTIFIER. All invalid keys
// will be reported as an event when the container is starting. When a key exists in multiple
// sources, the value associated with the last source will take precedence.
// Values defined by an Env with a duplicate key will take precedence.
// Cannot be updated.
// +optional
EnvFrom []corev1.EnvFromSource `json:"envFrom,omitempty"`
}

// GetRestartPolicy returns the name of the application image to use
Expand Down
3 changes: 3 additions & 0 deletions api/v1/coherenceresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package v1

import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -87,4 +88,6 @@ type CoherenceResource interface {
GetAPIVersion() string
// IsForceExit is a flag to determine whether the Operator calls System.exit when the main class finishes.
IsForceExit() bool
// GetEnvVarFrom returns the array of EnvVarSource configurations
GetEnvVarFrom() []corev1.EnvFromSource
}
15 changes: 15 additions & 0 deletions api/v1/coherenceresource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ func (in *Coherence) IsForceExit() bool {
return false
}

func (in *Coherence) GetEnvVarFrom() []corev1.EnvFromSource {
if in == nil {
return make([]corev1.EnvFromSource, 0)
}
return in.Spec.EnvFrom
}

// FindFullyQualifiedPortServiceNames returns a map of the exposed ports of this resource mapped to their Service's
// fully qualified domain name.
func (in *Coherence) FindFullyQualifiedPortServiceNames() map[string]string {
Expand Down Expand Up @@ -416,6 +423,14 @@ type CoherenceStatefulSetResourceSpec struct {
// Actions to execute once all the Pods are ready after an initial deployment
// +optional
Actions []Action `json:"actions,omitempty"`
// List of sources to populate environment variables in the container.
// The keys defined within a source must be a C_IDENTIFIER. All invalid keys
// will be reported as an event when the container is starting. When a key exists in multiple
// sources, the value associated with the last source will take precedence.
// Values defined by an Env with a duplicate key will take precedence.
// Cannot be updated.
// +optional
EnvFrom []corev1.EnvFromSource `json:"envFrom,omitempty"`
}

// CreateStatefulSetResource creates the deployment's StatefulSet resource.
Expand Down
12 changes: 1 addition & 11 deletions api/v1/coherenceresourcespec_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,6 @@ type CoherenceResourceSpec struct {
// +listMapKey=name
// +optional
Env []corev1.EnvVar `json:"env,omitempty"`
// List of sources to populate environment variables in the container.
// The keys defined within a source must be a C_IDENTIFIER. All invalid keys
// will be reported as an event when the container is starting. When a key exists in multiple
// sources, the value associated with the last source will take precedence.
// Values defined by an Env with a duplicate key will take precedence.
// Cannot be updated.
// +optional
EnvFrom *[]corev1.EnvFromSource `json:"envFrom,omitempty"`
// The extra labels to add to the all the Pods in this deployment.
// Labels here will add to or override those defined for the cluster.
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
Expand Down Expand Up @@ -733,9 +725,7 @@ func (in *CoherenceResourceSpec) CreateCoherenceContainer(deployment CoherenceRe
VolumeMounts: vm,
}

if in.EnvFrom != nil {
c.EnvFrom = *in.EnvFrom
}
c.EnvFrom = deployment.GetEnvVarFrom()

if in.ImagePullPolicy != nil {
c.ImagePullPolicy = *in.ImagePullPolicy
Expand Down
4 changes: 2 additions & 2 deletions api/v1/create_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ func TestCreateJobWithEnvVarsFrom(t *testing.T) {

spec := coh.CoherenceJobResourceSpec{
CoherenceResourceSpec: coh.CoherenceResourceSpec{
Env: []corev1.EnvVar{},
EnvFrom: &from,
Env: []corev1.EnvVar{},
},
EnvFrom: from,
}

// Create the test deployment
Expand Down
10 changes: 6 additions & 4 deletions api/v1/create_statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,15 @@ func TestCreateStatefulSetWithEnvVarsFrom(t *testing.T) {
ConfigMapRef: &cm,
})

spec := coh.CoherenceResourceSpec{
Env: []corev1.EnvVar{},
EnvFrom: &from,
spec := coh.CoherenceStatefulSetResourceSpec{
CoherenceResourceSpec: coh.CoherenceResourceSpec{
Env: []corev1.EnvVar{},
},
EnvFrom: from,
}

// Create the test deployment
deployment := createTestDeployment(spec)
deployment := createTestCoherenceDeployment(spec)
// Create expected StatefulSet
stsExpected := createMinimalExpectedStatefulSet(deployment)

Expand Down
26 changes: 26 additions & 0 deletions api/v1/hasher_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package v1_test

Check failure on line 1 in api/v1/hasher_test.go

View workflow job for this annotation

GitHub Actions / build

No copyright

import (
. "github.com/onsi/gomega"
coh "github.com/oracle/coherence-operator/api/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"testing"
)

func TestHash(t *testing.T) {
g := NewGomegaWithT(t)

spec := coh.CoherenceStatefulSetResourceSpec{}

deployment := &coh.Coherence{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test-ns",
Name: "test",
},
Spec: spec,
}

coh.EnsureHashLabel(deployment)

g.Expect(deployment.GetLabels()["coherence-hash"]).To(Equal("5cb9fd9f96"))
}
25 changes: 14 additions & 11 deletions api/v1/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion docs/about/04_coherence_spec.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ m| jvm | The JVM specific options m| &#42;<<JVMSpec,JVMSpec>> | false
m| ports | Ports specifies additional port mappings for the Pod and additional Services for those ports. m| []<<NamedPortSpec,NamedPortSpec>> | false
m| startQuorum | StartQuorum controls the start-up order of this Coherence resource in relation to other Coherence resources. m| []<<StartQuorum,StartQuorum>> | false
m| env | Env is additional environment variable mappings that will be passed to the Coherence container in the Pod. To specify extra variables add them as name value pairs the same as they would be added to a Pod containers spec. m| []https://{k8s-doc-link}/#envvar-v1-core[corev1.EnvVar] | false
m| envFrom | List of sources to populate environment variables in the container. The keys defined within a source must be a C_IDENTIFIER. All invalid keys will be reported as an event when the container is starting. When a key exists in multiple sources, the value associated with the last source will take precedence. Values defined by an Env with a duplicate key will take precedence. Cannot be updated. m| &#42;[]https://{k8s-doc-link}/#envfromsource-v1-core[corev1.EnvFromSource] | false
m| labels | The extra labels to add to the all the Pods in this deployment. Labels here will add to or override those defined for the cluster. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ m| map[string]string | false
m| annotations | Annotations are free-form yaml that will be added to the Coherence cluster member Pods as annotations. Any annotations should be placed BELOW this "annotations:" key, for example: +
+
Expand Down Expand Up @@ -905,6 +904,7 @@ m| suspendServiceTimeout | SuspendServiceTimeout sets the number of seconds to w
m| haBeforeUpdate | Whether to perform a StatusHA test on the cluster before performing an update or deletion. This field can be set to "false" to force through an update even when a Coherence deployment is in an unstable state. The default is true, to always check for StatusHA before updating a Coherence deployment. m| &#42;bool | false
m| allowUnsafeDelete | AllowUnsafeDelete controls whether the Operator will add a finalizer to the Coherence resource so that it can intercept deletion of the resource and initiate a controlled shutdown of the Coherence cluster. The default value is `false`. The primary use for setting this flag to `true` is in CI/CD environments so that cleanup jobs can delete a whole namespace without requiring the Operator to have removed finalizers from any Coherence resources deployed into that namespace. It is not recommended to set this flag to `true` in a production environment, especially when using Coherence persistence features. m| &#42;bool | false
m| actions | Actions to execute once all the Pods are ready after an initial deployment m| []<<Action,Action>> | false
m| envFrom | List of sources to populate environment variables in the container. The keys defined within a source must be a C_IDENTIFIER. All invalid keys will be reported as an event when the container is starting. When a key exists in multiple sources, the value associated with the last source will take precedence. Values defined by an Env with a duplicate key will take precedence. Cannot be updated. m| []https://{k8s-doc-link}/#envfromsource-v1-core[corev1.EnvFromSource] | false
|===
<<Table of Contents,Back to TOC>>

0 comments on commit 4267d83

Please sign in to comment.