-
Notifications
You must be signed in to change notification settings - Fork 8
/
wait.go
60 lines (47 loc) · 1.67 KB
/
wait.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package ctl
import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/tools/clientcmd"
"namespacelabs.dev/foundation/internal/console"
"namespacelabs.dev/foundation/internal/executor"
"namespacelabs.dev/foundation/internal/fnerrors"
"namespacelabs.dev/foundation/internal/providers/nscloud/api"
"namespacelabs.dev/foundation/internal/runtime/kubernetes/kubeobserver"
"namespacelabs.dev/foundation/std/tasks"
)
const kubeSystem = "kube-system"
var deployments = []string{
"coredns",
"local-path-provisioner",
}
func WaitKubeSystem(ctx context.Context, cluster *api.KubernetesCluster) error {
return tasks.Action("cluster.wait-kube-system").
Arg("id", cluster.ClusterId).Run(ctx, func(ctx context.Context) error {
cfg := clientcmd.NewDefaultClientConfig(MakeConfig(cluster), nil)
restcfg, err := cfg.ClientConfig()
if err != nil {
return fnerrors.New("failed to load kubernetes configuration: %w", err)
}
eg := executor.New(ctx, "wait")
for _, d := range deployments {
d := d
eg.Go(func(ctx context.Context) error {
fmt.Fprintf(console.Debug(ctx), "will wait for deployment %s\n", d)
obs := kubeobserver.WaitOnResource{
RestConfig: restcfg,
Name: d,
Namespace: kubeSystem,
Description: fmt.Sprintf("kube-system deployment %s", d),
GroupVersionKind: schema.FromAPIVersionAndKind("apps/v1", "Deployment"),
}
return obs.WaitUntilReady(ctx, nil)
})
}
return eg.Wait()
})
}