cli/cmd: don't use globals in clusterApply()
This should allow better structure for the code and should make easier
to move this code to some other package.
@@ -57,13 +57,25 @@ func runClusterApply(cmd *cobra.Command, args []string) {
"args": args,
})
- if err := clusterApply(contextLogger); err != nil {
+ options := clusterApplyOptions{
+ confirm: confirm,
+ upgradeKubelets: upgradeKubelets,
+ skipComponents: skipComponents,
+ }
+
+ if err := clusterApply(contextLogger, options); err != nil {
contextLogger.Fatalf("Applying cluster failed: %v", err)
}
}
+type clusterApplyOptions struct {
+ confirm bool
+ upgradeKubelets bool
+ skipComponents bool
+}
+
//nolint:funlen
-func clusterApply(contextLogger *log.Entry) error {
+func clusterApply(contextLogger *log.Entry, options clusterApplyOptions) error {
c, err := initialize(contextLogger)
if err != nil {
return fmt.Errorf("initializing: %w", err)
@@ -74,7 +86,7 @@ func clusterApply(contextLogger *log.Entry) error {
return fmt.Errorf("checking if cluster exists: %w", err)
}
- if exists && !confirm {
+ if exists && !options.confirm {
// TODO: We could plan to a file and use it when installing.
if err := c.terraformExecutor.Plan(); err != nil {
return fmt.Errorf("reconciling cluster state: %v", err)
@@ -121,7 +133,7 @@ func clusterApply(contextLogger *log.Entry) error {
charts := platform.CommonControlPlaneCharts()
- if upgradeKubelets {
+ if options.upgradeKubelets {
charts = append(charts, helm.LokomotiveChart{
Name: "kubelet",
Namespace: "kube-system",
@@ -141,7 +153,7 @@ func clusterApply(contextLogger *log.Entry) error {
}
}
- if skipComponents {
+ if options.skipComponents {
return nil
}
