Skip to content

Commit

Permalink
add app label to deployment obj
Browse files Browse the repository at this point in the history
  • Loading branch information
drmorr0 committed Jan 29, 2024
1 parent 2450f31 commit 24770a8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

test:
poetry run coverage erase
poetry run coverage run -m pytest -svv itests
JSII_SILENCE_WARNING_UNTESTED_NODE_VERSION=1 poetry run coverage run -m pytest -svv itests
poetry run coverage report --show-missing
5 changes: 2 additions & 3 deletions fireconfig/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

class DeploymentBuilder(ObjectBuilder):
def __init__(self, *, app_label: str, tag: T.Optional[str] = None):
super().__init__()
self._selector = {_APP_LABEL_KEY: app_label}
super().__init__(labels=self._selector)

self._replicas: T.Union[int, T.Tuple[int, int]] = 1
self._app_label = app_label
self._selector = {_APP_LABEL_KEY: app_label}
self._tag = "" if tag is None else f"{tag}-"

self._pod_annotations: T.MutableMapping[str, str] = {}
Expand Down Expand Up @@ -78,7 +78,6 @@ def with_toleration(self, key: str, value: str = "", effect: TaintEffect = Taint
return self

def _build(self, meta: k8s.ObjectMeta, chart: Chart) -> k8s.KubeDeployment:
# TODO auto-add app key
pod_meta: T.MutableMapping[str, T.Any] = {}
if self._pod_annotations:
pod_meta["annotations"] = self._pod_annotations
Expand Down
10 changes: 7 additions & 3 deletions fireconfig/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@


class ObjectBuilder(metaclass=ABCMeta):
def __init__(self: T.Self):
self._annotations: T.MutableMapping[str, str] = {}
self._labels: T.MutableMapping[str, str] = {}
def __init__(
self: T.Self,
annotations: T.MutableMapping[str, T.Any] = dict(),
labels: T.MutableMapping[str, T.Any] = dict(),
):
self._annotations: T.MutableMapping[str, str] = annotations
self._labels: T.MutableMapping[str, str] = labels
self._deps: T.List[ApiObject] = []

def with_annotation(self, key: str, value: str) -> T.Self:
Expand Down
4 changes: 2 additions & 2 deletions fireconfig/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ def find_deleted_nodes(
del_lines = False

for l in f.readlines():
chart_match = re.match("^\s*subgraph (.*)", l)
chart_match = re.match(r"^\s*subgraph (.*)", l)
if chart_match:
current_chart = chart_match.group(1)
elif re.match("^\s*end$", l):
elif re.match(r"^\s*end$", l):
current_chart = None
if l.startswith(DELETED_OBJS_START):
del_lines = True
Expand Down
2 changes: 2 additions & 0 deletions itests/output/0001-fc-test-package.k8s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ data:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
fireconfig.io/app: deployment1
name: fc-test-package-depl
namespace: the-namespace
spec:
Expand Down
3 changes: 2 additions & 1 deletion itests/test_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def test_deployment():
dag, diff = fire.compile(
{"the-namespace": [FCTestPackage()]},
dag_filename=old_dag_filename,
cdk8s_outdir=OUTPUT_DIR
cdk8s_outdir=OUTPUT_DIR,
dry_run=True,
)

assert diff == ""
Expand Down

0 comments on commit 24770a8

Please sign in to comment.