-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tiltfile-mgmt
133 lines (105 loc) · 3.95 KB
/
Tiltfile-mgmt
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# -*- mode: Python -*-
v1alpha1.extension_repo(name='ww-ext', url='https://github.com/weaveworks-experiments/tilt-extensions')
v1alpha1.extension(name='flux', repo_name='ww-ext', repo_path='flux')
v1alpha1.extension(name='project', repo_name='ww-ext', repo_path='project')
v1alpha1.extension(name='io', repo_name='ww-ext', repo_path='io')
v1alpha1.extension(name='capi', repo_name='ww-ext', repo_path='capi')
load("ext://project", "project_enable")
load("ext://flux", "flux_bootstrap")
load("ext://io", "info", "warn", "file_write")
load("ext://capi", "capi_deploycrds", "capi_create_kubeconfig_secret", "capi_create_cluster_yaml")
# set defaults
version_settings(True, ">=0.22.2")
settings = {
"deploy_capi_crds": True,
"kind_cluster_name": os.getenv("KIND_CLUSTER_NAME", "fleeet-mgmt"),
"github_token": os.getenv("GITHUB_TOKEN", ""),
"debug": {},
}
# global settings
tilt_file = "./tilt-settings-mgmt.yaml" if os.path.exists("./tilt-settings-mgmt.yaml") else "./tilt-settings-mgmt.json"
settings.update(read_yaml(
tilt_file,
default = {},
))
k8s_ctx = "kind-" + settings.get("kind_cluster_name")
info("allowed k8s context={ctx}".format(ctx = k8s_ctx))
allow_k8s_contexts(k8s_ctx)
os.putenv("KIND_CLUSTER_NAME", settings.get("kind_cluster_name"))
always_enable_projects = ["module"]
projects = {
"module": {
"context": "module",
"image": "squaremo/fleeet-control",
"live_reload_deps": [
"main.go",
"go.mod",
"go.sum",
"../pkg",
"api",
"controllers"
],
"kustomize_dir": "config/default",
"label": "module"
}
}
# kind_tenant_config = """
# kind: Cluster
# apiVersion: kind.x-k8s.io/v1alpha4
# networking:
# apiServerAddress: "{kind_ip_address}"
# """
# cluster_tenant_template = """
# apiVersion: cluster.x-k8s.io/v1alpha3
# kind: Cluster
# metadata:
# name: "{tenant_name}"
# """
# Users may define their own Tilt customizations in tilt.d. This directory is excluded from git and these files will
# not be checked in to version control.
def include_user_tilt_files():
user_tiltfiles = listdir("tilt.d")
for f in user_tiltfiles:
include(f)
def enable_projects():
for name in get_projects():
p = projects.get(name)
project_enable(name, p, settings.get("debug").get(name, {}))
#enable_project(name, )
def get_projects():
user_enable_projects = settings.get("enable_projects", [])
return {k: "" for k in user_enable_projects + always_enable_projects}.keys()
# def deploy_capi_crds():
# # We only care about the Cluster CRD at present
# crd_yaml = local("curl -fsSL https://raw.githubusercontent.com/kubernetes-sigs/cluster-api/main/config/crd/bases/cluster.x-k8s.io_clusters.yaml", quiet=True)
# k8s_yaml(crd_yaml)
def deploy_flux():
repo_owner = settings.get("repo_owner")
if repo_owner == None:
fail("you must supply a repo owner in the tilt-settings")
git_token = settings.get("github_token")
if git_token == None:
fail("you must supply a GitHub token via the GITHUB_TOKEN environment variable or in your tilt settings")
repo_name = "fleeet-demo"
if settings.get("repo_name"):
repo_name = settings.get("repo_name")
flux_bootstrap(repo_owner, repo_name, "./mgmt", git_token)
def register_tenant_cluster():
files = listdir("./.tiltbuild/")
tenant_num=0
for file in files:
if file.endswith(".kubeconfig"):
tenant_name = "tenant-{}".format(tenant_num)
secret = capi_create_kubeconfig_secret(tenant_name, "default", from_file=file)
k8s_yaml(secret)
cluster_yaml = capi_create_cluster_yaml(tenant_name, "default")
k8s_yaml(blob(cluster_yaml))
tenant_num = tenant_num+1
##############################
# Actual work happens here
##############################
include_user_tilt_files()
capi_deploycrds()
deploy_flux()
enable_projects()
register_tenant_cluster()