diff --git a/tools/crd-bumper/crd-bumper.py b/tools/crd-bumper/crd-bumper.py index 1deb02c..0ff2727 100755 --- a/tools/crd-bumper/crd-bumper.py +++ b/tools/crd-bumper/crd-bumper.py @@ -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) diff --git a/tools/crd-bumper/pkg/controllers.py b/tools/crd-bumper/pkg/controllers.py index 9251b07..b9b4c76 100644 --- a/tools/crd-bumper/pkg/controllers.py +++ b/tools/crd-bumper/pkg/controllers.py @@ -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.""" @@ -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.""" diff --git a/tools/crd-bumper/pkg/conversion_gen.py b/tools/crd-bumper/pkg/conversion_gen.py index 5be249d..0153263 100644 --- a/tools/crd-bumper/pkg/conversion_gen.py +++ b/tools/crd-bumper/pkg/conversion_gen.py @@ -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.""" @@ -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""" }}