From 2f5add7c1fe275913bf700030d419b3e5a53df7f Mon Sep 17 00:00:00 2001 From: vthwang Date: Sun, 22 Nov 2026 15:01:34 -0800 Subject: [PATCH 1/3] fix: configure workload health probes Ensure Kubernetes waits for serving endpoints before routing traffic. - add readiness, liveness, and startup probe support - use health endpoints exposed by current service images Signed-off-by: vthwang --- internal/k8s/component_jobs_test.go | 18 ++++- internal/k8s/component_resources.go | 49 ++++++++++--- internal/k8s/trust_registry_test.go | 2 +- internal/k8s/vta_resources.go | 25 ++++++- internal/k8s/vta_resources_test.go | 12 ++- internal/setup/orchestrator_fullstack.go | 93 ++++++++++++------------ internal/setup/orchestrator_vtc.go | 28 +++---- internal/setup/trust_registry.go | 2 +- 8 files changed, 150 insertions(+), 79 deletions(-) diff --git a/internal/k8s/component_jobs_test.go b/internal/k8s/component_jobs_test.go index f966c52..c9d67c8 100644 --- a/internal/k8s/component_jobs_test.go +++ b/internal/k8s/component_jobs_test.go @@ -114,10 +114,12 @@ func TestCreateComponentDeploymentUsesConfiguredHealthReadinessProbe(t *testing. client := &Client{kube: fake.NewSimpleClientset()} if err := client.CreateComponentDeployment(context.Background(), "test", ComponentDeploymentSpec{ - Name: "mediator", - Image: "example/mediator:test", - Port: 7037, - HealthCheckPath: "/mediator/v1/readyz", + Name: "mediator", + Image: "example/mediator:test", + Port: 7037, + ReadinessPath: "/mediator/v1/readyz", + LivenessPath: "/mediator/v1/livez", + StartupPath: "/mediator/v1/livez", }); err != nil { t.Fatalf("CreateComponentDeployment() error = %v", err) } @@ -135,6 +137,14 @@ func TestCreateComponentDeploymentUsesConfiguredHealthReadinessProbe(t *testing. if probe.HTTPGet.Path != "/mediator/v1/readyz" { t.Fatalf("readiness path = %q, want /mediator/v1/readyz", probe.HTTPGet.Path) } + liveness := deployment.Spec.Template.Spec.Containers[0].LivenessProbe + if liveness == nil || liveness.HTTPGet == nil || liveness.HTTPGet.Path != "/mediator/v1/livez" { + t.Fatalf("unexpected liveness probe: %+v", liveness) + } + startup := deployment.Spec.Template.Spec.Containers[0].StartupProbe + if startup == nil || startup.HTTPGet == nil || startup.HTTPGet.Path != "/mediator/v1/livez" { + t.Fatalf("unexpected startup probe: %+v", startup) + } if probe.HTTPGet.Port.IntVal != 7037 { t.Fatalf("readiness port = %d, want 7037", probe.HTTPGet.Port.IntVal) } diff --git a/internal/k8s/component_resources.go b/internal/k8s/component_resources.go index dc5ab83..24a7b0e 100644 --- a/internal/k8s/component_resources.go +++ b/internal/k8s/component_resources.go @@ -39,13 +39,19 @@ type ComponentDeploymentSpec struct { Labels map[string]string PlacementMode string Component string - // HealthCheckPath, if set, wires an HTTP readinessProbe against this path - // on Port. Without it, Kubernetes marks the pod Ready the instant the + // ReadinessPath, if set, wires an HTTP readinessProbe against this path on + // Port. Without it, Kubernetes marks the pod Ready the instant the // container process starts (no probe = ready-by-default), which is true // long before the app inside has actually bound its listener — so // WaitForComponentDeploymentReady's poll of ReadyReplicas was previously // a near-instant no-op rather than a real "is this serving" check. - HealthCheckPath string + ReadinessPath string + // LivenessPath is process-only: it must not fail merely because a remote + // dependency is unavailable, since restarting the process cannot repair it. + LivenessPath string + // StartupPath suppresses readiness and liveness until the HTTP runtime is + // serving, protecting slow store initialization from premature restarts. + StartupPath string // Resources sets the container's requests/limits. Memory always carries a // limit (incompressible); CPU deliberately gets requests only — a CFS quota // would throttle bursts even when node CPU is idle, while the request alone @@ -95,19 +101,40 @@ func (c *Client) CreateComponentDeployment(ctx context.Context, ns string, spec ports = []corev1.ContainerPort{{ContainerPort: spec.Port, Protocol: corev1.ProtocolTCP}} } - var readinessProbe *corev1.Probe - if spec.HealthCheckPath != "" { + var readinessProbe, livenessProbe, startupProbe *corev1.Probe + if spec.ReadinessPath != "" { readinessProbe = &corev1.Probe{ ProbeHandler: corev1.ProbeHandler{ HTTPGet: &corev1.HTTPGetAction{ - Path: spec.HealthCheckPath, + Path: spec.ReadinessPath, Port: intstr.FromInt32(spec.Port), }, }, - InitialDelaySeconds: 1, - PeriodSeconds: 2, - TimeoutSeconds: 2, - FailureThreshold: 3, + PeriodSeconds: 2, + TimeoutSeconds: 2, + FailureThreshold: 3, + } + } + if spec.LivenessPath != "" { + livenessProbe = &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{HTTPGet: &corev1.HTTPGetAction{ + Path: spec.LivenessPath, + Port: intstr.FromInt32(spec.Port), + }}, + PeriodSeconds: 10, + TimeoutSeconds: 2, + FailureThreshold: 3, + } + } + if spec.StartupPath != "" { + startupProbe = &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{HTTPGet: &corev1.HTTPGetAction{ + Path: spec.StartupPath, + Port: intstr.FromInt32(spec.Port), + }}, + PeriodSeconds: 2, + TimeoutSeconds: 2, + FailureThreshold: 60, } } @@ -135,6 +162,8 @@ func (c *Client) CreateComponentDeployment(ctx context.Context, ns string, spec Ports: ports, VolumeMounts: mounts, ReadinessProbe: readinessProbe, + LivenessProbe: livenessProbe, + StartupProbe: startupProbe, Resources: spec.Resources, }}, Volumes: volumes, diff --git a/internal/k8s/trust_registry_test.go b/internal/k8s/trust_registry_test.go index 2d08009..b2c6cb1 100644 --- a/internal/k8s/trust_registry_test.go +++ b/internal/k8s/trust_registry_test.go @@ -112,7 +112,7 @@ func TestRegistryJobRetryRetainsIdentityAndActiveJobs(t *testing.T) { func TestRegistryDeploymentKeepsCredentialInMemoryAndOutOfExports(t *testing.T) { kube := fake.NewSimpleClientset() client := &Client{kube: kube} - spec := ComponentDeploymentSpec{Name: "registry", Labels: map[string]string{"app": "registry"}, Image: "registry:image", ServiceAccount: VtaServiceAccount, Command: []string{"trust-registry"}, Port: 3232, HealthCheckPath: "/health", Recreate: true, + spec := ComponentDeploymentSpec{Name: "registry", Labels: map[string]string{"app": "registry"}, Image: "registry:image", ServiceAccount: VtaServiceAccount, Command: []string{"trust-registry"}, Port: 3232, ReadinessPath: "/health", LivenessPath: "/health", StartupPath: "/health", Recreate: true, Env: []corev1.EnvVar{{Name: "MEDIATOR_DID", Value: "did:webvh:mediator"}, {Name: "TR_VTA_CONTEXT_ID", Value: "registry-7"}, {Name: "TR_SECRETS_SEED", Value: "test-only-secret"}}, ExtraVolumes: []corev1.Volume{{Name: "credential", VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}}}}, ExtraMounts: []corev1.VolumeMount{{Name: "credential", MountPath: "/run/trust-registry", ReadOnly: true}}, diff --git a/internal/k8s/vta_resources.go b/internal/k8s/vta_resources.go index c39943e..ad2628b 100644 --- a/internal/k8s/vta_resources.go +++ b/internal/k8s/vta_resources.go @@ -591,10 +591,27 @@ func (c *Client) createVtaDeployment(ctx context.Context, ns string, sessionID u Port: intstr.FromInt32(port), }, }, - InitialDelaySeconds: 1, - PeriodSeconds: 2, - TimeoutSeconds: 2, - FailureThreshold: 3, + PeriodSeconds: 2, + TimeoutSeconds: 2, + FailureThreshold: 3, + }, + LivenessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{HTTPGet: &corev1.HTTPGetAction{ + Path: "/health", + Port: intstr.FromInt32(port), + }}, + PeriodSeconds: 10, + TimeoutSeconds: 2, + FailureThreshold: 3, + }, + StartupProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{HTTPGet: &corev1.HTTPGetAction{ + Path: "/health", + Port: intstr.FromInt32(port), + }}, + PeriodSeconds: 2, + TimeoutSeconds: 2, + FailureThreshold: 60, }, VolumeMounts: []corev1.VolumeMount{{ Name: "data", diff --git a/internal/k8s/vta_resources_test.go b/internal/k8s/vta_resources_test.go index 42ba745..399dec4 100644 --- a/internal/k8s/vta_resources_test.go +++ b/internal/k8s/vta_resources_test.go @@ -51,10 +51,20 @@ func TestCreateVtaDeploymentUsesHealthReadinessProbe(t *testing.T) { if probe.HTTPGet.Port.IntVal != 8100 { t.Fatalf("readiness port = %d, want 8100", probe.HTTPGet.Port.IntVal) } - if probe.InitialDelaySeconds != 1 || probe.PeriodSeconds != 2 || + if probe.InitialDelaySeconds != 0 || probe.PeriodSeconds != 2 || probe.TimeoutSeconds != 2 || probe.FailureThreshold != 3 { t.Fatalf("unexpected readiness timing: %+v", probe) } + liveness := deployment.Spec.Template.Spec.Containers[0].LivenessProbe + if liveness == nil || liveness.HTTPGet == nil || liveness.HTTPGet.Path != "/health" || + liveness.PeriodSeconds != 10 || liveness.TimeoutSeconds != 2 || liveness.FailureThreshold != 3 { + t.Fatalf("unexpected liveness probe: %+v", liveness) + } + startup := deployment.Spec.Template.Spec.Containers[0].StartupProbe + if startup == nil || startup.HTTPGet == nil || startup.HTTPGet.Path != "/health" || + startup.PeriodSeconds != 2 || startup.TimeoutSeconds != 2 || startup.FailureThreshold != 60 { + t.Fatalf("unexpected startup probe: %+v", startup) + } } func TestCreateVtaDeploymentSetsTuningEnv(t *testing.T) { diff --git a/internal/setup/orchestrator_fullstack.go b/internal/setup/orchestrator_fullstack.go index f6e68b1..2467bff 100644 --- a/internal/setup/orchestrator_fullstack.go +++ b/internal/setup/orchestrator_fullstack.go @@ -1082,19 +1082,19 @@ func (o *Orchestrator) fsDeployDids(ctx context.Context, ns string, s *model.Set } name := k8s.FSDidsName(s.ID) if err := o.k8s.CreateComponentDeployment(ctx, ns, k8s.ComponentDeploymentSpec{ - Name: name, - Image: s.DidsImage, - Command: []string{"did-hosting-daemon"}, - WorkingDir: "/work/dids", - ServiceAccount: k8s.VtaServiceAccount, - PVCMounts: []k8s.PVCMount{{Name: "dids-data", ClaimName: name, MountPath: "/work/dids"}}, - Env: append(fsNoColorEnv(), k8s.DidsTuningEnv()...), - Port: 8534, - Labels: fsLabels("dids", s.ID), - PlacementMode: k8s.PlacementModeFullStack, - Component: k8s.ComponentDids, - HealthCheckPath: "/health", - Resources: profiles.Requirements(k8s.ComponentDids), + Name: name, + Image: s.DidsImage, + Command: []string{"did-hosting-daemon"}, + WorkingDir: "/work/dids", + ServiceAccount: k8s.VtaServiceAccount, + PVCMounts: []k8s.PVCMount{{Name: "dids-data", ClaimName: name, MountPath: "/work/dids"}}, + Env: append(fsNoColorEnv(), k8s.DidsTuningEnv()...), + Port: 8534, + Labels: fsLabels("dids", s.ID), + PlacementMode: k8s.PlacementModeFullStack, + Component: k8s.ComponentDids, + ReadinessPath: "/health", + Resources: profiles.Requirements(k8s.ComponentDids), }); err != nil { return err } @@ -1119,21 +1119,23 @@ func (o *Orchestrator) fsDeployMediator(ctx context.Context, ns string, s *model env := append(fsNoColorEnv(), fsMediatorTuningEnv()...) env = append(env, k8s.VaultCAEnvVar()) if err := o.k8s.CreateComponentDeployment(ctx, ns, k8s.ComponentDeploymentSpec{ - Name: name, - Image: s.MediatorImage, - Command: []string{"mediator"}, - WorkingDir: "/work/mediator", - ServiceAccount: k8s.VtaServiceAccount, - PVCMounts: []k8s.PVCMount{{Name: "mediator-data", ClaimName: name, MountPath: "/work/mediator"}}, - Env: env, - ExtraVolumes: extraVolumes, - ExtraMounts: extraMounts, - Port: 7037, - Labels: fsLabels("mediator", s.ID), - PlacementMode: k8s.PlacementModeFullStack, - Component: k8s.ComponentMediator, - HealthCheckPath: "/mediator/v1/readyz", - Resources: profiles.Requirements(k8s.ComponentMediator), + Name: name, + Image: s.MediatorImage, + Command: []string{"mediator"}, + WorkingDir: "/work/mediator", + ServiceAccount: k8s.VtaServiceAccount, + PVCMounts: []k8s.PVCMount{{Name: "mediator-data", ClaimName: name, MountPath: "/work/mediator"}}, + Env: env, + ExtraVolumes: extraVolumes, + ExtraMounts: extraMounts, + Port: 7037, + Labels: fsLabels("mediator", s.ID), + PlacementMode: k8s.PlacementModeFullStack, + Component: k8s.ComponentMediator, + ReadinessPath: "/mediator/v1/readyz", + LivenessPath: "/mediator/v1/livez", + StartupPath: "/mediator/v1/livez", + Resources: profiles.Requirements(k8s.ComponentMediator), }); err != nil { return err } @@ -1174,12 +1176,11 @@ func (o *Orchestrator) fsStepImportAdminDid(ctx context.Context, ns string, s *m // fsDeployVta starts the VTA Deployment and waits for it to become Ready — // full_stack's step_vtc_setup makes live calls against it right // after, so the deploy_* invariant (returns only once the component is -// actually up) matters here too. HealthCheckPath wires a readinessProbe +// actually up) matters here too. ReadinessPath wires a readinessProbe // against GET /health (vta-service's unauthenticated health route) — without // it, Kubernetes marks the pod Ready the instant the container starts, -// before the REST/DIDComm/storage subsystems have finished their async -// startup, so WaitForComponentDeploymentReady below returned almost -// instantly regardless of whether VTA could actually serve a request yet. +// before the HTTP listener is serving, so WaitForComponentDeploymentReady +// below returned almost instantly and the next setup step raced the listener. func (o *Orchestrator) fsDeployVta(ctx context.Context, ns string, s *model.SetupSession) error { profiles, err := resourceprofile.Load(ctx, o.db) if err != nil { @@ -1187,19 +1188,21 @@ func (o *Orchestrator) fsDeployVta(ctx context.Context, ns string, s *model.Setu } name := k8s.FSVtaName(s.ID) if err := o.k8s.CreateComponentDeployment(ctx, ns, k8s.ComponentDeploymentSpec{ - Name: name, - Image: s.VtaImage, - Command: []string{"vta"}, - WorkingDir: "/work/vta", - ServiceAccount: k8s.VtaServiceAccount, - PVCMounts: []k8s.PVCMount{{Name: "vta-data", ClaimName: name, MountPath: "/work/vta"}}, - Env: append(fsNoColorEnv(), k8s.VtaTuningEnv()...), - Port: 8100, - Labels: fsLabels("vta", s.ID), - PlacementMode: k8s.PlacementModeFullStack, - Component: k8s.ComponentVTA, - HealthCheckPath: "/health", - Resources: profiles.Requirements(k8s.ComponentVTA), + Name: name, + Image: s.VtaImage, + Command: []string{"vta"}, + WorkingDir: "/work/vta", + ServiceAccount: k8s.VtaServiceAccount, + PVCMounts: []k8s.PVCMount{{Name: "vta-data", ClaimName: name, MountPath: "/work/vta"}}, + Env: append(fsNoColorEnv(), k8s.VtaTuningEnv()...), + Port: 8100, + Labels: fsLabels("vta", s.ID), + PlacementMode: k8s.PlacementModeFullStack, + Component: k8s.ComponentVTA, + ReadinessPath: "/health", + LivenessPath: "/health", + StartupPath: "/health", + Resources: profiles.Requirements(k8s.ComponentVTA), }); err != nil { return err } diff --git a/internal/setup/orchestrator_vtc.go b/internal/setup/orchestrator_vtc.go index 9cf37b1..f88f627 100644 --- a/internal/setup/orchestrator_vtc.go +++ b/internal/setup/orchestrator_vtc.go @@ -264,19 +264,21 @@ func (o *Orchestrator) fsDeployVtc(ctx context.Context, ns string, s *model.Setu } name := k8s.FSVtcName(s.ID) if err := o.k8s.CreateComponentDeployment(ctx, ns, k8s.ComponentDeploymentSpec{ - Name: name, - Image: s.VtcImage, - Command: []string{"vtc"}, - WorkingDir: "/work/vtc", - ServiceAccount: k8s.VtaServiceAccount, - PVCMounts: []k8s.PVCMount{{Name: "vtc-data", ClaimName: name, MountPath: "/work/vtc"}}, - Env: append(fsNoColorEnv(), k8s.VtcTuningEnv()...), - Port: 8200, - Labels: fsLabels("vtc", s.ID), - PlacementMode: k8s.PlacementModeFullStack, - Component: k8s.ComponentVTC, - HealthCheckPath: "/health", - Resources: profiles.Requirements(k8s.ComponentVTC), + Name: name, + Image: s.VtcImage, + Command: []string{"vtc"}, + WorkingDir: "/work/vtc", + ServiceAccount: k8s.VtaServiceAccount, + PVCMounts: []k8s.PVCMount{{Name: "vtc-data", ClaimName: name, MountPath: "/work/vtc"}}, + Env: append(fsNoColorEnv(), k8s.VtcTuningEnv()...), + Port: 8200, + Labels: fsLabels("vtc", s.ID), + PlacementMode: k8s.PlacementModeFullStack, + Component: k8s.ComponentVTC, + ReadinessPath: "/health", + LivenessPath: "/health", + StartupPath: "/health", + Resources: profiles.Requirements(k8s.ComponentVTC), }); err != nil { return err } diff --git a/internal/setup/trust_registry.go b/internal/setup/trust_registry.go index 185f6d3..484da8b 100644 --- a/internal/setup/trust_registry.go +++ b/internal/setup/trust_registry.go @@ -313,7 +313,7 @@ func (o *Orchestrator) deployTrustRegistry(ctx context.Context, ns string, s *mo Name: name, Image: s.TrustRegistryImage, Command: []string{"trust-registry"}, WorkingDir: "/work/trust-registry", ServiceAccount: k8s.VtaServiceAccount, Env: env, - Port: 3232, HealthCheckPath: "/health", Labels: labels, + Port: 3232, ReadinessPath: "/health", LivenessPath: "/health", StartupPath: "/health", Labels: labels, PlacementMode: k8s.PlacementModeFullStack, Component: k8s.ComponentTrustRegistry, Resources: profiles.Requirements(k8s.ComponentTrustRegistry), PVCMounts: []k8s.PVCMount{{Name: "registry-data", ClaimName: name, MountPath: "/work/trust-registry"}}, From 59bab6064bc770b7f284bd4851b8f6748622a0c8 Mon Sep 17 00:00:00 2001 From: vthwang Date: Mon, 23 Nov 2026 11:35:14 -0800 Subject: [PATCH 2/3] fix: reconcile health probes during upgrades Add missing component-specific probes during image upgrades while preserving operator-supplied probe configuration. Signed-off-by: vthwang --- internal/k8s/upgrade.go | 79 +++++++++++++++++++++++++++++++++--- internal/k8s/upgrade_test.go | 72 ++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+), 6 deletions(-) diff --git a/internal/k8s/upgrade.go b/internal/k8s/upgrade.go index b2a66d7..8e44b49 100644 --- a/internal/k8s/upgrade.go +++ b/internal/k8s/upgrade.go @@ -6,13 +6,78 @@ import ( "time" appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/client-go/util/retry" ) const recoveryRestartAnnotation = "vtafarm.ic3software.com/recovery-restarted-at" +type upgradeProbePaths struct { + readiness string + liveness string + startup string +} + +func upgradeProbePathsFor(app string) (upgradeProbePaths, bool) { + switch app { + case "vta", "fs-vta", "fs-vtc", "fs-trust-registry": + return upgradeProbePaths{readiness: "/health", liveness: "/health", startup: "/health"}, true + case "fs-mediator": + return upgradeProbePaths{ + readiness: "/mediator/v1/readyz", + liveness: "/mediator/v1/livez", + startup: "/mediator/v1/livez", + }, true + case "fs-dids": + // DID Hosting's /health includes its store and own DID. It is valid + // readiness, but using it for liveness could create a restart loop. + return upgradeProbePaths{readiness: "/health"}, true + default: + return upgradeProbePaths{}, false + } +} + +func upgradeHTTPProbe(path string, port int32, period, failures int32) *corev1.Probe { + if path == "" { + return nil + } + return &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{HTTPGet: &corev1.HTTPGetAction{ + Path: path, + Port: intstr.FromInt32(port), + }}, + PeriodSeconds: period, + TimeoutSeconds: 2, + FailureThreshold: failures, + } +} + +// reconcileUpgradeHealthProbes fills probes missing from an older Deployment. +// Existing operator-supplied probes are preserved. +func reconcileUpgradeHealthProbes(deployment *appsv1.Deployment) { + paths, ok := upgradeProbePathsFor(deployment.Labels["app"]) + if !ok || len(deployment.Spec.Template.Spec.Containers) == 0 { + return + } + container := &deployment.Spec.Template.Spec.Containers[0] + if len(container.Ports) == 0 { + return + } + port := container.Ports[0].ContainerPort + if container.ReadinessProbe == nil { + container.ReadinessProbe = upgradeHTTPProbe(paths.readiness, port, 2, 3) + } + if container.LivenessProbe == nil { + container.LivenessProbe = upgradeHTTPProbe(paths.liveness, port, 10, 3) + } + if container.StartupProbe == nil { + container.StartupProbe = upgradeHTTPProbe(paths.startup, port, 2, 60) + } +} + // VtaDeploymentName exposes vta_only's Deployment name (vta-) to // the upgrade runner, which patches Deployments created by CreateVtaDeployment. // full_stack components use the exported FS*Name funcs directly. @@ -21,12 +86,13 @@ func VtaDeploymentName(sessionID uint) string { } // SetDeploymentImage points every container in the Deployment at image and -// forces the Recreate strategy. The same rollout reconciles component tuning and an -// existing mediator's persisted Vault CA configuration. Recreate matters: these Deployments mount RWO -// PVCs, so the default RollingUpdate would start the new pod while the old -// one still holds the volume and deadlock the rollout. Replacing the whole -// Strategy struct also clears any rollingUpdate params, which the API server -// rejects alongside type Recreate. +// forces the Recreate strategy. The same rollout reconciles component tuning, +// missing health probes, and an existing mediator's persisted Vault CA +// configuration. Recreate matters: these Deployments mount RWO PVCs, so the +// default RollingUpdate would start the new pod while the old one still holds +// the volume and deadlock the rollout. Replacing the whole Strategy struct also +// clears any rollingUpdate params, which the API server rejects alongside type +// Recreate. func (c *Client) SetDeploymentImage(ctx context.Context, ns, name, image string) error { return retry.RetryOnConflict(retry.DefaultRetry, func() error { deploy, err := c.kube.AppsV1().Deployments(ns).Get(ctx, name, metav1.GetOptions{}) @@ -38,6 +104,7 @@ func (c *Client) SetDeploymentImage(ctx context.Context, ns, name, image string) deploy.Spec.Template.Spec.Containers[i].Image = image } reconcileTuningEnv(deploy) + reconcileUpgradeHealthProbes(deploy) ensureMediatorVaultCA(deploy, image) _, err = c.kube.AppsV1().Deployments(ns).Update(ctx, deploy, metav1.UpdateOptions{}) return err diff --git a/internal/k8s/upgrade_test.go b/internal/k8s/upgrade_test.go index 0ad4b09..d776de6 100644 --- a/internal/k8s/upgrade_test.go +++ b/internal/k8s/upgrade_test.go @@ -70,6 +70,78 @@ func deploymentEnv(t *testing.T, client *Client, name string) map[string]string return env } +func TestSetDeploymentImageAddsMissingHealthProbes(t *testing.T) { + cases := []struct { + app string + port int32 + readiness, liveness string + startup string + }{ + {app: "vta", port: 8100, readiness: "/health", liveness: "/health", startup: "/health"}, + {app: "fs-vta", port: 8100, readiness: "/health", liveness: "/health", startup: "/health"}, + {app: "fs-vtc", port: 8200, readiness: "/health", liveness: "/health", startup: "/health"}, + {app: "fs-trust-registry", port: 3232, readiness: "/health", liveness: "/health", startup: "/health"}, + {app: "fs-mediator", port: 7037, readiness: "/mediator/v1/readyz", liveness: "/mediator/v1/livez", startup: "/mediator/v1/livez"}, + {app: "fs-dids", port: 8534, readiness: "/health"}, + } + for _, tc := range cases { + t.Run(tc.app, func(t *testing.T) { + deployment := tuningTestDeployment("workload", tc.app) + deployment.Spec.Template.Spec.Containers[0].Ports = []corev1.ContainerPort{{ContainerPort: tc.port}} + client := &Client{kube: fake.NewSimpleClientset(deployment)} + + if err := client.SetDeploymentImage(context.Background(), "test", "workload", "example/new:image"); err != nil { + t.Fatalf("SetDeploymentImage() error = %v", err) + } + got, err := client.kube.AppsV1().Deployments("test").Get(context.Background(), "workload", metav1.GetOptions{}) + if err != nil { + t.Fatalf("get Deployment: %v", err) + } + container := got.Spec.Template.Spec.Containers[0] + assertHTTPProbe(t, "readiness", container.ReadinessProbe, tc.readiness, tc.port) + assertHTTPProbe(t, "liveness", container.LivenessProbe, tc.liveness, tc.port) + assertHTTPProbe(t, "startup", container.StartupProbe, tc.startup, tc.port) + }) + } +} + +func TestSetDeploymentImagePreservesExistingHealthProbes(t *testing.T) { + deployment := tuningTestDeployment("vta-7", "vta") + container := &deployment.Spec.Template.Spec.Containers[0] + container.Ports = []corev1.ContainerPort{{ContainerPort: 8100}} + container.ReadinessProbe = upgradeHTTPProbe("/operator-ready", 8100, 7, 4) + client := &Client{kube: fake.NewSimpleClientset(deployment)} + + if err := client.SetDeploymentImage(context.Background(), "test", "vta-7", "example/vta:new"); err != nil { + t.Fatalf("SetDeploymentImage() error = %v", err) + } + got, err := client.kube.AppsV1().Deployments("test").Get(context.Background(), "vta-7", metav1.GetOptions{}) + if err != nil { + t.Fatalf("get Deployment: %v", err) + } + probe := got.Spec.Template.Spec.Containers[0].ReadinessProbe + assertHTTPProbe(t, "readiness", probe, "/operator-ready", 8100) + if probe.PeriodSeconds != 7 || probe.FailureThreshold != 4 { + t.Fatalf("operator readiness timing changed: %+v", probe) + } +} + +func assertHTTPProbe(t *testing.T, name string, probe *corev1.Probe, path string, port int32) { + t.Helper() + if path == "" { + if probe != nil { + t.Fatalf("%s probe = %+v, want nil", name, probe) + } + return + } + if probe == nil || probe.HTTPGet == nil { + t.Fatalf("%s probe = %+v, want HTTP probe", name, probe) + } + if probe.HTTPGet.Path != path || probe.HTTPGet.Port.IntVal != port { + t.Fatalf("%s probe = %+v, want %s:%d", name, probe.HTTPGet, path, port) + } +} + func TestSetDeploymentImageAddsMissingVtaTuningEnv(t *testing.T) { for _, app := range []string{"vta", "fs-vta"} { t.Run(app, func(t *testing.T) { From 2bc23afd34cc3a2cd176eb2ed5e242c05577745d Mon Sep 17 00:00:00 2001 From: vthwang Date: Mon, 23 Nov 2026 11:45:18 -0800 Subject: [PATCH 3/3] fix: use dedicated workload probe endpoints Use the newly available readiness and liveness endpoints during creation and image upgrades. Preserve operator probes and restore legacy-compatible paths when a rollout is rolled back. Signed-off-by: vthwang --- internal/k8s/trust_registry_test.go | 2 +- internal/k8s/upgrade.go | 96 +++++++++++++++++++----- internal/k8s/upgrade_test.go | 78 ++++++++++++------- internal/k8s/vta_resources.go | 6 +- internal/k8s/vta_resources_test.go | 10 +-- internal/setup/orchestrator.go | 2 +- internal/setup/orchestrator_fullstack.go | 16 ++-- internal/setup/orchestrator_vtc.go | 8 +- internal/setup/trust_registry.go | 2 +- internal/upgrade/runner.go | 2 +- 10 files changed, 152 insertions(+), 70 deletions(-) diff --git a/internal/k8s/trust_registry_test.go b/internal/k8s/trust_registry_test.go index b2c6cb1..a395363 100644 --- a/internal/k8s/trust_registry_test.go +++ b/internal/k8s/trust_registry_test.go @@ -112,7 +112,7 @@ func TestRegistryJobRetryRetainsIdentityAndActiveJobs(t *testing.T) { func TestRegistryDeploymentKeepsCredentialInMemoryAndOutOfExports(t *testing.T) { kube := fake.NewSimpleClientset() client := &Client{kube: kube} - spec := ComponentDeploymentSpec{Name: "registry", Labels: map[string]string{"app": "registry"}, Image: "registry:image", ServiceAccount: VtaServiceAccount, Command: []string{"trust-registry"}, Port: 3232, ReadinessPath: "/health", LivenessPath: "/health", StartupPath: "/health", Recreate: true, + spec := ComponentDeploymentSpec{Name: "registry", Labels: map[string]string{"app": "registry"}, Image: "registry:image", ServiceAccount: VtaServiceAccount, Command: []string{"trust-registry"}, Port: 3232, ReadinessPath: "/readyz", LivenessPath: "/livez", StartupPath: "/livez", Recreate: true, Env: []corev1.EnvVar{{Name: "MEDIATOR_DID", Value: "did:webvh:mediator"}, {Name: "TR_VTA_CONTEXT_ID", Value: "registry-7"}, {Name: "TR_SECRETS_SEED", Value: "test-only-secret"}}, ExtraVolumes: []corev1.Volume{{Name: "credential", VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}}}}, ExtraMounts: []corev1.VolumeMount{{Name: "credential", MountPath: "/run/trust-registry", ReadOnly: true}}, diff --git a/internal/k8s/upgrade.go b/internal/k8s/upgrade.go index 8e44b49..cb59fe2 100644 --- a/internal/k8s/upgrade.go +++ b/internal/k8s/upgrade.go @@ -21,20 +21,31 @@ type upgradeProbePaths struct { startup string } -func upgradeProbePathsFor(app string) (upgradeProbePaths, bool) { +func currentProbePathsFor(app string) (upgradeProbePaths, bool) { switch app { - case "vta", "fs-vta", "fs-vtc", "fs-trust-registry": - return upgradeProbePaths{readiness: "/health", liveness: "/health", startup: "/health"}, true + case "vta", "fs-vta", "fs-vtc", "fs-trust-registry", "fs-dids": + return upgradeProbePaths{readiness: "/readyz", liveness: "/livez", startup: "/livez"}, true case "fs-mediator": return upgradeProbePaths{ readiness: "/mediator/v1/readyz", liveness: "/mediator/v1/livez", startup: "/mediator/v1/livez", }, true + default: + return upgradeProbePaths{}, false + } +} + +// rollbackProbePathsFor uses only endpoints available before the dedicated +// probes landed, so a failed new image can still roll back cleanly. +func rollbackProbePathsFor(app string) (upgradeProbePaths, bool) { + switch app { + case "vta", "fs-vta", "fs-vtc", "fs-trust-registry": + return upgradeProbePaths{readiness: "/health", liveness: "/health", startup: "/health"}, true case "fs-dids": - // DID Hosting's /health includes its store and own DID. It is valid - // readiness, but using it for liveness could create a restart loop. return upgradeProbePaths{readiness: "/health"}, true + case "fs-mediator": + return upgradeProbePaths{readiness: "/mediator/v1/readyz"}, true default: return upgradeProbePaths{}, false } @@ -55,27 +66,60 @@ func upgradeHTTPProbe(path string, port int32, period, failures int32) *corev1.P } } -// reconcileUpgradeHealthProbes fills probes missing from an older Deployment. -// Existing operator-supplied probes are preserved. -func reconcileUpgradeHealthProbes(deployment *appsv1.Deployment) { - paths, ok := upgradeProbePathsFor(deployment.Labels["app"]) +func isManagedHTTPProbe(probe *corev1.Probe, port, period, failures int32, paths ...string) bool { + if probe == nil || probe.HTTPGet == nil || probe.HTTPGet.Port.IntVal != port || + probe.PeriodSeconds != period || probe.TimeoutSeconds != 2 || + probe.FailureThreshold != failures { + return false + } + for _, path := range paths { + if path != "" && probe.HTTPGet.Path == path { + return true + } + } + return false +} + +func reconcileProbe( + probe **corev1.Probe, + desiredPath string, + port, period, failures int32, + managedPaths ...string, +) { + if *probe != nil && !isManagedHTTPProbe(*probe, port, period, failures, managedPaths...) { + return + } + *probe = upgradeHTTPProbe(desiredPath, port, period, failures) +} + +func reconcileHealthProbes(deployment *appsv1.Deployment, rollback bool) { + current, ok := currentProbePathsFor(deployment.Labels["app"]) if !ok || len(deployment.Spec.Template.Spec.Containers) == 0 { return } + legacy, _ := rollbackProbePathsFor(deployment.Labels["app"]) + desired := current + if rollback { + desired = legacy + } container := &deployment.Spec.Template.Spec.Containers[0] if len(container.Ports) == 0 { return } port := container.Ports[0].ContainerPort - if container.ReadinessProbe == nil { - container.ReadinessProbe = upgradeHTTPProbe(paths.readiness, port, 2, 3) - } - if container.LivenessProbe == nil { - container.LivenessProbe = upgradeHTTPProbe(paths.liveness, port, 10, 3) - } - if container.StartupProbe == nil { - container.StartupProbe = upgradeHTTPProbe(paths.startup, port, 2, 60) - } + reconcileProbe(&container.ReadinessProbe, desired.readiness, port, 2, 3, current.readiness, legacy.readiness) + reconcileProbe(&container.LivenessProbe, desired.liveness, port, 10, 3, current.liveness, legacy.liveness) + reconcileProbe(&container.StartupProbe, desired.startup, port, 2, 60, current.startup, legacy.startup) +} + +// reconcileUpgradeHealthProbes fills missing probes and migrates probes from +// the Farm's former `/health` policy. Other operator-supplied probes remain. +func reconcileUpgradeHealthProbes(deployment *appsv1.Deployment) { + reconcileHealthProbes(deployment, false) +} + +func reconcileRollbackHealthProbes(deployment *appsv1.Deployment) { + reconcileHealthProbes(deployment, true) } // VtaDeploymentName exposes vta_only's Deployment name (vta-) to @@ -94,6 +138,16 @@ func VtaDeploymentName(sessionID uint) string { // clears any rollingUpdate params, which the API server rejects alongside type // Recreate. func (c *Client) SetDeploymentImage(ctx context.Context, ns, name, image string) error { + return c.setDeploymentImage(ctx, ns, name, image, false) +} + +// RollbackDeploymentImage restores an older image with the legacy probe paths +// that image is guaranteed to expose. +func (c *Client) RollbackDeploymentImage(ctx context.Context, ns, name, image string) error { + return c.setDeploymentImage(ctx, ns, name, image, true) +} + +func (c *Client) setDeploymentImage(ctx context.Context, ns, name, image string, rollback bool) error { return retry.RetryOnConflict(retry.DefaultRetry, func() error { deploy, err := c.kube.AppsV1().Deployments(ns).Get(ctx, name, metav1.GetOptions{}) if err != nil { @@ -104,7 +158,11 @@ func (c *Client) SetDeploymentImage(ctx context.Context, ns, name, image string) deploy.Spec.Template.Spec.Containers[i].Image = image } reconcileTuningEnv(deploy) - reconcileUpgradeHealthProbes(deploy) + if rollback { + reconcileRollbackHealthProbes(deploy) + } else { + reconcileUpgradeHealthProbes(deploy) + } ensureMediatorVaultCA(deploy, image) _, err = c.kube.AppsV1().Deployments(ns).Update(ctx, deploy, metav1.UpdateOptions{}) return err diff --git a/internal/k8s/upgrade_test.go b/internal/k8s/upgrade_test.go index d776de6..5721bf3 100644 --- a/internal/k8s/upgrade_test.go +++ b/internal/k8s/upgrade_test.go @@ -70,42 +70,64 @@ func deploymentEnv(t *testing.T, client *Client, name string) map[string]string return env } -func TestSetDeploymentImageAddsMissingHealthProbes(t *testing.T) { +func TestImageUpgradeAndRollbackReconcileHealthProbes(t *testing.T) { cases := []struct { - app string - port int32 - readiness, liveness string - startup string + app string + port int32 + legacyReadiness, legacyLiveness string + legacyStartup string + currentReadiness, currentLiveness string + currentStartup string }{ - {app: "vta", port: 8100, readiness: "/health", liveness: "/health", startup: "/health"}, - {app: "fs-vta", port: 8100, readiness: "/health", liveness: "/health", startup: "/health"}, - {app: "fs-vtc", port: 8200, readiness: "/health", liveness: "/health", startup: "/health"}, - {app: "fs-trust-registry", port: 3232, readiness: "/health", liveness: "/health", startup: "/health"}, - {app: "fs-mediator", port: 7037, readiness: "/mediator/v1/readyz", liveness: "/mediator/v1/livez", startup: "/mediator/v1/livez"}, - {app: "fs-dids", port: 8534, readiness: "/health"}, + {app: "vta", port: 8100, legacyReadiness: "/health", legacyLiveness: "/health", legacyStartup: "/health", currentReadiness: "/readyz", currentLiveness: "/livez", currentStartup: "/livez"}, + {app: "fs-vta", port: 8100, legacyReadiness: "/health", legacyLiveness: "/health", legacyStartup: "/health", currentReadiness: "/readyz", currentLiveness: "/livez", currentStartup: "/livez"}, + {app: "fs-vtc", port: 8200, legacyReadiness: "/health", legacyLiveness: "/health", legacyStartup: "/health", currentReadiness: "/readyz", currentLiveness: "/livez", currentStartup: "/livez"}, + {app: "fs-trust-registry", port: 3232, legacyReadiness: "/health", legacyLiveness: "/health", legacyStartup: "/health", currentReadiness: "/readyz", currentLiveness: "/livez", currentStartup: "/livez"}, + {app: "fs-mediator", port: 7037, legacyReadiness: "/mediator/v1/readyz", currentReadiness: "/mediator/v1/readyz", currentLiveness: "/mediator/v1/livez", currentStartup: "/mediator/v1/livez"}, + {app: "fs-dids", port: 8534, legacyReadiness: "/health", currentReadiness: "/readyz", currentLiveness: "/livez", currentStartup: "/livez"}, } for _, tc := range cases { - t.Run(tc.app, func(t *testing.T) { - deployment := tuningTestDeployment("workload", tc.app) - deployment.Spec.Template.Spec.Containers[0].Ports = []corev1.ContainerPort{{ContainerPort: tc.port}} - client := &Client{kube: fake.NewSimpleClientset(deployment)} + for _, initial := range []string{"missing", "legacy"} { + t.Run(tc.app+"/"+initial, func(t *testing.T) { + deployment := tuningTestDeployment("workload", tc.app) + container := &deployment.Spec.Template.Spec.Containers[0] + container.Ports = []corev1.ContainerPort{{ContainerPort: tc.port}} + if initial == "legacy" { + container.ReadinessProbe = upgradeHTTPProbe(tc.legacyReadiness, tc.port, 2, 3) + container.LivenessProbe = upgradeHTTPProbe(tc.legacyLiveness, tc.port, 10, 3) + container.StartupProbe = upgradeHTTPProbe(tc.legacyStartup, tc.port, 2, 60) + } + client := &Client{kube: fake.NewSimpleClientset(deployment)} - if err := client.SetDeploymentImage(context.Background(), "test", "workload", "example/new:image"); err != nil { - t.Fatalf("SetDeploymentImage() error = %v", err) - } - got, err := client.kube.AppsV1().Deployments("test").Get(context.Background(), "workload", metav1.GetOptions{}) - if err != nil { - t.Fatalf("get Deployment: %v", err) - } - container := got.Spec.Template.Spec.Containers[0] - assertHTTPProbe(t, "readiness", container.ReadinessProbe, tc.readiness, tc.port) - assertHTTPProbe(t, "liveness", container.LivenessProbe, tc.liveness, tc.port) - assertHTTPProbe(t, "startup", container.StartupProbe, tc.startup, tc.port) - }) + if err := client.SetDeploymentImage(context.Background(), "test", "workload", "example/new:image"); err != nil { + t.Fatalf("SetDeploymentImage() error = %v", err) + } + got, err := client.kube.AppsV1().Deployments("test").Get(context.Background(), "workload", metav1.GetOptions{}) + if err != nil { + t.Fatalf("get Deployment: %v", err) + } + container = &got.Spec.Template.Spec.Containers[0] + assertHTTPProbe(t, "readiness", container.ReadinessProbe, tc.currentReadiness, tc.port) + assertHTTPProbe(t, "liveness", container.LivenessProbe, tc.currentLiveness, tc.port) + assertHTTPProbe(t, "startup", container.StartupProbe, tc.currentStartup, tc.port) + + if err := client.RollbackDeploymentImage(context.Background(), "test", "workload", "example/old:image"); err != nil { + t.Fatalf("RollbackDeploymentImage() error = %v", err) + } + got, err = client.kube.AppsV1().Deployments("test").Get(context.Background(), "workload", metav1.GetOptions{}) + if err != nil { + t.Fatalf("get rolled-back Deployment: %v", err) + } + container = &got.Spec.Template.Spec.Containers[0] + assertHTTPProbe(t, "rollback readiness", container.ReadinessProbe, tc.legacyReadiness, tc.port) + assertHTTPProbe(t, "rollback liveness", container.LivenessProbe, tc.legacyLiveness, tc.port) + assertHTTPProbe(t, "rollback startup", container.StartupProbe, tc.legacyStartup, tc.port) + }) + } } } -func TestSetDeploymentImagePreservesExistingHealthProbes(t *testing.T) { +func TestSetDeploymentImagePreservesOperatorHealthProbes(t *testing.T) { deployment := tuningTestDeployment("vta-7", "vta") container := &deployment.Spec.Template.Spec.Containers[0] container.Ports = []corev1.ContainerPort{{ContainerPort: 8100}} diff --git a/internal/k8s/vta_resources.go b/internal/k8s/vta_resources.go index ad2628b..fbf12f2 100644 --- a/internal/k8s/vta_resources.go +++ b/internal/k8s/vta_resources.go @@ -587,7 +587,7 @@ func (c *Client) createVtaDeployment(ctx context.Context, ns string, sessionID u ReadinessProbe: &corev1.Probe{ ProbeHandler: corev1.ProbeHandler{ HTTPGet: &corev1.HTTPGetAction{ - Path: "/health", + Path: "/readyz", Port: intstr.FromInt32(port), }, }, @@ -597,7 +597,7 @@ func (c *Client) createVtaDeployment(ctx context.Context, ns string, sessionID u }, LivenessProbe: &corev1.Probe{ ProbeHandler: corev1.ProbeHandler{HTTPGet: &corev1.HTTPGetAction{ - Path: "/health", + Path: "/livez", Port: intstr.FromInt32(port), }}, PeriodSeconds: 10, @@ -606,7 +606,7 @@ func (c *Client) createVtaDeployment(ctx context.Context, ns string, sessionID u }, StartupProbe: &corev1.Probe{ ProbeHandler: corev1.ProbeHandler{HTTPGet: &corev1.HTTPGetAction{ - Path: "/health", + Path: "/livez", Port: intstr.FromInt32(port), }}, PeriodSeconds: 2, diff --git a/internal/k8s/vta_resources_test.go b/internal/k8s/vta_resources_test.go index 399dec4..d7432f9 100644 --- a/internal/k8s/vta_resources_test.go +++ b/internal/k8s/vta_resources_test.go @@ -20,7 +20,7 @@ import ( const testActivationID = "00112233445566778899aabbccddeeff" -func TestCreateVtaDeploymentUsesHealthReadinessProbe(t *testing.T) { +func TestCreateVtaDeploymentUsesDedicatedHealthProbes(t *testing.T) { client := &Client{kube: fake.NewSimpleClientset()} if err := client.CreateVtaDeployment(context.Background(), "test", 42, "example/vta:test", ComponentResources("10m", "32Mi", "128Mi")); err != nil { @@ -45,8 +45,8 @@ func TestCreateVtaDeploymentUsesHealthReadinessProbe(t *testing.T) { if probe == nil || probe.HTTPGet == nil { t.Fatal("readiness probe is not an HTTP probe") } - if probe.HTTPGet.Path != "/health" { - t.Fatalf("readiness path = %q, want /health", probe.HTTPGet.Path) + if probe.HTTPGet.Path != "/readyz" { + t.Fatalf("readiness path = %q, want /readyz", probe.HTTPGet.Path) } if probe.HTTPGet.Port.IntVal != 8100 { t.Fatalf("readiness port = %d, want 8100", probe.HTTPGet.Port.IntVal) @@ -56,12 +56,12 @@ func TestCreateVtaDeploymentUsesHealthReadinessProbe(t *testing.T) { t.Fatalf("unexpected readiness timing: %+v", probe) } liveness := deployment.Spec.Template.Spec.Containers[0].LivenessProbe - if liveness == nil || liveness.HTTPGet == nil || liveness.HTTPGet.Path != "/health" || + if liveness == nil || liveness.HTTPGet == nil || liveness.HTTPGet.Path != "/livez" || liveness.PeriodSeconds != 10 || liveness.TimeoutSeconds != 2 || liveness.FailureThreshold != 3 { t.Fatalf("unexpected liveness probe: %+v", liveness) } startup := deployment.Spec.Template.Spec.Containers[0].StartupProbe - if startup == nil || startup.HTTPGet == nil || startup.HTTPGet.Path != "/health" || + if startup == nil || startup.HTTPGet == nil || startup.HTTPGet.Path != "/livez" || startup.PeriodSeconds != 2 || startup.TimeoutSeconds != 2 || startup.FailureThreshold != 60 { t.Fatalf("unexpected startup probe: %+v", startup) } diff --git a/internal/setup/orchestrator.go b/internal/setup/orchestrator.go index b2bffba..c1bd488 100644 --- a/internal/setup/orchestrator.go +++ b/internal/setup/orchestrator.go @@ -552,7 +552,7 @@ func (o *Orchestrator) deployVtaOnly(ctx context.Context, ns string, session *mo } // A Deployment exists before the VTA has finished initializing. Its - // /health readiness probe is the serving boundary: do not advertise this + // /readyz readiness probe is the serving boundary: do not advertise this // session as running until Kubernetes confirms at least one ready replica. if err := o.k8s.WaitForComponentDeploymentReady( ctx, ns, k8s.VtaDeploymentName(session.ID), 2*time.Minute, diff --git a/internal/setup/orchestrator_fullstack.go b/internal/setup/orchestrator_fullstack.go index 2467bff..184e00c 100644 --- a/internal/setup/orchestrator_fullstack.go +++ b/internal/setup/orchestrator_fullstack.go @@ -1073,8 +1073,8 @@ func (o *Orchestrator) fsStepVtaRegisterDids(ctx context.Context, ns string, s * // its Vault-backed secrets at every boot. Waits for the pod to actually // become Ready before returning: step_vta_register_dids (right after // deploy_mediator) live-resolves this daemon's DID over HTTPS, so a -// Deployment object existing isn't enough. The daemon's /health endpoint -// proves its HTTP listener and combined service router are serving. +// Deployment object existing isn't enough. The daemon's /readyz endpoint +// proves its HTTP listener and required stores are ready to serve. func (o *Orchestrator) fsDeployDids(ctx context.Context, ns string, s *model.SetupSession) error { profiles, err := resourceprofile.Load(ctx, o.db) if err != nil { @@ -1093,7 +1093,9 @@ func (o *Orchestrator) fsDeployDids(ctx context.Context, ns string, s *model.Set Labels: fsLabels("dids", s.ID), PlacementMode: k8s.PlacementModeFullStack, Component: k8s.ComponentDids, - ReadinessPath: "/health", + ReadinessPath: "/readyz", + LivenessPath: "/livez", + StartupPath: "/livez", Resources: profiles.Requirements(k8s.ComponentDids), }); err != nil { return err @@ -1177,7 +1179,7 @@ func (o *Orchestrator) fsStepImportAdminDid(ctx context.Context, ns string, s *m // full_stack's step_vtc_setup makes live calls against it right // after, so the deploy_* invariant (returns only once the component is // actually up) matters here too. ReadinessPath wires a readinessProbe -// against GET /health (vta-service's unauthenticated health route) — without +// against GET /readyz (vta-service's unauthenticated readiness route) — without // it, Kubernetes marks the pod Ready the instant the container starts, // before the HTTP listener is serving, so WaitForComponentDeploymentReady // below returned almost instantly and the next setup step raced the listener. @@ -1199,9 +1201,9 @@ func (o *Orchestrator) fsDeployVta(ctx context.Context, ns string, s *model.Setu Labels: fsLabels("vta", s.ID), PlacementMode: k8s.PlacementModeFullStack, Component: k8s.ComponentVTA, - ReadinessPath: "/health", - LivenessPath: "/health", - StartupPath: "/health", + ReadinessPath: "/readyz", + LivenessPath: "/livez", + StartupPath: "/livez", Resources: profiles.Requirements(k8s.ComponentVTA), }); err != nil { return err diff --git a/internal/setup/orchestrator_vtc.go b/internal/setup/orchestrator_vtc.go index f88f627..734f3df 100644 --- a/internal/setup/orchestrator_vtc.go +++ b/internal/setup/orchestrator_vtc.go @@ -254,7 +254,7 @@ func (o *Orchestrator) fsStepVtcSetup(ctx context.Context, ns string, s *model.S // /work/vtc with workingDir to match — the same layout every other // component uses — so vtc resolves its relative config.toml and data_dir // onto what step_vtc_setup/step_vtc_setup_key wrote. The unauthenticated -// /health probe confirms the HTTP listener is serving before the full stack +// /readyz probe confirms the service is ready before the full stack // can be marked running. Runs as SA vta — it reads its Vault key bundle at // every boot. func (o *Orchestrator) fsDeployVtc(ctx context.Context, ns string, s *model.SetupSession) error { @@ -275,9 +275,9 @@ func (o *Orchestrator) fsDeployVtc(ctx context.Context, ns string, s *model.Setu Labels: fsLabels("vtc", s.ID), PlacementMode: k8s.PlacementModeFullStack, Component: k8s.ComponentVTC, - ReadinessPath: "/health", - LivenessPath: "/health", - StartupPath: "/health", + ReadinessPath: "/readyz", + LivenessPath: "/livez", + StartupPath: "/livez", Resources: profiles.Requirements(k8s.ComponentVTC), }); err != nil { return err diff --git a/internal/setup/trust_registry.go b/internal/setup/trust_registry.go index 484da8b..cbb413c 100644 --- a/internal/setup/trust_registry.go +++ b/internal/setup/trust_registry.go @@ -313,7 +313,7 @@ func (o *Orchestrator) deployTrustRegistry(ctx context.Context, ns string, s *mo Name: name, Image: s.TrustRegistryImage, Command: []string{"trust-registry"}, WorkingDir: "/work/trust-registry", ServiceAccount: k8s.VtaServiceAccount, Env: env, - Port: 3232, ReadinessPath: "/health", LivenessPath: "/health", StartupPath: "/health", Labels: labels, + Port: 3232, ReadinessPath: "/readyz", LivenessPath: "/livez", StartupPath: "/livez", Labels: labels, PlacementMode: k8s.PlacementModeFullStack, Component: k8s.ComponentTrustRegistry, Resources: profiles.Requirements(k8s.ComponentTrustRegistry), PVCMounts: []k8s.PVCMount{{Name: "registry-data", ClaimName: name, MountPath: "/work/trust-registry"}}, diff --git a/internal/upgrade/runner.go b/internal/upgrade/runner.go index f33d451..2fc0899 100644 --- a/internal/upgrade/runner.go +++ b/internal/upgrade/runner.go @@ -268,7 +268,7 @@ func (r *Runner) rollbackTask(batch *model.UpgradeBatch, task *model.UpgradeTask r.setTask(task, model.UpgradeTaskRollbackFailed, cause+"; rollback failed: previous image is missing") return } - if err := r.k8s.SetDeploymentImage(ctx, ns, deployName, task.FromImage); err != nil { + if err := r.k8s.RollbackDeploymentImage(ctx, ns, deployName, task.FromImage); err != nil { r.setTask(task, model.UpgradeTaskRollbackFailed, cause+"; rollback failed: "+err.Error()) return }