Skip to content

Commit 84124e2

Browse files
authored
Allow vendor-new-api to vendor multi API versions from one repo (#271)
Force the user to tell us which of the existing APIs was the previous hub; because the symver libraries do not sort API version names for us. Signed-off-by: Dean Roehrich <dean.roehrich@hpe.com>
1 parent 6bceb41 commit 84124e2

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

tools/crd-bumper/pkg/vendoring.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,24 @@
2424
class Vendor:
2525
"""Tools for vendoring a new API version."""
2626

27-
def __init__(self, dryrun, module, hub_ver, vendor_hub_ver, multi_vend=False):
27+
def __init__(
28+
self,
29+
dryrun,
30+
module,
31+
hub_ver,
32+
vendor_hub_ver,
33+
multi_vend=False,
34+
vendor_prev_hub_ver=None,
35+
):
36+
"""Init"""
2837
self._dryrun = dryrun
2938
self._module = module
3039
self._hub_ver = hub_ver
3140
self._vendor_hub_ver = vendor_hub_ver
3241
self._current_ver = None
3342
self._preferred_alias = None
3443
self._multi_vend = multi_vend
44+
self._vendor_prev_hub_ver = vendor_prev_hub_ver
3545

3646
def current_api_version(self):
3747
"""Return the current in-use API version."""
@@ -59,9 +69,9 @@ def set_current_api_version(self):
5969
break
6070
if len(dir_names) > 1 and self._multi_vend:
6171
# Multiple APIs are vendored here, and the user wants us to allow
62-
# it. Verify that the desired version is one of them.
72+
# it. Verify that the indicated previous hub version is one of them.
6373
for dname in dir_names:
64-
if dname == self._vendor_hub_ver:
74+
if dname == self._vendor_prev_hub_ver:
6575
self._current_ver = dname
6676
print("Multiple APIs have been allowed with -M, continuing")
6777
break

tools/crd-bumper/vendor-new-api.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,23 @@
107107
dest="multi_vend",
108108
help="Allow multiple API versions to be vendored from a single peer module. Expect this to be an unusual case.",
109109
)
110+
PARSER.add_argument(
111+
"--vendor-prev-hub-ver",
112+
type=str,
113+
required=True,
114+
help="Version of the previous hub API for the repo being vendored. Requires -M. Expect this to be an unusual case.",
115+
)
110116

111117

112118
def main():
113119
"""main"""
114120

115121
args = PARSER.parse_args()
116122

123+
if args.vendor_prev_hub_ver and not args.multi_vend:
124+
print("Option --vendor-prev-hub-ver requires -M.")
125+
sys.exit(1)
126+
117127
gitcli = GitCLI(args.dryrun, args.nocommit)
118128
gitcli.clone_and_cd(args.repo, args.workdir)
119129

@@ -155,7 +165,12 @@ def vendor_new_api(args, makecmd, git, gocli, bumper_cfg):
155165
"""Vendor the new API into the repo."""
156166

157167
vendor = Vendor(
158-
args.dryrun, args.module, args.hub_ver, args.vendor_hub_ver, args.multi_vend
168+
args.dryrun,
169+
args.module,
170+
args.hub_ver,
171+
args.vendor_hub_ver,
172+
args.multi_vend,
173+
args.vendor_prev_hub_ver,
159174
)
160175

161176
if vendor.uses_module() is False:

0 commit comments

Comments
 (0)