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

Commit 263e915

Browse files
authored
fix(cli): add handling of --no-progress flag for glasskube bootstrap (#1007)
1 parent 193fcee commit 263e915

2 files changed

Lines changed: 27 additions & 12 deletions

File tree

cmd/glasskube/cmd/bootstrap.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func (o bootstrapOptions) asBootstrapOptions() bootstrap.BootstrapOptions {
109109
Force: o.force,
110110
CreateDefaultRepository: o.createDefaultRepository,
111111
DryRun: o.DryRun,
112+
NoProgress: rootCmdOptions.NoProgress,
112113
}
113114
}
114115

pkg/bootstrap/bootstrap.go

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type BootstrapOptions struct {
4747
Force bool
4848
CreateDefaultRepository bool
4949
DryRun bool
50+
NoProgress bool
5051
}
5152

5253
func DefaultOptions() BootstrapOptions {
@@ -113,44 +114,47 @@ func (c *BootstrapClient) Bootstrap(
113114
version, options.Type)
114115
}
115116

116-
fmt.Fprintln(os.Stderr, installMessage)
117+
if !options.NoProgress {
118+
fmt.Fprintln(os.Stderr, installMessage)
119+
}
117120

118-
statusMessage("Fetching Glasskube manifest from "+options.Url, true)
121+
statusMessage("Fetching Glasskube manifest from "+options.Url, true, options.NoProgress)
119122
manifests, err := clientutils.FetchResources(options.Url)
120123
if err != nil {
121-
statusMessage("Couldn't fetch Glasskube manifests", false)
124+
statusMessage("Couldn't fetch Glasskube manifests", false, false)
122125
telemetry.BootstrapFailure(time.Since(start))
123126
return nil, err
124127
}
125128

126-
statusMessage("Validating existing installation", true)
129+
statusMessage("Validating existing installation", true, options.NoProgress)
127130

128131
if err = c.preprocessManifests(ctx, manifests, &options); err != nil {
129132
telemetry.BootstrapFailure(time.Since(start))
130-
statusMessage(fmt.Sprintf("Couldn't prepare manifests: %v", err), false)
133+
statusMessage(fmt.Sprintf("Couldn't prepare manifests: %v", err), false, false)
131134
if !options.Force {
132135
return nil, err
133136
} else {
134-
statusMessage("Attempting to force bootstrap anyways (Force option is enabled)", true)
137+
statusMessage("Attempting to force bootstrap anyways (Force option is enabled)", true, false)
135138
}
136139
}
137140

138141
if options.CreateDefaultRepository {
139142
manifests = append(manifests, defaultRepository())
140143
}
141144

142-
statusMessage("Applying Glasskube manifests", true)
145+
statusMessage("Applying Glasskube manifests", true, options.NoProgress)
143146

144147
if err = c.applyManifests(ctx, manifests, options); err != nil {
145148
telemetry.BootstrapFailure(time.Since(start))
146-
statusMessage(fmt.Sprintf("Couldn't apply manifests: %v", err), false)
149+
statusMessage(fmt.Sprintf("Couldn't apply manifests: %v", err), false, false)
147150
return nil, err
148151
}
149152

150153
elapsed := time.Since(start)
151154
c.handleTelemetry(options.DisableTelemetry, elapsed)
152155

153-
statusMessage(fmt.Sprintf("Glasskube successfully installed! (took %v)", elapsed.Round(time.Second)), true)
156+
statusMessage(fmt.Sprintf("Glasskube successfully installed! (took %v)", elapsed.Round(time.Second)), true,
157+
options.NoProgress)
154158
return manifests, nil
155159
}
156160

@@ -204,7 +208,7 @@ func (c *BootstrapClient) applyManifests(
204208
objs []unstructured.Unstructured,
205209
options BootstrapOptions,
206210
) error {
207-
bar := progressbar.Default(int64(len(objs)), "Applying manifests")
211+
bar := getProgressBar(options.NoProgress, int64(len(objs)), "Applying manifests")
208212
progressbar.OptionClearOnFinish()(bar)
209213
progressbar.OptionOnCompletion(nil)(bar)
210214
progressbar.OptionThrottle(0)(bar)
@@ -290,7 +294,7 @@ func getDeleteOptions(options BootstrapOptions) metav1.DeleteOptions {
290294
func (c *BootstrapClient) handleTelemetry(disabled bool, elapsed time.Duration) {
291295
if !disabled {
292296
statusMessage("Telemetry is enabled for this cluster – "+
293-
"Run \"glasskube telemetry status\" for more info.", true)
297+
"Run \"glasskube telemetry status\" for more info.", true, false)
294298
telemetry.BootstrapSuccess(elapsed)
295299
}
296300
}
@@ -395,7 +399,10 @@ func (c *BootstrapClient) checkWorkloadReady(
395399
}
396400
}
397401

398-
func statusMessage(input string, success bool) {
402+
func statusMessage(input string, success bool, noProgress bool) {
403+
if noProgress {
404+
return
405+
}
399406
if success {
400407
green := color.New(color.FgGreen).SprintFunc()
401408
fmt.Fprintln(os.Stderr, green("* "+input))
@@ -404,3 +411,10 @@ func statusMessage(input string, success bool) {
404411
fmt.Fprintln(os.Stderr, red("* "+input))
405412
}
406413
}
414+
415+
func getProgressBar(noProgress bool, max int64, description string) *progressbar.ProgressBar {
416+
if noProgress {
417+
return progressbar.DefaultSilent(max, description)
418+
}
419+
return progressbar.Default(max, description)
420+
}

0 commit comments

Comments
 (0)