Merge pull request #2175 from lonelyCZ/pr-check-cluster

karmadactl exec: check if --cluster specify
This commit is contained in:
karmada-bot 2022-07-12 17:20:36 +08:00 committed by GitHub
commit 156a02a452
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 0 deletions

View File

@ -98,15 +98,21 @@ type ExecOptions struct {
// Complete verifies command line arguments and loads data from the command environment
func (o *ExecOptions) Complete(karmadaConfig KarmadaConfig, cmd *cobra.Command, argsIn []string, argsLenAtDash int) error {
if len(o.Cluster) == 0 {
return fmt.Errorf("must specify a cluster")
}
karmadaRestConfig, err := karmadaConfig.GetRestConfig(o.KarmadaContext, o.KubeConfig)
if err != nil {
return fmt.Errorf("failed to get control plane rest config. context: %s, kube-config: %s, error: %v",
o.KarmadaContext, o.KubeConfig, err)
}
clusterInfo, err := getClusterInfo(karmadaRestConfig, o.Cluster, o.KubeConfig, o.KarmadaContext)
if err != nil {
return err
}
f := getFactory(o.Cluster, clusterInfo, o.Namespace)
return o.KubectlExecOptions.Complete(f, cmd, argsIn, argsLenAtDash)
}