Skip to content

Support setting the Lifecycle field on the Coherence container #692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ docs/about/04_coherence_spec.adoc: $(API_GO_FILES) utils/docgen/main.go
api/v1/coherenceresourcespec_types.go \
api/v1/coherence_types.go \
api/v1/coherenceresource_types.go \
api/v1/coherencejobresource_types.go \
> docs/about/04_coherence_spec.adoc

# ----------------------------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion api/v1/coherencejobresource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

// ----- Coherence type ------------------------------------------------------------------

// CoherenceJob is the top level schema for the Coherence API and custom resource definition (CRD)
// CoherenceJob is the top level schema for the CoherenceJob API and custom resource definition (CRD)
// for configuring Coherence Job workloads.
//
// +kubebuilder:object:root=true
Expand Down
8 changes: 7 additions & 1 deletion api/v1/coherenceresourcespec_types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2024, Oracle and/or its affiliates.
* Copyright (c) 2020, 2025, Oracle and/or its affiliates.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
Expand Down Expand Up @@ -286,6 +286,10 @@ type CoherenceResourceSpec struct {
// The default labels to use are determined by the Operator.
// +optional
SiteLabel *string `json:"siteLabel,omitempty"`
// Lifecycle applies actions that the management system should take in response to container lifecycle events.
// Cannot be updated.
// +optional
Lifecycle *corev1.Lifecycle `json:"lifecycle,omitempty"`
}

// Action is an action to execute when the StatefulSet becomes ready.
Expand Down Expand Up @@ -877,6 +881,8 @@ func (in *CoherenceResourceSpec) CreateCoherenceContainer(deployment CoherenceRe
in.StartupProbe.UpdateProbeSpec(healthPort, DefaultLivenessPath, c.StartupProbe)
}

c.Lifecycle = in.Lifecycle

return c
}

Expand Down
35 changes: 34 additions & 1 deletion api/v1/create_job_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2024, Oracle and/or its affiliates.
* Copyright (c) 2020, 2025, Oracle and/or its affiliates.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
Expand All @@ -9,6 +9,7 @@ package v1_test
import (
coh "github.com/oracle/coherence-operator/api/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/ptr"
"testing"
)
Expand Down Expand Up @@ -136,3 +137,35 @@ func TestCreateJobWithEnvVarsFrom(t *testing.T) {
// assert that the StatefulSet is as expected
assertJobCreation(t, deployment, expected)
}

func TestAddLifecycleToJobCoherenceContainer(t *testing.T) {
lc := &corev1.Lifecycle{
PostStart: &corev1.LifecycleHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/foo",
Port: intstr.FromInt32(1234),
},
},
PreStop: &corev1.LifecycleHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/bar",
Port: intstr.FromInt32(987),
},
},
}

spec := coh.CoherenceJobResourceSpec{
CoherenceResourceSpec: coh.CoherenceResourceSpec{
Lifecycle: lc,
},
}

// Create the test deployment
deployment := createTestCoherenceJobDeployment(spec)
// Create expected StatefulSet
expected := createMinimalExpectedJob(deployment)
expected.Spec.Template.Spec.Containers[0].Lifecycle = lc

// assert that the StatefulSet is as expected
assertJobCreation(t, deployment, expected)
}
32 changes: 31 additions & 1 deletion api/v1/create_statefulset_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2024, Oracle and/or its affiliates.
* Copyright (c) 2020, 2025, Oracle and/or its affiliates.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
Expand Down Expand Up @@ -748,3 +748,33 @@ func TestCreateStatefulSetWithGlobalAnnotations(t *testing.T) {
// assert that the Job is as expected
assertStatefulSetCreation(t, deployment, stsExpected)
}

func TestAddLifecycleToStatefulSetCoherenceContainer(t *testing.T) {
lc := &corev1.Lifecycle{
PostStart: &corev1.LifecycleHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/foo",
Port: intstr.FromInt32(1234),
},
},
PreStop: &corev1.LifecycleHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/bar",
Port: intstr.FromInt32(987),
},
},
}

spec := coh.CoherenceResourceSpec{
Lifecycle: lc,
}

// Create the test deployment
deployment := createTestDeployment(spec)
// Create expected StatefulSet
stsExpected := createMinimalExpectedStatefulSet(deployment)
stsExpected.Spec.Template.Spec.Containers[0].Lifecycle = lc

// assert that the StatefulSet is as expected
assertStatefulSetCreation(t, deployment, stsExpected)
}
Loading
Loading