Skip to content

Commit

Permalink
Fixed template manifests
Browse files Browse the repository at this point in the history
Manifests are processed in 2 steps now:

1. include files only
2. replace variables

This is not possible in 1 step

Signed-off-by: Marc Sluiter <[email protected]>
  • Loading branch information
slintes committed Dec 20, 2018
1 parent 2ada971 commit aceb177
Show file tree
Hide file tree
Showing 18 changed files with 157 additions and 69 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ vendor/**/*_test.go
**/polarion.xml
tools/manifest-templator/manifest-templator
tools/vms-generator/vms-generator
.coverprofile
.coverprofile
manifests/**/*.tmp
25 changes: 17 additions & 8 deletions hack/build-manifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,50 @@ source hack/config.sh

manifest_docker_prefix=${manifest_docker_prefix-${docker_prefix}}

# make sure manifests in dev are processed first, so that their result can be used in other manifests (see --dev-manifests-dir)
args=$(cd ${KUBEVIRT_DIR}/manifests && find * -type f -name "*.yaml.in" | sort)

rm -rf ${MANIFESTS_OUT_DIR}
rm -rf ${MANIFEST_TEMPLATES_OUT_DIR}

(cd ${KUBEVIRT_DIR}/tools/manifest-templator/ && go build)

# first process file includes only
args=$(cd ${KUBEVIRT_DIR}/manifests && find dev release -type f -name "*.yaml.in")
for arg in $args; do
outfile=${KUBEVIRT_DIR}/manifests/${arg}.tmp

${KUBEVIRT_DIR}/tools/manifest-templator/manifest-templator \
--process-files \
--generated-manifests-dir=${KUBEVIRT_DIR}/manifests/generated/ \
--dev-manifests-dir=${KUBEVIRT_DIR}/manifests/dev/ \
--input-file=${KUBEVIRT_DIR}/manifests/${arg} >${outfile}
done

# then process variables
args=$(cd ${KUBEVIRT_DIR}/manifests && find dev release -type f -name "*.yaml.in.tmp")
for arg in $args; do
final_out_dir=$(dirname ${MANIFESTS_OUT_DIR}/${arg})
final_templates_out_dir=$(dirname ${MANIFEST_TEMPLATES_OUT_DIR}/${arg})
mkdir -p ${final_out_dir}
mkdir -p ${final_templates_out_dir}
manifest=$(basename -s .in ${arg})
manifest=$(basename -s .in.tmp ${arg})
outfile=${final_out_dir}/${manifest}
template_outfile=${final_templates_out_dir}/${manifest}.j2

${KUBEVIRT_DIR}/tools/manifest-templator/manifest-templator \
--process-vars \
--namespace=${namespace} \
--cdi-namespace=${cdi_namespace} \
--container-prefix=${manifest_docker_prefix} \
--container-tag=${docker_tag} \
--image-pull-policy=${image_pull_policy} \
--generated-manifests-dir=${KUBEVIRT_DIR}/manifests/generated/ \
--dev-manifests-dir=${MANIFESTS_OUT_DIR}/dev/ \
--input-file=${KUBEVIRT_DIR}/manifests/$arg >${outfile}

${KUBEVIRT_DIR}/tools/manifest-templator/manifest-templator \
--process-vars \
--namespace="{{ namespace }}" \
--cdi-namespace="{{ cdi_namespace }}" \
--container-prefix="{{ docker_prefix }}" \
--container-tag="{{ docker_tag }}" \
--image-pull-policy="{{ image_pull_policy }}" \
--generated-manifests-dir=${KUBEVIRT_DIR}/manifests/generated/ \
--dev-manifests-dir=${MANIFESTS_OUT_DIR}/dev/ \
--input-file=${KUBEVIRT_DIR}/manifests/$arg >${template_outfile}
done

Expand Down
10 changes: 5 additions & 5 deletions hack/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ ${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=vmirs >${KUBE
${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=vmipreset >${KUBEVIRT_DIR}/manifests/generated/vmipreset-resource.yaml
${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=vm >${KUBEVIRT_DIR}/manifests/generated/vm-resource.yaml
${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=vmim >${KUBEVIRT_DIR}/manifests/generated/vmim-resource.yaml
${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=rbac --namespace=${namespace} >${KUBEVIRT_DIR}/manifests/generated/rbac.authorization.k8s.yaml
${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=prometheus --namespace=${namespace} >${KUBEVIRT_DIR}/manifests/generated/prometheus.yaml
${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=virt-api --namespace=${namespace} --repository=${docker_prefix} --version=${docker_tag} --pullPolicy=${image_pull_policy} >${KUBEVIRT_DIR}/manifests/generated/virt-api.yaml
${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=virt-controller --namespace=${namespace} --repository=${docker_prefix} --version=${docker_tag} --pullPolicy=${image_pull_policy} >${KUBEVIRT_DIR}/manifests/generated/virt-controller.yaml
${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=virt-handler --namespace=${namespace} --repository=${docker_prefix} --version=${docker_tag} --pullPolicy=${image_pull_policy} >${KUBEVIRT_DIR}/manifests/generated/virt-handler.yaml
${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=rbac --namespace={{.Namespace}} >${KUBEVIRT_DIR}/manifests/generated/rbac.authorization.k8s.yaml.in
${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=prometheus --namespace={{.Namespace}} >${KUBEVIRT_DIR}/manifests/generated/prometheus.yaml.in
${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=virt-api --namespace={{.Namespace}} --repository={{.DockerPrefix}} --version={{.DockerTag}} --pullPolicy={{.ImagePullPolicy}} >${KUBEVIRT_DIR}/manifests/generated/virt-api.yaml.in
${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=virt-controller --namespace={{.Namespace}} --repository={{.DockerPrefix}} --version={{.DockerTag}} --pullPolicy={{.ImagePullPolicy}} >${KUBEVIRT_DIR}/manifests/generated/virt-controller.yaml.in
${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=virt-handler --namespace={{.Namespace}} --repository={{.DockerPrefix}} --version={{.DockerTag}} --pullPolicy={{.ImagePullPolicy}} >${KUBEVIRT_DIR}/manifests/generated/virt-handler.yaml.in

(cd ${KUBEVIRT_DIR}/tools/vms-generator/ && go build)
${KUBEVIRT_DIR}/tools/vms-generator/vms-generator --generated-vms-dir=${KUBEVIRT_DIR}/cluster/examples
Expand Down
2 changes: 1 addition & 1 deletion manifests/dev/prometheus.yaml.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{index .GeneratedManifests "prometheus.yaml"}}
{{index .GeneratedManifests "prometheus.yaml.in"}}
2 changes: 1 addition & 1 deletion manifests/dev/rbac.authorization.k8s.yaml.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{index .GeneratedManifests "rbac.authorization.k8s.yaml"}}
{{index .GeneratedManifests "rbac.authorization.k8s.yaml.in"}}
2 changes: 1 addition & 1 deletion manifests/dev/virt-api.yaml.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{index .GeneratedManifests "virt-api.yaml"}}
{{index .GeneratedManifests "virt-api.yaml.in"}}
2 changes: 1 addition & 1 deletion manifests/dev/virt-controller.yaml.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{index .GeneratedManifests "virt-controller.yaml"}}
{{index .GeneratedManifests "virt-controller.yaml.in"}}
2 changes: 1 addition & 1 deletion manifests/dev/virt-handler.yaml.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{index .GeneratedManifests "virt-handler.yaml"}}
{{index .GeneratedManifests "virt-handler.yaml.in"}}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
kubevirt.io: ""
prometheus.kubevirt.io: ""
name: kubevirt-prometheus-metrics
namespace: kubevirt
namespace: {{.Namespace}}
spec:
ports:
- name: metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,31 +128,31 @@ metadata:
labels:
kubevirt.io: ""
name: kubevirt-privileged
namespace: kubevirt
namespace: {{.Namespace}}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
kubevirt.io: ""
name: kubevirt-privileged-cluster-admin
namespace: kubevirt
namespace: {{.Namespace}}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: kubevirt-privileged
namespace: kubevirt
namespace: {{.Namespace}}
---
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
kubevirt.io: ""
name: kubevirt-apiserver
namespace: kubevirt
namespace: {{.Namespace}}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down Expand Up @@ -233,39 +233,39 @@ metadata:
labels:
kubevirt.io: ""
name: kubevirt-apiserver
namespace: kubevirt
namespace: {{.Namespace}}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kubevirt-apiserver
subjects:
- kind: ServiceAccount
name: kubevirt-apiserver
namespace: kubevirt
namespace: {{.Namespace}}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
kubevirt.io: ""
name: kubevirt-apiserver-auth-delegator
namespace: kubevirt
namespace: {{.Namespace}}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:auth-delegator
subjects:
- kind: ServiceAccount
name: kubevirt-apiserver
namespace: kubevirt
namespace: {{.Namespace}}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
labels:
kubevirt.io: ""
name: kubevirt-apiserver
namespace: kubevirt
namespace: {{.Namespace}}
rules:
- apiGroups:
- ""
Expand All @@ -292,23 +292,23 @@ metadata:
labels:
kubevirt.io: ""
name: kubevirt-apiserver
namespace: kubevirt
namespace: {{.Namespace}}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: kubevirt-apiserver
subjects:
- kind: ServiceAccount
name: kubevirt-apiserver
namespace: kubevirt
namespace: {{.Namespace}}
---
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
kubevirt.io: ""
name: kubevirt-controller
namespace: kubevirt
namespace: {{.Namespace}}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down Expand Up @@ -389,12 +389,12 @@ metadata:
labels:
kubevirt.io: ""
name: kubevirt-controller
namespace: kubevirt
namespace: {{.Namespace}}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kubevirt-controller
subjects:
- kind: ServiceAccount
name: kubevirt-controller
namespace: kubevirt
namespace: {{.Namespace}}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels:
kubevirt.io: virt-api
name: virt-api
namespace: kubevirt
namespace: {{.Namespace}}
spec:
ports:
- port: 443
Expand All @@ -20,7 +20,7 @@ metadata:
labels:
kubevirt.io: virt-api
name: virt-api
namespace: kubevirt
namespace: {{.Namespace}}
spec:
replicas: 2
selector:
Expand All @@ -43,7 +43,7 @@ spec:
- --port
- "8443"
- --subresources-only
image: kubevirt/virt-api:latest
image: {{.DockerPrefix}}/virt-api:{{.DockerTag}}
imagePullPolicy: IfNotPresent
name: virt-api
ports:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels:
kubevirt.io: virt-controller
name: virt-controller
namespace: kubevirt
namespace: {{.Namespace}}
spec:
replicas: 2
selector:
Expand All @@ -26,10 +26,10 @@ spec:
- command:
- virt-controller
- --launcher-image
- kubevirt/virt-launcher:latest
- {{.DockerPrefix}}/virt-launcher:{{.DockerTag}}
- --port
- "8443"
image: kubevirt/virt-controller:latest
image: {{.DockerPrefix}}/virt-controller:{{.DockerTag}}
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels:
kubevirt.io: virt-handler
name: virt-handler
namespace: kubevirt
namespace: {{.Namespace}}
spec:
selector:
matchLabels:
Expand Down Expand Up @@ -40,7 +40,7 @@ spec:
valueFrom:
fieldRef:
fieldPath: status.podIP
image: kubevirt/virt-handler:latest
image: {{.DockerPrefix}}/virt-handler:{{.DockerTag}}
imagePullPolicy: IfNotPresent
name: virt-handler
ports:
Expand Down
12 changes: 6 additions & 6 deletions manifests/release/kubevirt.yaml.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{{index .DevManifests "kubevirt-ns.yaml"}}
{{index .GeneratedManifests "prometheus.yaml"}}
{{index .GeneratedManifests "rbac.authorization.k8s.yaml"}}
{{index .GeneratedManifests "virt-api.yaml"}}
{{index .GeneratedManifests "virt-controller.yaml"}}
{{index .GeneratedManifests "virt-handler.yaml"}}
{{index .DevManifests "kubevirt-ns.yaml.in"}}
{{index .GeneratedManifests "prometheus.yaml.in"}}
{{index .GeneratedManifests "rbac.authorization.k8s.yaml.in"}}
{{index .GeneratedManifests "virt-api.yaml.in"}}
{{index .GeneratedManifests "virt-controller.yaml.in"}}
{{index .GeneratedManifests "virt-handler.yaml.in"}}
{{index .GeneratedManifests "vmi-resource.yaml"}}
{{index .GeneratedManifests "vmirs-resource.yaml"}}
{{index .GeneratedManifests "vmipreset-resource.yaml"}}
Expand Down
Loading

0 comments on commit aceb177

Please sign in to comment.