Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
# Conflicts:
#	Dockerfile
#	deploy/kubernetes/v1.20/controller.yml
#	deploy/kubernetes/v1.20/node.yml
#	deploy/kubernetes/v1.20/snapshotter/snapshotter.yaml
#	go.mod
#	pkg/driver/controllerserver.go
  • Loading branch information
zebernst committed Nov 12, 2023
2 parents 4783491 + a4270a3 commit 26e76bd
Show file tree
Hide file tree
Showing 22 changed files with 122 additions and 55 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright 2021 Synology Inc.

############## Build stage ##############
FROM golang:1.20.3-alpine as builder
FROM golang:1.20.5-alpine as builder

RUN apk add --no-cache alpine-sdk
WORKDIR /go/src/synok8scsiplugin
Expand All @@ -23,7 +23,7 @@ FROM alpine:latest as driver
LABEL maintainers="Synology Authors" \
description="Synology CSI Plugin"

RUN <<-EOF
RUN <<-EOF
apk add --no-cache \
bash \
blkid \
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

REGISTRY_NAME=ghcr.io/zebernst
IMAGE_NAME=synology-csi
IMAGE_VERSION=v1.1.2
IMAGE_VERSION=v1.1.3
IMAGE_TAG=$(REGISTRY_NAME)/$(IMAGE_NAME):$(IMAGE_VERSION)

# For now, only build linux/amd64 platform
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ modified for support with [Talos Linux](https://www.talos.dev)
Driver Name: csi.san.synology.com
| Driver Version | Image | Supported K8s Version |
| -------------------------------------------------------------------------------- | --------------------------------------------------------------------- | --------------------- |
| [v1.1.2](https://github.com/SynologyOpenSource/synology-csi/tree/release-v1.1.2) | [synology-csi:v1.1.2](https://hub.docker.com/r/synology/synology-csi) | 1.20+ |
| [v1.1.3](https://github.com/SynologyOpenSource/synology-csi/tree/release-v1.1.3) | [synology-csi:v1.1.3](https://hub.docker.com/r/synology/synology-csi) | 1.20+ |



Expand Down Expand Up @@ -117,9 +117,10 @@ Create and apply StorageClasses with the properties you want.
name: synostorage
provisioner: csi.san.synology.com
parameters:
fsType: 'ext4'
fsType: 'btrfs'
dsm: '192.168.1.1'
location: '/volume1'
formatOptions: '--nodiscard'
reclaimPolicy: Retain
allowVolumeExpansion: true
```
Expand Down
6 changes: 3 additions & 3 deletions charts/synology-csi/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apiVersion: v2
appVersion: v1.1.2
appVersion: v1.1.3
name: synology-csi
description: A Helm chart for the Synology CSI Driver
keywords:
- Synology
- CSI Driver
kubeVersion: ">= 1.20.0"
sources:
- https://github.com/christian-schlichtherle/synology-csi-chart/tree/main
- https://github.com/zebernst/synology-csi-talos/tree/main
- https://github.com/SynologyOpenSource/synology-csi/tree/main
version: 0.9.3
version: 0.9.4
10 changes: 5 additions & 5 deletions charts/synology-csi/templates/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ spec:
fieldRef:
fieldPath: spec.nodeName
- name: REGISTRATION_PATH
value: /var/lib/kubelet/plugins/csi.san.synology.com/csi.sock
value: {{ $.Values.node.kubeletPath }}/plugins/csi.san.synology.com/csi.sock
{{- with .nodeDriverRegistrar }}
image: {{ .image }}:{{ .tag }}
imagePullPolicy: {{ .pullPolicy }}
Expand Down Expand Up @@ -123,7 +123,7 @@ spec:
- name: host-root
mountPath: /host
- name: kubelet-dir
mountPath: /var/lib/kubelet
mountPath: {{ $.Values.node.kubeletPath }}
mountPropagation: Bidirectional
- name: plugin-dir
mountPath: /csi
Expand All @@ -148,15 +148,15 @@ spec:
type: Directory
- name: kubelet-dir
hostPath:
path: /var/lib/kubelet
path: {{ .kubeletPath }}
type: Directory
- name: plugin-dir
hostPath:
path: /var/lib/kubelet/plugins/csi.san.synology.com
path: {{ .kubeletPath }}/plugins/csi.san.synology.com
type: DirectoryOrCreate
- name: registration-dir
hostPath:
path: /var/lib/kubelet/plugins_registry
path: {{ .kubeletPath }}/plugins_registry
type: Directory
{{- end }}
{{- end }}
2 changes: 1 addition & 1 deletion charts/synology-csi/templates/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ metadata:
spec:
accessModes:
- ReadWriteOnce
storageClassName: {{ include "synology-csi.fullname" $ }}-delete
storageClassName: synology-iscsi-storage-delete
resources:
requests:
storage: 1Gi
Expand Down
3 changes: 3 additions & 0 deletions charts/synology-csi/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ node:
affinity: { }
nodeSelector: { }
tolerations: [ ]
# If your kubelet path is not standard, specify it here :
## example for miocrok8s distrib : /var/snap/microk8s/common/var/lib/kubelet
kubeletPath: /var/lib/kubelet
# Specifies affinity, nodeSelector and tolerations for the snapshotter StatefulSet
snapshotter:
affinity: { }
Expand Down
3 changes: 2 additions & 1 deletion deploy/kubernetes/v1.19/controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ spec:
- --timeout=60s
- --csi-address=$(ADDRESS)
- --v=5
- --extra-create-metadata
env:
- name: ADDRESS
value: /var/lib/csi/sockets/pluginproxy/csi.sock
Expand Down Expand Up @@ -143,7 +144,7 @@ spec:
capabilities:
add: ["SYS_ADMIN"]
allowPrivilegeEscalation: true
image: synology/synology-csi:v1.1.2
image: synology/synology-csi:v1.1.3
args:
- --nodeid=NotUsed
- --endpoint=$(CSI_ENDPOINT)
Expand Down
2 changes: 1 addition & 1 deletion deploy/kubernetes/v1.19/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ spec:
securityContext:
privileged: true
imagePullPolicy: IfNotPresent
image: synology/synology-csi:v1.1.2
image: synology/synology-csi:v1.1.3
args:
- --nodeid=$(KUBE_NODE_NAME)
- --endpoint=$(CSI_ENDPOINT)
Expand Down
2 changes: 1 addition & 1 deletion deploy/kubernetes/v1.19/snapshotter/snapshotter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ spec:
capabilities:
add: ["SYS_ADMIN"]
allowPrivilegeEscalation: true
image: synology/synology-csi:v1.1.2
image: synology/synology-csi:v1.1.3
args:
- --nodeid=NotUsed
- --endpoint=$(CSI_ENDPOINT)
Expand Down
3 changes: 2 additions & 1 deletion deploy/kubernetes/v1.20/controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ spec:
- --timeout=60s
- --csi-address=$(ADDRESS)
- --v=5
- --extra-create-metadata
env:
- name: ADDRESS
value: /var/lib/csi/sockets/pluginproxy/csi.sock
Expand Down Expand Up @@ -143,7 +144,7 @@ spec:
capabilities:
add: ["SYS_ADMIN"]
allowPrivilegeEscalation: true
image: ghcr.io/zebernst/synology-csi:v1.1.2
image: ghcr.io/zebernst/synology-csi:v1.1.3
args:
- --nodeid=NotUsed
- --endpoint=$(CSI_ENDPOINT)
Expand Down
2 changes: 1 addition & 1 deletion deploy/kubernetes/v1.20/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ spec:
securityContext:
privileged: true
imagePullPolicy: IfNotPresent
image: ghcr.io/zebernst/synology-csi:v1.1.2
image: ghcr.io/zebernst/synology-csi:v1.1.3
args:
- --nodeid=$(KUBE_NODE_NAME)
- --endpoint=$(CSI_ENDPOINT)
Expand Down
2 changes: 1 addition & 1 deletion deploy/kubernetes/v1.20/snapshotter/snapshotter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ spec:
capabilities:
add: ["SYS_ADMIN"]
allowPrivilegeEscalation: true
image: ghcr.io/zebernst/synology-csi:v1.1.2
image: ghcr.io/zebernst/synology-csi:v1.1.3
args:
- --nodeid=NotUsed
- --endpoint=$(CSI_ENDPOINT)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/kubernetes-csi/csi-test/v4 v4.3.0
github.com/sirupsen/logrus v1.7.0
github.com/spf13/cobra v1.1.3
golang.org/x/sys v0.5.0
google.golang.org/grpc v1.34.0
google.golang.org/protobuf v1.25.0
gopkg.in/yaml.v2 v2.4.0
Expand Down
10 changes: 10 additions & 0 deletions pkg/driver/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,20 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
// used only in NodeStageVolume though VolumeContext
formatOptions := params["formatOptions"]

lunDescription := ""
if _, ok := params["csi.storage.k8s.io/pvc/name"]; ok {
// if the /pvc/name is present, the namespace is present too
// as these parameters are reserved by external-provisioner
pvcNamespace := params["csi.storage.k8s.io/pvc/namespace"]
pvcName := params["csi.storage.k8s.io/pvc/name"]
lunDescription = pvcNamespace + "/" + pvcName
}

spec := &models.CreateK8sVolumeSpec{
DsmIp: params["dsm"],
K8sVolumeName: volName,
LunName: models.GenLunName(volName),
LunDescription: lunDescription,
ShareName: models.GenShareName(volName),
Location: params["location"],
Size: sizeInByte,
Expand Down
6 changes: 3 additions & 3 deletions pkg/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

const (
DriverName = "csi.san.synology.com" // CSI dirver name
DriverVersion = "1.1.2"
DriverVersion = "1.1.3"
)

var (
Expand Down Expand Up @@ -79,8 +79,8 @@ func NewControllerAndNodeDriver(nodeID string, endpoint string, dsmService inter
d.addNodeServiceCapabilities([]csi.NodeServiceCapability_RPC_Type{
csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME,
csi.NodeServiceCapability_RPC_EXPAND_VOLUME,
csi.NodeServiceCapability_RPC_GET_VOLUME_STATS,
// csi.NodeServiceCapability_RPC_VOLUME_MOUNT_GROUP,
// csi.NodeServiceCapability_RPC_GET_VOLUME_STATS, //TODO
})

log.Infof("New driver created: name=%s, nodeID=%s, version=%s, endpoint=%s", d.name, d.nodeID, d.version, d.endpoint)
Expand Down Expand Up @@ -138,4 +138,4 @@ func (d *Driver) getVolumeCapabilityAccessModes() []*csi.VolumeCapability_Access

func isProtocolSupport(protocol string) bool {
return utils.SliceContains(supportedProtocolList, protocol)
}
}
33 changes: 26 additions & 7 deletions pkg/driver/initiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
)

type initiatorDriver struct {
chapUser string
chapUser string
chapPassword string
}

Expand Down Expand Up @@ -123,6 +123,21 @@ func iscsiadm_login(iqn, portal string) error {
return nil
}

func iscsiadm_update_node_startup(iqn, portal string) error {
cmd := iscsiadm(
"-m", "node",
"--targetname", iqn,
"--portal", portal,
"--op", "update",
"--name", "node.startup",
"--value", "manual")
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("%s (%v)", string(out), err)
}
return nil
}

func iscsiadm_logout(iqn string) error {
cmd := iscsiadm(
"-m", "node",
Expand Down Expand Up @@ -169,8 +184,8 @@ func listSessionsByIqn(targetIqn string) (matchedSessions []iscsiSession) {
return matchedSessions
}

func (d *initiatorDriver) login(targetIqn string, portal string) error{
if (hasSession(targetIqn, portal)) {
func (d *initiatorDriver) login(targetIqn string, portal string) error {
if hasSession(targetIqn, portal) {
log.Infof("Session[%s] already exists.", targetIqn)
return nil
}
Expand All @@ -185,13 +200,17 @@ func (d *initiatorDriver) login(targetIqn string, portal string) error{
return err
}

if err := iscsiadm_update_node_startup(targetIqn, portal); err != nil {
log.Warnf("Failed to update target node.startup to manual: %v", err)
}

log.Infof("Login target portal [%s], iqn [%s].", portal, targetIqn)

return nil
}

func (d *initiatorDriver) logout(targetIqn string, ip string) error{
if (!hasSession(targetIqn, "")) {
func (d *initiatorDriver) logout(targetIqn string, ip string) error {
if !hasSession(targetIqn, "") {
log.Infof("Session[%s] doesn't exist.", targetIqn)
return nil
}
Expand All @@ -208,8 +227,8 @@ func (d *initiatorDriver) logout(targetIqn string, ip string) error{
return nil
}

func (d *initiatorDriver) rescan(targetIqn string) error{
if (!hasSession(targetIqn, "")) {
func (d *initiatorDriver) rescan(targetIqn string) error {
if !hasSession(targetIqn, "") {
msg := fmt.Sprintf("Session[%s] doesn't exist.", targetIqn)
log.Error(msg)
return errors.New(msg)
Expand Down
36 changes: 31 additions & 5 deletions pkg/driver/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
log "github.com/sirupsen/logrus"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"golang.org/x/sys/unix"
"k8s.io/mount-utils"

"github.com/SynologyOpenSource/synology-csi/pkg/dsm/webapi"
Expand Down Expand Up @@ -584,14 +585,39 @@ func (ns *nodeServer) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVo
}, nil
}

lun := k8sVolume.Lun
// If we are dealing with a LUN use statfs
statfs := &unix.Statfs_t{}
err = unix.Statfs(volumePath, statfs)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get fs info on path %s: %v", req.VolumePath, err)
}

// Available is blocks available * fragment size
available := int64(statfs.Bavail) * int64(statfs.Bsize)

// Capacity is total block count * fragment size
capacity := int64(statfs.Blocks) * int64(statfs.Bsize)

// Usage is block being used * fragment size (aka block size).
usage := (int64(statfs.Blocks) - int64(statfs.Bfree)) * int64(statfs.Bsize)

inodes := int64(statfs.Files)
inodesFree := int64(statfs.Ffree)
inodesUsed := inodes - inodesFree

return &csi.NodeGetVolumeStatsResponse{
Usage: []*csi.VolumeUsage{
&csi.VolumeUsage{
Available: int64(lun.Size - lun.Used),
Total: int64(lun.Size),
Used: int64(lun.Used),
{
Unit: csi.VolumeUsage_BYTES,
Available: available,
Total: capacity,
Used: usage,
},
{
Unit: csi.VolumeUsage_INODES,
Available: inodesFree,
Total: inodes,
Used: inodesUsed,
},
},
}, nil
Expand Down
11 changes: 6 additions & 5 deletions pkg/dsm/service/dsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (service *DsmService) createMappingTarget(dsm *webapi.DSM, spec *models.Cre
}
targetSpec := webapi.TargetCreateSpec{
Name: spec.TargetName,
Iqn: genTargetIqn(),
Iqn: genTargetIqn(),
}

log.Debugf("TargetCreate spec: %v", targetSpec)
Expand Down Expand Up @@ -224,10 +224,11 @@ func (service *DsmService) createVolumeByDsm(dsm *webapi.DSM, spec *models.Creat

// 3. Create LUN
lunSpec := webapi.LunCreateSpec{
Name: spec.LunName,
Location: spec.Location,
Size: spec.Size,
Type: lunType,
Name: spec.LunName,
Description: spec.LunDescription,
Location: spec.Location,
Size: spec.Size,
Type: lunType,
}

log.Debugf("LunCreate spec: %v", lunSpec)
Expand Down
Loading

0 comments on commit 26e76bd

Please sign in to comment.