From aceb17757463283507fc17fd2e36b8e25bc06424 Mon Sep 17 00:00:00 2001 From: Marc Sluiter Date: Thu, 20 Dec 2018 14:29:12 +0100 Subject: [PATCH] Fixed template manifests 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 --- .gitignore | 3 +- hack/build-manifests.sh | 25 +++++--- hack/generate.sh | 10 +-- manifests/dev/prometheus.yaml.in | 2 +- manifests/dev/rbac.authorization.k8s.yaml.in | 2 +- manifests/dev/virt-api.yaml.in | 2 +- manifests/dev/virt-controller.yaml.in | 2 +- manifests/dev/virt-handler.yaml.in | 2 +- .../{prometheus.yaml => prometheus.yaml.in} | 2 +- ...8s.yaml => rbac.authorization.k8s.yaml.in} | 28 ++++---- .../{virt-api.yaml => virt-api.yaml.in} | 6 +- ...ontroller.yaml => virt-controller.yaml.in} | 6 +- ...virt-handler.yaml => virt-handler.yaml.in} | 4 +- manifests/release/kubevirt.yaml.in | 12 ++-- .../manifest-templator/manifest-templator.go | 64 +++++++++++++------ .../resource-generator/resource-generator.go | 2 +- tools/util/marshaller.go | 7 ++ tools/util/marshaller_test.go | 47 ++++++++++++++ 18 files changed, 157 insertions(+), 69 deletions(-) rename manifests/generated/{prometheus.yaml => prometheus.yaml.in} (90%) rename manifests/generated/{rbac.authorization.k8s.yaml => rbac.authorization.k8s.yaml.in} (94%) rename manifests/generated/{virt-api.yaml => virt-api.yaml.in} (92%) rename manifests/generated/{virt-controller.yaml => virt-controller.yaml.in} (89%) rename manifests/generated/{virt-handler.yaml => virt-handler.yaml.in} (95%) create mode 100644 tools/util/marshaller_test.go diff --git a/.gitignore b/.gitignore index 8f2053bc8891..0dea4760ea01 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,5 @@ vendor/**/*_test.go **/polarion.xml tools/manifest-templator/manifest-templator tools/vms-generator/vms-generator -.coverprofile \ No newline at end of file +.coverprofile +manifests/**/*.tmp \ No newline at end of file diff --git a/hack/build-manifests.sh b/hack/build-manifests.sh index cdb4f23bdb39..a1c7be5f1564 100755 --- a/hack/build-manifests.sh +++ b/hack/build-manifests.sh @@ -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 diff --git a/hack/generate.sh b/hack/generate.sh index 582460b05185..4195d50b60aa 100755 --- a/hack/generate.sh +++ b/hack/generate.sh @@ -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 diff --git a/manifests/dev/prometheus.yaml.in b/manifests/dev/prometheus.yaml.in index 7153347b174b..e31aa094d7ca 100644 --- a/manifests/dev/prometheus.yaml.in +++ b/manifests/dev/prometheus.yaml.in @@ -1 +1 @@ -{{index .GeneratedManifests "prometheus.yaml"}} +{{index .GeneratedManifests "prometheus.yaml.in"}} diff --git a/manifests/dev/rbac.authorization.k8s.yaml.in b/manifests/dev/rbac.authorization.k8s.yaml.in index bc039fcd9937..7257d6c9c2a9 100644 --- a/manifests/dev/rbac.authorization.k8s.yaml.in +++ b/manifests/dev/rbac.authorization.k8s.yaml.in @@ -1 +1 @@ -{{index .GeneratedManifests "rbac.authorization.k8s.yaml"}} +{{index .GeneratedManifests "rbac.authorization.k8s.yaml.in"}} diff --git a/manifests/dev/virt-api.yaml.in b/manifests/dev/virt-api.yaml.in index 44d0ff26ac93..caec335b961e 100644 --- a/manifests/dev/virt-api.yaml.in +++ b/manifests/dev/virt-api.yaml.in @@ -1 +1 @@ -{{index .GeneratedManifests "virt-api.yaml"}} +{{index .GeneratedManifests "virt-api.yaml.in"}} diff --git a/manifests/dev/virt-controller.yaml.in b/manifests/dev/virt-controller.yaml.in index cf042285853b..8cdf52f65799 100644 --- a/manifests/dev/virt-controller.yaml.in +++ b/manifests/dev/virt-controller.yaml.in @@ -1 +1 @@ -{{index .GeneratedManifests "virt-controller.yaml"}} +{{index .GeneratedManifests "virt-controller.yaml.in"}} diff --git a/manifests/dev/virt-handler.yaml.in b/manifests/dev/virt-handler.yaml.in index 72cf621c9053..229d8fd22e54 100644 --- a/manifests/dev/virt-handler.yaml.in +++ b/manifests/dev/virt-handler.yaml.in @@ -1 +1 @@ -{{index .GeneratedManifests "virt-handler.yaml"}} +{{index .GeneratedManifests "virt-handler.yaml.in"}} diff --git a/manifests/generated/prometheus.yaml b/manifests/generated/prometheus.yaml.in similarity index 90% rename from manifests/generated/prometheus.yaml rename to manifests/generated/prometheus.yaml.in index 873343880516..92763f99f024 100644 --- a/manifests/generated/prometheus.yaml +++ b/manifests/generated/prometheus.yaml.in @@ -6,7 +6,7 @@ metadata: kubevirt.io: "" prometheus.kubevirt.io: "" name: kubevirt-prometheus-metrics - namespace: kubevirt + namespace: {{.Namespace}} spec: ports: - name: metrics diff --git a/manifests/generated/rbac.authorization.k8s.yaml b/manifests/generated/rbac.authorization.k8s.yaml.in similarity index 94% rename from manifests/generated/rbac.authorization.k8s.yaml rename to manifests/generated/rbac.authorization.k8s.yaml.in index a37cef002a18..4a2c521664bc 100644 --- a/manifests/generated/rbac.authorization.k8s.yaml +++ b/manifests/generated/rbac.authorization.k8s.yaml.in @@ -128,7 +128,7 @@ metadata: labels: kubevirt.io: "" name: kubevirt-privileged - namespace: kubevirt + namespace: {{.Namespace}} --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding @@ -136,7 +136,7 @@ metadata: labels: kubevirt.io: "" name: kubevirt-privileged-cluster-admin - namespace: kubevirt + namespace: {{.Namespace}} roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole @@ -144,7 +144,7 @@ roleRef: subjects: - kind: ServiceAccount name: kubevirt-privileged - namespace: kubevirt + namespace: {{.Namespace}} --- apiVersion: v1 kind: ServiceAccount @@ -152,7 +152,7 @@ metadata: labels: kubevirt.io: "" name: kubevirt-apiserver - namespace: kubevirt + namespace: {{.Namespace}} --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole @@ -233,7 +233,7 @@ metadata: labels: kubevirt.io: "" name: kubevirt-apiserver - namespace: kubevirt + namespace: {{.Namespace}} roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole @@ -241,7 +241,7 @@ roleRef: subjects: - kind: ServiceAccount name: kubevirt-apiserver - namespace: kubevirt + namespace: {{.Namespace}} --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding @@ -249,7 +249,7 @@ metadata: labels: kubevirt.io: "" name: kubevirt-apiserver-auth-delegator - namespace: kubevirt + namespace: {{.Namespace}} roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole @@ -257,7 +257,7 @@ roleRef: subjects: - kind: ServiceAccount name: kubevirt-apiserver - namespace: kubevirt + namespace: {{.Namespace}} --- apiVersion: rbac.authorization.k8s.io/v1 kind: Role @@ -265,7 +265,7 @@ metadata: labels: kubevirt.io: "" name: kubevirt-apiserver - namespace: kubevirt + namespace: {{.Namespace}} rules: - apiGroups: - "" @@ -292,7 +292,7 @@ metadata: labels: kubevirt.io: "" name: kubevirt-apiserver - namespace: kubevirt + namespace: {{.Namespace}} roleRef: apiGroup: rbac.authorization.k8s.io kind: Role @@ -300,7 +300,7 @@ roleRef: subjects: - kind: ServiceAccount name: kubevirt-apiserver - namespace: kubevirt + namespace: {{.Namespace}} --- apiVersion: v1 kind: ServiceAccount @@ -308,7 +308,7 @@ metadata: labels: kubevirt.io: "" name: kubevirt-controller - namespace: kubevirt + namespace: {{.Namespace}} --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole @@ -389,7 +389,7 @@ metadata: labels: kubevirt.io: "" name: kubevirt-controller - namespace: kubevirt + namespace: {{.Namespace}} roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole @@ -397,4 +397,4 @@ roleRef: subjects: - kind: ServiceAccount name: kubevirt-controller - namespace: kubevirt + namespace: {{.Namespace}} diff --git a/manifests/generated/virt-api.yaml b/manifests/generated/virt-api.yaml.in similarity index 92% rename from manifests/generated/virt-api.yaml rename to manifests/generated/virt-api.yaml.in index 72eaedad3587..e822030c30f8 100644 --- a/manifests/generated/virt-api.yaml +++ b/manifests/generated/virt-api.yaml.in @@ -5,7 +5,7 @@ metadata: labels: kubevirt.io: virt-api name: virt-api - namespace: kubevirt + namespace: {{.Namespace}} spec: ports: - port: 443 @@ -20,7 +20,7 @@ metadata: labels: kubevirt.io: virt-api name: virt-api - namespace: kubevirt + namespace: {{.Namespace}} spec: replicas: 2 selector: @@ -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: diff --git a/manifests/generated/virt-controller.yaml b/manifests/generated/virt-controller.yaml.in similarity index 89% rename from manifests/generated/virt-controller.yaml rename to manifests/generated/virt-controller.yaml.in index 8cdd27fbb233..9b919933379f 100644 --- a/manifests/generated/virt-controller.yaml +++ b/manifests/generated/virt-controller.yaml.in @@ -5,7 +5,7 @@ metadata: labels: kubevirt.io: virt-controller name: virt-controller - namespace: kubevirt + namespace: {{.Namespace}} spec: replicas: 2 selector: @@ -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 diff --git a/manifests/generated/virt-handler.yaml b/manifests/generated/virt-handler.yaml.in similarity index 95% rename from manifests/generated/virt-handler.yaml rename to manifests/generated/virt-handler.yaml.in index 5123456c003b..f7a0ddb491af 100644 --- a/manifests/generated/virt-handler.yaml +++ b/manifests/generated/virt-handler.yaml.in @@ -5,7 +5,7 @@ metadata: labels: kubevirt.io: virt-handler name: virt-handler - namespace: kubevirt + namespace: {{.Namespace}} spec: selector: matchLabels: @@ -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: diff --git a/manifests/release/kubevirt.yaml.in b/manifests/release/kubevirt.yaml.in index 0e4fc6e1060e..aeaa25fba887 100644 --- a/manifests/release/kubevirt.yaml.in +++ b/manifests/release/kubevirt.yaml.in @@ -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"}} diff --git a/tools/manifest-templator/manifest-templator.go b/tools/manifest-templator/manifest-templator.go index 7817ea41cb5f..5f943cbe90f7 100644 --- a/tools/manifest-templator/manifest-templator.go +++ b/tools/manifest-templator/manifest-templator.go @@ -48,48 +48,72 @@ func main() { genDir := flag.String("generated-manifests-dir", "", "") devDir := flag.String("dev-manifests-dir", "", "") inputFile := flag.String("input-file", "", "") + processFiles := flag.Bool("process-files", false, "") + processVars := flag.Bool("process-vars", false, "") pflag.CommandLine.AddGoFlagSet(flag.CommandLine) pflag.CommandLine.ParseErrorsWhitelist.UnknownFlags = true pflag.Parse() + if !(*processFiles || *processVars) { + panic("at least one of process-files or process-vars must be true") + } + data := templateData{ - Namespace: *namespace, - CDINamespace: *cdiNamespace, - DockerTag: *dockerTag, - DockerPrefix: *dockerPrefix, - ImagePullPolicy: *imagePullPolicy, GeneratedManifests: make(map[string]string), DevManifests: make(map[string]string), } - manifests, err := ioutil.ReadDir(*genDir) - if err != nil { - panic(err) + if *processVars { + data.Namespace = *namespace + data.CDINamespace = *cdiNamespace + data.DockerTag = *dockerTag + data.DockerPrefix = *dockerPrefix + data.ImagePullPolicy = *imagePullPolicy + } else { + // keep templates + data.Namespace = "{{.Namespace}}" + data.CDINamespace = "{{.CDINamespace}}" + data.DockerTag = "{{.DockerTag}}" + data.DockerPrefix = "{{.DockerPrefix}}" + data.ImagePullPolicy = "{{.ImagePullPolicy}}" } - for _, manifest := range manifests { - b, err := ioutil.ReadFile(filepath.Join(*genDir, manifest.Name())) + if *processFiles { + manifests, err := ioutil.ReadDir(*genDir) if err != nil { panic(err) } - data.GeneratedManifests[manifest.Name()] = string(b) - } - manifests, err = ioutil.ReadDir(*devDir) - if err != nil { - panic(err) - } + for _, manifest := range manifests { + if manifest.IsDir() { + continue + } + b, err := ioutil.ReadFile(filepath.Join(*genDir, manifest.Name())) + if err != nil { + panic(err) + } + data.GeneratedManifests[manifest.Name()] = string(b) + } - for _, manifest := range manifests { - b, err := ioutil.ReadFile(filepath.Join(*devDir, manifest.Name())) + manifests, err = ioutil.ReadDir(*devDir) if err != nil { panic(err) } - data.DevManifests[manifest.Name()] = string(b) + + for _, manifest := range manifests { + if manifest.IsDir() { + continue + } + b, err := ioutil.ReadFile(filepath.Join(*devDir, manifest.Name())) + if err != nil { + panic(err) + } + data.DevManifests[manifest.Name()] = string(b) + } } tmpl := template.Must(template.ParseFiles(*inputFile)) - err = tmpl.Execute(os.Stdout, data) + err := tmpl.Execute(os.Stdout, data) if err != nil { panic(err) } diff --git a/tools/resource-generator/resource-generator.go b/tools/resource-generator/resource-generator.go index 18e5cbcc8263..e14c8b61a40f 100644 --- a/tools/resource-generator/resource-generator.go +++ b/tools/resource-generator/resource-generator.go @@ -49,7 +49,7 @@ func main() { case string(v1.PullIfNotPresent): imagePullPolicy = v1.PullIfNotPresent default: - panic(fmt.Errorf("unknown pull policy %s", *pullPolicy)) + imagePullPolicy = v1.PullIfNotPresent } switch *resourceType { diff --git a/tools/util/marshaller.go b/tools/util/marshaller.go index 2c1878459631..79cc33c88510 100644 --- a/tools/util/marshaller.go +++ b/tools/util/marshaller.go @@ -21,6 +21,7 @@ package util import ( "encoding/json" "io" + "strings" "github.com/ghodss/yaml" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -52,6 +53,12 @@ func MarshallObject(obj interface{}, writer io.Writer) error { return err } + // fix templates by removing quotes... + s := string(yamlBytes) + s = strings.Replace(s, "'{{", "{{", -1) + s = strings.Replace(s, "}}'", "}}", -1) + yamlBytes = []byte(s) + _, err = writer.Write([]byte("---\n")) if err != nil { return err diff --git a/tools/util/marshaller_test.go b/tools/util/marshaller_test.go new file mode 100644 index 000000000000..bd6e909466d8 --- /dev/null +++ b/tools/util/marshaller_test.go @@ -0,0 +1,47 @@ +/* + * This file is part of the KubeVirt project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Copyright 2018 Red Hat, Inc. + * + */ +package util + +import ( + "strings" + "testing" + + "k8s.io/api/core/v1" + + "kubevirt.io/kubevirt/pkg/virt-operator/creation/components" +) + +func TestMarshallObject(t *testing.T) { + + handler, err := components.NewHandlerDeamonSet("{{.Namespace}}", "{{.DockerPrefix}}", "{{.DockerTag}}", v1.PullIfNotPresent) + if err != nil { + t.Fatalf("error generating virt-handler deployment for marshall test %v", err) + } + + writer := strings.Builder{} + + MarshallObject(handler, &writer) + + result := writer.String() + + if !strings.Contains(result, "namespace: {{.Namespace}}") { + t.Fail() + } + +}