Skip to content

Commit

Permalink
operator: add readiness check to Cluster statefulset
Browse files Browse the repository at this point in the history
  • Loading branch information
joejulian committed Oct 19, 2023
1 parent b3399a1 commit 9c56d76
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/go/k8s/pkg/resources/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,20 @@ func (r *StatefulSetResource) obj(

tlsVolumes, tlsVolumeMounts := r.volumeProvider.Volumes()

rpkFlags := []string{}
u := fmt.Sprintf("%s://${POD_NAME}.%s:%d", r.pandaCluster.AdminAPIInternal().GetHTTPScheme(), r.serviceFQDN, r.pandaCluster.AdminAPIInternal().GetPort())
rpkFlags = append(rpkFlags, fmt.Sprintf("--api-urls %q", u))
if r.pandaCluster.AdminAPIInternal().GetTLS().Enabled {
rpkFlags = append(rpkFlags,
"--admin-api-tls-enabled",
fmt.Sprintf("--admin-api-tls-truststore %q", path.Join(resourcetypes.GetTLSMountPoints().AdminAPI.NodeCertMountDir, "tls.crt")))
}
if r.pandaCluster.AdminAPIInternal().GetTLS().RequireClientAuth {
rpkFlags = append(rpkFlags,
fmt.Sprintf("--tls-cert %q", path.Join(resourcetypes.GetTLSMountPoints().AdminAPI.ClientCAMountDir, "tls.crt")),
fmt.Sprintf("--tls-key %q", path.Join(resourcetypes.GetTLSMountPoints().AdminAPI.ClientCAMountDir, "tls.key")))
}

// We set statefulset replicas via status.currentReplicas in order to control it from the handleScaling function
replicas := r.pandaCluster.GetCurrentReplicas()

Expand Down Expand Up @@ -526,6 +540,13 @@ func (r *StatefulSetResource) obj(
ContainerPort: int32(r.pandaCluster.Spec.Configuration.RPCServer.Port),
},
}, r.getPorts()...),
ReadinessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: []string{"bash", "-xc", fmt.Sprintf("rpk cluster health %s| grep 'Healthy:.*true'", strings.Join(rpkFlags, " "))},
},
},
},
SecurityContext: &corev1.SecurityContext{
RunAsUser: pointer.Int64(userID),
RunAsGroup: pointer.Int64(groupID),
Expand Down

0 comments on commit 9c56d76

Please sign in to comment.