Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject annotations for deployments in addonTemplates #747

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion hack/bundle-automation/generate-charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,36 @@ def updateDeployments(chartName, helmChart, exclusions, inclusions):
if 'pullSecretOverride' in inclusions:
addPullSecretOverride(deployment)

# injectAnnotationsForAddonTemplate injects following annotations for deployments in the AddonTemplate:
# - target.workload.openshift.io/management: '{"effect": "PreferredDuringScheduling"}'
def injectAnnotationsForAddonTemplate(helmChart):
logging.info("Injecting Annotations for deployments in the AddonTemplate ...")

addonTemplates = findTemplatesOfType(helmChart, 'AddOnTemplate')
for addonTemplate in addonTemplates:
injected = False
with open(addonTemplate, 'r') as f:
templateContent = yaml.safe_load(f)
agentSpec = templateContent['spec']['agentSpec']
if 'workload' not in agentSpec:
return
workload = agentSpec['workload']
if 'manifests' not in workload:
return
manifests = workload['manifests']
for manifest in manifests:
if manifest['kind'] == 'Deployment':
metadata = manifest['spec']['template']['metadata']
if 'annotations' not in metadata:
metadata['annotations'] = {}
if 'target.workload.openshift.io/management' not in metadata['annotations']:
metadata['annotations']['target.workload.openshift.io/management'] = '{"effect": "PreferredDuringScheduling"}'
injected = True
if injected:
with open(addonTemplate, 'w') as f:
yaml.dump(templateContent, f, width=float("inf"))
logging.info("Annotations injected successfully. \n")


# fixImageReferencesForAddonTemplate identify the image references for every deployment in addontemplates, if any exist
# in the image field, insert helm flow control code to reference it, and add image-key to the values.yaml file.
Expand Down Expand Up @@ -503,7 +533,6 @@ def fixImageReferencesForAddonTemplate(helmChart, imageKeyMapping):
logging.critical("No image key mapping provided for imageKey: %s" % image_key)
exit(1)
imageKeys.append(image_key)
temp = container['image']
container['image'] = "{{ .Values.global.imageOverrides." + image_key + " }}"
# container['imagePullPolicy'] = "{{ .Values.global.pullPolicy }}"
with open(addonTemplate, 'w') as f:
Expand Down Expand Up @@ -548,6 +577,7 @@ def injectRequirements(helmChart, chartName, imageKeyMapping, skipRBACOverrides,
fixImageReferences(helmChart, imageKeyMapping)
fixEnvVarImageReferences(helmChart, imageKeyMapping)
fixImageReferencesForAddonTemplate(helmChart, imageKeyMapping)
injectAnnotationsForAddonTemplate(helmChart)
if not skipRBACOverrides:
updateRBAC(helmChart, chartName)
updateDeployments(chartName, helmChart, exclusions, inclusions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ spec:
addon-agent: managed-serviceaccount
template:
metadata:
annotations:
target.workload.openshift.io/management: '{"effect": "PreferredDuringScheduling"}'
labels:
addon-agent: managed-serviceaccount
spec:
Expand Down
Loading