feat: show pods related to current step of the Rollout in describe cmd (#111)

* feat: show pods related to current step of the Rollout in describe cmd

Signed-off-by: maanugh <manusin46@gmail.com>
This commit is contained in:
Kiraat 2025-01-29 19:32:58 -05:00 committed by GitHub
parent 2d0a16f996
commit f422c7d1cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 34 additions and 19 deletions

View File

@ -75,6 +75,7 @@ type DescribeRolloutOptions struct {
RolloutViewerFn func(runtime.Object) (interface{}, error) RolloutViewerFn func(runtime.Object) (interface{}, error)
Watch bool Watch bool
NoColor bool NoColor bool
All bool
TimeoutSeconds int TimeoutSeconds int
RolloutsV1beta1Client rolloutsv1beta1types.RolloutInterface RolloutsV1beta1Client rolloutsv1beta1types.RolloutInterface
RolloutsV1alpha1Client rolloutv1alpha1types.RolloutInterface RolloutsV1alpha1Client rolloutv1alpha1types.RolloutInterface
@ -136,6 +137,7 @@ func NewCmdDescribeRollout(f cmdutil.Factory, streams genericclioptions.IOStream
cmd.Flags().BoolVarP(&o.Watch, "watch", "w", false, "Watch for changes to the rollout") cmd.Flags().BoolVarP(&o.Watch, "watch", "w", false, "Watch for changes to the rollout")
cmd.Flags().BoolVar(&o.NoColor, "no-color", false, "If true, print output without color") cmd.Flags().BoolVar(&o.NoColor, "no-color", false, "If true, print output without color")
cmd.Flags().IntVar(&o.TimeoutSeconds, "timeout", 0, "Timeout after specified seconds") cmd.Flags().IntVar(&o.TimeoutSeconds, "timeout", 0, "Timeout after specified seconds")
cmd.Flags().BoolVar(&o.All, "all", false, "Show all pods in the rollout")
return cmd return cmd
} }
@ -288,11 +290,12 @@ func (o *DescribeRolloutOptions) clearScreen() {
} }
type RolloutWorkloadRef struct { type RolloutWorkloadRef struct {
Kind string Kind string
Name string Name string
StableRevision string StableRevision string
CanaryRevision string CanaryRevision string
PodTemplateHash string PodTemplateHash string
CurrentStepIndex int32
} }
func (o *DescribeRolloutOptions) GetResources(rollout RolloutWorkloadRef) (*WorkloadInfo, error) { func (o *DescribeRolloutOptions) GetResources(rollout RolloutWorkloadRef) (*WorkloadInfo, error) {
@ -375,9 +378,19 @@ func (o *DescribeRolloutOptions) GetResources(rollout RolloutWorkloadRef) (*Work
labelSelectorParam = "controller-revision-hash" labelSelectorParam = "controller-revision-hash"
} }
SelectorParam := rollout.PodTemplateHash selectorParam := rollout.PodTemplateHash
if SelectorParam == "" { if selectorParam == "" {
SelectorParam = rollout.StableRevision selectorParam = rollout.StableRevision
}
labelSelectors := []string{
fmt.Sprintf("%s=%s", labelSelectorParam, selectorParam),
}
if !o.All && rollout.CurrentStepIndex != 0 {
labelSelectors = append(labelSelectors,
fmt.Sprintf("rollouts.kruise.io/rollout-batch-id=%v",
rollout.CurrentStepIndex))
} }
// Fetch pods // Fetch pods
@ -385,7 +398,7 @@ func (o *DescribeRolloutOptions) GetResources(rollout RolloutWorkloadRef) (*Work
WithScheme(internalapi.GetScheme(), scheme.Scheme.PrioritizedVersionsAllGroups()...). WithScheme(internalapi.GetScheme(), scheme.Scheme.PrioritizedVersionsAllGroups()...).
NamespaceParam(o.Namespace).DefaultNamespace(). NamespaceParam(o.Namespace).DefaultNamespace().
ResourceTypes("pods"). ResourceTypes("pods").
LabelSelectorParam(fmt.Sprintf("%s=%s", labelSelectorParam, SelectorParam)). LabelSelectorParam(strings.Join(labelSelectors, ",")).
Latest(). Latest().
Flatten(). Flatten().
Do() Do()
@ -543,11 +556,12 @@ func extractRolloutInfo(obj interface{}) *RolloutInfo {
info.CurrentStepIndex = r.Status.CanaryStatus.CurrentStepIndex info.CurrentStepIndex = r.Status.CanaryStatus.CurrentStepIndex
info.CurrentStepState = string(r.Status.CanaryStatus.CurrentStepState) info.CurrentStepState = string(r.Status.CanaryStatus.CurrentStepState)
info.WorkloadRef = RolloutWorkloadRef{ info.WorkloadRef = RolloutWorkloadRef{
Kind: r.Spec.WorkloadRef.Kind, Kind: r.Spec.WorkloadRef.Kind,
Name: r.Spec.WorkloadRef.Name, Name: r.Spec.WorkloadRef.Name,
StableRevision: r.Status.CanaryStatus.StableRevision, StableRevision: r.Status.CanaryStatus.StableRevision,
CanaryRevision: r.Status.CanaryStatus.CanaryRevision, CanaryRevision: r.Status.CanaryStatus.CanaryRevision,
PodTemplateHash: r.Status.CanaryStatus.PodTemplateHash, PodTemplateHash: r.Status.CanaryStatus.PodTemplateHash,
CurrentStepIndex: r.Status.CanaryStatus.CurrentStepIndex,
} }
if r.Spec.Strategy.Canary != nil { if r.Spec.Strategy.Canary != nil {
@ -564,11 +578,12 @@ func extractRolloutInfo(obj interface{}) *RolloutInfo {
info.CurrentStepIndex = r.Status.CanaryStatus.CurrentStepIndex info.CurrentStepIndex = r.Status.CanaryStatus.CurrentStepIndex
info.CurrentStepState = string(r.Status.CanaryStatus.CurrentStepState) info.CurrentStepState = string(r.Status.CanaryStatus.CurrentStepState)
info.WorkloadRef = RolloutWorkloadRef{ info.WorkloadRef = RolloutWorkloadRef{
Kind: r.Spec.ObjectRef.WorkloadRef.Kind, Kind: r.Spec.ObjectRef.WorkloadRef.Kind,
Name: r.Spec.ObjectRef.WorkloadRef.Name, Name: r.Spec.ObjectRef.WorkloadRef.Name,
StableRevision: r.Status.CanaryStatus.StableRevision, StableRevision: r.Status.CanaryStatus.StableRevision,
CanaryRevision: r.Status.CanaryStatus.CanaryRevision, CanaryRevision: r.Status.CanaryStatus.CanaryRevision,
PodTemplateHash: r.Status.CanaryStatus.PodTemplateHash, PodTemplateHash: r.Status.CanaryStatus.PodTemplateHash,
CurrentStepIndex: r.Status.CanaryStatus.CurrentStepIndex,
} }
if r.Spec.Strategy.Canary != nil { if r.Spec.Strategy.Canary != nil {