Skip to content

Commit 6bceb41

Browse files
authored
Allow vendor-new-api to vendor multi API versions from one repo (#270)
Signed-off-by: Dean Roehrich <dean.roehrich@hpe.com>
1 parent cc917b9 commit 6bceb41

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

tools/crd-bumper/pkg/vendoring.py

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

27-
def __init__(self, dryrun, module, hub_ver, vendor_hub_ver):
27+
def __init__(self, dryrun, module, hub_ver, vendor_hub_ver, multi_vend=False):
2828
self._dryrun = dryrun
2929
self._module = module
3030
self._hub_ver = hub_ver
3131
self._vendor_hub_ver = vendor_hub_ver
3232
self._current_ver = None
3333
self._preferred_alias = None
34+
self._multi_vend = multi_vend
3435

3536
def current_api_version(self):
3637
"""Return the current in-use API version."""
@@ -56,6 +57,16 @@ def set_current_api_version(self):
5657
# Only one API vendored here.
5758
self._current_ver = dir_names[0]
5859
break
60+
if len(dir_names) > 1 and self._multi_vend:
61+
# Multiple APIs are vendored here, and the user wants us to allow
62+
# it. Verify that the desired version is one of them.
63+
for dname in dir_names:
64+
if dname == self._vendor_hub_ver:
65+
self._current_ver = dname
66+
print("Multiple APIs have been allowed with -M, continuing")
67+
break
68+
if self._current_ver is not None:
69+
break
5970
raise ValueError(
6071
f"Expected to find one API at {path}, but found {len(dir_names)}."
6172
)

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import sys
2525
import yaml
2626

27-
from pkg.conversion_gen import ConversionGen
2827
from pkg.git_cli import GitCLI
2928
from pkg.make_cmd import MakeCmd
3029
from pkg.vendoring import Vendor
@@ -102,6 +101,12 @@
102101
default=WORKING_DIR,
103102
help=f"Name for working directory. All repos will be cloned below this directory. Default: {WORKING_DIR}.",
104103
)
104+
PARSER.add_argument(
105+
"-M",
106+
action="store_true",
107+
dest="multi_vend",
108+
help="Allow multiple API versions to be vendored from a single peer module. Expect this to be an unusual case.",
109+
)
105110

106111

107112
def main():
@@ -149,7 +154,9 @@ def main():
149154
def vendor_new_api(args, makecmd, git, gocli, bumper_cfg):
150155
"""Vendor the new API into the repo."""
151156

152-
vendor = Vendor(args.dryrun, args.module, args.hub_ver, args.vendor_hub_ver)
157+
vendor = Vendor(
158+
args.dryrun, args.module, args.hub_ver, args.vendor_hub_ver, args.multi_vend
159+
)
153160

154161
if vendor.uses_module() is False:
155162
print(

0 commit comments

Comments
 (0)