Skip to content

Commit 0946375

Browse files
shafinhasnatsyed.shafin
andauthored
Liveness (#5)
* New sdk adopted * e2fsprogs added in apk install * deviice used for mount logic * detachvolume implemented with new api * SDK added to project path to fix faulty parts * AppVersion taken optionally from chart.yml * Probe and liveness sidecar implemented * liveness probe configured * device check added * Chart version updated --------- Co-authored-by: syed.shafin <syed.shafin@bracits.com>
1 parent 7ebabcf commit 0946375

6 files changed

Lines changed: 68 additions & 20 deletions

File tree

Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
1212
-X main.version=${VERSION} \
1313
-X k8s.io/csi-hyperstack/pkg/driver.DriverName=hyperstack.csi.nexgencloud.com \
1414
-X k8s.io/csi-hyperstack/pkg/driver.DriverVersion=${VERSION}" \
15-
-o /csi-hyperstack .
15+
-o /csi-hyperstack
1616

1717
FROM alpine:3.20 as runtime
1818
RUN apk add --no-cache --update e2fsprogs
19-
19+
RUN wget "https://github.com/fullstorydev/grpcurl/releases/download/v1.7.0/grpcurl_1.7.0_linux_x86_64.tar.gz" \
20+
&& tar -xvf grpcurl_1.7.0_linux_x86_64.tar.gz -C /usr/local/bin grpcurl \
21+
&& chmod +x /usr/local/bin/grpcurl \
22+
&& rm -rf grpcurl_1.7.0_linux_x86_64.tar.gz
2023
COPY --from=build /csi-hyperstack .
2124
RUN chmod +x csi-hyperstack
2225
RUN mkdir -p /csi

charts/csi-hyperstack/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ name: csi-hyperstack
33
description: |
44
HELM chart for Hyperstack CSI drvier deployment
55
type: application
6-
version: 0.0.5
6+
version: 0.0.3
77
appVersion: v0.0.4

charts/csi-hyperstack/templates/daemonset-node.yaml

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,32 @@ spec:
3232
args:
3333
- "start"
3434
- "--endpoint=unix:///csi/csi.sock"
35-
- "--hyperstack-api-address={{ .Values.hyperstack.apiKey }}"
36-
- "--hyperstack-api-key={{ .Values.hyperstack.apiAddress }}"
37-
- "--service-node-enabled"
35+
- "--hyperstack-api-address={{ .Values.hyperstack.apiAddress }}"
36+
- "--hyperstack-api-key={{ .Values.hyperstack.apiKey }}"
37+
- "--service-node-enabled=true"
38+
livenessProbe:
39+
exec:
40+
command:
41+
- /bin/sh
42+
- -c
43+
- |
44+
grpcurl -plaintext -unix /csi/csi.sock csi.v1.Identity.GetPluginInfo >/dev/null 2>&1 \
45+
&& grpcurl -plaintext -unix /csi/csi.sock csi.v1.Node.NodeGetInfo >/dev/null 2>&1
46+
# initialDelaySeconds: 20
47+
# periodSeconds: 10
48+
readinessProbe:
49+
exec:
50+
command:
51+
- /bin/sh
52+
- -c
53+
- |
54+
grpcurl -plaintext -unix /csi/csi.sock csi.v1.Identity.GetPluginInfo >/dev/null 2>&1 \
55+
&& grpcurl -plaintext -unix /csi/csi.sock csi.v1.Node.NodeGetInfo >/dev/null 2>&1
56+
# initialDelaySeconds: 20
57+
# periodSeconds: 10
58+
# timeoutSeconds: 5
59+
# failureThreshold: 3
60+
# successThreshold: 1
3861
env:
3962
- name: DRIVER_NAME
4063
value: "hyperstack.csi.nexgencloud.com"
@@ -61,6 +84,12 @@ spec:
6184
- --v=5
6285
- --csi-address=/csi/csi.sock
6386
- --kubelet-registration-path=/var/lib/kubelet/plugins/hyperstack.csi.nexgencloud.com/csi.sock
87+
livenessProbe:
88+
exec:
89+
command:
90+
- /csi-node-driver-registrar
91+
- --kubelet-registration-path=/var/lib/kubelet/plugins/hyperstack.csi.nexgencloud.com/csi.sock
92+
- --mode=kubelet-registration-probe
6493
securityContext:
6594
privileged: true
6695
env:

charts/csi-hyperstack/templates/deployment-controller.yaml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,30 @@ spec:
2525
image: {{ .Values.components.csiHyperstack.image }}:{{ .Values.components.csiHyperstack.tag | default .Chart.AppVersion }}
2626
imagePullPolicy: {{ .Values.components.csiHyperstack.imagePullPolicy }}
2727
# command: ["csi-hyperstack"]
28+
livenessProbe:
29+
exec:
30+
command:
31+
- /bin/sh
32+
- -c
33+
- ls -l /csi/csi.sock
34+
# initialDelaySeconds: 20
35+
# periodSeconds: 10
36+
# readinessProbe:
37+
# exec:
38+
# command:
39+
# - /bin/sh
40+
# - -c
41+
# - |
42+
# grpcurl -plaintext -unix /csi/csi.sock csi.v1.Identity.GetPluginInfo >/dev/null 2>&1 \
43+
# && grpcurl -plaintext -unix /csi/csi.sock csi.v1.Controller.ControllerGetCapabilities >/dev/null 2>&1
44+
# initialDelaySeconds: 20
45+
# periodSeconds: 10
2846
args:
2947
- "start"
3048
- "--endpoint=unix:///csi/csi.sock"
3149
- "--hyperstack-api-address={{ .Values.hyperstack.apiAddress }}"
3250
- "--hyperstack-api-key={{ .Values.hyperstack.apiKey }}"
33-
- "--service-controller-enabled"
51+
- "--service-controller-enabled=true"
3452
env:
3553
- name: CSI_ENDPOINT
3654
value: unix:///csi/csi.sock

pkg/driver/controllerserver.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,14 @@ func (cs *controllerServer) ControllerPublishVolume(ctx context.Context, req *cs
201201
klog.Infof("ControllerPublishVolume: GetVolume succeeded -\nStatus: %s\nName: %s\nID: %d\nSize:%d", *getVolume.Status, *getVolume.Name, *getVolume.Id, *getVolume.Size)
202202
if *getVolume.Status == "in-use" { //Volume is already attached
203203
klog.Infof("ControllerPublishVolume: Volume %s is already in use", *getVolume.Name)
204-
return &csi.ControllerPublishVolumeResponse{
205-
PublishContext: map[string]string{
206-
volNameKeyFromControllerPublishVolume: *(*getVolume.Attachments)[0].Device,
207-
},
208-
}, nil
204+
if len(*getVolume.Attachments) > 0 {
205+
klog.Infof("ControllerPublishVolume: Volume %s is already attached to node %s", *getVolume.Name, *(*getVolume.Attachments)[0].InstanceId)
206+
return &csi.ControllerPublishVolumeResponse{
207+
PublishContext: map[string]string{
208+
volNameKeyFromControllerPublishVolume: *(*getVolume.Attachments)[0].Device,
209+
},
210+
}, nil
211+
}
209212
}
210213
if *getVolume.Status == "available" {
211214
attachVolume, err := cloud.AttachVolumeToNode(ctx, vmId, volumeIDInt)

pkg/driver/nodeserver.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
3636
klog.Infof("\n==============NodeStageVolume: called================\n")
3737
klog.Infof("NodeStageVolume: called with args %+v", protosanitizer.StripSecrets(*req))
3838
devicename := req.PublishContext[volNameKeyFromControllerPublishVolume]
39+
if devicename == "" {
40+
return nil, status.Error(codes.InvalidArgument, "Device name not found in publish context. Please wait for volume to be attached.")
41+
}
3942
klog.Infof("NodeStageVolume: devicename from publish context: %s", devicename)
4043
err := formateAndMakeFS(devicename, "ext4")
4144
if err != nil {
@@ -127,17 +130,11 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
127130
klog.Infof("==============NodePublishVolume: called================\n")
128131
klog.Infof("NodePublishVolume: called with args %+v", protosanitizer.StripSecrets(*req))
129132

130-
// make sure the requried fields are set and not empty
131-
132133
options := []string{"bind"}
133134
if req.Readonly {
134135
options = append(options, "ro")
135136
}
136137

137-
// get req.VolumeCaps and make sure that you handle request for block mode as well
138-
// here we are just handling request for filesystem mode
139-
// in case of block mode, the source is going to be the device dir where volume was attached form ControllerPubVolume RPC
140-
141138
fsType := "ext4"
142139
if req.VolumeCapability.GetMount().FsType != "" {
143140
fsType = req.VolumeCapability.GetMount().FsType
@@ -146,8 +143,6 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
146143
source := req.StagingTargetPath
147144
target := req.TargetPath
148145

149-
// we want to run mount -t fstype source target -o bind,ro
150-
151146
err := mountDevice(source, target, fsType, options)
152147
if err != nil {
153148
return nil, status.Error(codes.Internal, fmt.Sprintf("Error %s, mounting the volume from staging dir to target dir", err.Error()))

0 commit comments

Comments
 (0)