[k8s, k8s multicluster plugin] Implement health state for statefulset#6273
Merged
Conversation
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6273 +/- ##
==========================================
+ Coverage 28.72% 28.78% +0.05%
==========================================
Files 560 560
Lines 59749 59813 +64
==========================================
+ Hits 17165 17215 +50
- Misses 41265 41279 +14
Partials 1319 1319
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ffjlabo
commented
Sep 25, 2025
Comment on lines
+76
to
+106
| func statefulSetHealthStatus(obj *appsv1.StatefulSet) (sdk.ResourceHealthStatus, string) { | ||
| // Referred to: | ||
| // https://github.com/kubernetes/kubernetes/blob/7942dca975b7be9386540df3c17e309c3cb2de60/staging/src/k8s.io/kubectl/pkg/polymorphichelpers/rollout_status.go#L130-L149 | ||
| if obj.Status.ObservedGeneration == 0 || obj.Generation > obj.Status.ObservedGeneration { | ||
| return sdk.ResourceHealthStateUnhealthy, "Waiting for statefulset spec update to be observed" | ||
| } | ||
|
|
||
| if obj.Spec.Replicas == nil { | ||
| return sdk.ResourceHealthStateUnhealthy, "The number of desired replicas is unspecified" | ||
| } | ||
| if *obj.Spec.Replicas != obj.Status.ReadyReplicas { | ||
| return sdk.ResourceHealthStateUnhealthy, fmt.Sprintf("The number of ready replicas (%d) is different from the desired number (%d)", obj.Status.ReadyReplicas, *obj.Spec.Replicas) | ||
| } | ||
|
|
||
| // Check if the partitioned roll out is in progress. | ||
| if obj.Spec.UpdateStrategy.Type == appsv1.RollingUpdateStatefulSetStrategyType && obj.Spec.UpdateStrategy.RollingUpdate != nil { | ||
| if obj.Spec.Replicas != nil && obj.Spec.UpdateStrategy.RollingUpdate.Partition != nil { | ||
| if obj.Status.UpdatedReplicas < (*obj.Spec.Replicas - *obj.Spec.UpdateStrategy.RollingUpdate.Partition) { | ||
| return sdk.ResourceHealthStateUnhealthy, fmt.Sprintf("Waiting for partitioned roll out to finish because %d out of %d new pods have been updated", | ||
| obj.Status.UpdatedReplicas, (*obj.Spec.Replicas - *obj.Spec.UpdateStrategy.RollingUpdate.Partition)) | ||
| } | ||
| } | ||
| return sdk.ResourceHealthStateHealthy, "" | ||
| } | ||
|
|
||
| if obj.Status.UpdateRevision != obj.Status.CurrentRevision { | ||
| return sdk.ResourceHealthStateUnhealthy, fmt.Sprintf("Waiting for statefulset rolling update to complete %d pods at revision %s", obj.Status.UpdatedReplicas, obj.Status.UpdateRevision) | ||
| } | ||
|
|
||
| return sdk.ResourceHealthStateHealthy, "" | ||
| } |
Member
Author
There was a problem hiding this comment.
reference implementation:
pipecd/pkg/app/piped/platformprovider/kubernetes/state.go
Lines 200 to 246 in 24cb1ad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does:
as title
Implemented the health status for statefulset with reference to
determineStatefulSetHealthin pipedv0. This is almost all the same logic.pipecd/pkg/app/piped/platformprovider/kubernetes/state.go
Lines 200 to 246 in 24cb1ad
Notable policy
The health status in pipedv0 is associated with it in pipedv1, like the table below.
Why we need it:
We want to support the health status for statefulset
Which issue(s) this PR fixes:
Part of #5764
Does this PR introduce a user-facing change?: