-
Notifications
You must be signed in to change notification settings - Fork 290
/
update_mode.go
57 lines (44 loc) · 1.37 KB
/
update_mode.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
package liveupdates
import (
"fmt"
"github.com/tilt-dev/tilt/internal/docker"
"github.com/tilt-dev/tilt/internal/k8s"
)
type UpdateMode string
// A type to bind to flag values that need validation.
type UpdateModeFlag UpdateMode
var (
// Auto-pick the build mode based on
UpdateModeAuto UpdateMode = "auto"
// Only do image builds
UpdateModeImage UpdateMode = "image"
// Update containers in-place. This mode only works with DockerForDesktop and Minikube.
// If you try to use this mode with a different K8s cluster type, we will return an error
UpdateModeContainer UpdateMode = "container"
// Use `kubectl exec`
UpdateModeKubectlExec UpdateMode = "exec"
)
var AllUpdateModes = []UpdateMode{
UpdateModeAuto,
UpdateModeImage,
UpdateModeContainer,
UpdateModeKubectlExec,
}
func ProvideUpdateMode(flag UpdateModeFlag, kubeContext k8s.KubeContext, env docker.ClusterEnv) (UpdateMode, error) {
valid := false
for _, mode := range AllUpdateModes {
if mode == UpdateMode(flag) {
valid = true
}
}
if !valid {
return "", fmt.Errorf("unknown update mode %q. Valid Values: %v", flag, AllUpdateModes)
}
mode := UpdateMode(flag)
if mode == UpdateModeContainer {
if !docker.Env(env).WillBuildToKubeContext(kubeContext) {
return "", fmt.Errorf("update mode %q is only valid with local Docker clusters like Docker For Mac or Minikube", flag)
}
}
return mode, nil
}