Skip to content

Commit 3a6721c

Browse files
fra98adamjensenbot
authored andcommitted
Fix providers overwrite flags liqoctl install
1 parent 1b7fe3f commit 3a6721c

22 files changed

+76
-45
lines changed

cmd/liqoctl/cmd/docs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func newDocsCommand(ctx context.Context) *cobra.Command {
3232
Long: WithTemplate("Generate {{ .Executable }} documentation"),
3333
Args: cobra.NoArgs,
3434

35-
Run: func(cmd *cobra.Command, args []string) {
35+
Run: func(cmd *cobra.Command, _ []string) {
3636
options.Root = cmd.Root()
3737
util.CheckErr(options.Run(ctx))
3838
},

cmd/liqoctl/cmd/drain.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ func newDrainTenantCommand(ctx context.Context, f *factory.Factory) *cobra.Comma
6060
Args: cobra.ExactArgs(1),
6161
ValidArgsFunction: completion.Tenants(ctx, f, 1),
6262

63-
PreRun: func(cmd *cobra.Command, args []string) {
63+
PreRun: func(_ *cobra.Command, _ []string) {
6464
output.ExitOnErr(options.Printer.AskConfirm("drain", options.SkipConfirm))
6565
},
6666

67-
Run: func(cmd *cobra.Command, args []string) {
67+
Run: func(_ *cobra.Command, args []string) {
6868
options.Name = args[0]
6969
output.ExitOnErr(options.RunDrainTenant(ctx))
7070
},

cmd/liqoctl/cmd/install.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -182,19 +182,22 @@ func newInstallCommand(ctx context.Context, f *factory.Factory) *cobra.Command {
182182
f.AddLiqoNamespaceFlag(cmd.PersistentFlags())
183183

184184
base.RegisterFlags(cmd)
185-
cmd.AddCommand(newInstallProviderCommand(ctx, options, aks.New))
186-
cmd.AddCommand(newInstallProviderCommand(ctx, options, eks.New))
187-
cmd.AddCommand(newInstallProviderCommand(ctx, options, gke.New))
188-
cmd.AddCommand(newInstallProviderCommand(ctx, options, k3s.New))
189-
cmd.AddCommand(newInstallProviderCommand(ctx, options, kind.New))
190-
cmd.AddCommand(newInstallProviderCommand(ctx, options, kubeadm.New))
191-
cmd.AddCommand(newInstallProviderCommand(ctx, options, openshift.New))
185+
cmd.AddCommand(newInstallProviderCommand(ctx, options.CommonOptions, aks.New))
186+
cmd.AddCommand(newInstallProviderCommand(ctx, options.CommonOptions, eks.New))
187+
cmd.AddCommand(newInstallProviderCommand(ctx, options.CommonOptions, gke.New))
188+
cmd.AddCommand(newInstallProviderCommand(ctx, options.CommonOptions, k3s.New))
189+
cmd.AddCommand(newInstallProviderCommand(ctx, options.CommonOptions, kind.New))
190+
cmd.AddCommand(newInstallProviderCommand(ctx, options.CommonOptions, kubeadm.New))
191+
cmd.AddCommand(newInstallProviderCommand(ctx, options.CommonOptions, openshift.New))
192192

193193
return cmd
194194
}
195195

196-
func newInstallProviderCommand(ctx context.Context, options *install.Options, creator func(*install.Options) install.Provider) *cobra.Command {
197-
provider := creator(options)
196+
func newInstallProviderCommand(ctx context.Context, commonOpts *install.CommonOptions,
197+
creator func(*install.Options) install.Provider) *cobra.Command {
198+
options := install.Options{CommonOptions: commonOpts}
199+
provider := creator(&options)
200+
198201
cmd := &cobra.Command{
199202
Use: provider.Name(),
200203
Short: fmt.Sprintf("Install Liqo in the selected %s cluster", provider.Name()),

cmd/liqoctl/cmd/move.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ func newMoveVolumeCommand(ctx context.Context, f *factory.Factory) *cobra.Comman
7676
Args: cobra.ExactArgs(1),
7777
ValidArgsFunction: completion.PVCs(ctx, f, 1),
7878

79-
PreRun: func(cmd *cobra.Command, args []string) {
79+
PreRun: func(_ *cobra.Command, _ []string) {
8080
options.ContainersCPURequests = containersCPURequests.Quantity
8181
options.ContainersCPULimits = containersCPULimits.Quantity
8282
options.ContainersRAMRequests = containersRAMRequests.Quantity
8383
options.ContainersRAMLimits = containersRAMLimits.Quantity
8484
},
8585

86-
Run: func(cmd *cobra.Command, args []string) {
86+
Run: func(_ *cobra.Command, args []string) {
8787
options.VolumeName = args[0]
8888
output.ExitOnErr(options.Run(ctx))
8989
},

cmd/liqoctl/cmd/offload.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ func newOffloadNamespaceCommand(ctx context.Context, f *factory.Factory) *cobra.
104104
Args: cobra.ExactArgs(1),
105105
ValidArgsFunction: completion.Namespaces(ctx, f, 1),
106106

107-
PreRun: func(cmd *cobra.Command, args []string) {
107+
PreRun: func(_ *cobra.Command, _ []string) {
108108
options.PodOffloadingStrategy = offloadingv1beta1.PodOffloadingStrategyType(podOffloadingStrategy.Value)
109109
options.NamespaceMappingStrategy = offloadingv1beta1.NamespaceMappingStrategyType(namespaceMappingStrategy.Value)
110110
options.RemoteNamespaceName = remoteNamespaceName
111111
options.OutputFormat = outputFormat.Value
112112
options.Printer.CheckErr(options.ParseClusterSelectors(selectors))
113113
},
114114

115-
Run: func(cmd *cobra.Command, args []string) {
115+
Run: func(_ *cobra.Command, args []string) {
116116
options.Namespace = args[0]
117117
output.ExitOnErr(options.Run(ctx))
118118
},

cmd/liqoctl/cmd/root.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func NewRootCommand(ctx context.Context) *cobra.Command {
103103
// The behavior can be customized in subcommands defining an appropriate PersistentPreRun function.
104104
// Yet, the initialization is skipped for the __complete command, as characterized by a peculiar behavior
105105
// in terms of flags parsing (https://github.com/spf13/cobra/issues/1291#issuecomment-739056690).
106-
PersistentPreRun: func(cmd *cobra.Command, args []string) {
106+
PersistentPreRun: func(cmd *cobra.Command, _ []string) {
107107
if cmd != nil && cmd.Name() != cobra.ShellCompRequestCmd {
108108
singleClusterPersistentPreRun(cmd, f)
109109
}

cmd/liqoctl/cmd/uninstall.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ func newUninstallCommand(ctx context.Context, f *factory.Factory) *cobra.Command
5050
Long: WithTemplate(liqoctlUninstallLongHelp),
5151
Args: cobra.NoArgs,
5252

53-
PreRun: func(cmd *cobra.Command, args []string) {
53+
PreRun: func(_ *cobra.Command, _ []string) {
5454
output.ExitOnErr(options.Printer.AskConfirm("uninstall", f.SkipConfirm))
5555
},
5656

57-
Run: func(cmd *cobra.Command, args []string) {
57+
Run: func(_ *cobra.Command, _ []string) {
5858
output.ExitOnErr(options.Run(ctx))
5959
},
6060
}

cmd/liqoctl/cmd/unoffload.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ func newUnoffloadNamespaceCommand(ctx context.Context, f *factory.Factory) *cobr
5959
Args: cobra.ExactArgs(1),
6060
ValidArgsFunction: completion.OffloadedNamespaces(ctx, f, 1),
6161

62-
PreRun: func(cmd *cobra.Command, args []string) {
62+
PreRun: func(_ *cobra.Command, _ []string) {
6363
output.ExitOnErr(f.Printer.AskConfirm("unoffload", f.SkipConfirm))
6464
},
6565

66-
Run: func(cmd *cobra.Command, args []string) {
66+
Run: func(_ *cobra.Command, args []string) {
6767
options.Namespace = args[0]
6868
output.ExitOnErr(options.Run(ctx))
6969
},

pkg/liqoctl/install/aks/aks_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ var _ = Describe("Extract elements from AKS", func() {
3636
var options Options
3737

3838
BeforeEach(func() {
39-
options = Options{Options: &install.Options{ClusterLabels: map[string]string{}}}
39+
options = Options{Options: &install.Options{
40+
CommonOptions: &install.CommonOptions{
41+
ClusterLabels: map[string]string{},
42+
},
43+
}}
4044
})
4145

4246
It("test parse values", func() {

pkg/liqoctl/install/aks/provider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434

3535
var _ install.Provider = (*Options)(nil)
3636

37-
// Options encapsulates the arguments of the install command.
37+
// Options encapsulates the arguments of the install aks command.
3838
type Options struct {
3939
*install.Options
4040

pkg/liqoctl/install/eks/eks_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ var _ = Describe("Extract elements from EKS", func() {
3636
var options Options
3737

3838
BeforeEach(func() {
39-
options = Options{Options: &install.Options{ClusterLabels: map[string]string{}}}
39+
options = Options{Options: &install.Options{
40+
CommonOptions: &install.CommonOptions{
41+
ClusterLabels: map[string]string{},
42+
},
43+
}}
4044
})
4145

4246
It("test parse values", func() {

pkg/liqoctl/install/eks/provider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828

2929
var _ install.Provider = (*Options)(nil)
3030

31-
// Options encapsulates the arguments of the install command.
31+
// Options encapsulates the arguments of the install eks command.
3232
type Options struct {
3333
*install.Options
3434

pkg/liqoctl/install/generic/provider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (o *Options) RegisterFlags(cmd *cobra.Command) {
5252
}
5353

5454
// Initialize performs the initialization tasks to retrieve the provider-specific parameters.
55-
func (o *Options) Initialize(ctx context.Context) error { return nil }
55+
func (o *Options) Initialize(_ context.Context) error { return nil }
5656

5757
// Values returns the customized provider-specifc values file parameters.
5858
func (o *Options) Values() map[string]interface{} {

pkg/liqoctl/install/gke/gke_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ var _ = Describe("Extract elements from GKE", func() {
3434
var options Options
3535

3636
BeforeEach(func() {
37-
options = Options{Options: &install.Options{ClusterLabels: map[string]string{}}}
37+
options = Options{Options: &install.Options{
38+
CommonOptions: &install.CommonOptions{
39+
ClusterLabels: map[string]string{},
40+
},
41+
}}
3842
})
3943

4044
It("test parse values", func() {

pkg/liqoctl/install/gke/provider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232

3333
var _ install.Provider = (*Options)(nil)
3434

35-
// Options encapsulates the arguments of the install command.
35+
// Options encapsulates the arguments of the install gke command.
3636
type Options struct {
3737
*install.Options
3838

pkg/liqoctl/install/handler.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ type Provider interface {
6363

6464
// Options encapsulates the arguments of the install command.
6565
type Options struct {
66+
*CommonOptions
67+
68+
APIServer string
69+
PodCIDR string
70+
ServiceCIDR string
71+
}
72+
73+
// CommonOptions encapsulates common arguments (not modified by providers) of the install command.
74+
type CommonOptions struct {
6675
*factory.Factory
6776
CommandName string
6877

@@ -85,13 +94,10 @@ type Options struct {
8594
ClusterID liqov1beta1.ClusterID
8695
ClusterLabels map[string]string
8796

88-
APIServer string
8997
EnableHA bool
9098
EnableMetrics bool
9199
DisableTelemetry bool
92100

93-
PodCIDR string
94-
ServiceCIDR string
95101
ReservedSubnets []string
96102

97103
DisableAPIServerSanityChecks bool
@@ -104,8 +110,10 @@ type Options struct {
104110
// NewOptions returns a new Options struct.
105111
func NewOptions(f *factory.Factory, commandName string) *Options {
106112
return &Options{
107-
CommandName: commandName,
108-
Factory: f,
113+
CommonOptions: &CommonOptions{
114+
CommandName: commandName,
115+
Factory: f,
116+
},
109117
}
110118
}
111119

pkg/liqoctl/install/k3s/provider.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
var _ install.Provider = (*Options)(nil)
2626

27-
// Options encapsulates the arguments of the install command.
27+
// Options encapsulates the arguments of the install k3s command.
2828
type Options struct {
2929
*install.Options
3030
}
@@ -59,7 +59,7 @@ func (o *Options) RegisterFlags(cmd *cobra.Command) {
5959
}
6060

6161
// Initialize performs the initialization tasks to retrieve the provider-specific parameters.
62-
func (o *Options) Initialize(ctx context.Context) error {
62+
func (o *Options) Initialize(_ context.Context) error {
6363
// Typically, the URL refers to a localhost address.
6464
o.DisableAPIServerSanityChecks = true
6565
return nil

pkg/liqoctl/install/kind/provider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323

2424
var _ install.Provider = (*Options)(nil)
2525

26-
// Options encapsulates the arguments of the install command.
26+
// Options encapsulates the arguments of the install kind command.
2727
type Options struct {
2828
*kubeadm.Options
2929
}

pkg/liqoctl/install/kubeadm/kubeadm_test.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,14 @@ var _ = Describe("Extract elements from apiServer", func() {
8484
)
8585

8686
JustBeforeEach(func() {
87-
options = Options{Options: &install.Options{Factory: &factory.Factory{
88-
KubeClient: fake.NewSimpleClientset(pods...),
89-
Printer: output.NewFakePrinter(GinkgoWriter),
90-
}}}
87+
options = Options{Options: &install.Options{
88+
CommonOptions: &install.CommonOptions{
89+
Factory: &factory.Factory{
90+
KubeClient: fake.NewSimpleClientset(pods...),
91+
Printer: output.NewFakePrinter(GinkgoWriter),
92+
},
93+
},
94+
}}
9195
})
9296

9397
When("no kube-controller-manager pods is present", func() {

pkg/liqoctl/install/kubeadm/provider.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var _ install.Provider = (*Options)(nil)
3030

3131
var kubeControllerManagerLabels = map[string]string{"component": "kube-controller-manager", "tier": "control-plane"}
3232

33-
// Options encapsulates the arguments of the install k3s command.
33+
// Options encapsulates the arguments of the install kubeadm command.
3434
type Options struct {
3535
*install.Options
3636
}
@@ -52,7 +52,7 @@ func (o *Options) Examples() string {
5252
}
5353

5454
// RegisterFlags registers the flags for the given provider.
55-
func (o *Options) RegisterFlags(cmd *cobra.Command) {}
55+
func (o *Options) RegisterFlags(_ *cobra.Command) {}
5656

5757
// Initialize performs the initialization tasks to retrieve the provider-specific parameters.
5858
func (o *Options) Initialize(ctx context.Context) error {

pkg/liqoctl/install/openshift/provider.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828

2929
var _ install.Provider = (*Options)(nil)
3030

31-
// Options encapsulates the arguments of the install k3s command.
31+
// Options encapsulates the arguments of the install openshift command.
3232
type Options struct {
3333
*install.Options
3434
}
@@ -50,7 +50,7 @@ func (o *Options) Examples() string {
5050
}
5151

5252
// RegisterFlags registers the flags for the given provider.
53-
func (o *Options) RegisterFlags(cmd *cobra.Command) {}
53+
func (o *Options) RegisterFlags(_ *cobra.Command) {}
5454

5555
// Initialize performs the initialization tasks to retrieve the provider-specific parameters.
5656
func (o *Options) Initialize(ctx context.Context) error {

pkg/liqoctl/install/validation_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ var _ = Describe("Validation", func() {
4343
)
4444

4545
BeforeEach(func() {
46-
options = Options{Factory: &factory.Factory{}}
46+
options = Options{
47+
CommonOptions: &CommonOptions{
48+
Factory: &factory.Factory{},
49+
},
50+
}
4751
ctx = context.Background()
4852
})
4953

0 commit comments

Comments
 (0)