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

Test cache and node publish #26

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
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: 0 additions & 2 deletions images/sds-local-volume-controller/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,4 @@ func main() {
log.Error(err, "[main] unable to mgr.Start")
os.Exit(1)
}

log.Info("[main] successfully starts the manager")
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,28 @@ import (
"context"
"errors"
"fmt"
"reflect"
v1alpha1 "sds-local-volume-controller/api/v1alpha1"
"sds-local-volume-controller/pkg/config"
"sds-local-volume-controller/pkg/logger"
"sds-local-volume-controller/pkg/monitoring"
"strings"
"time"

corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/storage/v1"
errors2 "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/workqueue"
"k8s.io/utils/strings/slices"
"reflect"
v1alpha1 "sds-local-volume-controller/api/v1alpha1"
"sds-local-volume-controller/pkg/config"
"sds-local-volume-controller/pkg/logger"
"sds-local-volume-controller/pkg/monitoring"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
"sigs.k8s.io/yaml"
"strings"
"time"

"sigs.k8s.io/controller-runtime/pkg/manager"
)
Expand Down Expand Up @@ -443,13 +444,19 @@ func reconcileLSCUpdateFunc(
}

func patchSCByLSC(sc *v1.StorageClass, lsc *v1alpha1.LocalStorageClass) *v1.StorageClass {
lscDefault := "false"

if lsc.Spec.IsDefault {
lscDefault = "true"
if sc.Annotations == nil {
sc.Annotations = make(map[string]string)
}
sc.Annotations[DefaultStorageClassAnnotationKey] = "true"
} else {
_, isDefault := sc.Annotations[DefaultStorageClassAnnotationKey]
if isDefault {
delete(sc.Annotations, DefaultStorageClassAnnotationKey)
}
}

sc.Annotations[DefaultStorageClassAnnotationKey] = lscDefault

return sc
}

Expand Down
21 changes: 13 additions & 8 deletions images/sds-local-volume-csi/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ func (d *Driver) CreateVolume(ctx context.Context, request *csi.CreateVolumeRequ
d.log.Error(err, "error GetStorageClassLVGs")
return nil, status.Errorf(codes.Internal, err.Error())
}
// TODO: Consider refactoring the naming strategy for llvName and lvName.
// Currently, we use the same name for llvName (the name of the LVMLogicalVolume resource in Kubernetes)
// and lvName (the name of the LV in LVM on the node) because the PV name is unique within the cluster,
// preventing name collisions. This approach simplifies matching between nodes and Kubernetes by maintaining
// the same name in both contexts. Future consideration should be given to optimizing this logic to enhance
// code readability and maintainability.
// TODO: Consider refactoring the naming strategy for llvName and lvName.
// Currently, we use the same name for llvName (the name of the LVMLogicalVolume resource in Kubernetes)
// and lvName (the name of the LV in LVM on the node) because the PV name is unique within the cluster,
// preventing name collisions. This approach simplifies matching between nodes and Kubernetes by maintaining
// the same name in both contexts. Future consideration should be given to optimizing this logic to enhance
// code readability and maintainability.
llvName := request.Name
lvName := request.Name
d.log.Info(fmt.Sprintf("llv name: %s ", llvName))
Expand All @@ -90,7 +90,7 @@ func (d *Driver) CreateVolume(ctx context.Context, request *csi.CreateVolumeRequ

preferredNode = selectedNodeName
d.log.Info(fmt.Sprintf("Selected node: %s, free space %s ", selectedNodeName, freeSpace.String()))
if LvmType == internal.LLMTypeThick {
if LvmType == internal.LVMTypeThick {
if llvSize.Value() > freeSpace.Value() {
return nil, status.Errorf(codes.Internal, "requested size: %s is greater than free space: %s", llvSize.String(), freeSpace.String())
}
Expand Down Expand Up @@ -150,6 +150,11 @@ func (d *Driver) CreateVolume(ctx context.Context, request *csi.CreateVolumeRequ

volumeCtx[internal.SubPath] = request.Name
volumeCtx[internal.VGNameKey] = selectedLVG.Spec.ActualVGNameOnTheNode
if llvSpec.Type == internal.LVMTypeThin {
volumeCtx[internal.ThinPoolNameKey] = llvSpec.Thin.PoolName
} else {
volumeCtx[internal.ThinPoolNameKey] = ""
}

return &csi.CreateVolumeResponse{
Volume: &csi.Volume{
Expand Down Expand Up @@ -301,7 +306,7 @@ func (d *Driver) ControllerExpandVolume(ctx context.Context, request *csi.Contro
return nil, status.Errorf(codes.Internal, "error getting LVMVolumeGroup: %v", err)
}

if llv.Spec.Type == internal.LLMTypeThick {
if llv.Spec.Type == internal.LVMTypeThick {
lvgFreeSpace, err := utils.GetLVMVolumeGroupFreeSpace(*lvg)
if err != nil {
return nil, status.Errorf(codes.Internal, "error getting LVMVolumeGroupCapacity: %v", err)
Expand Down
17 changes: 14 additions & 3 deletions images/sds-local-volume-csi/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ func (d *Driver) NodeUnstageVolume(ctx context.Context, request *csi.NodeUnstage
}

func (d *Driver) NodePublishVolume(ctx context.Context, request *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
d.log.Info("method NodePublishVolume")
d.log.Info("Start method NodePublishVolume")
d.log.Trace("------------- NodePublishVolume --------------")
d.log.Trace(request.String())
d.log.Trace("------------- NodePublishVolume --------------")

dev := fmt.Sprintf("/dev/%s/%s", request.GetVolumeContext()[internal.VGNameKey], request.VolumeId)
lvmType := request.GetVolumeContext()[internal.LvmTypeKey]
lvmThinPoolName := request.GetVolumeContext()[internal.ThinPoolNameKey]
d.log.Info(fmt.Sprintf("dev = %s", dev))

var mountOptions []string
if request.GetReadonly() {
Expand All @@ -61,12 +64,20 @@ func (d *Driver) NodePublishVolume(ctx context.Context, request *csi.NodePublish
mountOptions = append(mountOptions, mnt.GetMountFlags()...)
}

err := d.storeManager.Mount(dev, request.GetTargetPath(), IsBlock, fsType, false, mountOptions)
d.log.Info(fmt.Sprintf("mountOptions = %s", mountOptions))
d.log.Info(fmt.Sprintf("lvmType = %s", lvmType))
d.log.Info(fmt.Sprintf("lvmThinPoolName = %s", lvmThinPoolName))
d.log.Info(fmt.Sprintf("fsType = %s", fsType))
d.log.Info(fmt.Sprintf("IsBlock = %t", IsBlock))

err := d.storeManager.Mount(dev, request.GetTargetPath(), IsBlock, fsType, false, mountOptions, lvmType, lvmThinPoolName)
if err != nil {
d.log.Error(err, "d.mounter.Mount :")
return nil, err
}

d.log.Info("Success method NodePublishVolume")

return &csi.NodePublishVolumeResponse{}, nil
}

Expand Down Expand Up @@ -139,7 +150,7 @@ func (d *Driver) NodeGetCapabilities(ctx context.Context, request *csi.NodeGetCa

func (d *Driver) NodeGetInfo(ctx context.Context, request *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
d.log.Info("method NodeGetInfo")
d.log.Info("hostID = ", d.hostID)
d.log.Info(fmt.Sprintf("hostID = %s", d.hostID))

return &csi.NodeGetInfoResponse{
NodeId: d.hostID,
Expand Down
58 changes: 30 additions & 28 deletions images/sds-local-volume-csi/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,56 @@ go 1.21
require (
github.com/container-storage-interface/spec v1.9.0
github.com/go-logr/logr v1.4.1
github.com/golang/protobuf v1.5.3
github.com/golang/protobuf v1.5.4
golang.org/x/sync v0.6.0
google.golang.org/grpc v1.60.1
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.29.0
k8s.io/apiextensions-apiserver v0.29.0
k8s.io/apimachinery v0.29.0
k8s.io/client-go v0.29.0
k8s.io/klog/v2 v2.110.1
k8s.io/mount-utils v0.29.1
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
sigs.k8s.io/controller-runtime v0.17.0
google.golang.org/grpc v1.62.1
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.29.3
k8s.io/apiextensions-apiserver v0.29.3
k8s.io/apimachinery v0.29.3
k8s.io/client-go v0.29.3
k8s.io/klog/v2 v2.120.1
k8s.io/mount-utils v0.29.3
k8s.io/utils v0.0.0-20240310230437-4693a0247e57
sigs.k8s.io/controller-runtime v0.17.2
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/emicklei/go-restful/v3 v3.12.0 // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/imdario/mergo v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/moby/sys/mountinfo v0.6.2 // indirect
github.com/moby/sys/mountinfo v0.7.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240108191215-35c7eff3a6b1 // indirect
google.golang.org/protobuf v1.32.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/kube-openapi v0.0.0-20240322212309-b815d8309940 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

replace github.com/imdario/mergo => github.com/imdario/mergo v0.3.16
Loading
Loading