deploy: added json field tags for csi config map

This commit adds the json field tags for csi config map for
encoding and decoding JSON.

Signed-off-by: Praveen M <m.praveen@ibm.com>
This commit is contained in:
Praveen M
2023-12-18 16:34:31 +05:30
committed by mergify[bot]
parent 35f034f156
commit 50e505619c
10 changed files with 74 additions and 124 deletions

View File

@ -24,6 +24,8 @@ import (
"reflect"
"strings"
"testing"
cephcsi "github.com/ceph/ceph-csi/api/deploy/kubernetes"
)
func TestGetClusterMappingInfo(t *testing.T) {
@ -304,7 +306,7 @@ func TestFetchMappedClusterIDAndMons(t *testing.T) {
mappingBasePath := t.TempDir()
csiConfigFile := mappingBasePath + "/config.json"
clusterMappingConfigFile := mappingBasePath + "/cluster-mapping.json"
csiConfig := []ClusterInfo{
csiConfig := []cephcsi.ClusterInfo{
{
ClusterID: "cluster-1",
Monitors: []string{"ip-1", "ip-2"},

View File

@ -22,6 +22,8 @@ import (
"fmt"
"os"
"strings"
"github.com/ceph/ceph-csi/api/deploy/kubernetes"
)
const (
@ -36,49 +38,6 @@ const (
ClusterIDKey = "clusterID"
)
// ClusterInfo strongly typed JSON spec for the below JSON structure.
type ClusterInfo struct {
// ClusterID is used for unique identification
ClusterID string `json:"clusterID"`
// Monitors is monitor list for corresponding cluster ID
Monitors []string `json:"monitors"`
// CephFS contains CephFS specific options
CephFS CephFS `json:"cephFS"`
// RBD Contains RBD specific options
RBD RBD `json:"rbd"`
// NFS contains NFS specific options
NFS NFS `json:"nfs"`
// Read affinity map options
ReadAffinity ReadAffinity `json:"readAffinity"`
}
type CephFS struct {
// symlink filepath for the network namespace where we need to execute commands.
NetNamespaceFilePath string `json:"netNamespaceFilePath"`
// SubvolumeGroup contains the name of the SubvolumeGroup for CSI volumes
SubvolumeGroup string `json:"subvolumeGroup"`
// KernelMountOptions contains the kernel mount options for CephFS volumes
KernelMountOptions string `json:"kernelMountOptions"`
// FuseMountOptions contains the fuse mount options for CephFS volumes
FuseMountOptions string `json:"fuseMountOptions"`
}
type RBD struct {
// symlink filepath for the network namespace where we need to execute commands.
NetNamespaceFilePath string `json:"netNamespaceFilePath"`
// RadosNamespace is a rados namespace in the pool
RadosNamespace string `json:"radosNamespace"`
}
type NFS struct {
// symlink filepath for the network namespace where we need to execute commands.
NetNamespaceFilePath string `json:"netNamespaceFilePath"`
}
type ReadAffinity struct {
Enabled bool `json:"enabled"`
CrushLocationLabels []string `json:"crushLocationLabels"`
}
// Expected JSON structure in the passed in config file is,
//nolint:godot // example json content should not contain unwanted dot.
/*
@ -96,8 +55,8 @@ type ReadAffinity struct {
}
}]
*/
func readClusterInfo(pathToConfig, clusterID string) (*ClusterInfo, error) {
var config []ClusterInfo
func readClusterInfo(pathToConfig, clusterID string) (*kubernetes.ClusterInfo, error) {
var config []kubernetes.ClusterInfo
// #nosec
content, err := os.ReadFile(pathToConfig)

View File

@ -20,6 +20,8 @@ import (
"encoding/json"
"os"
"testing"
cephcsi "github.com/ceph/ceph-csi/api/deploy/kubernetes"
)
var (
@ -164,18 +166,18 @@ func TestGetRBDNetNamespaceFilePath(t *testing.T) {
},
}
csiConfig := []ClusterInfo{
csiConfig := []cephcsi.ClusterInfo{
{
ClusterID: "cluster-1",
Monitors: []string{"ip-1", "ip-2"},
RBD: RBD{
RBD: cephcsi.RBD{
NetNamespaceFilePath: "/var/lib/kubelet/plugins/rbd.ceph.csi.com/cluster1-net",
},
},
{
ClusterID: "cluster-2",
Monitors: []string{"ip-3", "ip-4"},
RBD: RBD{
RBD: cephcsi.RBD{
NetNamespaceFilePath: "/var/lib/kubelet/plugins/rbd.ceph.csi.com/cluster2-net",
},
},
@ -234,18 +236,18 @@ func TestGetCephFSNetNamespaceFilePath(t *testing.T) {
},
}
csiConfig := []ClusterInfo{
csiConfig := []cephcsi.ClusterInfo{
{
ClusterID: "cluster-1",
Monitors: []string{"ip-1", "ip-2"},
CephFS: CephFS{
CephFS: cephcsi.CephFS{
NetNamespaceFilePath: "/var/lib/kubelet/plugins/cephfs.ceph.csi.com/cluster1-net",
},
},
{
ClusterID: "cluster-2",
Monitors: []string{"ip-3", "ip-4"},
CephFS: CephFS{
CephFS: cephcsi.CephFS{
NetNamespaceFilePath: "/var/lib/kubelet/plugins/cephfs.ceph.csi.com/cluster2-net",
},
},
@ -304,18 +306,18 @@ func TestGetNFSNetNamespaceFilePath(t *testing.T) {
},
}
csiConfig := []ClusterInfo{
csiConfig := []cephcsi.ClusterInfo{
{
ClusterID: "cluster-1",
Monitors: []string{"ip-1", "ip-2"},
NFS: NFS{
NFS: cephcsi.NFS{
NetNamespaceFilePath: "/var/lib/kubelet/plugins/nfs.ceph.csi.com/cluster1-net",
},
},
{
ClusterID: "cluster-2",
Monitors: []string{"ip-3", "ip-4"},
NFS: NFS{
NFS: cephcsi.NFS{
NetNamespaceFilePath: "/var/lib/kubelet/plugins/nfs.ceph.csi.com/cluster2-net",
},
},
@ -394,10 +396,10 @@ func TestGetReadAffinityOptions(t *testing.T) {
},
}
csiConfig := []ClusterInfo{
csiConfig := []cephcsi.ClusterInfo{
{
ClusterID: "cluster-1",
ReadAffinity: ReadAffinity{
ReadAffinity: cephcsi.ReadAffinity{
Enabled: true,
CrushLocationLabels: []string{
"topology.kubernetes.io/region",
@ -408,7 +410,7 @@ func TestGetReadAffinityOptions(t *testing.T) {
},
{
ClusterID: "cluster-2",
ReadAffinity: ReadAffinity{
ReadAffinity: cephcsi.ReadAffinity{
Enabled: true,
CrushLocationLabels: []string{
"topology.kubernetes.io/region",
@ -417,7 +419,7 @@ func TestGetReadAffinityOptions(t *testing.T) {
},
{
ClusterID: "cluster-3",
ReadAffinity: ReadAffinity{
ReadAffinity: cephcsi.ReadAffinity{
Enabled: false,
CrushLocationLabels: []string{
"topology.io/rack",
@ -482,24 +484,24 @@ func TestGetCephFSMountOptions(t *testing.T) {
},
}
csiConfig := []ClusterInfo{
csiConfig := []cephcsi.ClusterInfo{
{
ClusterID: "cluster-1",
CephFS: CephFS{
CephFS: cephcsi.CephFS{
KernelMountOptions: "crc",
FuseMountOptions: "ro",
},
},
{
ClusterID: "cluster-2",
CephFS: CephFS{
CephFS: cephcsi.CephFS{
KernelMountOptions: "",
FuseMountOptions: "",
},
},
{
ClusterID: "cluster-3",
CephFS: CephFS{},
CephFS: cephcsi.CephFS{},
},
}
csiConfigFileContent, err := json.Marshal(csiConfig)