Skip to content
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
4 changes: 2 additions & 2 deletions pkg/cmd/addon/enable/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ func NewCmd(clusteradmFlags *genericclioptionsclusteradm.ClusteradmFlags, stream
},
}

cmd.Flags().StringVar(&o.names, "name", "", "Names of the add-on to deploy (comma separated)")
cmd.Flags().StringSliceVar(&o.names, "name", []string{}, "Names of the add-on to deploy (comma separated)")
cmd.Flags().StringVarP(&o.namespace, "namespace", "n", "open-cluster-management-agent-addon", "Specified namespace to addon addon")
cmd.Flags().StringVar(&o.clusters, "cluster", "", "Names of the managed cluster to deploy the add-on to (comma separated)")
cmd.Flags().StringSliceVar(&o.clusters, "cluster", []string{}, "Names of the managed cluster to deploy the add-on to (comma separated)")
cmd.Flags().StringVar(&o.outputFile, "output-file", "", "The generated resources will be copied in the specified file")

return cmd
Expand Down
29 changes: 6 additions & 23 deletions pkg/cmd/addon/enable/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ package enable
import (
"context"
"fmt"
"strings"

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

apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
clusterclientset "open-cluster-management.io/api/client/cluster/clientset/versioned"
Expand Down Expand Up @@ -42,37 +42,20 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
}

func (o *Options) validate() error {
if o.names == "" {
if len(o.names) == 0 {
return fmt.Errorf("names is missing")
}

if o.clusters == "" {
if len(o.clusters) == 0 {
return fmt.Errorf("clusters is misisng")
}

return nil
}

func (o *Options) run() error {
alreadyProvidedAddons := make(map[string]bool)
addons := make([]string, 0)
names := strings.Split(o.names, ",")
for _, n := range names {
if _, ok := alreadyProvidedAddons[n]; !ok {
alreadyProvidedAddons[n] = true
addons = append(addons, strings.TrimSpace(n))
}
}

alreadyProvidedClusters := make(map[string]bool)
clusters := make([]string, 0)
cs := strings.Split(o.clusters, ",")
for _, c := range cs {
if _, ok := alreadyProvidedClusters[c]; !ok {
alreadyProvidedClusters[c] = true
clusters = append(clusters, strings.TrimSpace(c))
}
}
addons := sets.NewString(o.names...)
clusters := sets.NewString(o.clusters...)

klog.V(3).InfoS("values:", "addon", addons, "clusters", clusters)

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

return o.runWithClient(clusterClient, kubeClient, apiExtensionsClient, dynamicClient, o.ClusteradmFlags.DryRun, addons, clusters)
return o.runWithClient(clusterClient, kubeClient, apiExtensionsClient, dynamicClient, o.ClusteradmFlags.DryRun, addons.List(), clusters.List())
}

func (o *Options) runWithClient(clusterClient clusterclientset.Interface,
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/addon/enable/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var _ = ginkgo.Describe("addon enable", func() {
}

addons := []string{appMgrAddonName}
clusters := []string{cluster1Name}
clusters := []string{cluster1Name, cluster1Name, cluster1Name}

err := o.runWithClient(clusterClient, kubeClient, apiExtensionsClient, dynamicClient, false, addons, clusters)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
Expand All @@ -87,7 +87,7 @@ var _ = ginkgo.Describe("addon enable", func() {
}

addons := []string{appMgrAddonName}
clusters := []string{cluster1Name, cluster2Name}
clusters := []string{cluster1Name, cluster2Name, cluster1Name}

err := o.runWithClient(clusterClient, kubeClient, apiExtensionsClient, dynamicClient, false, addons, clusters)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/addon/enable/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ type Options struct {
//ClusteradmFlags: The generic optiosn from the clusteradm cli-runtime.
ClusteradmFlags *genericclioptionsclusteradm.ClusteradmFlags
//A list of comma separated addon names
names string
names []string
//The sepcified namespace for addon to install
namespace string
//A list of comma separated cluster names
clusters string
clusters []string
//The file to output the resources will be sent to the file.
outputFile string
//
Expand Down