Skip to content

Commit

Permalink
deploy: added json field tags for csi config map
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
iPraveenParihar authored and Rakshith-R committed Dec 20, 2023
1 parent 8a2bf60 commit 54ac157
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 124 deletions.
2 changes: 1 addition & 1 deletion api/deploy/kubernetes/cephfs/csi-config-map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ func TestNewCSIConfigMapYAML(t *testing.T) {

require.NoError(t, err)
require.NotEqual(t, "", yaml)
}
}
30 changes: 15 additions & 15 deletions api/deploy/kubernetes/csi-config-map.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,42 @@ package kubernetes

type ClusterInfo struct {
// ClusterID is used for unique identification
ClusterID string
ClusterID string `json:"clusterID"`
// Monitors is monitor list for corresponding cluster ID
Monitors []string
Monitors []string `json:"monitors"`
// CephFS contains CephFS specific options
CephFS CephFS
CephFS CephFS `json:"cephFS"`
// RBD Contains RBD specific options
RBD RBD
RBD RBD `json:"rbd"`
// NFS contains NFS specific options
NFS NFS
NFS NFS `json:"nfs"`
// Read affinity map options
ReadAffinity ReadAffinity
ReadAffinity ReadAffinity `json:"readAffinity"`
}

type CephFS struct {
// 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 string
SubvolumeGroup string `json:"subvolumeGroup"`
// 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 string
FuseMountOptions string `json:"fuseMountOptions"`
}
type RBD struct {
// 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 string
RadosNamespace string `json:"radosNamespace"`
}

type NFS struct {
// symlink filepath for the network namespace where we need to execute commands.
NetNamespaceFilePath string
NetNamespaceFilePath string `json:"netNamespaceFilePath"`
}

type ReadAffinity struct {
Enabled bool
CrushLocationLabels []string
Enabled bool `json:"enabled"`
CrushLocationLabels []string `json:"crushLocationLabels"`
}
16 changes: 5 additions & 11 deletions e2e/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"encoding/json"
"fmt"

"github.com/ceph/ceph-csi/internal/util"
cephcsi "github.com/ceph/ceph-csi/api/deploy/kubernetes"

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

for i, j := range clusterID {
conmap[i].ClusterID = j
Expand Down
8 changes: 4 additions & 4 deletions internal/cephfs/nodeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (

"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/store"
csicommon "github.com/ceph/ceph-csi/internal/csi-common"
"github.com/ceph/ceph-csi/internal/util"
)

func Test_setMountOptions(t *testing.T) {
Expand All @@ -39,17 +39,17 @@ func Test_setMountOptions(t *testing.T) {
configKernelMountOptions := "crc"
configFuseMountOptions := "allow_other"

csiConfig := []util.ClusterInfo{
csiConfig := []cephcsi.ClusterInfo{
{
ClusterID: "cluster-1",
CephFS: util.CephFS{
CephFS: cephcsi.CephFS{
KernelMountOptions: configKernelMountOptions,
FuseMountOptions: configFuseMountOptions,
},
},
{
ClusterID: "cluster-2",
CephFS: util.CephFS{
CephFS: cephcsi.CephFS{
KernelMountOptions: "",
FuseMountOptions: "",
},
Expand Down
5 changes: 3 additions & 2 deletions internal/cephfs/store/volumeoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"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"
cerrors "github.com/ceph/ceph-csi/internal/cephfs/errors"
fsutil "github.com/ceph/ceph-csi/internal/cephfs/util"
Expand Down Expand Up @@ -164,7 +165,7 @@ func extractMounter(dest *string, options map[string]string) error {
return nil
}

func GetClusterInformation(options map[string]string) (*util.ClusterInfo, error) {
func GetClusterInformation(options map[string]string) (*cephcsi.ClusterInfo, error) {
clusterID, ok := options["clusterID"]
if !ok {
err := fmt.Errorf("clusterID must be set")
Expand All @@ -189,7 +190,7 @@ func GetClusterInformation(options map[string]string) (*util.ClusterInfo, error)

return nil, err
}
clusterData := &util.ClusterInfo{
clusterData := &cephcsi.ClusterInfo{
ClusterID: clusterID,
Monitors: strings.Split(monitors, ","),
}
Expand Down
18 changes: 5 additions & 13 deletions internal/rbd/nodeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"testing"

cephcsi "github.com/ceph/ceph-csi/api/deploy/kubernetes"
csicommon "github.com/ceph/ceph-csi/internal/csi-common"
"github.com/ceph/ceph-csi/internal/util"

Expand Down Expand Up @@ -209,13 +210,10 @@ func TestReadAffinity_GetReadAffinityMapOptions(t *testing.T) {
}
topology := map[string]string{}

csiConfig := []util.ClusterInfo{
csiConfig := []cephcsi.ClusterInfo{
{
ClusterID: "cluster-1",
ReadAffinity: struct {
Enabled bool `json:"enabled"`
CrushLocationLabels []string `json:"crushLocationLabels"`
}{
ReadAffinity: cephcsi.ReadAffinity{
Enabled: true,
CrushLocationLabels: []string{
"topology.kubernetes.io/region",
Expand All @@ -224,10 +222,7 @@ func TestReadAffinity_GetReadAffinityMapOptions(t *testing.T) {
},
{
ClusterID: "cluster-2",
ReadAffinity: struct {
Enabled bool `json:"enabled"`
CrushLocationLabels []string `json:"crushLocationLabels"`
}{
ReadAffinity: cephcsi.ReadAffinity{
Enabled: false,
CrushLocationLabels: []string{
"topology.kubernetes.io/region",
Expand All @@ -236,10 +231,7 @@ func TestReadAffinity_GetReadAffinityMapOptions(t *testing.T) {
},
{
ClusterID: "cluster-3",
ReadAffinity: struct {
Enabled bool `json:"enabled"`
CrushLocationLabels []string `json:"crushLocationLabels"`
}{
ReadAffinity: cephcsi.ReadAffinity{
Enabled: true,
CrushLocationLabels: []string{},
},
Expand Down
4 changes: 3 additions & 1 deletion internal/util/cluster_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"reflect"
"strings"
"testing"

cephcsi "github.com/ceph/ceph-csi/api/deploy/kubernetes"
)

func TestGetClusterMappingInfo(t *testing.T) {
Expand Down Expand Up @@ -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"},
Expand Down
49 changes: 4 additions & 45 deletions internal/util/csiconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"fmt"
"os"
"strings"

"github.com/ceph/ceph-csi/api/deploy/kubernetes"
)

const (
Expand All @@ -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.
/*
Expand All @@ -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)
Expand Down
Loading

0 comments on commit 54ac157

Please sign in to comment.