Skip to content

Commit c0c1c13

Browse files
committed
Invoke helper Pod on resize
Update the resize function to invoke the helper Pod with the "resize" script. This also adds some dummy resize scripts, which store the resize data in a file in the PV. It does not add though any sample script for the XFS quota resize. Signed-off-by: Marjus Cako <marios.cako@gmail.com>
1 parent 2fbdd9c commit c0c1c13

File tree

6 files changed

+82
-6
lines changed

6 files changed

+82
-6
lines changed

debug/config.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,27 @@ data:
7474
done
7575
7676
rm -rf ${absolutePath}
77+
resize: |-
78+
#!/bin/sh
79+
while getopts "m:s:p:" opt
80+
do
81+
case $opt in
82+
p)
83+
absolutePath=$OPTARG
84+
;;
85+
s)
86+
sizeInBytes=$OPTARG
87+
;;
88+
m)
89+
volMode=$OPTARG
90+
;;
91+
esac
92+
done
93+
94+
echo "VOL_DIR: $VOL_DIR" > "$VOL_DIR/.resizerdata"
95+
echo "VOL_MODE: $VOL_MODE" >> "$VOL_DIR/.resizerdata"
96+
echo "VOL_SIZE_BYTES: $VOL_SIZE_BYTES" >> "$VOL_DIR/.resizerdata"
97+
7798
helperPod.yaml: |-
7899
apiVersion: v1
79100
kind: Pod

deploy/example-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ data:
2929
#!/bin/sh
3030
set -eu
3131
rm -rf "$VOL_DIR"
32+
resize: |-
33+
echo "VOL_DIR: $VOL_DIR" > "$VOL_DIR/.resizerdata"
34+
echo "VOL_MODE: $VOL_MODE" >> "$VOL_DIR/.resizerdata"
35+
echo "VOL_SIZE_BYTES: $VOL_SIZE_BYTES" >> "$VOL_DIR/.resizerdata"
3236
helperPod.yaml: |-
3337
apiVersion: v1
3438
kind: Pod

deploy/local-path-storage.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ data:
145145
#!/bin/sh
146146
set -eu
147147
rm -rf "$VOL_DIR"
148+
resize: |-
149+
echo "VOL_DIR: $VOL_DIR" > "$VOL_DIR/.resizerdata"
150+
echo "VOL_MODE: $VOL_MODE" >> "$VOL_DIR/.resizerdata"
151+
echo "VOL_SIZE_BYTES: $VOL_SIZE_BYTES" >> "$VOL_DIR/.resizerdata"
148152
helperPod.yaml: |-
149153
apiVersion: v1
150154
kind: Pod

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func findConfigFileFromConfigMap(kubeClient clientset.Interface, namespace, conf
180180
}
181181
value, ok := cm.Data[key]
182182
if !ok {
183-
return "", fmt.Errorf("%v is not exist in local-path-config ConfigMap", key)
183+
return "", fmt.Errorf("%v does not exist in local-path-config ConfigMap", key)
184184
}
185185
return value, nil
186186
}
@@ -279,7 +279,7 @@ func startDaemon(c *cli.Context) error {
279279
pvController.VolumesInformer(volumeInformer),
280280
)
281281

282-
resizer := NewResizer()
282+
resizer := NewResizer(provisioner)
283283
rc := resizeController.NewResizeController(
284284
LocalPathResizerName,
285285
resizer,

provisioner.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ type ConfigData struct {
8787
SharedFileSystemPath string `json:"sharedFileSystemPath,omitempty"`
8888
SetupCommand string `json:"setupCommand,omitempty"`
8989
TeardownCommand string `json:"teardownCommand,omitempty"`
90+
ResizeCommand string `json:"resizeCommand,omitempty"`
9091
}
9192

9293
type NodePathMap struct {
@@ -99,6 +100,7 @@ type Config struct {
99100
SharedFileSystemPath string
100101
SetupCommand string
101102
TeardownCommand string
103+
ResizeCommand string
102104
}
103105

104106
func NewProvisioner(ctx context.Context, kubeClient *clientset.Clientset,
@@ -526,6 +528,13 @@ func (p *LocalPathProvisioner) createHelperPod(action ActionType, cmd []string,
526528
})
527529
}
528530

531+
if p.config.ResizeCommand == "" {
532+
keyToPathItems = append(keyToPathItems, v1.KeyToPath{
533+
Key: "resize",
534+
Path: "resize",
535+
})
536+
}
537+
529538
if len(keyToPathItems) > 0 {
530539
lpvVolumes = append(lpvVolumes, v1.Volume{
531540
Name: "script",
@@ -674,6 +683,7 @@ func canonicalizeConfig(data *ConfigData) (cfg *Config, err error) {
674683
cfg.SharedFileSystemPath = data.SharedFileSystemPath
675684
cfg.SetupCommand = data.SetupCommand
676685
cfg.TeardownCommand = data.TeardownCommand
686+
cfg.ResizeCommand = data.ResizeCommand
677687
cfg.NodePathMap = map[string]*NodePathMap{}
678688
for _, n := range data.NodePathMap {
679689
if cfg.NodePathMap[n.Node] != nil {

resizer.go

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
package main
22

33
import (
4+
"github.com/Sirupsen/logrus"
45
v1 "k8s.io/api/core/v1"
56
"k8s.io/apimachinery/pkg/api/resource"
67
)
78

8-
const LocalPathResizerName = "LocalPathResizer"
9+
const (
10+
LocalPathResizerName = "LocalPathResizer"
11+
ActionTypeResize = "resize"
12+
)
913

1014
type LocalPathResizer struct {
11-
name string
15+
name string
16+
provisioner *LocalPathProvisioner
1217
}
1318

1419
func (r *LocalPathResizer) Name() string {
@@ -24,12 +29,44 @@ func (r *LocalPathResizer) CanSupport(pv *v1.PersistentVolume, pvc *v1.Persisten
2429
}
2530

2631
func (r *LocalPathResizer) Resize(pv *v1.PersistentVolume, requestSize resource.Quantity) (newSize resource.Quantity, fsResizeRequired bool, err error) {
32+
33+
logrus.Debugf("Resize reconciler for pv %q with request size %q", pv.Name, requestSize.String())
34+
path, node, err := r.provisioner.getPathAndNodeForPV(pv)
35+
if err != nil {
36+
logrus.Errorf("failed to get path and node: %v", err)
37+
return requestSize, false, err
38+
}
39+
40+
if node == "" {
41+
logrus.Infof("Resizing volume %v at %v", pv.Name, path)
42+
} else {
43+
logrus.Infof("Resizing volume %v at %v:%v", pv.Name, node, path)
44+
}
45+
46+
resizeCmd := make([]string, 0, 2)
47+
if r.provisioner.config.ResizeCommand == "" {
48+
resizeCmd = append(resizeCmd, "/bin/sh", "/script/resize")
49+
} else {
50+
resizeCmd = append(resizeCmd, r.provisioner.config.ResizeCommand)
51+
}
52+
53+
if err := r.provisioner.createHelperPod(ActionTypeResize, resizeCmd, volumeOptions{
54+
Name: pv.Name,
55+
Path: path,
56+
Mode: *pv.Spec.VolumeMode,
57+
SizeInBytes: requestSize.Value(),
58+
Node: node,
59+
}); err != nil {
60+
return requestSize, false, err
61+
}
62+
2763
return requestSize, false, nil
2864
}
2965

30-
func NewResizer() *LocalPathResizer {
66+
func NewResizer(p *LocalPathProvisioner) *LocalPathResizer {
3167
r := &LocalPathResizer{
32-
name: LocalPathResizerName,
68+
name: LocalPathResizerName,
69+
provisioner: p,
3370
}
3471
return r
3572
}

0 commit comments

Comments
 (0)