Skip to content

Commit

Permalink
prompt warnings while running either hub oriented command against man…
Browse files Browse the repository at this point in the history
…agedcluster or managedcluster oriented command against hub

Signed-off-by: ycyaoxdu <[email protected]>
  • Loading branch information
ycyaoxdu committed Oct 24, 2022
1 parent acb1e52 commit ee5f16c
Show file tree
Hide file tree
Showing 28 changed files with 332 additions and 54 deletions.
21 changes: 16 additions & 5 deletions pkg/cmd/accept/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ 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"
operatorclient "open-cluster-management.io/api/client/operator/clientset/versioned"
"open-cluster-management.io/clusteradm/pkg/helpers"
"open-cluster-management.io/clusteradm/pkg/helpers/warning"
)

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

func (o *Options) Validate() error {
config, err := o.ClusteradmFlags.KubectlFactory.ToRESTConfig()
if err != nil {
return err
}
client, err := operatorclient.NewForConfig(config)
if err != nil {
return err
}
warning.CheckKlusterletAbsent(client)

return nil
}

Expand Down
16 changes: 14 additions & 2 deletions pkg/cmd/addon/disable/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ 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"
"k8s.io/client-go/kubernetes"
"k8s.io/klog/v2"
addonclient "open-cluster-management.io/api/client/addon/clientset/versioned"
clusterclientset "open-cluster-management.io/api/client/cluster/clientset/versioned"
operatorclient "open-cluster-management.io/api/client/operator/clientset/versioned"
"open-cluster-management.io/clusteradm/pkg/helpers"
"open-cluster-management.io/clusteradm/pkg/helpers/warning"
)

func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
Expand All @@ -26,6 +27,16 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
}

func (o *Options) Validate() (err error) {
config, err := o.ClusteradmFlags.KubectlFactory.ToRESTConfig()
if err != nil {
return err
}
client, err := operatorclient.NewForConfig(config)
if err != nil {
return err
}
warning.CheckKlusterletAbsent(client)

if len(o.Names) == 0 {
return fmt.Errorf("names is missing")
}
Expand All @@ -37,6 +48,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
17 changes: 14 additions & 3 deletions pkg/cmd/addon/enable/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ 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"
operatorclient "open-cluster-management.io/api/client/operator/clientset/versioned"
"open-cluster-management.io/clusteradm/pkg/cmd/addon/enable/scenario"
"open-cluster-management.io/clusteradm/pkg/helpers"
"open-cluster-management.io/clusteradm/pkg/helpers/warning"
)

type ClusterAddonInfo struct {
Expand Down Expand Up @@ -53,6 +54,16 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
}

func (o *Options) Validate() error {
config, err := o.ClusteradmFlags.KubectlFactory.ToRESTConfig()
if err != nil {
return err
}
client, err := operatorclient.NewForConfig(config)
if err != nil {
return err
}
warning.CheckKlusterletAbsent(client)

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
13 changes: 13 additions & 0 deletions pkg/cmd/clusterset/bind/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterclientset "open-cluster-management.io/api/client/cluster/clientset/versioned"
operatorclient "open-cluster-management.io/api/client/operator/clientset/versioned"
clusterapiv1beta1 "open-cluster-management.io/api/cluster/v1beta1"
"open-cluster-management.io/clusteradm/pkg/helpers/warning"
)

func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
Expand All @@ -27,9 +29,20 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
}

func (o *Options) Validate() (err error) {
config, err := o.ClusteradmFlags.KubectlFactory.ToRESTConfig()
if err != nil {
return err
}
client, err := operatorclient.NewForConfig(config)
if err != nil {
return err
}
warning.CheckKlusterletAbsent(client)

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

return nil
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/cmd/clusterset/set/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterclientset "open-cluster-management.io/api/client/cluster/clientset/versioned"
operatorclient "open-cluster-management.io/api/client/operator/clientset/versioned"
"open-cluster-management.io/clusteradm/pkg/helpers/warning"
)

func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
Expand All @@ -25,9 +27,20 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
}

func (o *Options) Validate() (err error) {
config, err := o.ClusteradmFlags.KubectlFactory.ToRESTConfig()
if err != nil {
return err
}
client, err := operatorclient.NewForConfig(config)
if err != nil {
return err
}
warning.CheckKlusterletAbsent(client)

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

return nil
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/cmd/clusterset/unbind/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterclientset "open-cluster-management.io/api/client/cluster/clientset/versioned"
operatorclient "open-cluster-management.io/api/client/operator/clientset/versioned"
"open-cluster-management.io/clusteradm/pkg/helpers/warning"
)

func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
Expand All @@ -26,9 +28,20 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
}

func (o *Options) Validate() (err error) {
config, err := o.ClusteradmFlags.KubectlFactory.ToRESTConfig()
if err != nil {
return err
}
client, err := operatorclient.NewForConfig(config)
if err != nil {
return err
}
warning.CheckKlusterletAbsent(client)

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

return nil
}

Expand Down
14 changes: 13 additions & 1 deletion pkg/cmd/create/clusterset/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,35 @@ import (
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterclientset "open-cluster-management.io/api/client/cluster/clientset/versioned"
operatorclient "open-cluster-management.io/api/client/operator/clientset/versioned"
clusterapiv1beta1 "open-cluster-management.io/api/cluster/v1beta1"
"open-cluster-management.io/clusteradm/pkg/helpers/warning"
)

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

o.Clustersets = args

return nil
}

func (o *Options) Validate() (err error) {
config, err := o.ClusteradmFlags.KubectlFactory.ToRESTConfig()
if err != nil {
return err
}
client, err := operatorclient.NewForConfig(config)
if err != nil {
return err
}
warning.CheckKlusterletAbsent(client)

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
11 changes: 11 additions & 0 deletions pkg/cmd/create/sampleapp/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import (
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
clusterclientset "open-cluster-management.io/api/client/cluster/clientset/versioned"
operatorclient "open-cluster-management.io/api/client/operator/clientset/versioned"
"open-cluster-management.io/clusteradm/pkg/cmd/create/sampleapp/scenario"
"open-cluster-management.io/clusteradm/pkg/helpers"
"open-cluster-management.io/clusteradm/pkg/helpers/warning"
)

const (
Expand All @@ -45,6 +47,15 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
}

func (o *Options) Validate() (err error) {
config, err := o.ClusteradmFlags.KubectlFactory.ToRESTConfig()
if err != nil {
return err
}
client, err := operatorclient.NewForConfig(config)
if err != nil {
return err
}
warning.CheckKlusterletAbsent(client)

return nil
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/cmd/create/work/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/cli-runtime/pkg/resource"
clusterclientset "open-cluster-management.io/api/client/cluster/clientset/versioned"
operatorclient "open-cluster-management.io/api/client/operator/clientset/versioned"
workclientset "open-cluster-management.io/api/client/work/clientset/versioned"
clusterv1beta1 "open-cluster-management.io/api/cluster/v1beta1"
workapiv1 "open-cluster-management.io/api/work/v1"
"open-cluster-management.io/clusteradm/pkg/helpers/warning"
)

func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
Expand All @@ -34,6 +36,16 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
}

func (o *Options) validate() (err error) {
config, err := o.ClusteradmFlags.KubectlFactory.ToRESTConfig()
if err != nil {
return err
}
client, err := operatorclient.NewForConfig(config)
if err != nil {
return err
}
warning.CheckKlusterletAbsent(client)

if len(o.Cluster) == 0 && len(o.Placement) == 0 {
return fmt.Errorf("--clusters or --placement must be specified")
}
Expand All @@ -46,6 +58,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
13 changes: 13 additions & 0 deletions pkg/cmd/delete/clusterset/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
clusterclientset "open-cluster-management.io/api/client/cluster/clientset/versioned"
operatorclient "open-cluster-management.io/api/client/operator/clientset/versioned"
"open-cluster-management.io/clusteradm/pkg/helpers"
"open-cluster-management.io/clusteradm/pkg/helpers/warning"
)

func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
Expand All @@ -21,12 +23,23 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
}

func (o *Options) validate() (err error) {
config, err := o.ClusteradmFlags.KubectlFactory.ToRESTConfig()
if err != nil {
return err
}
client, err := operatorclient.NewForConfig(config)
if err != nil {
return err
}
warning.CheckKlusterletAbsent(client)

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
Loading

0 comments on commit ee5f16c

Please sign in to comment.