2021-12-21 14:23:26 +00:00
|
|
|
/*
|
|
|
|
Copyright 2021 The Ceph-CSI Authors.
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
package e2e
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/ceph/ceph-csi/internal/util"
|
|
|
|
|
|
|
|
v1 "k8s.io/api/core/v1"
|
|
|
|
apierrs "k8s.io/apimachinery/pkg/api/errors"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
"k8s.io/client-go/kubernetes"
|
|
|
|
"k8s.io/kubernetes/test/e2e/framework"
|
|
|
|
)
|
|
|
|
|
|
|
|
func deleteConfigMap(pluginPath string) error {
|
|
|
|
path := pluginPath + configMap
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2021-07-28 03:51:18 +00:00
|
|
|
return retryKubectlFile(cephCSINamespace, kubectlDelete, path, deployTimeout)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func createConfigMap(pluginPath string, c kubernetes.Interface, f *framework.Framework) error {
|
|
|
|
path := pluginPath + configMap
|
|
|
|
cm := v1.ConfigMap{}
|
|
|
|
err := unmarshal(path, &cm)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-08 11:08:32 +00:00
|
|
|
fsID, err := getClusterID(f)
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2022-04-08 11:08:32 +00:00
|
|
|
return fmt.Errorf("failed to get clusterID: %w", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2022-04-08 11:08:32 +00:00
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
// get mon list
|
|
|
|
mons, err := getMons(rookNamespace, c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
conmap := []util.ClusterInfo{{
|
2022-04-18 06:08:52 +00:00
|
|
|
ClusterID: fsID,
|
|
|
|
Monitors: mons,
|
|
|
|
RBD: struct {
|
|
|
|
NetNamespaceFilePath string `json:"netNamespaceFilePath"`
|
|
|
|
RadosNamespace string `json:"radosNamespace"`
|
|
|
|
}{
|
|
|
|
RadosNamespace: radosNamespace,
|
|
|
|
},
|
2023-10-30 08:23:12 +00:00
|
|
|
ReadAffinity: struct {
|
|
|
|
Enabled bool `json:"enabled"`
|
|
|
|
CrushLocationLabels []string `json:"crushLocationLabels"`
|
|
|
|
}{
|
|
|
|
Enabled: true,
|
|
|
|
CrushLocationLabels: []string{
|
|
|
|
crushLocationRegionLabel,
|
|
|
|
crushLocationZoneLabel,
|
|
|
|
},
|
|
|
|
},
|
2020-09-03 09:34:29 +00:00
|
|
|
}}
|
|
|
|
if upgradeTesting {
|
|
|
|
subvolumegroup = "csi"
|
|
|
|
}
|
|
|
|
conmap[0].CephFS.SubvolumeGroup = subvolumegroup
|
|
|
|
data, err := json.Marshal(conmap)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
cm.Data["config.json"] = string(data)
|
|
|
|
cm.Namespace = cephCSINamespace
|
|
|
|
// if the configmap is present update it,during cephcsi helm charts
|
|
|
|
// deployment empty configmap gets created we need to override it
|
|
|
|
_, err = c.CoreV1().ConfigMaps(cephCSINamespace).Get(context.TODO(), cm.Name, metav1.GetOptions{})
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
_, updateErr := c.CoreV1().ConfigMaps(cephCSINamespace).Update(context.TODO(), &cm, metav1.UpdateOptions{})
|
|
|
|
if updateErr != nil {
|
2021-05-11 09:28:56 +00:00
|
|
|
return fmt.Errorf("failed to update configmap: %w", updateErr)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if apierrs.IsNotFound(err) {
|
|
|
|
_, err = c.CoreV1().ConfigMaps(cephCSINamespace).Create(context.TODO(), &cm, metav1.CreateOptions{})
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// createCustomConfigMap provides multiple clusters information.
|
2021-10-01 04:06:06 +00:00
|
|
|
func createCustomConfigMap(
|
|
|
|
c kubernetes.Interface,
|
|
|
|
pluginPath string,
|
2022-06-01 10:17:19 +00:00
|
|
|
clusterInfo map[string]map[string]string,
|
|
|
|
) error {
|
2020-09-03 09:34:29 +00:00
|
|
|
path := pluginPath + configMap
|
|
|
|
cm := v1.ConfigMap{}
|
|
|
|
err := unmarshal(path, &cm)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// get mon list
|
|
|
|
mons, err := getMons(rookNamespace, c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// get clusterIDs
|
|
|
|
var clusterID []string
|
2021-10-01 04:06:06 +00:00
|
|
|
for key := range clusterInfo {
|
2020-09-03 09:34:29 +00:00
|
|
|
clusterID = append(clusterID, key)
|
|
|
|
}
|
2021-10-01 04:15:45 +00:00
|
|
|
conmap := make([]util.ClusterInfo, len(clusterID))
|
|
|
|
|
|
|
|
for i, j := range clusterID {
|
|
|
|
conmap[i].ClusterID = j
|
|
|
|
conmap[i].Monitors = mons
|
2021-07-13 13:09:31 +00:00
|
|
|
}
|
2021-10-01 04:06:06 +00:00
|
|
|
|
|
|
|
// fill radosNamespace and subvolgroups
|
|
|
|
for cluster, confItems := range clusterInfo {
|
|
|
|
for i, j := range confItems {
|
|
|
|
switch i {
|
|
|
|
case "subvolumeGroup":
|
|
|
|
for c := range conmap {
|
|
|
|
if conmap[c].ClusterID == cluster {
|
|
|
|
conmap[c].CephFS.SubvolumeGroup = j
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "radosNamespace":
|
|
|
|
for c := range conmap {
|
|
|
|
if conmap[c].ClusterID == cluster {
|
2022-04-18 06:08:52 +00:00
|
|
|
conmap[c].RBD.RadosNamespace = j
|
2021-10-01 04:06:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2021-10-01 04:06:06 +00:00
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
data, err := json.Marshal(conmap)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
cm.Data["config.json"] = string(data)
|
|
|
|
cm.Namespace = cephCSINamespace
|
|
|
|
// since a configmap is already created, update the existing configmap
|
|
|
|
_, err = c.CoreV1().ConfigMaps(cephCSINamespace).Update(context.TODO(), &cm, metav1.UpdateOptions{})
|
2021-05-11 09:28:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to update configmap: %w", err)
|
|
|
|
}
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2021-05-11 09:28:56 +00:00
|
|
|
return nil
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|