Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deploy: added json field tags for csi config map #4329

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -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
@@ -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
@@ -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"
@@ -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,
@@ -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
8 changes: 4 additions & 4 deletions internal/cephfs/nodeserver_test.go
Original file line number Diff line number Diff line change
@@ -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) {
@@ -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: "",
},
5 changes: 3 additions & 2 deletions internal/cephfs/store/volumeoptions.go
Original file line number Diff line number Diff line change
@@ -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"
@@ -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")
@@ -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, ","),
}
18 changes: 5 additions & 13 deletions internal/rbd/nodeserver_test.go
Original file line number Diff line number Diff line change
@@ -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"

@@ -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",
@@ -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",
@@ -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{},
},
4 changes: 3 additions & 1 deletion internal/util/cluster_mapping_test.go
Original file line number Diff line number Diff line change
@@ -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"},
49 changes: 4 additions & 45 deletions internal/util/csiconfig.go
Original file line number Diff line number Diff line change
@@ -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)
36 changes: 19 additions & 17 deletions internal/util/csiconfig_test.go
Original file line number Diff line number Diff line change
@@ -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)