Skip to content

Commit

Permalink
fix: remove clusterset add, add clusterset set (#153)
Browse files Browse the repository at this point in the history
Signed-off-by: ycyaoxdu <[email protected]>
  • Loading branch information
ycyaoxdu authored Mar 15, 2022
1 parent 1a74a74 commit a22434d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
4 changes: 2 additions & 2 deletions pkg/cmd/clusterset/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ package clusterset
import (
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"open-cluster-management.io/clusteradm/pkg/cmd/clusterset/add"
"open-cluster-management.io/clusteradm/pkg/cmd/clusterset/bind"
"open-cluster-management.io/clusteradm/pkg/cmd/clusterset/set"
"open-cluster-management.io/clusteradm/pkg/cmd/clusterset/unbind"
genericclioptionsclusteradm "open-cluster-management.io/clusteradm/pkg/genericclioptions"
)
Expand All @@ -17,7 +17,7 @@ func NewCmd(clusteradmFlags *genericclioptionsclusteradm.ClusteradmFlags, stream
Short: "clusterset sub-command",
}

cmd.AddCommand(add.NewCmd(clusteradmFlags, streams))
cmd.AddCommand(set.NewCmd(clusteradmFlags, streams))
cmd.AddCommand(bind.NewCmd(clusteradmFlags, streams))
cmd.AddCommand(unbind.NewCmd(clusteradmFlags, streams))

Expand Down
13 changes: 6 additions & 7 deletions pkg/cmd/clusterset/add/cmd.go → pkg/cmd/clusterset/set/cmd.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright Contributors to the Open Cluster Management project
package add
package set

import (
"fmt"
Expand All @@ -12,17 +12,17 @@ import (
)

var example = `
# add clusters to a clusterset.
%[1]s clusterset add clusterset1 --clusters cluster1,cluster2
# set clusters to a clusterset.
%[1]s clusterset set clusterset1 --clusters cluster1,cluster2
`

// NewCmd...
func NewCmd(clusteradmFlags *genericclioptionsclusteradm.ClusteradmFlags, streams genericclioptions.IOStreams) *cobra.Command {
o := newOptions(clusteradmFlags, streams)

cmd := &cobra.Command{
Use: "add",
Short: "add clusters to a clusterset",
Use: "set",
Short: "set clusters to a clusterset",
Example: fmt.Sprintf(example, clusteradmhelpers.GetExampleHeader()),
SilenceUsage: true,
PreRunE: func(c *cobra.Command, args []string) error {
Expand All @@ -45,8 +45,7 @@ func NewCmd(clusteradmFlags *genericclioptionsclusteradm.ClusteradmFlags, stream
},
}

cmd.Flags().StringSliceVar(&o.Clusters, "clusters", []string{}, "Names of the managed cluster to add to the clusterset (comma separated)")
cmd.Flags().BoolVar(&o.replace, "replace", false, "directly add cluster in clusterset1 to clusterset2 if --replace is set")
cmd.Flags().StringSliceVar(&o.Clusters, "clusters", []string{}, "Names of the managed cluster to set to the clusterset (comma separated)")

return cmd
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright Contributors to the Open Cluster Management project
package add
package set

import (
"context"
Expand Down Expand Up @@ -53,11 +53,7 @@ func (o *Options) run() (err error) {

clusterset := cluster.Labels["cluster.open-cluster-management.io/clusterset"]
if clusterset == o.Clusterset {
fmt.Fprintf(o.Streams.Out, "Cluster %s is already added into Clusterset %s\n", clusterName, o.Clusterset)
continue
}
if !o.replace {
fmt.Fprintf(o.Streams.Out, "Cluster %s is already added into Clusterset %s, you can't add it to %s\n", clusterName, clusterset, o.Clusterset)
fmt.Fprintf(o.Streams.Out, "Cluster %s is already in Clusterset %s\n", clusterName, o.Clusterset)
continue
}

Expand All @@ -67,7 +63,7 @@ func (o *Options) run() (err error) {
return err
}

fmt.Fprintf(o.Streams.Out, "Cluster %s is added into Clusterset %s\n", clusterName, o.Clusterset)
fmt.Fprintf(o.Streams.Out, "Cluster %s is set, from ClusterSet %s to Clusterset %s\n", clusterName, clusterset, o.Clusterset)
}

return nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright Contributors to the Open Cluster Management project
package add
package set

import (
"k8s.io/cli-runtime/pkg/genericclioptions"
Expand All @@ -15,8 +15,6 @@ type Options struct {
Clusters []string

Clusterset string

replace bool
}

func newOptions(clusteradmFlags *genericclioptionsclusteradm.ClusteradmFlags, streams genericclioptions.IOStreams) *Options {
Expand Down

0 comments on commit a22434d

Please sign in to comment.