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

Allow kustomize examples to be bumped by crd-bumper #208

Merged
merged 1 commit into from
Sep 10, 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
6 changes: 5 additions & 1 deletion tools/crd-bumper/crd-bumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,13 @@ def bump_controllers(cgen, makecmd, git, stage, project, args, bumper_cfg):
controllers.edit_util_conversion_test()

# Bump any other, non-controller, directories of code.
if bumper_cfg is not None and 'extra_go_dirs' in bumper_cfg:
if bumper_cfg is not None and "extra_go_dirs" in bumper_cfg:
for extra_dir in bumper_cfg["extra_go_dirs"].split(","):
controllers.update_extras(extra_dir)
# Bump any necessary references in the config/ dir.
if bumper_cfg is not None and "extra_config_dirs" in bumper_cfg:
for extra_dir in bumper_cfg["extra_config_dirs"].split(","):
controllers.update_extra_config(extra_dir)

makecmd.fmt()
controllers.commit_bump_controllers(git, stage)
Expand Down
38 changes: 38 additions & 0 deletions tools/crd-bumper/pkg/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,26 @@ def update_extras(self, dirname):
if fname.endswith(".go"):
self._point_at_new_hub(kinds, full_path)

def update_extra_config(self, dirname):
"""Walk over Kustomize config files and bump them to point at the new hub.
This is for any resource that may be exposed to ArgoCD, which would would
otherwise mark the resource as OutOfSync because the argocd queries will
show it with the new hub.
"""

kinds = self._project.kinds(self._prev_ver)
if len(kinds) == 0:
raise ValueError(f"Nothing found at version {self._prev_ver}")

if os.path.isdir(dirname) is False:
raise ValueError(f"{dirname} is not a directory")

for root, _, f_names in os.walk(dirname, followlinks=False):
for fname in f_names:
full_path = os.path.join(root, fname)
if fname.endswith(".yaml"):
self._point_config_at_new_hub(kinds, full_path)

def _walk_files(self, top, kinds):
"""Walk the files in the given directory, and update them to point at the new hub."""

Expand Down Expand Up @@ -157,6 +177,24 @@ def _point_at_new_hub(self, kinds, path):
fu.replace_in_file(f"{group}{self._prev_ver}.", f"{group}{self._new_ver}.")
fu.store()

def _point_config_at_new_hub(self, kinds, path):
"""Update the given file to point it at the new hub."""

fu = FileUtil(self._dryrun, path)

if self._preferred_alias is None:
# Pick the first kind, use its group.
group = self._project.group(kinds[0], self._prev_ver)
else:
group = self._preferred_alias

pat = f"apiVersion: {group}"
line = fu.find_in_file(pat)
if line is not None:
line2 = line.replace(self._prev_ver, self._new_ver)
fu.replace_in_file(line, line2)
fu.store()

def _update_suite_test(self, kinds, path):
"""Update the suite_test.go file to include the setup of the new hub."""

Expand Down
8 changes: 1 addition & 7 deletions tools/crd-bumper/pkg/conversion_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,6 @@ def fix_kubebuilder_import_alias(self):
)
fu.store()

# for root, _, f_names in os.walk(f"api/{self._new_ver}", followlinks=False):
# for fname in f_names:
# full_path = os.path.join(root, fname)
# fu = FileUtil(self._dryrun, full_path)
# fu.replace_in_file(f"{group}{self._new_ver}", f"{self._preferred_alias}{self._new_ver}")
# fu.store()

def module(self):
"""Return the name of this Go module."""

Expand Down Expand Up @@ -389,6 +382,7 @@ def mk_spoke_fuzz_test(self):
fu.append(template)

# Wake up! Multi-line f-string:
# pylint: disable=f-string-without-interpolation
template = f"""
}}

Expand Down
Loading