Skip to content

Commit

Permalink
Update manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
allenporter committed Apr 23, 2024
1 parent 9c9fe9c commit cdb86ce
Showing 1 changed file with 42 additions and 25 deletions.
67 changes: 42 additions & 25 deletions flux_local/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class HelmChart(BaseManifest):
name: str
"""The name of the chart within the HelmRepository."""

version: Optional[str] = field(metadata={"serialize":"omit"})
version: Optional[str] = field(metadata={"serialize": "omit"})
"""The version of the chart."""

repo_name: str
Expand All @@ -104,7 +104,7 @@ class HelmChart(BaseManifest):
repo_namespace: str
"""The namespace of the repository."""

repo_kind: str
repo_kind: str = HELM_REPOSITORY
"""The kind of the soruceRef of the repository (e.g. HelmRepository, GitRepository)."""

@classmethod
Expand All @@ -131,7 +131,7 @@ def parse_doc(cls, doc: dict[str, Any], default_namespace: str) -> "HelmChart":
version=version,
repo_name=source_ref["name"],
repo_namespace=source_ref.get("namespace", default_namespace),
repo_kind=source_ref.get("kind", "HelmRepository"),
repo_kind=source_ref.get("kind", HELM_REPOSITORY),
)

@property
Expand All @@ -155,15 +155,20 @@ class ValuesReference(BaseManifest):
name: str
"""The name of the resource."""

values_key: str = field(metadata=field_options(alias="valuesKey"), default="values.yaml")
values_key: str = field(
metadata=field_options(alias="valuesKey"), default="values.yaml"
)
"""The key in the resource that contains the values."""

target_path: Optional[str] = field(metadata=field_options(alias="targetPath"), default=None)
target_path: Optional[str] = field(
metadata=field_options(alias="targetPath"), default=None
)
"""The path in the HelmRelease values to store the values."""

optional: bool = False
"""Whether the reference is optional."""


@dataclass
class HelmRelease(BaseManifest):
"""A representation of a Flux HelmRelease."""
Expand All @@ -177,10 +182,10 @@ class HelmRelease(BaseManifest):
chart: HelmChart
"""A mapping to a specific helm chart for this HelmRelease."""

values: Optional[dict[str, Any]] = field(metadata={"serialize":"omit"})
values: Optional[dict[str, Any]] = field(metadata={"serialize": "omit"})
"""The values to install in the chart."""

values_from: Optional[list[ValuesReference]] = field(metadata={"serialize":"omit"})
values_from: Optional[list[ValuesReference]] = field(metadata={"serialize": "omit"})
"""A list of values to reference from an ConfigMap or Secret."""

images: list[str] | None = field(default=None)
Expand All @@ -200,7 +205,9 @@ def parse_doc(cls, doc: dict[str, Any]) -> "HelmRelease":
spec = doc["spec"]
values_from: list[ValuesReference] | None = None
if values_from_dict := spec.get("valuesFrom"):
values_from = [ValuesReference.from_dict(subdoc) for subdoc in values_from_dict]
values_from = [
ValuesReference.from_dict(subdoc) for subdoc in values_from_dict
]
return HelmRelease(
name=name,
namespace=namespace,
Expand Down Expand Up @@ -278,7 +285,7 @@ class ClusterPolicy(BaseManifest):
namespace: str | None = None
"""The namespace of the kustomization."""

doc: dict[str, Any] | None = field(metadata={"serialize":"omit"}, default=None)
doc: dict[str, Any] | None = field(metadata={"serialize": "omit"}, default=None)
"""The raw ClusterPolicy document."""

@classmethod
Expand All @@ -305,10 +312,12 @@ class ConfigMap(BaseManifest):
namespace: str | None = None
"""The namespace of the kustomization."""

data: dict[str, Any] | None = field(metadata={"serialize":"omit"}, default=None)
data: dict[str, Any] | None = field(metadata={"serialize": "omit"}, default=None)
"""The data in the ConfigMap."""

binary_data: dict[str, Any] | None = field(metadata={"serialize":"omit"}, default=None)
binary_data: dict[str, Any] | None = field(
metadata={"serialize": "omit"}, default=None
)
"""The binary data in the ConfigMap."""

@classmethod
Expand Down Expand Up @@ -338,10 +347,12 @@ class Secret(BaseManifest):
namespace: str | None = None
"""The namespace of the kustomization."""

data: dict[str, Any] | None = field(metadata={"serialize":"omit"}, default=None)
data: dict[str, Any] | None = field(metadata={"serialize": "omit"}, default=None)
"""The data in the Secret."""

string_data: dict[str, Any] | None = field(metadata={"serialize":"omit"}, default=None)
string_data: dict[str, Any] | None = field(
metadata={"serialize": "omit"}, default=None
)
"""The string data in the Secret."""

@classmethod
Expand Down Expand Up @@ -379,6 +390,7 @@ class SubstituteReference(BaseManifest):
optional: bool = False
"""Whether the reference is optional."""


@dataclass
class Kustomization(BaseManifest):
"""A Kustomization is a set of declared cluster artifacts.
Expand Down Expand Up @@ -412,34 +424,40 @@ class Kustomization(BaseManifest):
secrets: list[Secret] = field(default_factory=list)
"""The list of secrets referenced in the kustomization."""

source_path: str | None = field(metadata={"serialize":"omit"}, default=None)
source_path: str | None = field(metadata={"serialize": "omit"}, default=None)
"""Optional source path for this Kustomization, relative to the build path."""

source_kind: str | None = field(metadata={"serialize":"omit"}, default=None)
source_kind: str | None = field(metadata={"serialize": "omit"}, default=None)
"""The sourceRef kind that provides this Kustomization e.g. GitRepository etc."""

source_name: str | None = field(metadata={"serialize":"omit"}, default=None)
source_name: str | None = field(metadata={"serialize": "omit"}, default=None)
"""The name of the sourceRef that provides this Kustomization."""

source_namespace: str | None = field(metadata={"serialize":"omit"}, default=None)
source_namespace: str | None = field(metadata={"serialize": "omit"}, default=None)
"""The namespace of the sourceRef that provides this Kustomization."""

target_namespace: str | None = field(metadata={"serialize":"omit"}, default=None)
target_namespace: str | None = field(metadata={"serialize": "omit"}, default=None)
"""The namespace to target when performing the operation."""

contents: dict[str, Any] | None = field(metadata={"serialize":"omit"}, default=None)
contents: dict[str, Any] | None = field(
metadata={"serialize": "omit"}, default=None
)
"""Contents of the raw Kustomization document."""

images: list[str] | None = field(default=None)
"""The list of images referenced in the kustomization."""

postbuild_substitute: Optional[dict[str, Any]] = field(metadata={"serialize":"omit"}, default=None)
postbuild_substitute: Optional[dict[str, Any]] = field(
metadata={"serialize": "omit"}, default=None
)
"""A map of key/value pairs to substitute into the final YAML manifest, after building."""

postbuild_substitute_from: Optional[list[SubstituteReference]] = field(metadata={"serialize":"omit"}, default=None)
postbuild_substitute_from: Optional[list[SubstituteReference]] = field(
metadata={"serialize": "omit"}, default=None
)
"""A list of substitutions to reference from an ConfigMap or Secret."""

depends_on: list[str] | None = field(metadata={"serialize":"omit"}, default=None)
depends_on: list[str] | None = field(metadata={"serialize": "omit"}, default=None)
"""A list of namespaced names that this Kustomization depends on."""

@classmethod
Expand Down Expand Up @@ -494,7 +512,6 @@ def namespaced_name(self) -> str:
"""Return the namespace and name concatenated as an id."""
return f"{self.namespace}/{self.name}"


def validate_depends_on(self, all_ks: set[str]) -> None:
"""Validate depends_on values are all correct given the list of Kustomizations."""
depends_on = set(self.depends_on or {})
Expand All @@ -505,7 +522,7 @@ def validate_depends_on(self, all_ks: set[str]) -> None:
missing,
)
self.depends_on = list(depends_on - missing)

def update_postbuild_substitutions(self, substitutions: dict[str, Any]) -> None:
"""Update the postBuild.substitutions in the extracted values and raw doc contents."""
if self.postbuild_substitute is None:
Expand All @@ -518,6 +535,7 @@ def update_postbuild_substitutions(self, substitutions: dict[str, Any]) -> None:
post_build["substitute"] = substitute
substitute.update(substitutions)


@dataclass
class Cluster(BaseManifest):
"""A set of nodes that run containerized applications.
Expand Down Expand Up @@ -573,7 +591,6 @@ class Manifest(BaseManifest):
"""A list of Clusters represented in the repo."""



async def read_manifest(manifest_path: Path) -> Manifest:
"""Return the contents of a serialized manifest file.
Expand Down

0 comments on commit cdb86ce

Please sign in to comment.