github.com/grahambrereton-form3/tilt@v0.10.18/internal/engine/update_mode.go (about) 1 package engine 2 3 import ( 4 "fmt" 5 6 "github.com/windmilleng/tilt/internal/container" 7 "github.com/windmilleng/tilt/internal/k8s" 8 ) 9 10 type UpdateMode string 11 12 // A type to bind to flag values that need validation. 13 type UpdateModeFlag UpdateMode 14 15 var ( 16 // Auto-pick the build mode based on 17 UpdateModeAuto UpdateMode = "auto" 18 19 // Only do image builds 20 UpdateModeImage UpdateMode = "image" 21 22 // Only do image builds from scratch 23 UpdateModeNaive UpdateMode = "naive" 24 25 // Deploy a synclet to make container updates faster 26 UpdateModeSynclet UpdateMode = "synclet" 27 28 // Update containers in-place. This mode only works with DockerForDesktop and Minikube. 29 // If you try to use this mode with a different K8s cluster type, we will return an error 30 UpdateModeContainer UpdateMode = "container" 31 32 // Use `kubectl exec` 33 UpdateModeKubectlExec UpdateMode = "exec" 34 ) 35 36 var AllUpdateModes = []UpdateMode{ 37 UpdateModeAuto, 38 UpdateModeImage, 39 UpdateModeNaive, 40 UpdateModeSynclet, 41 UpdateModeContainer, 42 UpdateModeKubectlExec, 43 } 44 45 func ProvideUpdateMode(flag UpdateModeFlag, env k8s.Env, runtime container.Runtime) (UpdateMode, error) { 46 valid := false 47 for _, mode := range AllUpdateModes { 48 if mode == UpdateMode(flag) { 49 valid = true 50 } 51 } 52 53 if !valid { 54 return "", fmt.Errorf("unknown update mode %q. Valid Values: %v", flag, AllUpdateModes) 55 } 56 57 mode := UpdateMode(flag) 58 if mode == UpdateModeContainer { 59 if !env.UsesLocalDockerRegistry() || runtime != container.RuntimeDocker { 60 return "", fmt.Errorf("update mode %q is only valid with local Docker clusters like Docker For Mac, Minikube, and MicroK8s", flag) 61 } 62 } 63 64 if mode == UpdateModeSynclet { 65 if runtime != container.RuntimeDocker { 66 return "", fmt.Errorf("update mode %q is only valid with Docker container runtime (and will NOT work with"+ 67 "containerd, cri-o, etc.)", flag) 68 69 } 70 } 71 72 return mode, nil 73 }