1- #!/bin/env python
1+ #!/usr/ bin/env python
22# vim: filetype=python syntax=python tabstop=4 expandtab
33
44import argparse
@@ -55,6 +55,26 @@ def parse_args(argv: list[str]) -> argparse.Namespace:
5555 required = True ,
5656 )
5757
58+ parser .add_argument (
59+ "--quay-release" ,
60+ help = "Use this release tag for quay images. Defaults to --release if not provided. Useful when issuing patch releases that use existing images." ,
61+ type = cli_parse_release ,
62+ )
63+
64+ parser .add_argument (
65+ "--replaces" ,
66+ help = "CSV version that is replaced by this release. Example: 23.11.0" ,
67+ type = cli_parse_release ,
68+ )
69+
70+ parser .add_argument (
71+ "--skips" ,
72+ nargs = "*" ,
73+ help = "CSV versions that are skipped by this release. Example: 24.3.0" ,
74+ default = list (),
75+ type = cli_parse_release ,
76+ )
77+
5878 parser .add_argument (
5979 "-o" ,
6080 "--repo-operator" ,
@@ -92,8 +112,17 @@ def parse_args(argv: list[str]) -> argparse.Namespace:
92112 action = "store_true" ,
93113 )
94114
115+ parser .add_argument (
116+ "--channel" ,
117+ help = "Channel name to use for the OLM bundle. Default: <major>.<minor> from the release number or 'alpha' for '0.0.0-dev'" ,
118+ )
119+
95120 args = parser .parse_args (argv )
96121
122+ # Default to the actual release if no quay release is given
123+ if not args .quay_release :
124+ args .quay_release = args .release
125+
97126 if not args .repo_certified_operators :
98127 args .repo_certified_operators = (
99128 args .repo_operator .parent / "openshift-certified-operators"
@@ -136,21 +165,31 @@ def parse_args(argv: list[str]) -> argparse.Namespace:
136165 f"Certification repository path not found: { args .repo_certified_operators } or it's not a certified operator repository"
137166 )
138167
168+ ### Set bundle channel
169+ if not args .channel :
170+ if args .release == "0.0.0-dev" :
171+ args .channel = "alpha"
172+ else :
173+ args .channel = "." .join (args .release .split ("." )[:2 ])
139174 return args
140175
141176
142177def cli_validate_openshift_range (cli_arg : str ) -> str :
143178 if not re .match (r"^v4\.\d{2}-v4\.\d{2}$" , cli_arg ):
144- raise argparse .ArgumentTypeError ("Invalid OpenShift version range" )
179+ raise argparse .ArgumentTypeError (
180+ "Invalid OpenShift version range. Example: v4.11-v4.13"
181+ )
145182 return cli_arg
146183
147184
148185def cli_parse_release (cli_arg : str ) -> str :
149- if re .match (r"^\d{2}\.([1-9]|1[0-2])\.\d+$" , cli_arg ) or re .match (
186+ if re .match (r"^\d{2}\.([1-9]|1[0-2])\.\d+(-\d*)? $" , cli_arg ) or re .match (
150187 r"^0\.0\.0-dev$" , cli_arg
151188 ):
152189 return cli_arg
153- raise argparse .ArgumentTypeError ("Invalid release" )
190+ raise argparse .ArgumentTypeError (
191+ "Invalid version provided for release or replacement"
192+ )
154193
155194
156195def cli_log_level (cli_arg : str ) -> int :
@@ -189,7 +228,7 @@ def generate_csv_related_images(
189228 if c ["name" ] == args .op_name
190229 ]
191230 else :
192- return quay_image ([(args .op_name , args .release )])
231+ return quay_image ([(args .op_name , args .quay_release )])
193232
194233
195234def generate_manifests (args : argparse .Namespace ) -> list [dict ]:
@@ -214,11 +253,20 @@ def generate_manifests(args: argparse.Namespace) -> list[dict]:
214253 )
215254
216255 if not args .use_helm_images :
217- # patch the image of the operator container
218- # with the quay.io image
256+ # patch the image of the operator container with the quay.io image
219257 for c in op_deployment ["spec" ]["template" ]["spec" ]["containers" ]:
220258 if c ["name" ] == args .op_name :
221259 c ["image" ] = related_images [0 ]["image" ]
260+ # patch the annotation image of the operator deployment with the quay.io image
261+ try :
262+ if op_deployment ["spec" ]["template" ]["metadata" ]["annotations" ][
263+ "internal.stackable.tech/image"
264+ ]:
265+ op_deployment ["spec" ]["template" ]["metadata" ]["annotations" ][
266+ "internal.stackable.tech/image"
267+ ] = related_images [0 ]["image" ]
268+ except KeyError :
269+ pass
222270
223271 owned_crds = to_owned_crds (crds )
224272
@@ -358,10 +406,18 @@ def generate_csv(
358406
359407 result = load_resource ("csv.yaml" )
360408
409+ csv_name = (
410+ "spark-operator" if args .op_name == "spark-k8s-operator" else args .op_name
411+ )
412+
361413 result ["spec" ]["version" ] = args .release
414+ result ["spec" ]["replaces" ] = (
415+ f"{ csv_name } .v{ args .replaces } " if args .replaces else None
416+ )
417+ result ["spec" ]["skips" ] = [f"{ csv_name } .v{ v } " for v in args .skips ]
362418 result ["spec" ]["keywords" ] = [args .product ]
363419 result ["spec" ]["displayName" ] = CSV_DISPLAY_NAME [args .product ]
364- result ["metadata" ]["name" ] = f"{ args . op_name } .v{ args .release } "
420+ result ["metadata" ]["name" ] = f"{ csv_name } .v{ args .release } "
365421 result ["metadata" ]["annotations" ]["containerImage" ] = related_images [0 ]["image" ]
366422 result ["metadata" ]["annotations" ]["description" ] = CSV_DISPLAY_NAME [args .product ]
367423 result ["metadata" ]["annotations" ]["repository" ] = (
@@ -437,13 +493,18 @@ def generate_helm_templates(args: argparse.Namespace) -> list[dict]:
437493 }
438494 )
439495 ### Patch the version label
440- if (
441- crv := man ["metadata" ]["labels" ]["app.kubernetes.io/version" ]
442- ) != args .release :
443- logging .warning (
444- f"Version mismatch for '{ man ['metadata' ]['name' ]} '. Replacing '{ crv } ' with '{ args .release } '"
445- )
446- man ["metadata" ]["labels" ]["app.kubernetes.io/version" ] = args .release
496+ try :
497+ if (
498+ crv := man ["metadata" ]["labels" ]["app.kubernetes.io/version" ]
499+ ) != args .release :
500+ logging .warning (
501+ f"Version mismatch for '{ man ['metadata' ]['name' ]} '. Replacing '{ crv } ' with '{ args .release } '"
502+ )
503+ man ["metadata" ]["labels" ]["app.kubernetes.io/version" ] = (
504+ args .release
505+ )
506+ except KeyError :
507+ pass
447508
448509 logging .debug ("finish generate_helm_templates" )
449510
@@ -494,7 +555,7 @@ def quay_image(images: list[tuple[str, str]]) -> list[dict[str, str]]:
494555 data = json .load (response )
495556 if not data ["tags" ]:
496557 raise ManifestException (
497- f"Could not find manifest digest for request { tag_url } "
558+ f"Could not find manifest digest for release ' { release } ' on quay.io. Pass '--use-helm-images' to use docker.stackable.tech instead. "
498559 )
499560
500561 manifest_digest = [
@@ -523,6 +584,13 @@ def write_metadata(args: argparse.Namespace) -> None:
523584 )
524585 annos ["annotations" ]["com.redhat.openshift.versions" ] = args .openshift_versions
525586
587+ annos ["annotations" ][
588+ "operators.operatorframework.io.bundle.channel.default.v1"
589+ ] = args .channel
590+ annos ["annotations" ]["operators.operatorframework.io.bundle.channels.v1" ] = (
591+ args .channel
592+ )
593+
526594 anno_file = metadata_dir / "annotations.yaml"
527595 logging .info (f"Writing { anno_file } " )
528596 anno_file .write_text (yaml .dump (annos ))
0 commit comments