Skip to content

Commit

Permalink
error while running either hub oriented command against managedcluste…
Browse files Browse the repository at this point in the history
…r or managedcluster oriented command against hub

Signed-off-by: ycyaoxdu <[email protected]>
  • Loading branch information
ycyaoxdu committed Oct 27, 2022
1 parent 4a4add3 commit a2bfe7f
Show file tree
Hide file tree
Showing 35 changed files with 284 additions and 62 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kr/pretty v0.2.1 // indirect
github.com/kubernetes-sigs/kubebuilder v1.0.8 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,8 @@ github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kubernetes-sigs/kubebuilder v1.0.8 h1:zuzCYSTfqcORGhmGeck+X81t3wAQ7MqxPrIVvo2wmbk=
github.com/kubernetes-sigs/kubebuilder v1.0.8/go.mod h1:2i4kvfB3gkuZl1x+GtlrzNjOppLawK68DB1h/W6lbFg=
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o=
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
Expand Down
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

0 comments on commit a2bfe7f

Please sign in to comment.