Skip to content

Commit

Permalink
fix: specifying namespace on ops cmds. (#490)
Browse files Browse the repository at this point in the history
(cherry picked from commit 0c1c1e3)
  • Loading branch information
yipeng1030 committed Nov 19, 2024
1 parent a8b97a0 commit 1c85bad
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions pkg/cmd/cluster/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func newBaseOperationsOptions(f cmdutil.Factory, streams genericiooptions.IOStre
HasComponentNamesFlag: hasComponentNamesFlag,
AutoApprove: false,
CreateOptions: action.CreateOptions{
Factory: getFactory(f),
Factory: f,
IOStreams: streams,
CueTemplateName: "cluster_operations_template.cue",
GVR: types.OpsGVR(),
Expand All @@ -148,18 +148,6 @@ func newBaseOperationsOptions(f cmdutil.Factory, streams genericiooptions.IOStre
return o
}

// getFactory get a new factory when given factory isn't a TestFactory.
func getFactory(f cmdutil.Factory) cmdutil.Factory {
if factory, ok := f.(*testing.TestFactory); ok {
return factory
} else {
kubeConfigFlags := genericclioptions.NewConfigFlags(true)
matchVersionKubeConfigFlags := cmdutil.NewMatchVersionFlags(kubeConfigFlags)
newFactory := cmdutil.NewFactory(matchVersionKubeConfigFlags)
return newFactory
}
}

// addCommonFlags adds common flags for operations command
func (o *OperationsOptions) addCommonFlags(cmd *cobra.Command, f cmdutil.Factory) {
o.AddCommonFlags(cmd)
Expand Down Expand Up @@ -1083,8 +1071,20 @@ func buildCustomOpsExamples(t unstructured.Unstructured) string {
return templates.Examples(baseCommand)
}

// getTempFactory get a new factory when given factory isn't a TestFactory.
func getTempFactory(f cmdutil.Factory) cmdutil.Factory {
if factory, ok := f.(*testing.TestFactory); ok {
return factory
} else {
kubeConfigFlags := genericclioptions.NewConfigFlags(true)
matchVersionKubeConfigFlags := cmdutil.NewMatchVersionFlags(kubeConfigFlags)
newFactory := cmdutil.NewFactory(matchVersionKubeConfigFlags)
return newFactory
}
}

func buildCustomOpsCmds(option *OperationsOptions) []*cobra.Command {
dynamic, _ := option.Factory.DynamicClient()
dynamic, _ := getTempFactory(option.Factory).DynamicClient()
opsDefs, _ := dynamic.Resource(types.OpsDefinitionGVR()).List(context.TODO(), metav1.ListOptions{})
if opsDefs == nil {
return nil
Expand Down

0 comments on commit 1c85bad

Please sign in to comment.