From 86ef65dc07a264245203162ad47b8f26a29a7357 Mon Sep 17 00:00:00 2001 From: karthik-us Date: Tue, 30 May 2023 20:47:51 +0530 Subject: [PATCH 1/2] cleanup: Move common files to deploy folder Few common files related to deployments were kept in the examples folder initially. Moving them to deploy folder and updating the relevant files. Signed-off-by: karthik-us --- {examples => deploy}/ceph-conf.yaml | 0 {examples => deploy}/csi-config-map-sample.yaml | 0 {examples => deploy}/service-monitor.yaml | 0 docs/deploy-cephfs.md | 2 +- docs/deploy-rbd.md | 2 +- docs/metrics.md | 2 +- e2e/cephfs.go | 3 ++- e2e/nfs.go | 3 ++- e2e/rbd.go | 6 ++++-- e2e/utils.go | 10 ++++++++++ examples/README.md | 12 ++++++------ 11 files changed, 27 insertions(+), 13 deletions(-) rename {examples => deploy}/ceph-conf.yaml (100%) rename {examples => deploy}/csi-config-map-sample.yaml (100%) rename {examples => deploy}/service-monitor.yaml (100%) diff --git a/examples/ceph-conf.yaml b/deploy/ceph-conf.yaml similarity index 100% rename from examples/ceph-conf.yaml rename to deploy/ceph-conf.yaml diff --git a/examples/csi-config-map-sample.yaml b/deploy/csi-config-map-sample.yaml similarity index 100% rename from examples/csi-config-map-sample.yaml rename to deploy/csi-config-map-sample.yaml diff --git a/examples/service-monitor.yaml b/deploy/service-monitor.yaml similarity index 100% rename from examples/service-monitor.yaml rename to deploy/service-monitor.yaml diff --git a/docs/deploy-cephfs.md b/docs/deploy-cephfs.md index 8f23ab8a699..2087f0c87d0 100644 --- a/docs/deploy-cephfs.md +++ b/docs/deploy-cephfs.md @@ -148,7 +148,7 @@ for more information. **Deploy Ceph configuration ConfigMap for CSI pods:** ```bash -kubectl create -f ../../../examples/ceph-conf.yaml +kubectl create -f ../../ceph-conf.yaml ``` **Deploy CSI sidecar containers:** diff --git a/docs/deploy-rbd.md b/docs/deploy-rbd.md index 270d734d15e..e397ac066da 100644 --- a/docs/deploy-rbd.md +++ b/docs/deploy-rbd.md @@ -134,7 +134,7 @@ for more information. **Deploy Ceph configuration ConfigMap for CSI pods:** ```bash -kubectl create -f ../example/ceph-config.yaml +kubectl create -f ../../ceph-conf.yaml ``` **Deploy CSI sidecar containers:** diff --git a/docs/metrics.md b/docs/metrics.md index a39e1b7c072..8f19c8d2bc7 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -23,7 +23,7 @@ csi_liveness 1 ``` Promethues can be deployed through the promethues operator described [here](https://coreos.com/operators/prometheus/docs/latest/user-guides/getting-started.html). -The [service-monitor](../examples/service-monitor.yaml) will tell promethues how +The [service-monitor](../deploy/service-monitor.yaml) will tell promethues how to pull metrics out of CSI. Each CSI pod has a service to expose the endpoint to prometheus. By default, rbd diff --git a/e2e/cephfs.go b/e2e/cephfs.go index 19a1e6b54d5..b10498e1438 100644 --- a/e2e/cephfs.go +++ b/e2e/cephfs.go @@ -67,6 +67,7 @@ func deleteCephfsPlugin() { } func createORDeleteCephfsResources(action kubectlAction) { + cephConfigFile := getConfigFile(deployPath + cephConfconfigMap) resources := []ResourceDeployer{ // shared resources &yamlResource{ @@ -74,7 +75,7 @@ func createORDeleteCephfsResources(action kubectlAction) { allowMissing: true, }, &yamlResource{ - filename: examplePath + cephConfconfigMap, + filename: cephConfigFile, allowMissing: true, }, // dependencies for provisioner diff --git a/e2e/nfs.go b/e2e/nfs.go index 60d594e00d3..06d2f80b5fe 100644 --- a/e2e/nfs.go +++ b/e2e/nfs.go @@ -79,6 +79,7 @@ func deleteNFSPlugin() { } func createORDeleteNFSResources(f *framework.Framework, action kubectlAction) { + cephConfigFile := getConfigFile(deployPath + cephConfconfigMap) resources := []ResourceDeployer{ // shared resources &yamlResource{ @@ -86,7 +87,7 @@ func createORDeleteNFSResources(f *framework.Framework, action kubectlAction) { allowMissing: true, }, &yamlResource{ - filename: examplePath + cephConfconfigMap, + filename: cephConfigFile, allowMissing: true, }, // dependencies for provisioner diff --git a/e2e/rbd.go b/e2e/rbd.go index 76928341925..c820dee3202 100644 --- a/e2e/rbd.go +++ b/e2e/rbd.go @@ -44,7 +44,8 @@ var ( configMap = "csi-config-map.yaml" cephConfconfigMap = "ceph-conf.yaml" csiDriverObject = "csidriver.yaml" - rbdDirPath = "../deploy/rbd/kubernetes/" + deployPath = "../deploy/" + rbdDirPath = deployPath + "/rbd/kubernetes/" examplePath = "../examples/" rbdExamplePath = examplePath + "/rbd/" e2eTemplatesPath = "../e2e/templates/" @@ -129,6 +130,7 @@ func deleteRBDPlugin() { } func createORDeleteRbdResources(action kubectlAction) { + cephConfigFile := getConfigFile(deployPath + cephConfconfigMap) resources := []ResourceDeployer{ // shared resources &yamlResource{ @@ -136,7 +138,7 @@ func createORDeleteRbdResources(action kubectlAction) { allowMissing: true, }, &yamlResource{ - filename: examplePath + cephConfconfigMap, + filename: cephConfigFile, allowMissing: true, }, // dependencies for provisioner diff --git a/e2e/utils.go b/e2e/utils.go index d79d0e2c359..9150a791f32 100644 --- a/e2e/utils.go +++ b/e2e/utils.go @@ -1732,3 +1732,13 @@ func rwopMayFail(err error) bool { return !rwopSupported } + +// getConfigFile returns the passed config file location if it exists, else +// returns the old location of the config file under 'examples/' directory. +func getConfigFile(configFile string) string { + if _, err := os.Stat(configFile); os.IsNotExist(err) { + configFile = examplePath + cephConfconfigMap + } + + return configFile +} diff --git a/examples/README.md b/examples/README.md index f9e74447590..0fda351a669 100644 --- a/examples/README.md +++ b/examples/README.md @@ -2,17 +2,17 @@ ## Deploying Ceph-CSI services -Create [ceph-config](./ceph-conf.yaml) configmap using the following command. +Create [ceph-config](../deploy/ceph-conf.yaml) configmap using the following command. ```bash -kubectl apply -f ./ceph-conf.yaml +kubectl apply -f ../deploy/ceph-conf.yaml ``` Both `rbd` and `cephfs` directories contain `plugin-deploy.sh` and `plugin-teardown.sh` helper scripts. You can use those to help you deploy/teardown RBACs, sidecar containers and the plugin in one go. By default, they look for the YAML manifests in -`../../deploy/{rbd,cephfs}/kubernetes`. +`../deploy/{rbd,cephfs}/kubernetes`. You can override this path by running ```bash @@ -25,7 +25,7 @@ The CSI plugin requires configuration information regarding the Ceph cluster(s), that would host the dynamically or statically provisioned volumes. This is provided by adding a per-cluster identifier (referred to as clusterID), and the required monitor details for the same, as in the provided [sample config - map](./csi-config-map-sample.yaml). + map](../deploy/csi-config-map-sample.yaml). Gather the following information from the Ceph cluster(s) of choice, @@ -38,13 +38,13 @@ Gather the following information from the Ceph cluster(s) of choice, * Alternatively, choose a `` value that is distinct per Ceph cluster in use by this kubernetes cluster -Update the [sample configmap](./csi-config-map-sample.yaml) with values +Update the [sample configmap](../deploy/csi-config-map-sample.yaml) with values from a Ceph cluster and replace `` with the chosen clusterID, to create the manifest for the configmap which can be updated in the cluster using the following command, ```bash -kubectl replace -f ./csi-config-map-sample.yaml +kubectl replace -f ../deploy/csi-config-map-sample.yaml ``` Storage class and snapshot class, using `` as the value for the From 3b1cb503539abfa2e388ad6c187b63c129cfde68 Mon Sep 17 00:00:00 2001 From: karthik-us Date: Tue, 6 Jun 2023 18:46:27 +0530 Subject: [PATCH 2/2] e2e: Make getConfigFile() generic Update the getConfigFile() function to allow any file to be looked at on the preferred location first and fall back to the alternate location if it does not exist there. Signed-off-by: karthik-us --- e2e/cephfs.go | 2 +- e2e/nfs.go | 2 +- e2e/rbd.go | 2 +- e2e/utils.go | 9 +++++---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/e2e/cephfs.go b/e2e/cephfs.go index b10498e1438..1a23883019a 100644 --- a/e2e/cephfs.go +++ b/e2e/cephfs.go @@ -67,7 +67,7 @@ func deleteCephfsPlugin() { } func createORDeleteCephfsResources(action kubectlAction) { - cephConfigFile := getConfigFile(deployPath + cephConfconfigMap) + cephConfigFile := getConfigFile(cephConfconfigMap, deployPath, examplePath) resources := []ResourceDeployer{ // shared resources &yamlResource{ diff --git a/e2e/nfs.go b/e2e/nfs.go index 06d2f80b5fe..d06e06e4e82 100644 --- a/e2e/nfs.go +++ b/e2e/nfs.go @@ -79,7 +79,7 @@ func deleteNFSPlugin() { } func createORDeleteNFSResources(f *framework.Framework, action kubectlAction) { - cephConfigFile := getConfigFile(deployPath + cephConfconfigMap) + cephConfigFile := getConfigFile(cephConfconfigMap, deployPath, examplePath) resources := []ResourceDeployer{ // shared resources &yamlResource{ diff --git a/e2e/rbd.go b/e2e/rbd.go index c820dee3202..6bac023da66 100644 --- a/e2e/rbd.go +++ b/e2e/rbd.go @@ -130,7 +130,7 @@ func deleteRBDPlugin() { } func createORDeleteRbdResources(action kubectlAction) { - cephConfigFile := getConfigFile(deployPath + cephConfconfigMap) + cephConfigFile := getConfigFile(cephConfconfigMap, deployPath, examplePath) resources := []ResourceDeployer{ // shared resources &yamlResource{ diff --git a/e2e/utils.go b/e2e/utils.go index 9150a791f32..4a748f15d37 100644 --- a/e2e/utils.go +++ b/e2e/utils.go @@ -1733,11 +1733,12 @@ func rwopMayFail(err error) bool { return !rwopSupported } -// getConfigFile returns the passed config file location if it exists, else -// returns the old location of the config file under 'examples/' directory. -func getConfigFile(configFile string) string { +// getConfigFile returns the config file path at the preferred location if it +// exists there. Returns the fallback location otherwise. +func getConfigFile(filename, preferred, fallback string) string { + configFile := preferred + filename if _, err := os.Stat(configFile); os.IsNotExist(err) { - configFile = examplePath + cephConfconfigMap + configFile = fallback + filename } return configFile