Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 use local_mode in Tiltfile #51

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ temp
# Tilt files.
.tiltbuild
/tilt.d
tilt-settings.json
tilt-settings.yaml
tilt_config.json
.clusterstack.yaml
.cluster.yaml
Expand Down Expand Up @@ -81,3 +81,4 @@ main
# helm generated yamls
*.tgz.yaml
*.build.yaml
.release
78 changes: 53 additions & 25 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ settings = {
"allowed_contexts": [
"kind-cso",
],
"local_mode": False,
"deploy_cert_manager": True,
"preload_images_for_kind": True,
"kind_cluster_name": "cso",
"capi_version": "v1.5.2",
"capi_version": "v1.6.0",
"cert_manager_version": "v1.11.0",
"kustomize_substitutions": {
},
}

# global settings
settings.update(read_json(
"tilt-settings.json",
settings.update(read_yaml(
"tilt-settings.yaml",
default = {},
))

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

## This should have the same versions as the Dockerfile
tilt_dockerfile_header_cso = """
FROM docker.io/alpine/helm:3.12.2 as helm

FROM docker.io/library/alpine:3.18.0 as tilt
WORKDIR /
COPY --from=helm --chown=root:root --chmod=755 /usr/bin/helm /usr/local/bin/helm
COPY manager .
"""
if settings.get("local_mode"):
tilt_dockerfile_header_cso = """
FROM docker.io/alpine/helm:3.12.2 as helm

FROM docker.io/library/alpine:3.18.0 as tilt
WORKDIR /
COPY --from=helm --chown=root:root --chmod=755 /usr/bin/helm /usr/local/bin/helm
COPY .tiltbuild/manager .
COPY .release/ /tmp/cluster-stacks/
"""
else:
tilt_dockerfile_header_cso = """
FROM docker.io/alpine/helm:3.12.2 as helm

FROM docker.io/library/alpine:3.18.0 as tilt
WORKDIR /
COPY --from=helm --chown=root:root --chmod=755 /usr/bin/helm /usr/local/bin/helm
COPY manager .
"""

# Build CSO and add feature gates
def deploy_cso():
# yaml = str(kustomizesub("./hack/observability")) # build an observable kind deployment by default
yaml = str(kustomizesub("./config/default"))
if settings.get("local_mode"):
yaml = str(kustomizesub("./config/localmode"))
else:
yaml = str(kustomizesub("./config/default"))
local_resource(
name = "cso-components",
cmd = ["sh", "-ec", sed_cmd, yaml, "|", envsubst_cmd],
Expand Down Expand Up @@ -152,18 +166,32 @@ def deploy_cso():

# Set up an image build for the provider. The live update configuration syncs the output from the local_resource
# build into the container.
docker_build_with_restart(
ref = "ghcr.io/sovereigncloudstack/cso-staging",
context = "./.tiltbuild/",
dockerfile_contents = tilt_dockerfile_header_cso,
target = "tilt",
entrypoint = entrypoint,
only = "manager",
live_update = [
sync(".tiltbuild/manager", "/manager"),
],
ignore = ["templates"],
)
if settings.get("local_mode"):
docker_build_with_restart(
ref = "ghcr.io/sovereigncloudstack/cso-staging",
context = ".",
dockerfile_contents = tilt_dockerfile_header_cso,
target = "tilt",
entrypoint = entrypoint,
live_update = [
sync(".tiltbuild/manager", "/manager"),
sync(".release", "/tmp/cluster-stacks"),
],
ignore = ["templates"],
)
else:
docker_build_with_restart(
ref = "ghcr.io/sovereigncloudstack/cso-staging",
context = "./.tiltbuild/",
dockerfile_contents = tilt_dockerfile_header_cso,
target = "tilt",
entrypoint = entrypoint,
live_update = [
sync(".tiltbuild/manager", "/manager"),
],
ignore = ["templates"],
)

k8s_yaml(blob(yaml))
k8s_resource(workload = "cso-controller-manager", labels = ["CSO"])
k8s_resource(
Expand Down
10 changes: 9 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/SovereignCloudStack/cluster-stack-operator/internal/controller"
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/csoversion"
githubclient "github.com/SovereignCloudStack/cluster-stack-operator/pkg/github/client"
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/github/client/fake"
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/kube"
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/utillog"
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/workloadcluster"
Expand Down Expand Up @@ -67,6 +68,7 @@ var (
clusterAddonConcurrency int
logLevel string
releaseDir string
localMode bool
qps float64
burst int
)
Expand All @@ -83,6 +85,7 @@ func main() {
flag.IntVar(&clusterAddonConcurrency, "clusteraddon-concurrency", 1, "Number of ClusterAddons to process simultaneously")
flag.StringVar(&logLevel, "log-level", "info", "Specifies log level. Options are 'debug', 'info' and 'error'")
flag.StringVar(&releaseDir, "release-dir", "/tmp/downloads/", "Specify release directory for cluster-stack releases")
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.")
flag.Float64Var(&qps, "qps", 50, "Enable custom query per second for kubernetes API server")
flag.IntVar(&burst, "burst", 100, "Enable custom burst defines how many queries the API server will accept before enforcing the limit established by qps")

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

gitFactory := githubclient.NewFactory()
var gitFactory githubclient.Factory
if localMode {
gitFactory = fake.NewFactory()
} else {
gitFactory = githubclient.NewFactory()
}

restConfig := mgr.GetConfig()
restConfig.QPS = float32(qps)
Expand Down
2 changes: 1 addition & 1 deletion config/cso/clusterstack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ spec:
autoSubscribe: false
noProvider: true
versions:
- v2
- v2
43 changes: 43 additions & 0 deletions config/localmode/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace: cso-system

namePrefix: cso-

commonLabels:
cluster.x-k8s.io/provider: "infrastructure-cluster-stack-operator"

resources:
- ../crd
- ../rbac
- ../manager
- ../certmanager

patchesStrategicMerge:
- manager_config_patch.yaml
- manager_pull_policy.yaml
# vars:
# - name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
# objref:
# kind: Certificate
# group: cert-manager.io
# version: v1
# name: serving-cert # this name should match the one in certificate.yaml
# fieldref:
# fieldpath: metadata.namespace
# - name: CERTIFICATE_NAME
# objref:
# kind: Certificate
# group: cert-manager.io
# version: v1
# name: serving-cert # this name should match the one in certificate.yaml
# - name: SERVICE_NAMESPACE # namespace of the service
# objref:
# kind: Service
# version: v1
# name: webhook-service
# fieldref:
# fieldpath: metadata.namespace
# - name: SERVICE_NAME
# objref:
# kind: Service
# version: v1
# name: webhook-service
15 changes: 15 additions & 0 deletions config/localmode/manager_config_patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
spec:
template:
spec:
containers:
- image: ghcr.io/sovereigncloudstack/cso-staging:dev
name: manager
args:
- --leader-elect=true
- --release-dir=/tmp
- --local=true
11 changes: 11 additions & 0 deletions config/localmode/manager_pull_policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
spec:
template:
spec:
containers:
- name: manager
imagePullPolicy: Always
23 changes: 23 additions & 0 deletions config/localmode/manager_webhook_patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
spec:
template:
spec:
containers:
- name: manager
ports:
- containerPort: 9443
name: webhook-server
protocol: TCP
volumeMounts:
- mountPath: /tmp/k8s-webhook-server/serving-certs
name: cert
readOnly: true
volumes:
- name: cert
secret:
defaultMode: 420
secretName: cso-webhook-server-cert
9 changes: 9 additions & 0 deletions config/localmode/webhookcainjection_patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This patch add annotation to admission webhook config and
# the variables $(CERTIFICATE_NAMESPACE) and $(CERTIFICATE_NAME) will be substituted by kustomize.
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: validating-webhook-configuration
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
Loading
Loading