Skip to content

Commit

Permalink
Update dev environment for Kustomize
Browse files Browse the repository at this point in the history
In 514091a the k8s namespace resource got moved to a kustomization.
This requires running `kubectl apply` with the `-k` flag instead of
`-f`, otherwise the namespace doesn't get created and `inv dev-env`
exits with an error.

We copy the entire `manifests/` directory to a temporary directory
to keep the code DRY and accommodate future changes to the
kustomization. YAML files which aren't mentioned in
`kustomization.yaml` aren't applied when using `-k`, so we can safely
apply the entire manifests directory.
  • Loading branch information
johananl committed Mar 22, 2020
1 parent 6e13a3d commit 3c3c1a7
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions tasks.py
@@ -1,7 +1,8 @@
import glob
import os.path
import os
import re
import semver
import shutil
import sys
import yaml
import tempfile
Expand Down Expand Up @@ -196,14 +197,21 @@ def dev_env(ctx, architecture="amd64", name="kind", cni=None):
run("kind load docker-image --name={} metallb/mirror-server:dev-{}".format(name, architecture), echo=True)

run("kubectl delete po -nmetallb-system --all", echo=True)
with open("manifests/metallb.yaml") as f:
manifest = f.read()
manifest = manifest.replace(":main", ":dev-{}".format(architecture))
manifest = manifest.replace("imagePullPolicy: Always", "imagePullPolicy: Never")
with tempfile.NamedTemporaryFile() as tmp:
tmp.write(manifest.encode("utf-8"))
tmp.flush()
run("kubectl apply -f {}".format(tmp.name), echo=True)

manifests_dir = os.getcwd() + "/manifests"
with tempfile.TemporaryDirectory() as tmpdir:
# Copy manifests dir to temp dir.
shutil.copytree(manifests_dir, tmpdir, dirs_exist_ok=True)

with open(tmpdir + "/metallb.yaml") as f:
manifest = f.read()
manifest = manifest.replace(":main", ":dev-{}".format(architecture))
manifest = manifest.replace("imagePullPolicy: Always", "imagePullPolicy: Never")
with open(tmpdir + "/metallb.yaml", "w") as f:
f.write(manifest)
f.flush()

run("kubectl apply -k {}".format(tmpdir), echo=True)

with open("e2etest/manifests/mirror-server.yaml") as f:
manifest = f.read()
Expand Down

0 comments on commit 3c3c1a7

Please sign in to comment.