Skip to content

Commit

Permalink
split kustomize into prod and sim
Browse files Browse the repository at this point in the history
  • Loading branch information
drmorr0 committed Sep 23, 2024
1 parent f190042 commit 46947b4
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ repos:
language: system
entry: bash -c 'make kustomize && git diff --quiet'
pass_filenames: false
files: 'lib/api/v1/.*|k8s/.*|Cargo.toml'
files: 'sk-api/v1/.*|k8s/.*|Cargo.toml'
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ This package provides the following components:

## Installation

`kubectl apply -k k8s/kustomize`
1. To install `sk-tracer` in your prod cluster: `kubectl apply -k k8s/kustomize/prod`
2. To install `sk-ctrl` in your simulation cluster: `kubectl apply -k k8s/kustomize/sim`
3. To install `skctl` on your dev machine: `cargo install skctl`

## Documentation

Expand Down
2 changes: 1 addition & 1 deletion build
Submodule build updated 1 files
+1 −1 k8s.mk
18 changes: 14 additions & 4 deletions docs/intro/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,29 @@ SimKube images are [hosted on quay.io](https://quay.io/organization/appliedcompu
run SimKube in your cluster is to use these images along with the provided [kustomize](https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/)
YAML files in `k8s/kustomize`:

```
```bash
git clone https://github.com/acrlabs/simkube && cd simkube
kubectl apply -k k8s/kustomize

export PROD_CONTEXT=<your production cluster context name>
export SIM_CONTEXT=<your simulation environment context name>

# install sk-tracer in your production cluster
kubectl --context ${PROD_CONTEXT} apply -k k8s/kustomize/prod

# install sk-ctrl in your simulation environment
kubectl --context ${SIM_CONTEXT} apply -k k8s/kustomize/sim
```

You should now see the SimKube pods running in your cluster:


```
> kubectl get pods -n simkube
> kubectl --context ${PROD_CONTEXT} get pods -n simkube
NAMESPACE NAME READY STATUS RESTARTS AGE
simkube sk-ctrl-depl-b6fbb7744-l8bwm 1/1 Running 0 11h
simkube sk-tracer-depl-74546ccb48-5gmbc 1/1 Running 0 11h
> kubectl --context ${SIM_CONTEXT} get pods -n simkube
NAMESPACE NAME READY STATUS RESTARTS AGE
simkube sk-ctrl-depl-b6fbb7744-l8bwm 1/1 Running 0 11h
```

You'll need to also install `skctl` to start or interact with simulations; `skctl` is available on
Expand Down
5 changes: 5 additions & 0 deletions k8s/kustomize/base/kustomization.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- sk-namespace.yml
File renamed without changes.
6 changes: 6 additions & 0 deletions k8s/kustomize/prod/kustomization.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../base
- sk-tracer.yml
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../base
- simkube.io_simulations.yml
- 0000-global.k8s.yaml
- 0001-sk-tracer.k8s.yaml
- 0002-sk-ctrl.k8s.yaml
- sk-ctrl.yml
File renamed without changes.
File renamed without changes.
50 changes: 42 additions & 8 deletions k8s/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,29 @@

DAG_FILENAME = "dag.mermaid"
DIFF_FILENAME = "k8s.df"
KUSTOMIZATION_YML = """
---

KUSTOMIZATION_YML_BASE = """---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- sk-namespace.yml
"""
KUSTOMIZATION_YML_PROD = """---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../base
- sk-tracer.yml
"""
KUSTOMIZATION_YML_SIM = """---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../base
- simkube.io_simulations.yml
- 0000-global.k8s.yaml
- 0001-sk-tracer.k8s.yaml
- 0002-sk-ctrl.k8s.yaml
- sk-ctrl.yml
"""

QUAY_IO_PREFIX = "quay.io/appliedcomputing"


Expand Down Expand Up @@ -48,14 +61,36 @@ def get_images(to_build: T.List, kustomize: bool, build_dir: str) -> T.List[str]
return images


def write_kustomize_files(build_dir: str):
# This is all super brittle and could fail if, well, really anything changes, but I want to replace
# this whole system at some point anyways so I'm just gonna deal with fixing it then
os.makedirs(f"{build_dir}/base", exist_ok=True)
os.makedirs(f"{build_dir}/prod", exist_ok=True)
os.makedirs(f"{build_dir}/sim", exist_ok=True)

kustomization_path_base = f"{build_dir}/base/kustomization.yml"
kustomization_path_prod = f"{build_dir}/prod/kustomization.yml"
kustomization_path_sim = f"{build_dir}/sim/kustomization.yml"
with open(kustomization_path_base, "w", encoding="utf-8") as f:
f.write(KUSTOMIZATION_YML_BASE)
with open(kustomization_path_prod, "w", encoding="utf-8") as f:
f.write(KUSTOMIZATION_YML_PROD)
with open(kustomization_path_sim, "w", encoding="utf-8") as f:
f.write(KUSTOMIZATION_YML_SIM)

os.rename(f"{build_dir}/0000-global.k8s.yaml", f"{build_dir}/base/sk-namespace.yml")
os.rename(f"{build_dir}/0001-sk-tracer.k8s.yaml", f"{build_dir}/prod/sk-tracer.yml")
os.rename(f"{build_dir}/0002-sk-ctrl.k8s.yaml", f"{build_dir}/sim/sk-ctrl.yml")
os.rename(f"{build_dir}/simkube.io_simulations.yml", f"{build_dir}/sim/simkube.io_simulations.yml")


def main():
args = setup_args()
debug = not args.kustomize

build_dir = os.getenv("BUILD_DIR")
dag_path = None if args.kustomize else f"{build_dir}/{DAG_FILENAME}"
diff_path = f"{build_dir}/{DIFF_FILENAME}"
kustomization_path = f"{build_dir}/kustomization.yml"

apps = [SkTracer, SkCtrl]
images = get_images(apps, args.kustomize, build_dir)
Expand All @@ -66,8 +101,7 @@ def main():
)

if args.kustomize:
with open(kustomization_path, "w", encoding="utf-8") as f:
f.write(KUSTOMIZATION_YML)
write_kustomize_files(build_dir)
else:
with open(dag_path, "w", encoding="utf-8") as f:
f.write(graph)
Expand Down

0 comments on commit 46947b4

Please sign in to comment.