1
- #!/bin/env python
1
+ #!/usr/ bin/env python
2
2
# vim: filetype=python syntax=python tabstop=4 expandtab
3
3
4
4
import argparse
@@ -55,6 +55,26 @@ def parse_args(argv: list[str]) -> argparse.Namespace:
55
55
required = True ,
56
56
)
57
57
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
+
58
78
parser .add_argument (
59
79
"-o" ,
60
80
"--repo-operator" ,
@@ -92,8 +112,17 @@ def parse_args(argv: list[str]) -> argparse.Namespace:
92
112
action = "store_true" ,
93
113
)
94
114
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
+
95
120
args = parser .parse_args (argv )
96
121
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
+
97
126
if not args .repo_certified_operators :
98
127
args .repo_certified_operators = (
99
128
args .repo_operator .parent / "openshift-certified-operators"
@@ -136,21 +165,31 @@ def parse_args(argv: list[str]) -> argparse.Namespace:
136
165
f"Certification repository path not found: { args .repo_certified_operators } or it's not a certified operator repository"
137
166
)
138
167
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 ])
139
174
return args
140
175
141
176
142
177
def cli_validate_openshift_range (cli_arg : str ) -> str :
143
178
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
+ )
145
182
return cli_arg
146
183
147
184
148
185
def 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 (
150
187
r"^0\.0\.0-dev$" , cli_arg
151
188
):
152
189
return cli_arg
153
- raise argparse .ArgumentTypeError ("Invalid release" )
190
+ raise argparse .ArgumentTypeError (
191
+ "Invalid version provided for release or replacement"
192
+ )
154
193
155
194
156
195
def cli_log_level (cli_arg : str ) -> int :
@@ -189,7 +228,7 @@ def generate_csv_related_images(
189
228
if c ["name" ] == args .op_name
190
229
]
191
230
else :
192
- return quay_image ([(args .op_name , args .release )])
231
+ return quay_image ([(args .op_name , args .quay_release )])
193
232
194
233
195
234
def generate_manifests (args : argparse .Namespace ) -> list [dict ]:
@@ -214,11 +253,20 @@ def generate_manifests(args: argparse.Namespace) -> list[dict]:
214
253
)
215
254
216
255
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
219
257
for c in op_deployment ["spec" ]["template" ]["spec" ]["containers" ]:
220
258
if c ["name" ] == args .op_name :
221
259
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
222
270
223
271
owned_crds = to_owned_crds (crds )
224
272
@@ -358,10 +406,18 @@ def generate_csv(
358
406
359
407
result = load_resource ("csv.yaml" )
360
408
409
+ csv_name = (
410
+ "spark-operator" if args .op_name == "spark-k8s-operator" else args .op_name
411
+ )
412
+
361
413
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 ]
362
418
result ["spec" ]["keywords" ] = [args .product ]
363
419
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 } "
365
421
result ["metadata" ]["annotations" ]["containerImage" ] = related_images [0 ]["image" ]
366
422
result ["metadata" ]["annotations" ]["description" ] = CSV_DISPLAY_NAME [args .product ]
367
423
result ["metadata" ]["annotations" ]["repository" ] = (
@@ -437,13 +493,18 @@ def generate_helm_templates(args: argparse.Namespace) -> list[dict]:
437
493
}
438
494
)
439
495
### 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
447
508
448
509
logging .debug ("finish generate_helm_templates" )
449
510
@@ -494,7 +555,7 @@ def quay_image(images: list[tuple[str, str]]) -> list[dict[str, str]]:
494
555
data = json .load (response )
495
556
if not data ["tags" ]:
496
557
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. "
498
559
)
499
560
500
561
manifest_digest = [
@@ -523,6 +584,13 @@ def write_metadata(args: argparse.Namespace) -> None:
523
584
)
524
585
annos ["annotations" ]["com.redhat.openshift.versions" ] = args .openshift_versions
525
586
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
+
526
594
anno_file = metadata_dir / "annotations.yaml"
527
595
logging .info (f"Writing { anno_file } " )
528
596
anno_file .write_text (yaml .dump (annos ))
0 commit comments