Skip to content

Commit 7b2c52f

Browse files
Improve error messages for kind and minikube install (#585)
* improve minikube quickstart errors * improve kind quickstart errors * remove error from messages
1 parent 36c379c commit 7b2c52f

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

pkg/kind/kind.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func SetUp(name, kVersion string, installServing, installEventing, installKindRe
6868
}
6969

7070
if err := createKindCluster(installKindRegistry, installKindExtraMountHostPath, installKindExtraMountContainerPath); err != nil {
71-
return fmt.Errorf("creating cluster: %w", err)
71+
return fmt.Errorf("failed to create kind cluster: %w", err)
7272
}
7373
if installKnative {
7474
if installServing {
@@ -80,18 +80,18 @@ func SetUp(name, kVersion string, installServing, installEventing, installKindRe
8080
registries = fmt.Sprintf("localhost:%s", container_reg_port)
8181
}
8282
if err := install.Serving(registries); err != nil {
83-
return fmt.Errorf("install serving: %w", err)
83+
return fmt.Errorf("failed to install serving to kind cluster %s: %w", clusterName, err)
8484
}
8585
if err := install.Kourier(); err != nil {
86-
return fmt.Errorf("install kourier: %w", err)
86+
return fmt.Errorf("failed to install kourier to kind cluster %s: %w", clusterName, err)
8787
}
8888
if err := install.KourierKind(); err != nil {
89-
return fmt.Errorf("configure kourier: %w", err)
89+
return fmt.Errorf("failed while configuring kourier for kind cluster %s: %w", clusterName, err)
9090
}
9191
}
9292
if installEventing {
9393
if err := install.Eventing(); err != nil {
94-
return fmt.Errorf("install eventing: %w", err)
94+
return fmt.Errorf("failed to install eventing to king cluster %s: %w", clusterName, err)
9595
}
9696
}
9797
}
@@ -109,7 +109,7 @@ func createKindCluster(registry bool, extraMountHostPath string, extraMountConta
109109
}
110110
fmt.Println("✅ Checking dependencies...")
111111
if err := checkKindVersion(); err != nil {
112-
return fmt.Errorf("kind version: %w", err)
112+
return fmt.Errorf("unable to check kind version: %w", err)
113113
}
114114
if registry {
115115
fmt.Println("💽 Installing local registry...")
@@ -127,7 +127,7 @@ func createKindCluster(registry bool, extraMountHostPath string, extraMountConta
127127
}
128128

129129
if err := checkForExistingCluster(registry, extraMountHostPath, extraMountContainerPath); err != nil {
130-
return fmt.Errorf("existing cluster: %w", err)
130+
return fmt.Errorf("failed while handling or checking for existing kind cluster: %w", err)
131131
}
132132

133133
return nil
@@ -237,13 +237,13 @@ func checkKindVersion() error {
237237
versionCheck := exec.Command("kind", "version", "-q")
238238
out, err := versionCheck.CombinedOutput()
239239
if err != nil {
240-
return fmt.Errorf("kind version: %w", err)
240+
return fmt.Errorf("failed to get kind version: %w", err)
241241
}
242242
fmt.Printf(" Kind version is: %s", string(out))
243243

244244
userKindVersion, err := parseKindVersion(string(out))
245245
if err != nil {
246-
return fmt.Errorf("parsing kind version: %w", err)
246+
return fmt.Errorf("unable to parse kind version: %w", err)
247247
}
248248
if userKindVersion < kindVersion {
249249
var resp string
@@ -267,7 +267,7 @@ func checkForExistingCluster(registry bool, extraMountHostPath string, extraMoun
267267
getClusters := exec.Command("kind", "get", "clusters", "-q")
268268
out, err := getClusters.CombinedOutput()
269269
if err != nil {
270-
return fmt.Errorf("check cluster: %w", err)
270+
return fmt.Errorf("unable to get kind clusters: %w", err)
271271
}
272272
// TODO Add tests for regex
273273
r := regexp.MustCompile(fmt.Sprintf(`(?m)^%s\n`, clusterName))
@@ -278,7 +278,7 @@ func checkForExistingCluster(registry bool, extraMountHostPath string, extraMoun
278278
fmt.Scanf("%s", &resp)
279279
if resp == "y" || resp == "Y" {
280280
if err := recreateCluster(registry, extraMountHostPath, extraMountContainerPath); err != nil {
281-
return fmt.Errorf("new cluster: %w", err)
281+
return fmt.Errorf("failed while recreating kind cluster %s: %w", clusterName, err)
282282
}
283283
} else {
284284
fmt.Println("\n Installation skipped")
@@ -287,14 +287,14 @@ func checkForExistingCluster(registry bool, extraMountHostPath string, extraMoun
287287
namespaces := string(output)
288288
if err != nil {
289289
fmt.Println(string(output))
290-
return fmt.Errorf("check existing cluster: %w", err)
290+
return fmt.Errorf("unable to get kubernetes namspaces for kind cluster %s: %w", clusterName, err)
291291
}
292292
if strings.Contains(namespaces, "knative") {
293293
fmt.Print("Knative installation already exists.\nDelete and recreate the cluster [y/N]: ")
294294
fmt.Scanf("%s", &resp)
295295
if resp == "y" || resp == "Y" {
296296
if err := recreateCluster(registry, extraMountHostPath, extraMountContainerPath); err != nil {
297-
return fmt.Errorf("new cluster: %w", err)
297+
return fmt.Errorf("failed to recreate kind cluster: %w", err)
298298
}
299299
} else {
300300
fmt.Println("Skipping installation")
@@ -307,11 +307,11 @@ func checkForExistingCluster(registry bool, extraMountHostPath string, extraMoun
307307
} else {
308308
dcli, err := dclient.NewClientWithOpts(dclient.FromEnv, dclient.WithAPIVersionNegotiation())
309309
if err != nil {
310-
return fmt.Errorf("new cluster: %w", err)
310+
return fmt.Errorf("failed to initialize new api client: %w", err)
311311
}
312312

313313
if err := createNewCluster(extraMountHostPath, extraMountContainerPath); err != nil {
314-
return fmt.Errorf("new cluster: %w", err)
314+
return fmt.Errorf("%w", err)
315315
}
316316
if registry {
317317
if err := createLocalRegistry(dcli); err != nil {
@@ -332,25 +332,25 @@ func recreateCluster(registry bool, extraMountHostPath string, extraMountContain
332332

333333
dcli, err := dclient.NewClientWithOpts(dclient.FromEnv, dclient.WithAPIVersionNegotiation())
334334
if err != nil {
335-
return fmt.Errorf("delete cluster: %w", err)
335+
return fmt.Errorf("failed to initialize new api client: %w", err)
336336
}
337337

338338
deleteCluster := exec.Command("kind", "delete", "cluster", "--name", clusterName)
339339
if err := deleteCluster.Run(); err != nil {
340-
return fmt.Errorf("delete cluster: %w", err)
340+
return fmt.Errorf("failed to delete kind cluster %s: %w", clusterName, err)
341341
}
342342
if err := deleteContainerRegistry(dcli); err != nil {
343-
return fmt.Errorf("delete container registry: %w", err)
343+
return fmt.Errorf("failed to delete container registry: %w", err)
344344
}
345345
if err := createNewCluster(extraMountHostPath, extraMountContainerPath); err != nil {
346-
return fmt.Errorf("new cluster: %w", err)
346+
return fmt.Errorf("%w", err)
347347
}
348348
if registry {
349349
if err := createLocalRegistry(dcli); err != nil {
350350
return fmt.Errorf("%w", err)
351351
}
352352
if err := connectLocalRegistry(dcli); err != nil {
353-
return fmt.Errorf("local-registry: %w", err)
353+
return fmt.Errorf("unable to connect local-registry: %w", err)
354354
}
355355
}
356356
return nil
@@ -391,7 +391,7 @@ nodes:
391391
createCluster := exec.Command("kind", "create", "cluster", "--wait=120s", "--config=-")
392392
createCluster.Stdin = strings.NewReader(config)
393393
if err := runCommandWithOutput(createCluster); err != nil {
394-
return fmt.Errorf("kind create: %w", err)
394+
return fmt.Errorf("failed to create kind cluster %s: %w", clusterName, err)
395395
}
396396

397397
return nil

pkg/minikube/minikube.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func SetUp(name, kVersion string, installServing, installEventing bool) error {
5959
}
6060

6161
if err := createMinikubeCluster(); err != nil {
62-
return fmt.Errorf("creating cluster: %w", err)
62+
return fmt.Errorf("failed to create minikube cluster: %w", err)
6363
}
6464
fmt.Print("\n")
6565
fmt.Println("To finish setting up networking for minikube, run the following command in a separate terminal window:")
@@ -70,18 +70,18 @@ func SetUp(name, kVersion string, installServing, installEventing bool) error {
7070
if installKnative {
7171
if installServing {
7272
if err := install.Serving(""); err != nil {
73-
return fmt.Errorf("install serving: %w", err)
73+
return fmt.Errorf("failed to install serving to minikube cluster %s: %w", clusterName, err)
7474
}
7575
if err := install.Kourier(); err != nil {
76-
return fmt.Errorf("install kourier: %w", err)
76+
return fmt.Errorf("failed to install kourier to minikube cluster %s: %w", clusterName, err)
7777
}
7878
if err := install.KourierMinikube(); err != nil {
79-
return fmt.Errorf("configure kourier: %w", err)
79+
return fmt.Errorf("failed while configuring kourier for minikube cluster %s: %w", clusterName, err)
8080
}
8181
}
8282
if installEventing {
8383
if err := install.Eventing(); err != nil {
84-
return fmt.Errorf("install eventing: %w", err)
84+
return fmt.Errorf("failed to install eventing to minikube cluster %s: %w", clusterName, err)
8585
}
8686
}
8787
}
@@ -95,10 +95,10 @@ func SetUp(name, kVersion string, installServing, installEventing bool) error {
9595

9696
func createMinikubeCluster() error {
9797
if err := checkMinikubeVersion(); err != nil {
98-
return fmt.Errorf("minikube version: %w", err)
98+
return fmt.Errorf("unable to get minikube version: %w", err)
9999
}
100100
if err := checkForExistingCluster(); err != nil {
101-
return fmt.Errorf("existing cluster: %w", err)
101+
return fmt.Errorf("failure while handling or checking for existing minikube cluster: %w", err)
102102
}
103103
return nil
104104
}
@@ -109,13 +109,13 @@ func checkMinikubeVersion() error {
109109
versionCheck := exec.Command("minikube", "version", "--short")
110110
out, err := versionCheck.CombinedOutput()
111111
if err != nil {
112-
return fmt.Errorf("minikube version: %w", err)
112+
return fmt.Errorf("unable to check minikube version: %w", err)
113113
}
114114
fmt.Printf("Minikube version is: %s\n", string(out))
115115

116116
userMinikubeVersion, err := parseMinikubeVersion(string(out))
117117
if err != nil {
118-
return fmt.Errorf("parsing minikube version: %w", err)
118+
return fmt.Errorf("unable to parse minikube version: %w", err)
119119
}
120120
if userMinikubeVersion < minikubeVersion {
121121
var resp string
@@ -143,7 +143,7 @@ func checkForExistingCluster() error {
143143
// if there were no profiles, we simply want to create a new one and not stop the install
144144
// so if the error is the "MK_USAGE_NO_PROFILE" error, we ignore it and continue onwards
145145
if !strings.Contains(string(out), "MK_USAGE_NO_PROFILE") {
146-
return fmt.Errorf("check cluster: %w", err)
146+
return fmt.Errorf("failed to get existing minikube profiles: %w", err)
147147
}
148148
}
149149
// TODO Add tests for regex
@@ -160,7 +160,7 @@ func checkForExistingCluster() error {
160160
namespaces := string(output)
161161
if err != nil {
162162
fmt.Println(string(output))
163-
return fmt.Errorf("check existing cluster: %w", err)
163+
return fmt.Errorf("unable to get existing kubernetes namespaces for minikube cluster %s: %w", clusterName, err)
164164
}
165165
if strings.Contains(namespaces, "knative") {
166166
fmt.Print("Knative installation already exists.\nDelete and recreate the cluster [y/N]: ")
@@ -171,20 +171,20 @@ func checkForExistingCluster() error {
171171
return nil
172172
} else {
173173
if err := recreateCluster(); err != nil {
174-
return fmt.Errorf("failed recreating cluster: %w", err)
174+
return fmt.Errorf("failed while recreating minikube cluster: %w", err)
175175
}
176176
}
177177
}
178178
return nil
179179
}
180180
if err := recreateCluster(); err != nil {
181-
return fmt.Errorf("failed recreating cluster: %w", err)
181+
return fmt.Errorf("failed while recreating minikube cluster: %w", err)
182182
}
183183
return nil
184184
}
185185

186186
if err := createNewCluster(); err != nil {
187-
return fmt.Errorf("new cluster: %w", err)
187+
return fmt.Errorf("%w", err)
188188
}
189189

190190
return nil
@@ -223,7 +223,7 @@ func createNewCluster() error {
223223
"--insecure-registry", "10.0.0.0/24",
224224
"--addons=registry")
225225
if err := runCommandWithOutput(createCluster); err != nil {
226-
return fmt.Errorf("minikube create: %w", err)
226+
return fmt.Errorf("failed to create new minikube cluster %s: %w", clusterName, err)
227227
}
228228

229229
return nil
@@ -264,10 +264,10 @@ func recreateCluster() error {
264264
fmt.Println("deleting cluster...")
265265
deleteCluster := exec.Command("minikube", "delete", "--profile", clusterName)
266266
if err := deleteCluster.Run(); err != nil {
267-
return fmt.Errorf("delete cluster: %w", err)
267+
return fmt.Errorf("failed to delete minikube cluster %s: %w", clusterName, err)
268268
}
269269
if err := createNewCluster(); err != nil {
270-
return fmt.Errorf("new cluster: %w", err)
270+
return fmt.Errorf("%w", err)
271271
}
272272
return nil
273273
}

0 commit comments

Comments
 (0)