Refactor cmd global variables into structs
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
This commit is contained in:
@@ -48,17 +48,17 @@ func init() {
|
||||
}
|
||||
|
||||
func getKsCmdRun(cmd *cobra.Command, args []string) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||
defer cancel()
|
||||
|
||||
kubeClient, err := utils.KubeClient(kubeconfig, kubecontext)
|
||||
kubeClient, err := utils.KubeClient(rootArgs.kubeconfig, rootArgs.kubecontext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var listOpts []client.ListOption
|
||||
if !allNamespaces {
|
||||
listOpts = append(listOpts, client.InNamespace(namespace))
|
||||
if !getArgs.allNamespaces {
|
||||
listOpts = append(listOpts, client.InNamespace(rootArgs.namespace))
|
||||
}
|
||||
var list kustomizev1.KustomizationList
|
||||
err = kubeClient.List(ctx, &list, listOpts...)
|
||||
@@ -67,12 +67,12 @@ func getKsCmdRun(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if len(list.Items) == 0 {
|
||||
logger.Failuref("no kustomizations found in %s namespace", namespace)
|
||||
logger.Failuref("no kustomizations found in %s namespace", rootArgs.namespace)
|
||||
return nil
|
||||
}
|
||||
|
||||
header := []string{"Name", "Ready", "Message", "Revision", "Suspended"}
|
||||
if allNamespaces {
|
||||
if getArgs.allNamespaces {
|
||||
header = append([]string{"Namespace"}, header...)
|
||||
}
|
||||
var rows [][]string
|
||||
@@ -95,7 +95,7 @@ func getKsCmdRun(cmd *cobra.Command, args []string) error {
|
||||
strings.Title(strconv.FormatBool(kustomization.Spec.Suspend)),
|
||||
}
|
||||
}
|
||||
if allNamespaces {
|
||||
if getArgs.allNamespaces {
|
||||
row = append([]string{kustomization.Namespace}, row...)
|
||||
}
|
||||
rows = append(rows, row)
|
||||
|
||||
Reference in New Issue
Block a user