|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright 2025 The Kubernetes Authors. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +import os |
| 17 | +import glob |
| 18 | +import re |
| 19 | +import argparse |
| 20 | + |
| 21 | +def main(): |
| 22 | + parser = argparse.ArgumentParser(description='Generate release manifests.') |
| 23 | + parser.add_argument('--tag', required=True, help='The git tag for the release.') |
| 24 | + args = parser.parse_args() |
| 25 | + |
| 26 | + # Create the release_assets directory if it doesn't exist |
| 27 | + if not os.path.exists('release_assets'): |
| 28 | + os.makedirs('release_assets') |
| 29 | + |
| 30 | + all_yaml_files = glob.glob('k8s/**/*.yaml', recursive=True) |
| 31 | + image_url = f'registry.k8s.io/agent-sandbox/agent-sandbox-controller:{args.tag}' |
| 32 | + |
| 33 | + # --- Generate manifest.yaml --- |
| 34 | + print('INFO: Preparing core manifest.yaml') |
| 35 | + manifest_files = [f for f in all_yaml_files if 'extensions' not in os.path.basename(f)] |
| 36 | + with open('release_assets/manifest.yaml', 'w') as outfile: |
| 37 | + for fname in sorted(manifest_files): |
| 38 | + with open(fname) as infile: |
| 39 | + outfile.write(infile.read()) |
| 40 | + outfile.write('---\n') |
| 41 | + |
| 42 | + |
| 43 | + # Replace image placeholder in manifest.yaml |
| 44 | + print(f'INFO: Replacing image placeholder in core manifest.yaml with: {image_url}') |
| 45 | + with open('release_assets/manifest.yaml', 'r') as file: |
| 46 | + filedata = file.read() |
| 47 | + |
| 48 | + filedata = re.sub(r'ko://sigs.k8s.io/agent-sandbox/cmd/agent-sandbox-controller.*', image_url, filedata) |
| 49 | + |
| 50 | + with open('release_assets/manifest.yaml', 'w') as file: |
| 51 | + file.write(filedata) |
| 52 | + print('INFO: Successfully created release_assets/manifest.yaml') |
| 53 | + |
| 54 | + # --- Generate extensions.yaml --- |
| 55 | + print('INFO: Preparing extensions.yaml') |
| 56 | + extension_files = [f for f in all_yaml_files if 'extensions' in os.path.basename(f)] |
| 57 | + with open('release_assets/extensions.yaml', 'w') as outfile: |
| 58 | + for fname in sorted(extension_files): |
| 59 | + with open(fname) as infile: |
| 60 | + outfile.write(infile.read()) |
| 61 | + outfile.write('---\n') |
| 62 | + |
| 63 | + # Replace image placeholder in extensions.yaml |
| 64 | + print(f'INFO: Replacing image placeholder in extensions.yaml with: {image_url}') |
| 65 | + with open('release_assets/extensions.yaml', 'r') as file: |
| 66 | + filedata = file.read() |
| 67 | + |
| 68 | + filedata = re.sub(r'ko://sigs.k8s.io/agent-sandbox/cmd/agent-sandbox-controller.*', image_url, filedata) |
| 69 | + |
| 70 | + with open('release_assets/extensions.yaml', 'w') as file: |
| 71 | + file.write(filedata) |
| 72 | + print('INFO: Successfully created release_assets/extensions.yaml') |
| 73 | + |
| 74 | + |
| 75 | +if __name__ == '__main__': |
| 76 | + main() |
0 commit comments