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

@ -35,4 +35,4 @@ func TestNewCSIConfigMapYAML(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.NotEqual(t, "", yaml) require.NotEqual(t, "", yaml)
} }

View File

@ -18,42 +18,42 @@ package kubernetes
type ClusterInfo struct { type ClusterInfo struct {
// ClusterID is used for unique identification // ClusterID is used for unique identification
ClusterID string ClusterID string `json:"clusterID"`
// Monitors is monitor list for corresponding cluster ID // Monitors is monitor list for corresponding cluster ID
Monitors []string Monitors []string `json:"monitors"`
// CephFS contains CephFS specific options // CephFS contains CephFS specific options
CephFS CephFS CephFS CephFS `json:"cephFS"`
// RBD Contains RBD specific options // RBD Contains RBD specific options
RBD RBD RBD RBD `json:"rbd"`
// NFS contains NFS specific options // NFS contains NFS specific options
NFS NFS NFS NFS `json:"nfs"`
// Read affinity map options // Read affinity map options
ReadAffinity ReadAffinity ReadAffinity ReadAffinity `json:"readAffinity"`
} }
type CephFS struct { type CephFS struct {
// symlink filepath for the network namespace where we need to execute commands. // symlink filepath for the network namespace where we need to execute commands.
NetNamespaceFilePath string NetNamespaceFilePath string `json:"netNamespaceFilePath"`
// SubvolumeGroup contains the name of the SubvolumeGroup for CSI volumes // SubvolumeGroup contains the name of the SubvolumeGroup for CSI volumes
SubvolumeGroup string SubvolumeGroup string `json:"subvolumeGroup"`
// KernelMountOptions contains the kernel mount options for CephFS volumes // KernelMountOptions contains the kernel mount options for CephFS volumes
KernelMountOptions string KernelMountOptions string `json:"kernelMountOptions"`
// FuseMountOptions contains the fuse mount options for CephFS volumes // FuseMountOptions contains the fuse mount options for CephFS volumes
FuseMountOptions string FuseMountOptions string `json:"fuseMountOptions"`
} }
type RBD struct { type RBD struct {
// symlink filepath for the network namespace where we need to execute commands. // symlink filepath for the network namespace where we need to execute commands.
NetNamespaceFilePath string NetNamespaceFilePath string `json:"netNamespaceFilePath"`
// RadosNamespace is a rados namespace in the pool // RadosNamespace is a rados namespace in the pool
RadosNamespace string RadosNamespace string `json:"radosNamespace"`
} }
type NFS struct { type NFS struct {
// symlink filepath for the network namespace where we need to execute commands. // symlink filepath for the network namespace where we need to execute commands.
NetNamespaceFilePath string NetNamespaceFilePath string `json:"netNamespaceFilePath"`
} }
type ReadAffinity struct { type ReadAffinity struct {
Enabled bool Enabled bool `json:"enabled"`
CrushLocationLabels []string CrushLocationLabels []string `json:"crushLocationLabels"`
} }

View File

@ -21,7 +21,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/ceph/ceph-csi/internal/util" cephcsi "github.com/ceph/ceph-csi/api/deploy/kubernetes"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors" apierrs "k8s.io/apimachinery/pkg/api/errors"
@ -54,19 +54,13 @@ func createConfigMap(pluginPath string, c kubernetes.Interface, f *framework.Fra
if err != nil { if err != nil {
return err return err
} }
conmap := []util.ClusterInfo{{ conmap := []cephcsi.ClusterInfo{{
ClusterID: fsID, ClusterID: fsID,
Monitors: mons, Monitors: mons,
RBD: struct { RBD: cephcsi.RBD{
NetNamespaceFilePath string `json:"netNamespaceFilePath"`
RadosNamespace string `json:"radosNamespace"`
}{
RadosNamespace: radosNamespace, RadosNamespace: radosNamespace,
}, },
ReadAffinity: struct { ReadAffinity: cephcsi.ReadAffinity{
Enabled bool `json:"enabled"`
CrushLocationLabels []string `json:"crushLocationLabels"`
}{
Enabled: true, Enabled: true,
CrushLocationLabels: []string{ CrushLocationLabels: []string{
crushLocationRegionLabel, crushLocationRegionLabel,
@ -123,7 +117,7 @@ func createCustomConfigMap(
for key := range clusterInfo { for key := range clusterInfo {
clusterID = append(clusterID, key) clusterID = append(clusterID, key)
} }
conmap := make([]util.ClusterInfo, len(clusterID)) conmap := make([]cephcsi.ClusterInfo, len(clusterID))
for i, j := range clusterID { for i, j := range clusterID {
conmap[i].ClusterID = j conmap[i].ClusterID = j

View File

@ -24,10 +24,10 @@ import (
"github.com/container-storage-interface/spec/lib/go/csi" "github.com/container-storage-interface/spec/lib/go/csi"
cephcsi "github.com/ceph/ceph-csi/api/deploy/kubernetes"
"github.com/ceph/ceph-csi/internal/cephfs/mounter" "github.com/ceph/ceph-csi/internal/cephfs/mounter"
"github.com/ceph/ceph-csi/internal/cephfs/store" "github.com/ceph/ceph-csi/internal/cephfs/store"
csicommon "github.com/ceph/ceph-csi/internal/csi-common" csicommon "github.com/ceph/ceph-csi/internal/csi-common"
"github.com/ceph/ceph-csi/internal/util"
) )
func Test_setMountOptions(t *testing.T) { func Test_setMountOptions(t *testing.T) {
@ -39,17 +39,17 @@ func Test_setMountOptions(t *testing.T) {
configKernelMountOptions := "crc" configKernelMountOptions := "crc"
configFuseMountOptions := "allow_other" configFuseMountOptions := "allow_other"
csiConfig := []util.ClusterInfo{ csiConfig := []cephcsi.ClusterInfo{
{ {
ClusterID: "cluster-1", ClusterID: "cluster-1",
CephFS: util.CephFS{ CephFS: cephcsi.CephFS{
KernelMountOptions: configKernelMountOptions, KernelMountOptions: configKernelMountOptions,
FuseMountOptions: configFuseMountOptions, FuseMountOptions: configFuseMountOptions,
}, },
}, },
{ {
ClusterID: "cluster-2", ClusterID: "cluster-2",
CephFS: util.CephFS{ CephFS: cephcsi.CephFS{
KernelMountOptions: "", KernelMountOptions: "",
FuseMountOptions: "", FuseMountOptions: "",
}, },

View File

@ -26,6 +26,7 @@ import (
"github.com/container-storage-interface/spec/lib/go/csi" "github.com/container-storage-interface/spec/lib/go/csi"
cephcsi "github.com/ceph/ceph-csi/api/deploy/kubernetes"
"github.com/ceph/ceph-csi/internal/cephfs/core" "github.com/ceph/ceph-csi/internal/cephfs/core"
cerrors "github.com/ceph/ceph-csi/internal/cephfs/errors" cerrors "github.com/ceph/ceph-csi/internal/cephfs/errors"
fsutil "github.com/ceph/ceph-csi/internal/cephfs/util" fsutil "github.com/ceph/ceph-csi/internal/cephfs/util"
@ -164,7 +165,7 @@ func extractMounter(dest *string, options map[string]string) error {
return nil return nil
} }
func GetClusterInformation(options map[string]string) (*util.ClusterInfo, error) { func GetClusterInformation(options map[string]string) (*cephcsi.ClusterInfo, error) {
clusterID, ok := options["clusterID"] clusterID, ok := options["clusterID"]
if !ok { if !ok {
err := fmt.Errorf("clusterID must be set") err := fmt.Errorf("clusterID must be set")
@ -189,7 +190,7 @@ func GetClusterInformation(options map[string]string) (*util.ClusterInfo, error)
return nil, err return nil, err
} }
clusterData := &util.ClusterInfo{ clusterData := &cephcsi.ClusterInfo{
ClusterID: clusterID, ClusterID: clusterID,
Monitors: strings.Split(monitors, ","), Monitors: strings.Split(monitors, ","),
} }

View File

@ -22,6 +22,7 @@ import (
"os" "os"
"testing" "testing"
cephcsi "github.com/ceph/ceph-csi/api/deploy/kubernetes"
csicommon "github.com/ceph/ceph-csi/internal/csi-common" csicommon "github.com/ceph/ceph-csi/internal/csi-common"
"github.com/ceph/ceph-csi/internal/util" "github.com/ceph/ceph-csi/internal/util"
@ -209,13 +210,10 @@ func TestReadAffinity_GetReadAffinityMapOptions(t *testing.T) {
} }
topology := map[string]string{} topology := map[string]string{}
csiConfig := []util.ClusterInfo{ csiConfig := []cephcsi.ClusterInfo{
{ {
ClusterID: "cluster-1", ClusterID: "cluster-1",
ReadAffinity: struct { ReadAffinity: cephcsi.ReadAffinity{
Enabled bool `json:"enabled"`
CrushLocationLabels []string `json:"crushLocationLabels"`
}{
Enabled: true, Enabled: true,
CrushLocationLabels: []string{ CrushLocationLabels: []string{
"topology.kubernetes.io/region", "topology.kubernetes.io/region",
@ -224,10 +222,7 @@ func TestReadAffinity_GetReadAffinityMapOptions(t *testing.T) {
}, },
{ {
ClusterID: "cluster-2", ClusterID: "cluster-2",
ReadAffinity: struct { ReadAffinity: cephcsi.ReadAffinity{
Enabled bool `json:"enabled"`
CrushLocationLabels []string `json:"crushLocationLabels"`
}{
Enabled: false, Enabled: false,
CrushLocationLabels: []string{ CrushLocationLabels: []string{
"topology.kubernetes.io/region", "topology.kubernetes.io/region",
@ -236,10 +231,7 @@ func TestReadAffinity_GetReadAffinityMapOptions(t *testing.T) {
}, },
{ {
ClusterID: "cluster-3", ClusterID: "cluster-3",
ReadAffinity: struct { ReadAffinity: cephcsi.ReadAffinity{
Enabled bool `json:"enabled"`
CrushLocationLabels []string `json:"crushLocationLabels"`
}{
Enabled: true, Enabled: true,
CrushLocationLabels: []string{}, CrushLocationLabels: []string{},
}, },

View File

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

View File

@ -22,6 +22,8 @@ import (
"fmt" "fmt"
"os" "os"
"strings" "strings"
"github.com/ceph/ceph-csi/api/deploy/kubernetes"
) )
const ( const (
@ -36,49 +38,6 @@ const (
ClusterIDKey = "clusterID" 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, // Expected JSON structure in the passed in config file is,
//nolint:godot // example json content should not contain unwanted dot. //nolint:godot // example json content should not contain unwanted dot.
/* /*
@ -96,8 +55,8 @@ type ReadAffinity struct {
} }
}] }]
*/ */
func readClusterInfo(pathToConfig, clusterID string) (*ClusterInfo, error) { func readClusterInfo(pathToConfig, clusterID string) (*kubernetes.ClusterInfo, error) {
var config []ClusterInfo var config []kubernetes.ClusterInfo
// #nosec // #nosec
content, err := os.ReadFile(pathToConfig) content, err := os.ReadFile(pathToConfig)

View File

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

View File

@ -18,42 +18,42 @@ package kubernetes
type ClusterInfo struct { type ClusterInfo struct {
// ClusterID is used for unique identification // ClusterID is used for unique identification
ClusterID string ClusterID string `json:"clusterID"`
// Monitors is monitor list for corresponding cluster ID // Monitors is monitor list for corresponding cluster ID
Monitors []string Monitors []string `json:"monitors"`
// CephFS contains CephFS specific options // CephFS contains CephFS specific options
CephFS CephFS CephFS CephFS `json:"cephFS"`
// RBD Contains RBD specific options // RBD Contains RBD specific options
RBD RBD RBD RBD `json:"rbd"`
// NFS contains NFS specific options // NFS contains NFS specific options
NFS NFS NFS NFS `json:"nfs"`
// Read affinity map options // Read affinity map options
ReadAffinity ReadAffinity ReadAffinity ReadAffinity `json:"readAffinity"`
} }
type CephFS struct { type CephFS struct {
// symlink filepath for the network namespace where we need to execute commands. // symlink filepath for the network namespace where we need to execute commands.
NetNamespaceFilePath string NetNamespaceFilePath string `json:"netNamespaceFilePath"`
// SubvolumeGroup contains the name of the SubvolumeGroup for CSI volumes // SubvolumeGroup contains the name of the SubvolumeGroup for CSI volumes
SubvolumeGroup string SubvolumeGroup string `json:"subvolumeGroup"`
// KernelMountOptions contains the kernel mount options for CephFS volumes // KernelMountOptions contains the kernel mount options for CephFS volumes
KernelMountOptions string KernelMountOptions string `json:"kernelMountOptions"`
// FuseMountOptions contains the fuse mount options for CephFS volumes // FuseMountOptions contains the fuse mount options for CephFS volumes
FuseMountOptions string FuseMountOptions string `json:"fuseMountOptions"`
} }
type RBD struct { type RBD struct {
// symlink filepath for the network namespace where we need to execute commands. // symlink filepath for the network namespace where we need to execute commands.
NetNamespaceFilePath string NetNamespaceFilePath string `json:"netNamespaceFilePath"`
// RadosNamespace is a rados namespace in the pool // RadosNamespace is a rados namespace in the pool
RadosNamespace string RadosNamespace string `json:"radosNamespace"`
} }
type NFS struct { type NFS struct {
// symlink filepath for the network namespace where we need to execute commands. // symlink filepath for the network namespace where we need to execute commands.
NetNamespaceFilePath string NetNamespaceFilePath string `json:"netNamespaceFilePath"`
} }
type ReadAffinity struct { type ReadAffinity struct {
Enabled bool Enabled bool `json:"enabled"`
CrushLocationLabels []string CrushLocationLabels []string `json:"crushLocationLabels"`
} }