forked from tilt-dev/tilt-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tiltfile
75 lines (56 loc) · 2.94 KB
/
Tiltfile
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
68
69
70
71
72
73
74
75
load('ext://restart_process', 'docker_build_with_restart')
def kubebuilder(DOMAIN, GROUP, VERSION, KIND, IMG='controller:latest', CONTROLLERGEN='crd:trivialVersions=true rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases;', DISABLE_SECURITY_CONTEXT=True):
DOCKERFILE = '''FROM golang:alpine
WORKDIR /
COPY ./tilt_bin/manager /
CMD ["/manager"]
'''
def yaml():
data = local('cd config/manager; kustomize edit set image controller=' + IMG + '; cd ../..; kustomize build config/default')
if DISABLE_SECURITY_CONTEXT:
decoded = decode_yaml_stream(data)
if decoded:
for d in decoded:
# Live update conflicts with SecurityContext, until a better solution, just remove it
if d["kind"] == "Deployment":
if "securityContext" in d['spec']['template']['spec']:
d['spec']['template']['spec'].pop('securityContext')
for c in d['spec']['template']['spec']['containers']:
if "securityContext" in c:
c.pop('securityContext')
return encode_yaml_stream(decoded)
return data
def manifests():
return 'controller-gen ' + CONTROLLERGEN
def generate():
return 'controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./...";'
def vetfmt():
return 'go vet ./...; go fmt ./...'
# build to tilt_bin beause kubebuilder has a dockerignore for bin/
def binary():
return 'CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -o tilt_bin/manager cmd/main.go'
installed = local("which kubebuilder")
print("kubebuilder is present:", installed)
DIRNAME = os.path.basename(os. getcwd())
# if kubebuilder
if os.path.exists('go.mod') == False:
local("go mod init %s" % DIRNAME)
if os.path.exists('PROJECT') == False:
local("kubebuilder init --domain %s" % DOMAIN)
if os.path.exists('api') == False:
local("kubebuilder create api --resource --controller --group %s --version %s --kind %s" % (GROUP, VERSION, KIND))
local(manifests() + generate())
local_resource('CRD', manifests() + 'kustomize build config/crd | kubectl apply -f -', deps=["api"])
k8s_yaml(yaml())
deps = ['internal/controller', 'cmd/main.go']
deps.append('api')
local_resource('Watch&Compile', generate() + binary(), deps=deps, ignore=['*/*/zz_generated.deepcopy.go'])
local_resource('Sample YAML', 'kubectl apply -f ./config/samples', deps=["./config/samples"], resource_deps=[DIRNAME + "-controller-manager"])
docker_build_with_restart(IMG, '.',
dockerfile_contents=DOCKERFILE,
entrypoint='/manager',
only=['./tilt_bin/manager'],
live_update=[
sync('./tilt_bin/manager', '/manager'),
]
)