Skip to content

Commit

Permalink
Infinispan 15 Operands are using deprecated health probes. Fixes #2077
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanemerson authored and rigazilla committed May 16, 2024
1 parent 9a294fb commit 19ec56a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
7 changes: 4 additions & 3 deletions controllers/zero_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ func (z *zeroCapacityController) isZeroPodReady(request reconcile.Request, ctx c
}

func (z *zeroCapacityController) zeroPodSpec(name, namespace string, podSecurityCtx *corev1.PodSecurityContext, ispn *v1.Infinispan, zeroSpec *zeroCapacitySpec) (*corev1.Pod, error) {
operand, _ := z.VersionManager.WithRef(ispn.Spec.Version)
podResources, err := PodResources(zeroSpec.Container)
if err != nil {
return nil, err
Expand All @@ -330,14 +331,14 @@ func (z *zeroCapacityController) zeroPodSpec(name, namespace string, podSecurity
Name: InfinispanContainer,
Env: PodEnv(ispn, &[]corev1.EnvVar{{Name: "IDENTITIES_BATCH", Value: consts.ServerOperatorSecurity + "/" + consts.ServerIdentitiesBatchFilename}}),
Lifecycle: PodLifecycle(),
LivenessProbe: PodLivenessProbe(ispn),
LivenessProbe: PodLivenessProbe(ispn, operand),
Ports: []corev1.ContainerPort{
{ContainerPort: consts.InfinispanAdminPort, Name: consts.InfinispanAdminPortName, Protocol: corev1.ProtocolTCP},
{ContainerPort: consts.InfinispanPingPort, Name: consts.InfinispanPingPortName, Protocol: corev1.ProtocolTCP},
},
ReadinessProbe: PodReadinessProbe(ispn),
ReadinessProbe: PodReadinessProbe(ispn, operand),
Resources: *podResources,
StartupProbe: PodStartupProbe(ispn),
StartupProbe: PodStartupProbe(ispn, operand),
Args: []string{"-c", "operator/infinispan-zero.xml", "-l", OperatorConfMountPath + "/log4j.xml"},
VolumeMounts: []corev1.VolumeMount{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func StatefulSetRollingUpgrade(i *ispnv1.Infinispan, ctx pipeline.Context) {
}
}

requestedOperand := ctx.Operand()
// Changes to probes
probedChanged := func(current, new *corev1.Probe) bool {
if reflect.DeepEqual(current, new) {
Expand All @@ -92,12 +93,11 @@ func StatefulSetRollingUpgrade(i *ispnv1.Infinispan, ctx pipeline.Context) {
*current = *new
return true
}
updateNeeded = probedChanged(container.LivenessProbe, provision.PodLivenessProbe(i)) || updateNeeded
updateNeeded = probedChanged(container.ReadinessProbe, provision.PodReadinessProbe(i)) || updateNeeded
updateNeeded = probedChanged(container.StartupProbe, provision.PodStartupProbe(i)) || updateNeeded
updateNeeded = probedChanged(container.LivenessProbe, provision.PodLivenessProbe(i, requestedOperand)) || updateNeeded
updateNeeded = probedChanged(container.ReadinessProbe, provision.PodReadinessProbe(i, requestedOperand)) || updateNeeded
updateNeeded = probedChanged(container.StartupProbe, provision.PodStartupProbe(i, requestedOperand)) || updateNeeded

// Check if the base-image has been upgraded due to a CVE
requestedOperand := ctx.Operand()
userProvidedImage := i.Spec.Image != nil
if !userProvidedImage && requestedOperand.CVE && container.Image != requestedOperand.Image {
ctx.Log().Info(fmt.Sprintf("CVE release '%s'. StatefulSet Rolling upgrade required", requestedOperand.Ref()))
Expand Down
24 changes: 16 additions & 8 deletions pkg/reconcile/pipeline/infinispan/handler/provision/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"fmt"
"os"

"github.com/blang/semver"
ispnv1 "github.com/infinispan/infinispan-operator/api/v1"
consts "github.com/infinispan/infinispan-operator/controllers/constants"
"github.com/infinispan/infinispan-operator/pkg/infinispan/version"
kube "github.com/infinispan/infinispan-operator/pkg/kubernetes"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
Expand Down Expand Up @@ -48,24 +50,30 @@ func PodLifecycle() *corev1.Lifecycle {
}
}

func PodLivenessProbe(i *ispnv1.Infinispan) *corev1.Probe {
return probe(i.Spec.Service.Container.LivenessProbe)
func PodLivenessProbe(i *ispnv1.Infinispan, operand version.Operand) *corev1.Probe {
return probe(i.Spec.Service.Container.LivenessProbe, operand)
}

func PodReadinessProbe(i *ispnv1.Infinispan) *corev1.Probe {
return probe(i.Spec.Service.Container.ReadinessProbe)
func PodReadinessProbe(i *ispnv1.Infinispan, operand version.Operand) *corev1.Probe {
return probe(i.Spec.Service.Container.ReadinessProbe, operand)
}

func PodStartupProbe(i *ispnv1.Infinispan) *corev1.Probe {
return probe(i.Spec.Service.Container.StartupProbe)
func PodStartupProbe(i *ispnv1.Infinispan, operand version.Operand) *corev1.Probe {
return probe(i.Spec.Service.Container.StartupProbe, operand)
}

func probe(p ispnv1.ContainerProbeSpec) *corev1.Probe {
func probe(p ispnv1.ContainerProbeSpec, operand version.Operand) *corev1.Probe {
var path string
if operand.UpstreamVersion.GTE(semver.Version{Major: 15}) {
path = "rest/v2/container/health/status"
} else {
path = "rest/v2/cache-managers/default/health/status"
}
return &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Scheme: corev1.URISchemeHTTP,
Path: "rest/v2/cache-managers/default/health/status",
Path: path,
Port: intstr.FromInt(consts.InfinispanAdminPort)},
},
FailureThreshold: *p.FailureThreshold,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package provision
import (
"testing"

"github.com/blang/semver"
"github.com/golang/mock/gomock"
ispnv1 "github.com/infinispan/infinispan-operator/api/v1"
"github.com/infinispan/infinispan-operator/pkg/infinispan/version"
"github.com/infinispan/infinispan-operator/pkg/reconcile/pipeline/infinispan"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -35,6 +37,7 @@ var _ = Describe("Provision", func() {
},
)
ctx.EXPECT().Resources().Return(resources)
ctx.EXPECT().Operand().AnyTimes().Return(version.Operand{UpstreamVersion: &semver.Version{Major: 15, Minor: 0, Patch: 0}})

ispn := &ispnv1.Infinispan{
ObjectMeta: metav1.ObjectMeta{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func ClusterStatefulSetSpec(statefulSetName string, i *ispnv1.Infinispan, ctx pi

// We can ignore the err here as the validating webhook ensures that the resources are valid
podResources, _ := PodResources(i.Spec.Container)
operand := ctx.Operand()
statefulSet := &appsv1.StatefulSet{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1",
Expand Down Expand Up @@ -111,10 +112,10 @@ func ClusterStatefulSetSpec(statefulSetName string, i *ispnv1.Infinispan, ctx pi
Name: InfinispanContainer,
Env: podEnvs,
Lifecycle: PodLifecycle(),
LivenessProbe: PodLivenessProbe(i),
LivenessProbe: PodLivenessProbe(i, operand),
Ports: PodPortsWithXsite(i),
ReadinessProbe: PodReadinessProbe(i),
StartupProbe: PodStartupProbe(i),
ReadinessProbe: PodReadinessProbe(i, operand),
StartupProbe: PodStartupProbe(i, operand),
Resources: *podResources,
VolumeMounts: []corev1.VolumeMount{{
Name: ConfigVolumeName,
Expand Down

0 comments on commit 19ec56a

Please sign in to comment.