Skip to content
This repository was archived by the owner on Jun 29, 2022. It is now read-only.

Commit d9fe3c1

Browse files
authored
Merge pull request #968 from kinvolk/invidian/improvements
cli/cmd: make some variable names consistent
2 parents c62be62 + d9b0e2d commit d9fe3c1

File tree

5 files changed

+61
-61
lines changed

5 files changed

+61
-61
lines changed

cli/cmd/cluster-apply.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,57 +53,57 @@ func init() {
5353

5454
//nolint:funlen
5555
func runClusterApply(cmd *cobra.Command, args []string) {
56-
ctxLogger := log.WithFields(log.Fields{
56+
contextLogger := log.WithFields(log.Fields{
5757
"command": "lokoctl cluster apply",
5858
"args": args,
5959
})
6060

61-
ex, p, lokoConfig, assetDir := initialize(ctxLogger)
61+
ex, p, lokoConfig, assetDir := initialize(contextLogger)
6262

63-
exists := clusterExists(ctxLogger, ex)
63+
exists := clusterExists(contextLogger, ex)
6464
if exists && !confirm {
6565
// TODO: We could plan to a file and use it when installing.
6666
if err := ex.Plan(); err != nil {
67-
ctxLogger.Fatalf("Failed to reconcile cluster state: %v", err)
67+
contextLogger.Fatalf("Failed to reconcile cluster state: %v", err)
6868
}
6969

7070
if !askForConfirmation("Do you want to proceed with cluster apply?") {
71-
ctxLogger.Println("Cluster apply cancelled")
71+
contextLogger.Println("Cluster apply cancelled")
7272

7373
return
7474
}
7575
}
7676

7777
if err := p.Apply(ex); err != nil {
78-
ctxLogger.Fatalf("error applying cluster: %v", err)
78+
contextLogger.Fatalf("error applying cluster: %v", err)
7979
}
8080

8181
fmt.Printf("\nYour configurations are stored in %s\n", assetDir)
8282

83-
kubeconfig, err := getKubeconfig(ctxLogger, lokoConfig, true)
83+
kubeconfig, err := getKubeconfig(contextLogger, lokoConfig, true)
8484
if err != nil {
85-
ctxLogger.Fatalf("Failed to get kubeconfig: %v", err)
85+
contextLogger.Fatalf("Failed to get kubeconfig: %v", err)
8686
}
8787

8888
if err := verifyCluster(kubeconfig, p.Meta().ExpectedNodes); err != nil {
89-
ctxLogger.Fatalf("Verify cluster: %v", err)
89+
contextLogger.Fatalf("Verify cluster: %v", err)
9090
}
9191

9292
// Update all the pre installed namespaces with lokomotive specific label.
9393
// `lokomotive.kinvolk.io/name: <namespace_name>`.
9494
if err := updateInstalledNamespaces(kubeconfig); err != nil {
95-
ctxLogger.Fatalf("Updating installed namespace: %v", err)
95+
contextLogger.Fatalf("Updating installed namespace: %v", err)
9696
}
9797

9898
// Do controlplane upgrades only if cluster already exists and it is not a managed platform.
9999
if exists && !p.Meta().Managed {
100100
fmt.Printf("\nEnsuring that cluster controlplane is up to date.\n")
101101

102102
cu := controlplaneUpdater{
103-
kubeconfig: kubeconfig,
104-
assetDir: assetDir,
105-
ctxLogger: *ctxLogger,
106-
ex: *ex,
103+
kubeconfig: kubeconfig,
104+
assetDir: assetDir,
105+
contextLogger: *contextLogger,
106+
ex: *ex,
107107
}
108108

109109
charts := platform.CommonControlPlaneCharts()
@@ -122,7 +122,7 @@ func runClusterApply(cmd *cobra.Command, args []string) {
122122

123123
if ph, ok := p.(platform.PlatformWithPostApplyHook); ok {
124124
if err := ph.PostApplyHook(kubeconfig); err != nil {
125-
ctxLogger.Fatalf("Running platform post install hook failed: %v", err)
125+
contextLogger.Fatalf("Running platform post install hook failed: %v", err)
126126
}
127127
}
128128

@@ -135,11 +135,11 @@ func runClusterApply(cmd *cobra.Command, args []string) {
135135
componentsToApply = append(componentsToApply, component.Name)
136136
}
137137

138-
ctxLogger.Println("Applying component configuration")
138+
contextLogger.Println("Applying component configuration")
139139

140140
if len(componentsToApply) > 0 {
141141
if err := applyComponents(lokoConfig, kubeconfig, componentsToApply...); err != nil {
142-
ctxLogger.Fatalf("Applying component configuration failed: %v", err)
142+
contextLogger.Fatalf("Applying component configuration failed: %v", err)
143143
}
144144
}
145145
}

cli/cmd/cluster-destroy.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,31 @@ func init() {
3535
}
3636

3737
func runClusterDestroy(cmd *cobra.Command, args []string) {
38-
ctxLogger := log.WithFields(log.Fields{
38+
contextLogger := log.WithFields(log.Fields{
3939
"command": "lokoctl cluster destroy",
4040
"args": args,
4141
})
4242

43-
ex, p, _, _ := initialize(ctxLogger)
43+
ex, p, _, _ := initialize(contextLogger)
4444

45-
if !clusterExists(ctxLogger, ex) {
46-
ctxLogger.Println("Cluster already destroyed, nothing to do")
45+
if !clusterExists(contextLogger, ex) {
46+
contextLogger.Println("Cluster already destroyed, nothing to do")
4747

4848
return
4949
}
5050

5151
if !confirm {
5252
confirmation := askForConfirmation("WARNING: This action cannot be undone. Do you really want to destroy the cluster?")
5353
if !confirmation {
54-
ctxLogger.Println("Cluster destroy canceled")
54+
contextLogger.Println("Cluster destroy canceled")
5555
return
5656
}
5757
}
5858

5959
if err := p.Destroy(ex); err != nil {
60-
ctxLogger.Fatalf("error destroying cluster: %v", err)
60+
contextLogger.Fatalf("error destroying cluster: %v", err)
6161
}
6262

63-
ctxLogger.Println("Cluster destroyed successfully")
64-
ctxLogger.Println("You can safely remove the assets directory now")
63+
contextLogger.Println("Cluster destroyed successfully")
64+
contextLogger.Println("You can safely remove the assets directory now")
6565
}

cli/cmd/cluster.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,29 @@ func init() {
4343

4444
// initialize does common initialization actions between cluster operations
4545
// and returns created objects to the caller for further use.
46-
func initialize(ctxLogger *logrus.Entry) (*terraform.Executor, platform.Platform, *config.Config, string) {
46+
func initialize(contextLogger *logrus.Entry) (*terraform.Executor, platform.Platform, *config.Config, string) {
4747
lokoConfig, diags := getLokoConfig()
4848
if len(diags) > 0 {
49-
ctxLogger.Fatal(diags)
49+
contextLogger.Fatal(diags)
5050
}
5151

5252
p, diags := getConfiguredPlatform(lokoConfig, true)
5353
if diags.HasErrors() {
5454
for _, diagnostic := range diags {
55-
ctxLogger.Error(diagnostic.Error())
55+
contextLogger.Error(diagnostic.Error())
5656
}
5757

58-
ctxLogger.Fatal("Errors found while loading cluster configuration")
58+
contextLogger.Fatal("Errors found while loading cluster configuration")
5959
}
6060

6161
// Get the configured backend for the cluster. Backend types currently supported: local, s3.
6262
b, diags := getConfiguredBackend(lokoConfig)
6363
if diags.HasErrors() {
6464
for _, diagnostic := range diags {
65-
ctxLogger.Error(diagnostic.Error())
65+
contextLogger.Error(diagnostic.Error())
6666
}
6767

68-
ctxLogger.Fatal("Errors found while loading cluster configuration")
68+
contextLogger.Fatal("Errors found while loading cluster configuration")
6969
}
7070

7171
// Use a local backend if no backend is configured.
@@ -75,36 +75,36 @@ func initialize(ctxLogger *logrus.Entry) (*terraform.Executor, platform.Platform
7575

7676
assetDir, err := homedir.Expand(p.Meta().AssetDir)
7777
if err != nil {
78-
ctxLogger.Fatalf("Error expanding path: %v", err)
78+
contextLogger.Fatalf("Error expanding path: %v", err)
7979
}
8080

8181
// Validate backend configuration.
8282
if err = b.Validate(); err != nil {
83-
ctxLogger.Fatalf("Failed to validate backend configuration: %v", err)
83+
contextLogger.Fatalf("Failed to validate backend configuration: %v", err)
8484
}
8585

86-
ex := initializeTerraform(ctxLogger, p, b)
86+
ex := initializeTerraform(contextLogger, p, b)
8787

8888
return ex, p, lokoConfig, assetDir
8989
}
9090

9191
// initializeTerraform initialized Terraform directory using given backend and platform
9292
// and returns configured executor.
93-
func initializeTerraform(ctxLogger *logrus.Entry, p platform.Platform, b backend.Backend) *terraform.Executor {
93+
func initializeTerraform(contextLogger *logrus.Entry, p platform.Platform, b backend.Backend) *terraform.Executor {
9494
assetDir, err := homedir.Expand(p.Meta().AssetDir)
9595
if err != nil {
96-
ctxLogger.Fatalf("Error expanding path: %v", err)
96+
contextLogger.Fatalf("Error expanding path: %v", err)
9797
}
9898

9999
// Render backend configuration.
100100
renderedBackend, err := b.Render()
101101
if err != nil {
102-
ctxLogger.Fatalf("Failed to render backend configuration file: %v", err)
102+
contextLogger.Fatalf("Failed to render backend configuration file: %v", err)
103103
}
104104

105105
// Configure Terraform directory, module and backend.
106106
if err := terraform.Configure(assetDir, renderedBackend); err != nil {
107-
ctxLogger.Fatalf("Failed to configure Terraform : %v", err)
107+
contextLogger.Fatalf("Failed to configure Terraform : %v", err)
108108
}
109109

110110
conf := terraform.Config{
@@ -114,15 +114,15 @@ func initializeTerraform(ctxLogger *logrus.Entry, p platform.Platform, b backend
114114

115115
ex, err := terraform.NewExecutor(conf)
116116
if err != nil {
117-
ctxLogger.Fatalf("Failed to create Terraform executor: %v", err)
117+
contextLogger.Fatalf("Failed to create Terraform executor: %v", err)
118118
}
119119

120120
if err := p.Initialize(ex); err != nil {
121-
ctxLogger.Fatalf("Failed to initialize Platform: %v", err)
121+
contextLogger.Fatalf("Failed to initialize Platform: %v", err)
122122
}
123123

124124
if err := ex.Init(); err != nil {
125-
ctxLogger.Fatalf("Failed to initialize Terraform: %v", err)
125+
contextLogger.Fatalf("Failed to initialize Terraform: %v", err)
126126
}
127127

128128
return ex
@@ -131,21 +131,21 @@ func initializeTerraform(ctxLogger *logrus.Entry, p platform.Platform, b backend
131131
// clusterExists determines if cluster has already been created by getting all
132132
// outputs from the Terraform. If there is any output defined, it means 'terraform apply'
133133
// run at least once.
134-
func clusterExists(ctxLogger *logrus.Entry, ex *terraform.Executor) bool {
134+
func clusterExists(contextLogger *logrus.Entry, ex *terraform.Executor) bool {
135135
o := map[string]interface{}{}
136136

137137
if err := ex.Output("", &o); err != nil {
138-
ctxLogger.Fatalf("Failed to check if cluster exists: %v", err)
138+
contextLogger.Fatalf("Failed to check if cluster exists: %v", err)
139139
}
140140

141141
return len(o) != 0
142142
}
143143

144144
type controlplaneUpdater struct {
145-
kubeconfig []byte
146-
assetDir string
147-
ctxLogger logrus.Entry
148-
ex terraform.Executor
145+
kubeconfig []byte
146+
assetDir string
147+
contextLogger logrus.Entry
148+
ex terraform.Executor
149149
}
150150

151151
func (c controlplaneUpdater) getControlplaneChart(name string) (*chart.Chart, error) {
@@ -176,29 +176,29 @@ func (c controlplaneUpdater) getControlplaneValues(name string) (map[string]inte
176176
}
177177

178178
func (c controlplaneUpdater) upgradeComponent(component, namespace string) {
179-
ctxLogger := c.ctxLogger.WithFields(logrus.Fields{
179+
contextLogger := c.contextLogger.WithFields(logrus.Fields{
180180
"action": "controlplane-upgrade",
181181
"component": component,
182182
})
183183

184184
actionConfig, err := util.HelmActionConfig(namespace, c.kubeconfig)
185185
if err != nil {
186-
ctxLogger.Fatalf("Failed initializing helm: %v", err)
186+
contextLogger.Fatalf("Failed initializing helm: %v", err)
187187
}
188188

189189
helmChart, err := c.getControlplaneChart(component)
190190
if err != nil {
191-
ctxLogger.Fatalf("Loading chart from assets failed: %v", err)
191+
contextLogger.Fatalf("Loading chart from assets failed: %v", err)
192192
}
193193

194194
values, err := c.getControlplaneValues(component)
195195
if err != nil {
196-
ctxLogger.Fatalf("Failed to get kubernetes values.yaml from Terraform: %v", err)
196+
contextLogger.Fatalf("Failed to get kubernetes values.yaml from Terraform: %v", err)
197197
}
198198

199199
exists, err := util.ReleaseExists(*actionConfig, component)
200200
if err != nil {
201-
ctxLogger.Fatalf("Failed checking if controlplane component is installed: %v", err)
201+
contextLogger.Fatalf("Failed checking if controlplane component is installed: %v", err)
202202
}
203203

204204
if !exists {
@@ -213,7 +213,7 @@ func (c controlplaneUpdater) upgradeComponent(component, namespace string) {
213213
if _, err := install.Run(helmChart, values); err != nil {
214214
fmt.Println("Failed!")
215215

216-
ctxLogger.Fatalf("Installing controlplane component failed: %v", err)
216+
contextLogger.Fatalf("Installing controlplane component failed: %v", err)
217217
}
218218

219219
fmt.Println("Done.")
@@ -228,7 +228,7 @@ func (c controlplaneUpdater) upgradeComponent(component, namespace string) {
228228
if _, err := update.Run(component, helmChart, values); err != nil {
229229
fmt.Println("Failed!")
230230

231-
ctxLogger.Fatalf("Updating chart failed: %v", err)
231+
contextLogger.Fatalf("Updating chart failed: %v", err)
232232
}
233233

234234
fmt.Println("Done.")

cli/cmd/component-delete.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func runDelete(cmd *cobra.Command, args []string) {
6262
log.SetLevel(log.DebugLevel)
6363
}
6464

65-
lokoCfg, diags := getLokoConfig()
65+
lokoConfig, diags := getLokoConfig()
6666
if len(diags) > 0 {
6767
contextLogger.Fatal(diags)
6868
}
@@ -71,9 +71,9 @@ func runDelete(cmd *cobra.Command, args []string) {
7171
copy(componentsToDelete, args)
7272

7373
if len(args) == 0 {
74-
componentsToDelete = make([]string, len(lokoCfg.RootConfig.Components))
74+
componentsToDelete = make([]string, len(lokoConfig.RootConfig.Components))
7575

76-
for i, component := range lokoCfg.RootConfig.Components {
76+
for i, component := range lokoConfig.RootConfig.Components {
7777
componentsToDelete[i] = component.Name
7878
}
7979
}
@@ -99,7 +99,7 @@ func runDelete(cmd *cobra.Command, args []string) {
9999
return
100100
}
101101

102-
kubeconfig, err := getKubeconfig(contextLogger, lokoCfg, false)
102+
kubeconfig, err := getKubeconfig(contextLogger, lokoConfig, false)
103103
if err != nil {
104104
contextLogger.Debugf("Error in finding kubeconfig file: %s", err)
105105
contextLogger.Fatal("Suitable kubeconfig file not found. Did you run 'lokoctl cluster apply' ?")

cli/cmd/document/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ func init() {
3232
}
3333

3434
func runDocument(docCmd *cobra.Command, args []string) {
35-
ctxLogger := log.WithFields(log.Fields{
35+
contextLogger := log.WithFields(log.Fields{
3636
"command": "go run cli/cmd/document/main.go",
3737
"args": args,
3838
})
3939

4040
err := doc.GenMarkdownTree(cmd.RootCmd, args[0])
4141
if err != nil {
42-
ctxLogger.Fatalf("Failed to generate markdown documentation: %v", err)
42+
contextLogger.Fatalf("Failed to generate markdown documentation: %v", err)
4343
}
4444

45-
ctxLogger.Printf("Markdown documentation written to %s\n", args[0])
45+
contextLogger.Printf("Markdown documentation written to %s\n", args[0])
4646
}

0 commit comments

Comments
 (0)