Skip to content

Instantly share code, notes, and snippets.

@0xFelix
Last active March 20, 2023 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 0xFelix/42f74f2f6359f74801b4a0e3b413144f to your computer and use it in GitHub Desktop.
Save 0xFelix/42f74f2f6359f74801b4a0e3b413144f to your computer and use it in GitHub Desktop.
rhel-subscribed-templates.yaml
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: rhel-subscribed-templates
spec:
params:
- name: activationKey
description: Activation key that is injected into the VM template's cloud-init configuration
type: string
- name: organization
description: Organization that is injected into the VM template's cloud-init configuration
type: string
- name: sourceTemplateNamespace
description: Namespace of the Templates which are used to create subscribed Templates.
type: string
default: openshift
tasks:
- name: create-pipelineruns
params:
- name: SCRIPT
value: |
#!/usr/bin/env bash
cat <<EOF > /tmp/output.tpl
{{- range .items -}}
{{- if slice .metadata.name 0 4 | eq "rhel" -}}
{{.metadata.name}};{{index .metadata.annotations "openshift.io/display-name"}};{{index .metadata.labels "template.kubevirt.io/default-os-variant"}}{{"\n"}}
{{- end -}}
{{- end -}}
EOF
while read -r line; do
IFS=';' read -ra template <<< "$line"
oc create -f - <<EOF
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: rhel-inject-subscription-
spec:
params:
- name: activationKey
value: "$(params.activationKey)"
- name: organization
value: "$(params.organization)"
- name: sourceTemplateName
value: "${template[0]}"
- name: sourceTemplateNamespace
value: "$(params.sourceTemplateNamespace)"
- name: subscribedTemplateName
value: "${template[0]}-subscribed"
- name: subscribedTemplateDisplayName
value: "Subscribed ${template[1]}"
- name: subscribedTemplateDefaultVariant
value: "${template[2]}"
pipelineRef:
name: rhel-inject-subscription
serviceAccountName: pipeline
timeout: 10m
EOF
done < <(oc get template -n $(params.sourceTemplateNamespace) -o go-template-file=/tmp/output.tpl)
timeout: 10m
taskRef:
kind: ClusterTask
name: openshift-client
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment