1+ # default values
2+ settings = {
3+ "allowedContexts" : [
4+ "docker-desktop" ,
5+ "minikube" ,
6+ "kind-kind" ,
7+ ],
8+ "installMinio" : True ,
9+ "installWandb" : True ,
10+ "wandbCRD" : "default" ,
11+ }
12+
13+ # global settings
14+ settings .update (read_json (
15+ "tilt-settings.json" ,
16+ default = {},
17+ ))
18+
19+ allow_k8s_contexts (settings .get ("allowed_k8s_contexts" ))
20+
21+ os .putenv ('PATH' , './bin:' + os .getenv ('PATH' ))
22+
23+ load ('ext://restart_process' , 'docker_build_with_restart' )
24+
25+ DOCKERFILE = '''
26+ FROM registry.access.redhat.com/ubi9/ubi
27+
28+ ADD tilt_bin/manager /manager
29+
30+ ENV HELM_CACHE_HOME=/helm/.cache/helm
31+ ENV HELM_CONFIG_HOME=/helm/.config/helm
32+ ENV HELM_DATA_HOME=/helm/.local/share/helm
33+ '''
34+ DOMAIN = "wandb.com"
35+ GROUP = "apps"
36+ VERSION = "v1"
37+ KIND = "wandb"
38+ IMG = 'controller:latest'
39+ CONTROLLERGEN = 'rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases;'
40+ DISABLE_SECURITY_CONTEXT = True
41+
42+ def yaml ():
43+ data = local ('cd config/manager; kustomize edit set image controller=' + IMG + '; cd ../..; kustomize build config/manager' )
44+ if DISABLE_SECURITY_CONTEXT :
45+ decoded = decode_yaml_stream (data )
46+ if decoded :
47+ for d in decoded :
48+ # Live update conflicts with SecurityContext, until a better solution, just remove it
49+ if d ["kind" ] == "Deployment" :
50+ if "securityContext" in d ['spec' ]['template' ]['spec' ]:
51+ d ['spec' ]['template' ]['spec' ].pop ('securityContext' )
52+ for c in d ['spec' ]['template' ]['spec' ]['containers' ]:
53+ if "securityContext" in c :
54+ c .pop ('securityContext' )
55+
56+ return encode_yaml_stream (decoded )
57+ return data
58+
59+ def manifests ():
60+ return 'controller-gen ' + CONTROLLERGEN
61+
62+ def generate ():
63+ return 'controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./...";'
64+
65+ def vetfmt ():
66+ return 'go vet ./...; go fmt ./...'
67+
68+ # build to tilt_bin beause kubebuilder has a dockerignore for bin/
69+ def binary ():
70+ return 'CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -o tilt_bin/manager main.go'
71+
72+ installed = local ("which kubebuilder" )
73+ print ("kubebuilder is present:" , installed )
74+
75+ DIRNAME = os .path .basename (os . getcwd ())
76+
77+ local (manifests () + generate ())
78+
79+ if settings .get ("installMinio" ):
80+ local_resource ('Minio' , 'kubectl apply -f ./hack/testing-manifests/minio/minio.yaml' )
81+
82+ local_resource ('CRD' , manifests () + 'kustomize build config/crd | kubectl apply -f -' , deps = ["api" ])
83+
84+ local_resource ('RBAC' , 'kustomize build config/rbac | kubectl apply -f -' , deps = ["config/rbac" ])
85+
86+ k8s_yaml (yaml ())
87+
88+ deps = ['controllers' , 'pkg' , 'main.go' ]
89+ deps .append ('api' )
90+
91+ local_resource ('Watch&Compile' , generate () + binary (), deps = deps , ignore = ['*/*/zz_generated.deepcopy.go' ])
92+
93+ if settings .get ("installWandb" ):
94+ local_resource ('Sample YAML' , 'kubectl apply -f ./hack/testing-manifests/wandb/' + settings .get ('wandbCRD' ) + '.yaml' , deps = ["./hack/testing-manifests/wandb/default.yaml" ], resource_deps = ["controller-manager" ])
95+
96+ docker_build_with_restart (IMG , '.' ,
97+ dockerfile_contents = DOCKERFILE ,
98+ entrypoint = '/manager' ,
99+ only = ['./tilt_bin/manager' ],
100+ live_update = [
101+ sync ('./tilt_bin/manager' , '/manager' ),
102+ ]
103+ )
0 commit comments