Skip to content

Commit

Permalink
Invoke helper Pod on resize
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
marjus45 committed Jan 31, 2024
1 parent 2fbdd9c commit c0c1c13
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 6 deletions.
21 changes: 21 additions & 0 deletions debug/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,27 @@ data:
done
rm -rf ${absolutePath}
resize: |-
#!/bin/sh
while getopts "m:s:p:" opt
do
case $opt in
p)
absolutePath=$OPTARG
;;
s)
sizeInBytes=$OPTARG
;;
m)
volMode=$OPTARG
;;
esac
done
echo "VOL_DIR: $VOL_DIR" > "$VOL_DIR/.resizerdata"
echo "VOL_MODE: $VOL_MODE" >> "$VOL_DIR/.resizerdata"
echo "VOL_SIZE_BYTES: $VOL_SIZE_BYTES" >> "$VOL_DIR/.resizerdata"
helperPod.yaml: |-
apiVersion: v1
kind: Pod
Expand Down
4 changes: 4 additions & 0 deletions deploy/example-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ data:
#!/bin/sh
set -eu
rm -rf "$VOL_DIR"
resize: |-
echo "VOL_DIR: $VOL_DIR" > "$VOL_DIR/.resizerdata"
echo "VOL_MODE: $VOL_MODE" >> "$VOL_DIR/.resizerdata"
echo "VOL_SIZE_BYTES: $VOL_SIZE_BYTES" >> "$VOL_DIR/.resizerdata"
helperPod.yaml: |-
apiVersion: v1
kind: Pod
Expand Down
4 changes: 4 additions & 0 deletions deploy/local-path-storage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ data:
#!/bin/sh
set -eu
rm -rf "$VOL_DIR"
resize: |-
echo "VOL_DIR: $VOL_DIR" > "$VOL_DIR/.resizerdata"
echo "VOL_MODE: $VOL_MODE" >> "$VOL_DIR/.resizerdata"
echo "VOL_SIZE_BYTES: $VOL_SIZE_BYTES" >> "$VOL_DIR/.resizerdata"
helperPod.yaml: |-
apiVersion: v1
kind: Pod
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func findConfigFileFromConfigMap(kubeClient clientset.Interface, namespace, conf
}
value, ok := cm.Data[key]
if !ok {
return "", fmt.Errorf("%v is not exist in local-path-config ConfigMap", key)
return "", fmt.Errorf("%v does not exist in local-path-config ConfigMap", key)
}
return value, nil
}
Expand Down Expand Up @@ -279,7 +279,7 @@ func startDaemon(c *cli.Context) error {
pvController.VolumesInformer(volumeInformer),
)

resizer := NewResizer()
resizer := NewResizer(provisioner)
rc := resizeController.NewResizeController(
LocalPathResizerName,
resizer,
Expand Down
10 changes: 10 additions & 0 deletions provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type ConfigData struct {
SharedFileSystemPath string `json:"sharedFileSystemPath,omitempty"`
SetupCommand string `json:"setupCommand,omitempty"`
TeardownCommand string `json:"teardownCommand,omitempty"`
ResizeCommand string `json:"resizeCommand,omitempty"`
}

type NodePathMap struct {
Expand All @@ -99,6 +100,7 @@ type Config struct {
SharedFileSystemPath string
SetupCommand string
TeardownCommand string
ResizeCommand string
}

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

if p.config.ResizeCommand == "" {
keyToPathItems = append(keyToPathItems, v1.KeyToPath{
Key: "resize",
Path: "resize",
})
}

if len(keyToPathItems) > 0 {
lpvVolumes = append(lpvVolumes, v1.Volume{
Name: "script",
Expand Down Expand Up @@ -674,6 +683,7 @@ func canonicalizeConfig(data *ConfigData) (cfg *Config, err error) {
cfg.SharedFileSystemPath = data.SharedFileSystemPath
cfg.SetupCommand = data.SetupCommand
cfg.TeardownCommand = data.TeardownCommand
cfg.ResizeCommand = data.ResizeCommand
cfg.NodePathMap = map[string]*NodePathMap{}
for _, n := range data.NodePathMap {
if cfg.NodePathMap[n.Node] != nil {
Expand Down
45 changes: 41 additions & 4 deletions resizer.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package main

import (
"github.com/Sirupsen/logrus"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
)

const LocalPathResizerName = "LocalPathResizer"
const (
LocalPathResizerName = "LocalPathResizer"
ActionTypeResize = "resize"
)

type LocalPathResizer struct {
name string
name string
provisioner *LocalPathProvisioner
}

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

func (r *LocalPathResizer) Resize(pv *v1.PersistentVolume, requestSize resource.Quantity) (newSize resource.Quantity, fsResizeRequired bool, err error) {

logrus.Debugf("Resize reconciler for pv %q with request size %q", pv.Name, requestSize.String())
path, node, err := r.provisioner.getPathAndNodeForPV(pv)
if err != nil {
logrus.Errorf("failed to get path and node: %v", err)
return requestSize, false, err
}

if node == "" {
logrus.Infof("Resizing volume %v at %v", pv.Name, path)
} else {
logrus.Infof("Resizing volume %v at %v:%v", pv.Name, node, path)
}

resizeCmd := make([]string, 0, 2)
if r.provisioner.config.ResizeCommand == "" {
resizeCmd = append(resizeCmd, "/bin/sh", "/script/resize")
} else {
resizeCmd = append(resizeCmd, r.provisioner.config.ResizeCommand)
}

if err := r.provisioner.createHelperPod(ActionTypeResize, resizeCmd, volumeOptions{
Name: pv.Name,
Path: path,
Mode: *pv.Spec.VolumeMode,
SizeInBytes: requestSize.Value(),
Node: node,
}); err != nil {
return requestSize, false, err
}

return requestSize, false, nil
}

func NewResizer() *LocalPathResizer {
func NewResizer(p *LocalPathProvisioner) *LocalPathResizer {
r := &LocalPathResizer{
name: LocalPathResizerName,
name: LocalPathResizerName,
provisioner: p,
}
return r
}

0 comments on commit c0c1c13

Please sign in to comment.