Skip to content

Commit

Permalink
refactor: remove maintain global state pvs (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
whg517 authored Dec 30, 2024
1 parent 9dea930 commit 7c1a464
Showing 1 changed file with 3 additions and 31 deletions.
34 changes: 3 additions & 31 deletions internal/csi/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,14 @@ var (

type ControllerServer struct {
csi.UnimplementedControllerServer
client client.Client
volumes map[string]int64
client client.Client
}

var _ csi.ControllerServer = &ControllerServer{}

func NewControllerServer(client client.Client) *ControllerServer {
return &ControllerServer{
client: client,
volumes: map[string]int64{},
client: client,
}
}

Expand All @@ -56,11 +54,7 @@ func (c *ControllerServer) CreateVolume(ctx context.Context, request *csi.Create
}

requiredCap := request.CapacityRange.GetRequiredBytes()
if existCap, ok := c.volumes[request.Name]; ok && existCap < requiredCap {
return nil, status.Errorf(codes.AlreadyExists, "Volume: %q, capacity bytes: %d", request.Name, requiredCap)
}

c.volumes[request.Name] = requiredCap
if request.Parameters["secretFinalizer"] == "true" {
logger.V(1).Info("Finalizer is true")
}
Expand Down Expand Up @@ -189,11 +183,6 @@ func (c *ControllerServer) DeleteVolume(ctx context.Context, request *csi.Delete
return &csi.DeleteVolumeResponse{}, nil
}

if _, ok := c.volumes[request.VolumeId]; !ok {
// return nil, status.Errorf(codes.NotFound, "Volume ID: %q", request.VolumeId)
logger.V(1).Info("Volume not found, skip delete volume")
}

return &csi.DeleteVolumeResponse{}, nil
}

Expand Down Expand Up @@ -233,24 +222,7 @@ func (c *ControllerServer) ValidateVolumeCapabilities(ctx context.Context, reque
}

func (c *ControllerServer) ListVolumes(ctx context.Context, request *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) {
// impl list volumes
entries := make([]*csi.ListVolumesResponse_Entry, 0, len(c.volumes))
for volumeID, size := range c.volumes {
entries = append(entries, &csi.ListVolumesResponse_Entry{
Volume: &csi.Volume{
VolumeId: volumeID,
CapacityBytes: size,
VolumeContext: nil,
ContentSource: nil,
AccessibleTopology: nil,
},
})
}

return &csi.ListVolumesResponse{
Entries: entries,
}, nil

return nil, status.Error(codes.Unimplemented, "")
}

func (c *ControllerServer) ControllerGetCapabilities(ctx context.Context, request *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) {
Expand Down

0 comments on commit 7c1a464

Please sign in to comment.