Skip to content

Commit

Permalink
fix the panic of cli
Browse files Browse the repository at this point in the history
Signed-off-by: maanugh <[email protected]>
  • Loading branch information
maanugh committed Nov 1, 2024
1 parent 4d602ca commit c452f61
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions pkg/cmd/describe/describe_rollout.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ func NewCmdDescribeRollout(f cmdutil.Factory, streams genericclioptions.IOStream
Aliases: []string{"rollouts", "ro"},
Run: func(cmd *cobra.Command, args []string) {
cmdutil.CheckErr(o.Complete(f, args))
cmdutil.CheckErr(o.Validate())
cmdutil.CheckErr(o.Run())
},
}
Expand All @@ -127,6 +126,10 @@ func NewCmdDescribeRollout(f cmdutil.Factory, streams genericclioptions.IOStream
func (o *DescribeRolloutOptions) Complete(f cmdutil.Factory, args []string) error {
var err error

if len(args) == 0 {
return fmt.Errorf("required rollout name not specified")
}

o.Resources = args
o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()

Expand Down Expand Up @@ -157,13 +160,6 @@ func (o *DescribeRolloutOptions) Complete(f cmdutil.Factory, args []string) erro
return nil
}

func (o *DescribeRolloutOptions) Validate() error {
if len(o.Resources) == 0 {
return fmt.Errorf("required rollout name is not specified")
}
return nil
}

func (o *DescribeRolloutOptions) Run() error {
rolloutName := o.Resources[0]

Expand Down Expand Up @@ -334,12 +330,17 @@ func (o *DescribeRolloutOptions) GetResources(rollout *rolloutsapi.Rollout) (*Wo
labelSelectorParam = "controller-revision-hash"
}

SelectorParam := rollout.Status.CanaryStatus.PodTemplateHash
if SelectorParam == "" {
SelectorParam = rollout.Status.CanaryStatus.StableRevision
}

// Fetch pods
r2 := o.Builder().
WithScheme(internalapi.GetScheme(), scheme.Scheme.PrioritizedVersionsAllGroups()...).
NamespaceParam(o.Namespace).DefaultNamespace().
ResourceTypes("pods").
LabelSelectorParam(fmt.Sprintf("%s=%s", labelSelectorParam, rollout.Status.CanaryStatus.PodTemplateHash)).
LabelSelectorParam(fmt.Sprintf("%s=%s", labelSelectorParam, SelectorParam)).
Latest().
Flatten().
Do()
Expand Down

0 comments on commit c452f61

Please sign in to comment.