Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: error while run command against wrong cluser #283

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions pkg/cmd/accept/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@ import (
"strings"
"time"

"github.com/spf13/cobra"
certificatesv1 "k8s.io/api/certificates/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"k8s.io/klog/v2"
"open-cluster-management.io/clusteradm/pkg/helpers"

"github.com/spf13/cobra"
certificatesv1 "k8s.io/api/certificates/v1"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
clusterclientset "open-cluster-management.io/api/client/cluster/clientset/versioned"
"open-cluster-management.io/clusteradm/pkg/helpers"
)

const (
Expand Down Expand Up @@ -52,6 +51,11 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
}

func (o *Options) Validate() error {
err := o.ClusteradmFlags.ValidateHub()
if err != nil {
return err
}

return nil
}

Expand Down
9 changes: 7 additions & 2 deletions pkg/cmd/addon/disable/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (
"context"
"fmt"

"k8s.io/apimachinery/pkg/api/errors"

"github.com/spf13/cobra"
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/dynamic"
Expand All @@ -26,6 +25,11 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
}

func (o *Options) Validate() (err error) {
err = o.ClusteradmFlags.ValidateHub()
if err != nil {
return err
}

if len(o.Names) == 0 {
return fmt.Errorf("names is missing")
}
Expand All @@ -37,6 +41,7 @@ func (o *Options) Validate() (err error) {
if o.Allclusters && len(o.Clusters) != 0 {
return fmt.Errorf("flag --all-clusters and --clusters can not be set together")
}

return nil
}

Expand Down
12 changes: 8 additions & 4 deletions pkg/cmd/addon/enable/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import (
"strings"

"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"

"github.com/stolostron/applier/pkg/apply"
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"k8s.io/klog/v2"
clusterclientset "open-cluster-management.io/api/client/cluster/clientset/versioned"
"open-cluster-management.io/clusteradm/pkg/cmd/addon/enable/scenario"
"open-cluster-management.io/clusteradm/pkg/helpers"
Expand Down Expand Up @@ -52,7 +51,12 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
return nil
}

func (o *Options) Validate() error {
func (o *Options) Validate() (err error) {
err = o.ClusteradmFlags.ValidateHub()
if err != nil {
return err
}

if len(o.Names) == 0 {
return fmt.Errorf("names is missing")
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/cmd/clean/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import (
"log"
"time"

clustermanagerclient "open-cluster-management.io/api/client/operator/clientset/versioned"
"open-cluster-management.io/clusteradm/pkg/helpers"

"github.com/spf13/cobra"

apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -21,6 +17,8 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/util/retry"
"k8s.io/klog/v2"
clustermanagerclient "open-cluster-management.io/api/client/operator/clientset/versioned"
"open-cluster-management.io/clusteradm/pkg/helpers"
)

func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
Expand Down
6 changes: 6 additions & 0 deletions pkg/cmd/clusterset/bind/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
}

func (o *Options) Validate() (err error) {
err = o.ClusteradmFlags.ValidateHub()
if err != nil {
return err
}

if len(o.Namespace) == 0 {
return fmt.Errorf("namespace name must be specified in --namespace")
}

return nil
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/cmd/clusterset/set/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
}

func (o *Options) Validate() (err error) {
err = o.ClusteradmFlags.ValidateHub()
if err != nil {
return err
}

if len(o.Clusters) == 0 {
return fmt.Errorf("cluster name must be specified in --clusters")
}

return nil
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/cmd/clusterset/unbind/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
}

func (o *Options) Validate() (err error) {
err = o.ClusteradmFlags.ValidateHub()
if err != nil {
return err
}

if len(o.Namespace) == 0 {
return fmt.Errorf("namespace name must be specified in --namespace")
}

return nil
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/cmd/create/clusterset/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,24 @@ import (
)

func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {

o.Clustersets = args

return nil
}

func (o *Options) Validate() (err error) {
err = o.ClusteradmFlags.ValidateHub()
if err != nil {
return err
}

if len(o.Clustersets) == 0 {
return fmt.Errorf("the name of the clusterset must be specified")
}
if len(o.Clustersets) > 1 {
return fmt.Errorf("only one clusterset can be created")
}

return nil
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/create/sampleapp/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
}

func (o *Options) Validate() (err error) {
err = o.ClusteradmFlags.ValidateHub()
if err != nil {
return err
}

return nil
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/cmd/create/work/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
}

func (o *Options) validate() (err error) {
err = o.ClusteradmFlags.ValidateHub()
if err != nil {
return err
}

if len(o.Cluster) == 0 && len(o.Placement) == 0 {
return fmt.Errorf("--clusters or --placement must be specified")
}
Expand All @@ -46,6 +51,7 @@ func (o *Options) validate() (err error) {
if len(*o.FileNameFlags.Filenames) == 0 {
return fmt.Errorf("manifest files must be specified")
}

return nil
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/cmd/delete/clusterset/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
}

func (o *Options) validate() (err error) {
err = o.ClusteradmFlags.ValidateHub()
if err != nil {
return err
}

if len(o.Clustersets) == 0 {
return fmt.Errorf("the name of the clusterset must be specified")
}
if len(o.Clustersets) > 1 {
return fmt.Errorf("only one clusterset can be deleted")
}

return nil
}

Expand Down
9 changes: 3 additions & 6 deletions pkg/cmd/delete/token/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import (
"context"
"fmt"

"github.com/spf13/cobra"
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"k8s.io/client-go/kubernetes"
"open-cluster-management.io/clusteradm/pkg/config"
"open-cluster-management.io/clusteradm/pkg/helpers"

"github.com/spf13/cobra"

apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/client-go/kubernetes"
)

func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
Expand Down
13 changes: 8 additions & 5 deletions pkg/cmd/delete/work/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import (
"fmt"
"time"

"k8s.io/apimachinery/pkg/watch"

"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
workclientset "open-cluster-management.io/api/client/work/clientset/versioned"
"open-cluster-management.io/clusteradm/pkg/helpers"

"github.com/spf13/cobra"
)

func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
Expand All @@ -30,7 +28,12 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
return nil
}

func (o *Options) validate() error {
func (o *Options) validate() (err error) {
err = o.ClusteradmFlags.ValidateHub()
if err != nil {
return err
}

if len(o.Cluster) == 0 {
return fmt.Errorf("the name of the cluster must be specified")
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/cmd/get/addon/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
}

func (o *Options) validate() (err error) {
err = o.ClusteradmFlags.ValidateHub()
if err != nil {
return err
}

return nil
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/cmd/get/cluster/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
}

func (o *Options) validate(args []string) (err error) {
err = o.ClusteradmFlags.ValidateHub()
if err != nil {
return err
}

if len(args) != 0 {
return fmt.Errorf("there should be no argument")
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/cmd/get/clusterset/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
}

func (o *Options) validate(args []string) (err error) {
err = o.ClusteradmFlags.ValidateHub()
if err != nil {
return err
}

if len(args) != 0 {
return fmt.Errorf("there should be no argument")
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/cmd/get/hubinfo/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,16 @@ func (o *Options) complete(cmd *cobra.Command, args []string) error {
return nil
}

func (o *Options) validate(args []string) error {
func (o *Options) validate(args []string) (err error) {
err = o.ClusteradmFlags.ValidateHub()
if err != nil {
return err
}

if len(args) != 0 {
return fmt.Errorf("there should be no argument")
}

return nil
}

Expand Down
8 changes: 7 additions & 1 deletion pkg/cmd/get/klusterletinfo/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,16 @@ func (o *Options) complete(cmd *cobra.Command, args []string) error {
return nil
}

func (o *Options) validate(args []string) error {
func (o *Options) validate(args []string) (err error) {
err = o.ClusteradmFlags.ValidateManagedCluster()
if err != nil {
return err
}

if len(args) != 0 {
return fmt.Errorf("there should be no argument")
}

return nil
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/cmd/get/placement/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
}

func (o *Options) validate(args []string) (err error) {
err = o.ClusteradmFlags.ValidateHub()
if err != nil {
return err
}

if len(args) > 1 {
return fmt.Errorf("the number of placement name should be 0 or 1")
}
Expand Down
Loading