Skip to content

Commit 612f488

Browse files
authored
Merge pull request #51 from SovereignCloudStack/syself/enable-using-local-cluster-stacks
🌱 use local_mode in Tiltfile
2 parents a04233f + 0e957a4 commit 612f488

File tree

13 files changed

+379
-29
lines changed

13 files changed

+379
-29
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ temp
3131
# Tilt files.
3232
.tiltbuild
3333
/tilt.d
34-
tilt-settings.json
34+
tilt-settings.yaml
3535
tilt_config.json
3636
.clusterstack.yaml
3737
.cluster.yaml
@@ -81,3 +81,4 @@ main
8181
# helm generated yamls
8282
*.tgz.yaml
8383
*.build.yaml
84+
.release

Tiltfile

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@ settings = {
1717
"allowed_contexts": [
1818
"kind-cso",
1919
],
20+
"local_mode": False,
2021
"deploy_cert_manager": True,
2122
"preload_images_for_kind": True,
2223
"kind_cluster_name": "cso",
23-
"capi_version": "v1.5.2",
24+
"capi_version": "v1.6.0",
2425
"cert_manager_version": "v1.11.0",
2526
"kustomize_substitutions": {
2627
},
2728
}
2829

2930
# global settings
30-
settings.update(read_json(
31-
"tilt-settings.json",
31+
settings.update(read_yaml(
32+
"tilt-settings.yaml",
3233
default = {},
3334
))
3435

@@ -111,19 +112,32 @@ def fixup_yaml_empty_arrays(yaml_str):
111112
return yaml_str.replace("storedVersions: null", "storedVersions: []")
112113

113114
## This should have the same versions as the Dockerfile
114-
tilt_dockerfile_header_cso = """
115-
FROM docker.io/alpine/helm:3.12.2 as helm
116-
117-
FROM docker.io/library/alpine:3.18.0 as tilt
118-
WORKDIR /
119-
COPY --from=helm --chown=root:root --chmod=755 /usr/bin/helm /usr/local/bin/helm
120-
COPY manager .
121-
"""
115+
if settings.get("local_mode"):
116+
tilt_dockerfile_header_cso = """
117+
FROM docker.io/alpine/helm:3.12.2 as helm
118+
119+
FROM docker.io/library/alpine:3.18.0 as tilt
120+
WORKDIR /
121+
COPY --from=helm --chown=root:root --chmod=755 /usr/bin/helm /usr/local/bin/helm
122+
COPY .tiltbuild/manager .
123+
COPY .release/ /tmp/cluster-stacks/
124+
"""
125+
else:
126+
tilt_dockerfile_header_cso = """
127+
FROM docker.io/alpine/helm:3.12.2 as helm
128+
129+
FROM docker.io/library/alpine:3.18.0 as tilt
130+
WORKDIR /
131+
COPY --from=helm --chown=root:root --chmod=755 /usr/bin/helm /usr/local/bin/helm
132+
COPY manager .
133+
"""
122134

123135
# Build CSO and add feature gates
124136
def deploy_cso():
125-
# yaml = str(kustomizesub("./hack/observability")) # build an observable kind deployment by default
126-
yaml = str(kustomizesub("./config/default"))
137+
if settings.get("local_mode"):
138+
yaml = str(kustomizesub("./config/localmode"))
139+
else:
140+
yaml = str(kustomizesub("./config/default"))
127141
local_resource(
128142
name = "cso-components",
129143
cmd = ["sh", "-ec", sed_cmd, yaml, "|", envsubst_cmd],
@@ -152,18 +166,32 @@ def deploy_cso():
152166

153167
# Set up an image build for the provider. The live update configuration syncs the output from the local_resource
154168
# build into the container.
155-
docker_build_with_restart(
156-
ref = "ghcr.io/sovereigncloudstack/cso-staging",
157-
context = "./.tiltbuild/",
158-
dockerfile_contents = tilt_dockerfile_header_cso,
159-
target = "tilt",
160-
entrypoint = entrypoint,
161-
only = "manager",
162-
live_update = [
163-
sync(".tiltbuild/manager", "/manager"),
164-
],
165-
ignore = ["templates"],
166-
)
169+
if settings.get("local_mode"):
170+
docker_build_with_restart(
171+
ref = "ghcr.io/sovereigncloudstack/cso-staging",
172+
context = ".",
173+
dockerfile_contents = tilt_dockerfile_header_cso,
174+
target = "tilt",
175+
entrypoint = entrypoint,
176+
live_update = [
177+
sync(".tiltbuild/manager", "/manager"),
178+
sync(".release", "/tmp/cluster-stacks"),
179+
],
180+
ignore = ["templates"],
181+
)
182+
else:
183+
docker_build_with_restart(
184+
ref = "ghcr.io/sovereigncloudstack/cso-staging",
185+
context = "./.tiltbuild/",
186+
dockerfile_contents = tilt_dockerfile_header_cso,
187+
target = "tilt",
188+
entrypoint = entrypoint,
189+
live_update = [
190+
sync(".tiltbuild/manager", "/manager"),
191+
],
192+
ignore = ["templates"],
193+
)
194+
167195
k8s_yaml(blob(yaml))
168196
k8s_resource(workload = "cso-controller-manager", labels = ["CSO"])
169197
k8s_resource(

cmd/main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/SovereignCloudStack/cluster-stack-operator/internal/controller"
3030
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/csoversion"
3131
githubclient "github.com/SovereignCloudStack/cluster-stack-operator/pkg/github/client"
32+
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/github/client/fake"
3233
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/kube"
3334
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/utillog"
3435
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/workloadcluster"
@@ -67,6 +68,7 @@ var (
6768
clusterAddonConcurrency int
6869
logLevel string
6970
releaseDir string
71+
localMode bool
7072
qps float64
7173
burst int
7274
)
@@ -83,6 +85,7 @@ func main() {
8385
flag.IntVar(&clusterAddonConcurrency, "clusteraddon-concurrency", 1, "Number of ClusterAddons to process simultaneously")
8486
flag.StringVar(&logLevel, "log-level", "info", "Specifies log level. Options are 'debug', 'info' and 'error'")
8587
flag.StringVar(&releaseDir, "release-dir", "/tmp/downloads/", "Specify release directory for cluster-stack releases")
88+
flag.BoolVar(&localMode, "local", false, "Enable local mode where no release assets will be downloaded from a remote Git repository. Useful for implementing cluster stacks.")
8689
flag.Float64Var(&qps, "qps", 50, "Enable custom query per second for kubernetes API server")
8790
flag.IntVar(&burst, "burst", 100, "Enable custom burst defines how many queries the API server will accept before enforcing the limit established by qps")
8891

@@ -116,7 +119,12 @@ func main() {
116119
// Setup the context that's going to be used in controllers and for the manager.
117120
ctx := ctrl.SetupSignalHandler()
118121

119-
gitFactory := githubclient.NewFactory()
122+
var gitFactory githubclient.Factory
123+
if localMode {
124+
gitFactory = fake.NewFactory()
125+
} else {
126+
gitFactory = githubclient.NewFactory()
127+
}
120128

121129
restConfig := mgr.GetConfig()
122130
restConfig.QPS = float32(qps)

config/cso/clusterstack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ spec:
1111
autoSubscribe: false
1212
noProvider: true
1313
versions:
14-
- v2
14+
- v2
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
namespace: cso-system
2+
3+
namePrefix: cso-
4+
5+
commonLabels:
6+
cluster.x-k8s.io/provider: "infrastructure-cluster-stack-operator"
7+
8+
resources:
9+
- ../crd
10+
- ../rbac
11+
- ../manager
12+
- ../certmanager
13+
14+
patchesStrategicMerge:
15+
- manager_config_patch.yaml
16+
- manager_pull_policy.yaml
17+
# vars:
18+
# - name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
19+
# objref:
20+
# kind: Certificate
21+
# group: cert-manager.io
22+
# version: v1
23+
# name: serving-cert # this name should match the one in certificate.yaml
24+
# fieldref:
25+
# fieldpath: metadata.namespace
26+
# - name: CERTIFICATE_NAME
27+
# objref:
28+
# kind: Certificate
29+
# group: cert-manager.io
30+
# version: v1
31+
# name: serving-cert # this name should match the one in certificate.yaml
32+
# - name: SERVICE_NAMESPACE # namespace of the service
33+
# objref:
34+
# kind: Service
35+
# version: v1
36+
# name: webhook-service
37+
# fieldref:
38+
# fieldpath: metadata.namespace
39+
# - name: SERVICE_NAME
40+
# objref:
41+
# kind: Service
42+
# version: v1
43+
# name: webhook-service
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: controller-manager
5+
namespace: system
6+
spec:
7+
template:
8+
spec:
9+
containers:
10+
- image: ghcr.io/sovereigncloudstack/cso-staging:dev
11+
name: manager
12+
args:
13+
- --leader-elect=true
14+
- --release-dir=/tmp
15+
- --local=true
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: controller-manager
5+
namespace: system
6+
spec:
7+
template:
8+
spec:
9+
containers:
10+
- name: manager
11+
imagePullPolicy: Always
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: controller-manager
5+
namespace: system
6+
spec:
7+
template:
8+
spec:
9+
containers:
10+
- name: manager
11+
ports:
12+
- containerPort: 9443
13+
name: webhook-server
14+
protocol: TCP
15+
volumeMounts:
16+
- mountPath: /tmp/k8s-webhook-server/serving-certs
17+
name: cert
18+
readOnly: true
19+
volumes:
20+
- name: cert
21+
secret:
22+
defaultMode: 420
23+
secretName: cso-webhook-server-cert
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This patch add annotation to admission webhook config and
2+
# the variables $(CERTIFICATE_NAMESPACE) and $(CERTIFICATE_NAME) will be substituted by kustomize.
3+
---
4+
apiVersion: admissionregistration.k8s.io/v1
5+
kind: ValidatingWebhookConfiguration
6+
metadata:
7+
name: validating-webhook-configuration
8+
annotations:
9+
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)

0 commit comments

Comments
 (0)