-
Notifications
You must be signed in to change notification settings - Fork 5.1k
/
main.go
52 lines (43 loc) · 1.13 KB
/
main.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
package main
import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"time"
"k8s.io/client-go/kubernetes"
"github.com/argoproj/argo-cd/v2/util/errors"
"github.com/argoproj/gitops-engine/pkg/utils/kube"
"sigs.k8s.io/controller-runtime/pkg/envtest"
)
func main() {
testEnv := envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("manifests", "crds")},
}
println("Starting K8S...")
cfg, err := testEnv.Start()
errors.CheckError(err)
kubeConfigPath := "/tmp/kubeconfig"
if len(os.Args) > 2 {
kubeConfigPath = os.Args[1]
}
println(fmt.Sprintf("Kubeconfig is available at %s", kubeConfigPath))
errors.CheckError(kube.WriteKubeConfig(cfg, "default", kubeConfigPath))
client, err := kubernetes.NewForConfig(cfg)
errors.CheckError(err)
attempts := 5
interval := time.Second
for i := 0; i < attempts; i++ {
_, err = client.ServerVersion()
if err == nil {
break
}
time.Sleep(interval)
}
errors.CheckError(err)
cmd := exec.Command("kubectl", "apply", "-k", "manifests/base/config")
cmd.Env = []string{fmt.Sprintf("KUBECONFIG=%s", kubeConfigPath)}
errors.CheckError(cmd.Run())
<-context.Background().Done()
}