-
Notifications
You must be signed in to change notification settings - Fork 199
/
kubernetes.go
67 lines (56 loc) · 1.62 KB
/
kubernetes.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
61
62
63
64
65
66
67
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// ------------------------------------------------------------
package kubernetes
import (
"fmt"
"os"
"runtime"
"time"
"github.com/dapr/cli/pkg/print"
"github.com/dapr/cli/utils"
"github.com/briandowns/spinner"
scheme "github.com/dapr/dapr/pkg/client/clientset/versioned"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const daprManifestPath = "https://daprreleases.blob.core.windows.net/manifest/dapr-operator.yaml"
// Init deploys the Dapr operator
func Init() error {
client, err := DaprClient()
if err != nil {
return fmt.Errorf("can't connect to a Kubernetes cluster: %v", err)
}
msg := "Deploying the Dapr Operator to your cluster..."
var s *spinner.Spinner
if runtime.GOOS == "windows" {
print.InfoStatusEvent(os.Stdout, msg)
} else {
s = spinner.New(spinner.CharSets[0], 100*time.Millisecond)
s.Writer = os.Stdout
s.Color("cyan")
s.Suffix = fmt.Sprintf(" %s", msg)
s.Start()
}
err = utils.RunCmdAndWait("kubectl", "apply", "-f", daprManifestPath)
if err != nil {
err = ensureConfig(client)
if err != nil {
if s != nil {
s.Stop()
}
return err
}
}
if s != nil {
s.Stop()
print.SuccessStatusEvent(os.Stdout, msg)
}
return nil
}
// ensureConfig installs the configuration in cases where the CRDs are not registered fast enough in etcd
func ensureConfig(client scheme.Interface) error {
config := GetDefaultConfiguration()
_, err := client.ConfigurationV1alpha1().Configurations(meta_v1.NamespaceDefault).Create(&config)
return err
}