Repository: rook/rook
Pull request #8418 (2021-07-28 16:13:12)

ceph: embed ceph-csi templates in rook binary
Thanks to Golang 1.16, we can now embed files in the Go binary. This
means we don't need to add the CSI templates files to the container
image. They are added in the Go binary at build time.

The existing location of the template must be in the package calling it.
So they moved to pkg/operator/ceph/csi/template. All the files have been
symlinked back to cluster/examples/kubernetes/ceph/csi/template.

Closes: https://github.com/rook/rook/issues/7609
Signed-off-by: Sébastien Han <seb@redhat.com>

<!-- Please take a look at our [Contributing](https://rook.io/docs/rook/master/development-flow.html)
documentation before submitting a Pull Request!
Thank you for contributing to Rook! -->

**Description of your changes:**

**Which issue is resolved by this Pull Request:**
Resolves #

**Checklist:**

- [ ] **Commit Message Formatting**: Commit titles and messages follow guidelines in the [developer guide](https://rook.io/docs/rook/master/development-flow.html#commit-structure).
- [ ] **Skip Tests for Docs**: Add the flag for skipping the build if this is only a documentation change. See [here](https://github.com/rook/rook/blob/master/INSTALL.md#skip-ci) for the flag.
- [ ] **Skip Unrelated Tests**: Add a flag to run tests for a specific storage provider. See [test options](https://github.com/rook/rook/blob/master/INSTALL.md#test-storage-provider).
- [ ] Reviewed the developer guide on [Submitting a Pull Request](https://rook.io/docs/rook/master/development-flow.html#submitting-a-pull-request)
- [ ] Documentation has been updated, if necessary.
- [ ] Unit tests have been added, if necessary.
- [ ] Integration tests have been added, if necessary.
- [ ] Pending release notes updated with breaking and/or notable changes, if necessary.
- [ ] Upgrade from previous release is tested and upgrade user guide is updated, if necessary.
- [ ] Code generation (`make codegen`) has been run to update object specifications, if necessary.


leseb: > Why do we need symlinks? Seems like we don't need the templates under the cluster examples anymore.

I guess I was thinking that people could deploy manually 🤷🏻‍♂️  but we can leave that up to the ceph-csi official deployment I guess.
leseb: > This will be really nice to have, I'm just wondering if we should hold it for a bit until we're sure we don't need to support go 1.15 builds anymore.

Yes, this can stay until 1.17 is out I suppose. Assuming we can resurrect the 1.15 support with https://github.com/rook/rook/pull/8394 and its dependencies...
mergify[bot]: This pull request has merge conflicts that must be resolved before it can be merged. @leseb please rebase it. https://rook.io/docs/rook/master/development-flow.html#updating-your-fork
Madhu-1: ```
=== RUN   TestDaemonSetTemplate
    util_test.go:33: 
        	Error Trace:	util_test.go:33
        	Error:      	Expected nil, but got: failed to unmarshal daemonset template: error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go value of type v1.DaemonSet
        	Test:       	TestDaemonSetTemplate
--- FAIL: TestDaemonSetTemplate (0.00s)
=== RUN   TestDeploymentTemplate
    util_test.go:42: 
        	Error Trace:	util_test.go:42
        	Error:      	Expected nil, but got: failed to unmarshal deployment template: error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go value of type v1.Deployment
        	Test:       	TestDeploymentTemplate
```

@leseb unit test failure

Patch:
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 0a42af3c6..c55ae1524 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -57,29 +57,24 @@ jobs:
 
   linux-build-all:
     runs-on: ubuntu-18.04
-    strategy:
-      fail-fast: false
-      matrix:
-        go-version : ['1.16', '1.17']
     steps:
     - name: checkout
       uses: actions/checkout@v2
       with:
         fetch-depth: 0
 
-    - name: setup golang ${{ matrix.go-version }}
+    - name: setup golang
       uses: actions/setup-go@v2
       with:
-        go-version: ${{ matrix.go-version }}
+        go-version: 1.16
 
     - name: set up QEMU
       uses: docker/setup-qemu-action@master
       with:
         platforms: all
 
-    - name: build.all rook with go ${{ matrix.go-version }}
-      run: |
-        tests/scripts/github-action-helper.sh build_rook_all
+    - name: build.all rook
+      run: tests/scripts/github-action-helper.sh build_rook_all
 
     - name: setup tmate session for debugging
       if: failure()
diff --git a/build/crds/crds.go b/build/crds/crds.go
index 01bee7092..1bcaee88b 100644
--- a/build/crds/crds.go
+++ b/build/crds/crds.go
@@ -1,4 +1,3 @@
-//go:build crds
 // +build crds
 
 /*
diff --git a/build/makelib/golang.mk b/build/makelib/golang.mk
index fed6de033..38296d70c 100644
--- a/build/makelib/golang.mk
+++ b/build/makelib/golang.mk
@@ -48,7 +48,7 @@ GO_TEST_FLAGS ?=
 # ====================================================================================
 # Setup go environment
 
-GO_SUPPORTED_VERSIONS ?= 1.16|1.17
+GO_SUPPORTED_VERSIONS ?= 1.16
 
 GO_PACKAGES := $(foreach t,$(GO_SUBDIRS),$(GO_PROJECT)/$(t)/...)
 GO_INTEGRATION_TEST_PACKAGES := $(foreach t,$(GO_INTEGRATION_TESTS_SUBDIRS),$(GO_PROJECT)/$(t)/integration)
@@ -156,10 +156,7 @@ go.vet:
 
 .PHONY: go.fmt
 go.fmt: $(GOFMT)
-	# ignore deepcopy generated files since the tool hardcoded the header with a "// +build" which in Golang 1.17 makes it fail gofmt since "////go:build" is preferred
-	# see: https://github.com/kubernetes/gengo/blob/master/examples/deepcopy-gen/generators/deepcopy.go#L136
-	# https://github.com/kubernetes/gengo/pull/210
-	@gofmt_out=$$(find . -name "*.go" -not -name "*.deepcopy.go" | xargs $(GOFMT) -s -d -e 2>&1) && [ -z "$${gofmt_out}" ] || (echo "$${gofmt_out}" 1>&2; exit 1)
+	@gofmt_out=$$($(GOFMT) -s -d -e $(GO_SUBDIRS) $(GO_INTEGRATION_TESTS_SUBDIRS) 2>&1) && [ -z "$${gofmt_out}" ] || (echo "$${gofmt_out}" 1>&2; exit 1)
 
 go.validate: go.vet go.fmt
 
diff --git a/cmd/rook/ceph/operator.go b/cmd/rook/ceph/operator.go
index e17db78f4..9ff69f5fa 100644
--- a/cmd/rook/ceph/operator.go
+++ b/cmd/rook/ceph/operator.go
@@ -22,7 +22,6 @@ import (
 	"github.com/rook/rook/pkg/daemon/ceph/agent/flexvolume/attachment"
 	operator "github.com/rook/rook/pkg/operator/ceph"
 	cluster "github.com/rook/rook/pkg/operator/ceph/cluster"
-	"github.com/rook/rook/pkg/operator/ceph/csi"
 
 	opcontroller "github.com/rook/rook/pkg/operator/ceph/controller"
 	"github.com/rook/rook/pkg/operator/k8sutil"
@@ -42,14 +41,6 @@ https://github.com/rook/rook`,
 }
 
 func init() {
-	// csi deployment templates
-	operatorCmd.Flags().StringVar(&csi.RBDPluginTemplatePath, "csi-rbd-plugin-template-path", csi.DefaultRBDPluginTemplatePath, "path to ceph-csi rbd plugin template")
-
-	operatorCmd.Flags().StringVar(&csi.RBDProvisionerDepTemplatePath, "csi-rbd-provisioner-dep-template-path", csi.DefaultRBDProvisionerDepTemplatePath, "path to ceph-csi rbd provisioner deployment template")
-
-	operatorCmd.Flags().StringVar(&csi.CephFSPluginTemplatePath, "csi-cephfs-plugin-template-path", csi.DefaultCephFSPluginTemplatePath, "path to ceph-csi cephfs plugin template")
-	operatorCmd.Flags().StringVar(&csi.CephFSProvisionerDepTemplatePath, "csi-cephfs-provisioner-dep-template-path", csi.DefaultCephFSProvisionerDepTemplatePath, "path to ceph-csi cephfs provisioner deployment template")
-
 	operatorCmd.Flags().BoolVar(&cluster.EnableMachineDisruptionBudget, "enable-machine-disruption-budget", false, "enable fencing controllers")
 
 	flags.SetFlagsFromEnv(operatorCmd.Flags(), rook.RookEnvVarPrefix)
diff --git a/images/ceph/Dockerfile b/images/ceph/Dockerfile
index 5e66b9bbb..53f26151d 100644
--- a/images/ceph/Dockerfile
+++ b/images/ceph/Dockerfile
@@ -23,7 +23,6 @@ RUN curl --fail -sSL -o /tini https://github.com/krallin/tini/releases/download/
     chmod +x /tini
 
 COPY rook rookflex toolbox.sh set-ceph-debug-level /usr/local/bin/
-COPY ceph-csi /etc/ceph-csi
 COPY ceph-monitoring /etc/ceph-monitoring
 COPY rook-external /etc/rook-external/
 COPY ceph-csv-templates /etc/ceph-csv-templates
diff --git a/images/ceph/Makefile b/images/ceph/Makefile
index 267fa68e8..eea0bb3f0 100755
--- a/images/ceph/Makefile
+++ b/images/ceph/Makefile
@@ -60,7 +60,6 @@ do.build:
 	@cp set-ceph-debug-level $(TEMP)
 	@cp $(OUTPUT_DIR)/bin/linux_$(GOARCH)/rook $(TEMP)
 	@cp $(OUTPUT_DIR)/bin/linux_$(GOARCH)/rookflex $(TEMP)
-	@cp -r ../../cluster/examples/kubernetes/ceph/csi/template $(TEMP)/ceph-csi
 	@cp -r ../../cluster/examples/kubernetes/ceph/monitoring $(TEMP)/ceph-monitoring
 	@mkdir -p $(TEMP)/rook-external/test-data
 	@cp ../../cluster/examples/kubernetes/ceph/create-external-cluster-resources.* $(TEMP)/rook-external/
diff --git a/pkg/operator/ceph/csi/betav1csidriver.go b/pkg/operator/ceph/csi/betav1csidriver.go
index 3d33ecd14..255fcf6ee 100644
--- a/pkg/operator/ceph/csi/betav1csidriver.go
+++ b/pkg/operator/ceph/csi/betav1csidriver.go
@@ -108,7 +108,7 @@ func (d beta1CsiDriver) deleteCSIDriverInfo(ctx context.Context, clientset kuber
 	err := clientset.StorageV1beta1().CSIDrivers().Delete(ctx, name, metav1.DeleteOptions{})
 	if err != nil {
 		if apierrors.IsNotFound(err) {
-			logger.Debug("%q CSIDriver not found; skipping deletion.", name)
+			logger.Debugf("%q CSIDriver not found; skipping deletion.", name)
 			return nil
 		}
 	}
diff --git a/pkg/operator/ceph/csi/csidriver.go b/pkg/operator/ceph/csi/csidriver.go
index f30267462..fdd9f9c80 100644
--- a/pkg/operator/ceph/csi/csidriver.go
+++ b/pkg/operator/ceph/csi/csidriver.go
@@ -108,7 +108,7 @@ func (d v1CsiDriver) deleteCSIDriverInfo(ctx context.Context, clientset kubernet
 	err := clientset.StorageV1().CSIDrivers().Delete(ctx, name, metav1.DeleteOptions{})
 	if err != nil {
 		if apierrors.IsNotFound(err) {
-			logger.Debug("%s CSIDriver not found; skipping deletion.", name)
+			logger.Debugf("%s CSIDriver not found; skipping deletion.", name)
 			return nil
 		}
 	}
diff --git a/pkg/operator/ceph/csi/spec.go b/pkg/operator/ceph/csi/spec.go
index bc3a7bc51..e74fef5a5 100644
--- a/pkg/operator/ceph/csi/spec.go
+++ b/pkg/operator/ceph/csi/spec.go
@@ -18,6 +18,7 @@ package csi
 
 import (
 	"context"
+	_ "embed"
 	"fmt"
 	"strconv"
 	"strings"
@@ -87,13 +88,6 @@ var (
 	CephFSDriverName string
 	RBDDriverName    string
 
-	// template paths
-	RBDPluginTemplatePath         string
-	RBDProvisionerDepTemplatePath string
-
-	CephFSPluginTemplatePath         string
-	CephFSProvisionerDepTemplatePath string
-
 	// configuration map for csi
 	ConfigName = "rook-ceph-csi-config"
 	ConfigKey  = "csi-cluster-config-json"
@@ -115,6 +109,22 @@ var (
 	DefaultSnapshotterImage       = "k8s.gcr.io/sig-storage/csi-snapshotter:v4.1.1"
 	DefaultResizerImage           = "k8s.gcr.io/sig-storage/csi-resizer:v1.2.0"
 	DefaultVolumeReplicationImage = "quay.io/csiaddons/volumereplication-operator:v0.1.0"
+
+	// Local package template path for RBD
+	//go:embed template/rbd/csi-rbdplugin.yaml
+	RBDPluginTemplatePath string
+	//go:embed template/rbd/csi-rbdplugin-provisioner-dep.yaml
+	RBDProvisionerDepTemplatePath string
+	//go:embed template/rbd/csi-rbdplugin-svc.yaml
+	RBDPluginServiceTemplatePath string
+
+	// Local package template path for CephFS
+	//go:embed template/cephfs/csi-cephfsplugin.yaml
+	CephFSPluginTemplatePath string
+	//go:embed template/cephfs/csi-cephfsplugin-provisioner-dep.yaml
+	CephFSProvisionerDepTemplatePath string
+	//go:embed template/cephfs/csi-cephfsplugin-svc.yaml
+	CephFSPluginServiceTemplatePath string
 )
 
 const (
@@ -154,15 +164,6 @@ const (
 	// kubelet directory path
 	DefaultKubeletDirPath = "/var/lib/kubelet"
 
-	// template
-	DefaultRBDPluginTemplatePath         = "/etc/ceph-csi/rbd/csi-rbdplugin.yaml"
-	DefaultRBDProvisionerDepTemplatePath = "/etc/ceph-csi/rbd/csi-rbdplugin-provisioner-dep.yaml"
-	DefaultRBDPluginServiceTemplatePath  = "/etc/ceph-csi/rbd/csi-rbdplugin-svc.yaml"
-
-	DefaultCephFSPluginTemplatePath         = "/etc/ceph-csi/cephfs/csi-cephfsplugin.yaml"
-	DefaultCephFSProvisionerDepTemplatePath = "/etc/ceph-csi/cephfs/csi-cephfsplugin-provisioner-dep.yaml"
-	DefaultCephFSPluginServiceTemplatePath  = "/etc/ceph-csi/cephfs/csi-cephfsplugin-svc.yaml"
-
 	// grpc metrics and liveness port for cephfs  and rbd
 	DefaultCephFSGRPCMerticsPort     uint16 = 9091
 	DefaultCephFSLivenessMerticsPort uint16 = 9081
@@ -191,7 +192,6 @@ func CSIEnabled() bool {
 }
 
 func validateCSIParam() error {
-
 	if len(CSIParam.CSIPluginImage) == 0 {
 		return errors.New("missing csi rbd plugin image")
 	}
@@ -205,23 +205,6 @@ func validateCSIParam() error {
 		return errors.New("missing csi attacher image")
 	}
 
-	if EnableRBD {
-		if len(RBDPluginTemplatePath) == 0 {
-			return errors.New("missing rbd plugin template path")
-		}
-		if len(RBDProvisionerDepTemplatePath) == 0 {
-			return errors.New("missing rbd provisioner template path")
-		}
-	}
-
-	if EnableCephFS {
-		if len(CephFSPluginTemplatePath) == 0 {
-			return errors.New("missing cephfs plugin template path")
-		}
-		if len(CephFSProvisionerDepTemplatePath) == 0 {
-			return errors.New("missing ceph provisioner template path")
-		}
-	}
 	return nil
 }
 
@@ -430,7 +413,7 @@ func startDrivers(clientset kubernetes.Interface, rookclientset rookclient.Inter
 			return errors.Wrap(err, "failed to load rbd provisioner deployment template")
 		}
 
-		rbdService, err = templateToService("rbd-service", DefaultRBDPluginServiceTemplatePath, tp)
+		rbdService, err = templateToService("rbd-service", RBDPluginServiceTemplatePath, tp)
 		if err != nil {
 			return errors.Wrap(err, "failed to load rbd plugin service template")
 		}
@@ -448,7 +431,7 @@ func startDrivers(clientset kubernetes.Interface, rookclientset rookclient.Inter
 			return errors.Wrap(err, "failed to load rbd provisioner deployment template")
 		}
 
-		cephfsService, err = templateToService("cephfs-service", DefaultCephFSPluginServiceTemplatePath, tp)
+		cephfsService, err = templateToService("cephfs-service", CephFSPluginServiceTemplatePath, tp)
 		if err != nil {
 			return errors.Wrap(err, "failed to load cephfs plugin service template")
 		}
diff --git a/cluster/examples/kubernetes/ceph/csi/template/cephfs/csi-cephfsplugin-provisioner-dep.yaml b/pkg/operator/ceph/csi/template/cephfs/csi-cephfsplugin-provisioner-dep.yaml
similarity index 100%
rename from cluster/examples/kubernetes/ceph/csi/template/cephfs/csi-cephfsplugin-provisioner-dep.yaml
rename to pkg/operator/ceph/csi/template/cephfs/csi-cephfsplugin-provisioner-dep.yaml
diff --git a/cluster/examples/kubernetes/ceph/csi/template/cephfs/csi-cephfsplugin-svc.yaml b/pkg/operator/ceph/csi/template/cephfs/csi-cephfsplugin-svc.yaml
similarity index 100%
rename from cluster/examples/kubernetes/ceph/csi/template/cephfs/csi-cephfsplugin-svc.yaml
rename to pkg/operator/ceph/csi/template/cephfs/csi-cephfsplugin-svc.yaml
diff --git a/cluster/examples/kubernetes/ceph/csi/template/cephfs/csi-cephfsplugin.yaml b/pkg/operator/ceph/csi/template/cephfs/csi-cephfsplugin.yaml
similarity index 100%
rename from cluster/examples/kubernetes/ceph/csi/template/cephfs/csi-cephfsplugin.yaml
rename to pkg/operator/ceph/csi/template/cephfs/csi-cephfsplugin.yaml
diff --git a/cluster/examples/kubernetes/ceph/csi/template/rbd/csi-rbdplugin-provisioner-dep.yaml b/pkg/operator/ceph/csi/template/rbd/csi-rbdplugin-provisioner-dep.yaml
similarity index 100%
rename from cluster/examples/kubernetes/ceph/csi/template/rbd/csi-rbdplugin-provisioner-dep.yaml
rename to pkg/operator/ceph/csi/template/rbd/csi-rbdplugin-provisioner-dep.yaml
diff --git a/cluster/examples/kubernetes/ceph/csi/template/rbd/csi-rbdplugin-svc.yaml b/pkg/operator/ceph/csi/template/rbd/csi-rbdplugin-svc.yaml
similarity index 100%
rename from cluster/examples/kubernetes/ceph/csi/template/rbd/csi-rbdplugin-svc.yaml
rename to pkg/operator/ceph/csi/template/rbd/csi-rbdplugin-svc.yaml
diff --git a/cluster/examples/kubernetes/ceph/csi/template/rbd/csi-rbdplugin.yaml b/pkg/operator/ceph/csi/template/rbd/csi-rbdplugin.yaml
similarity index 100%
rename from cluster/examples/kubernetes/ceph/csi/template/rbd/csi-rbdplugin.yaml
rename to pkg/operator/ceph/csi/template/rbd/csi-rbdplugin.yaml
diff --git a/pkg/operator/ceph/csi/util.go b/pkg/operator/ceph/csi/util.go
index 4d3b2bf01..a79d3fd60 100644
--- a/pkg/operator/ceph/csi/util.go
+++ b/pkg/operator/ceph/csi/util.go
@@ -18,8 +18,6 @@ package csi
 
 import (
 	"bytes"
-	"io/ioutil"
-	"path/filepath"
 	"strconv"
 	"strings"
 	"text/template"
@@ -34,15 +32,10 @@ import (
 	"k8s.io/client-go/kubernetes"
 )
 
-func loadTemplate(name, templatePath string, p templateParam) (string, error) {
-	b, err := ioutil.ReadFile(filepath.Clean(templatePath))
-	if err != nil {
-		return "", err
-	}
-	data := string(b)
+func loadTemplate(name, templateData string, p templateParam) (string, error) {
 	var writer bytes.Buffer
 	t := template.New(name)
-	t, err = t.Parse(data)
+	t, err := t.Parse(templateData)
 	if err != nil {
 		return "", errors.Wrapf(err, "failed to parse template %v", name)
 	}
@@ -50,9 +43,9 @@ func loadTemplate(name, templatePath string, p templateParam) (string, error) {
 	return writer.String(), err
 }
 
-func templateToService(name, templatePath string, p templateParam) (*corev1.Service, error) {
+func templateToService(name, templateData string, p templateParam) (*corev1.Service, error) {
 	var svc corev1.Service
-	t, err := loadTemplate(name, templatePath, p)
+	t, err := loadTemplate(name, templateData, p)
 	if err != nil {
 		return nil, errors.Wrap(err, "failed to load service template")
 	}
@@ -64,9 +57,9 @@ func templateToService(name, templatePath string, p templateParam) (*corev1.Serv
 	return &svc, nil
 }
 
-func templateToDaemonSet(name, templatePath string, p templateParam) (*apps.DaemonSet, error) {
+func templateToDaemonSet(name, templateData string, p templateParam) (*apps.DaemonSet, error) {
 	var ds apps.DaemonSet
-	t, err := loadTemplate(name, templatePath, p)
+	t, err := loadTemplate(name, templateData, p)
 	if err != nil {
 		return nil, errors.Wrap(err, "failed to load daemonset template")
 	}
@@ -78,18 +71,18 @@ func templateToDaemonSet(name, templatePath string, p templateParam) (*apps.Daem
 	return &ds, nil
 }
 
-func templateToDeployment(name, templatePath string, p templateParam) (*apps.Deployment, error) {
-	var ds apps.Deployment
-	t, err := loadTemplate(name, templatePath, p)
+func templateToDeployment(name, templateData string, p templateParam) (*apps.Deployment, error) {
+	var dep apps.Deployment
+	t, err := loadTemplate(name, templateData, p)
 	if err != nil {
 		return nil, errors.Wrap(err, "failed to load deployment template")
 	}
 
-	err = yaml.Unmarshal([]byte(t), &ds)
+	err = yaml.Unmarshal([]byte(t), &dep)
 	if err != nil {
-		return nil, errors.Wrapf(err, "failed to unmarshal deployment template")
+		return nil, errors.Wrap(err, "failed to unmarshal deployment template")
 	}
-	return &ds, nil
+	return &dep, nil
 }
 
 func applyResourcesToContainers(clientset kubernetes.Interface, key string, podspec *corev1.PodSpec) {


Test patch:
diff --git a/pkg/operator/ceph/csi/spec_test.go b/pkg/operator/ceph/csi/spec_test.go
index 272fcd417..fbd035750 100644
--- a/pkg/operator/ceph/csi/spec_test.go
+++ b/pkg/operator/ceph/csi/spec_test.go
@@ -27,11 +27,6 @@ import (
 )
 
 func TestStartCSI(t *testing.T) {
-	RBDPluginTemplatePath = "csi-rbdplugin.yaml"
-	RBDProvisionerDepTemplatePath = "csi-rbdplugin-provisioner-dep.yaml"
-	CephFSPluginTemplatePath = "csi-cephfsplugin.yaml"
-	CephFSProvisionerDepTemplatePath = "csi-cephfsplugin-provisioner-dep.yaml"
-
 	CSIParam = Param{
 		CSIPluginImage:   "image",
 		RegistrarImage:   "image",
diff --git a/pkg/operator/ceph/csi/util_test.go b/pkg/operator/ceph/csi/util_test.go
index d211afd97..840307e75 100644
--- a/pkg/operator/ceph/csi/util_test.go
+++ b/pkg/operator/ceph/csi/util_test.go
@@ -17,7 +17,6 @@ limitations under the License.
 package csi
 
 import (
-	"io/ioutil"
 	"os"
 	"testing"
 
@@ -25,97 +24,21 @@ import (
 	"k8s.io/client-go/kubernetes/fake"
 )
 
-var (
-	testDSTemplate = []byte(`
-kind: DaemonSet
-apiVersion: apps/v1
-metadata:
-  name: test-label
-  namespace: {{ .Namespace }}
-spec:
-  selector:
-    matchLabels:
-      app: test-label
-  template:
-    metadata:
-      labels:
-        app: test-label
-    spec:
-      serviceAccount: test-sa
-      containers:
-        - name: registrar
-          image: {{ .RegistrarImage }}
-        - name: rbdplugin
-          image: {{ .CSIPluginImage }}
-        - name: cephfsplugin
-          image: {{ .CSIPluginImage }}
-`)
-	testDepTemplate = []byte(`
-kind: Deployment
-apiVersion: apps/v1
-metadata:
-  name: test-label
-  namespace: {{ .Namespace }}
-spec:
-  replicas: {{ .ProvisionerReplicas }}
-  selector:
-    matchLabels:
-      app: test-label
-  template:
-    metadata:
-      labels:
-        app: test-label
-    spec:
-      serviceAccount: test-sa
-      containers:
-        - name: csi-attacher
-          image: {{ .AttacherImage }}
-        - name: csi-snapshotter
-          image: {{ .SnapshotterImage }}
-        - name: csi-resizer
-          image: {{ .ResizerImage }}
-        - name: csi-provisioner
-          image: {{ .ProvisionerImage }}
-        - name: csi-cephfsplugin
-          image: {{ .CSIPluginImage }}
-`)
-)
-
 func TestDaemonSetTemplate(t *testing.T) {
-	tmp, err := ioutil.TempFile("", "yaml")
-	assert.Nil(t, err)
-
-	defer os.Remove(tmp.Name())
-
-	_, err = tmp.Write(testDSTemplate)
-	assert.Nil(t, err)
-	err = tmp.Close()
-	assert.Nil(t, err)
-
 	tp := templateParam{
 		Param:     CSIParam,
 		Namespace: "foo",
 	}
-	_, err = templateToDaemonSet("test-ds", tmp.Name(), tp)
+	_, err := templateToDaemonSet("test-ds", RBDPluginTemplatePath, tp)
 	assert.Nil(t, err)
 }
 
 func TestDeploymentTemplate(t *testing.T) {
-	tmp, err := ioutil.TempFile("", "yaml")
-	assert.Nil(t, err)
-
-	defer os.Remove(tmp.Name())
-
-	_, err = tmp.Write(testDepTemplate)
-	assert.Nil(t, err)
-	err = tmp.Close()
-	assert.Nil(t, err)
-
 	tp := templateParam{
 		Param:     CSIParam,
 		Namespace: "foo",
 	}
-	_, err = templateToDeployment("test-dep", tmp.Name(), tp)
+	_, err := templateToDeployment("test-dep", RBDProvisionerDepTemplatePath, tp)
 	assert.Nil(t, err)
 }