diff --git a/deploy/namespace.yaml b/deploy/0-namespace.yaml similarity index 100% rename from deploy/namespace.yaml rename to deploy/0-namespace.yaml diff --git a/deploy/daemonset.yaml b/deploy/daemonset.yaml index d3ab3f9..b920998 100644 --- a/deploy/daemonset.yaml +++ b/deploy/daemonset.yaml @@ -22,7 +22,7 @@ spec: - --endpoint=$(CSI_ENDPOINT) # - --logtostderr - --nodeid=$(NODE_NAME) - - --p5x-endpoint=http://172.20.0.22 + - --p5x-endpoint=http://172.20.0.174 - --p5x-token=1 env: - name: CSI_ENDPOINT @@ -103,4 +103,4 @@ spec: - hostPath: path: /var/lib/kubelet/plugins_registry/ type: Directory - name: registration-dir \ No newline at end of file + name: registration-dir diff --git a/deploy/statefulset.yaml b/deploy/statefulset.yaml index 7f55015..e74d57f 100644 --- a/deploy/statefulset.yaml +++ b/deploy/statefulset.yaml @@ -31,7 +31,7 @@ spec: - --endpoint=$(CSI_ENDPOINT) # - --logtostderr - --nodeid=$(NODE_NAME) - - --p5x-endpoint=http://172.20.0.22 + - --p5x-endpoint=http://172.20.0.174 - --p5x-token=1 env: - name: CSI_ENDPOINT diff --git a/deploy/examplepod.yaml b/examplepod.yaml similarity index 93% rename from deploy/examplepod.yaml rename to examplepod.yaml index 1f99e39..bd8adf4 100644 --- a/deploy/examplepod.yaml +++ b/examplepod.yaml @@ -44,9 +44,10 @@ metadata: name: example-pod-1 namespace: p5x-system spec: + nodeName: worker-4.k8s containers: - name: example-ct - image: fedora:39 + image: fedora:41 command: ['/bin/bash', '-c', '--'] args: ['while true; do sleep 30; done;'] volumeMounts: @@ -68,6 +69,7 @@ metadata: name: example-pod-2 namespace: p5x-system spec: + nodeName: worker-7.k8s containers: - name: example-ct image: fedora:39 @@ -79,4 +81,4 @@ spec: volumes: - name: example-pvc-3 persistentVolumeClaim: - claimName: example-pvc-3 \ No newline at end of file + claimName: example-pvc-3 diff --git a/pkg/csi/p5x.go b/pkg/csi/p5x.go index 7d51a9a..ccf52b2 100644 --- a/pkg/csi/p5x.go +++ b/pkg/csi/p5x.go @@ -18,9 +18,10 @@ type p5xApi struct { } type p5xVolume struct { - VolumeId int64 `json:"volumeId"` + VolumeId int64 `json:"id"` Name string `json:"name"` - SizeInBytes int64 `json:"sizeInBytes"` + SizeInBytes int64 `json:"size_in_bytes"` + Mountpoint string `json:"mountpoint,omitempty"` } func (p5x *p5xApi) CreateVolume(name string, sizeInBytes int64) (*p5xVolume, error) { @@ -36,7 +37,7 @@ func (p5x *p5xApi) CreateVolume(name string, sizeInBytes int64) (*p5xVolume, err return nil, err } - resBody, err := p5x.MakeRequest(http.MethodPost, "volumes", body) + resBody, err := p5x.MakeRequest(http.MethodPost, "volume", body) if err != nil { return nil, err } @@ -51,13 +52,13 @@ var ErrVolumeNotFound = errors.New("p5x volume not found") func (p5x *p5xApi) GetVolumeByName(name string) (*p5xVolume, error) { klog.Infof("p5x.GetVolumeByName: %s", name) - route := fmt.Sprintf("volumes/%s", name) + route := fmt.Sprintf("volume/%s", name) resBody, err := p5x.MakeRequest(http.MethodGet, route, nil) if err != nil { return nil, err } - if strings.Contains(string(resBody[:]), "Could not find volume with the name") { + if strings.Contains(string(resBody[:]), "Could not find a volume with that name") { return nil, ErrVolumeNotFound } @@ -73,7 +74,7 @@ func (p5x *p5xApi) GetVolumeByName(name string) (*p5xVolume, error) { func (p5x *p5xApi) DeleteVolume(volume *p5xVolume) error { klog.Info("p5x.DeleteVolume: ", volume) - route := fmt.Sprintf("volumes/%s", volume.Name) + route := fmt.Sprintf("volume/%s", volume.Name) resBody, err := p5x.MakeRequest(http.MethodDelete, route, []byte(`{}`)) if err != nil { return err @@ -85,7 +86,7 @@ func (p5x *p5xApi) DeleteVolume(volume *p5xVolume) error { func (p5x *p5xApi) TransferVolume(volume *p5xVolume, nodeName string) (*p5xVolume, error) { klog.Info("p5x.TransferVolume: ", volume, " | to node: ", nodeName) - route := fmt.Sprintf("volumes/%s/transfer-to/%s", volume.Name, nodeName) + route := fmt.Sprintf("volume/transfer/%s/to/%s", volume.Name, nodeName) resBody, err := p5x.MakeRequest(http.MethodPost, route, []byte(`{}`)) if err != nil { return nil, err @@ -101,60 +102,41 @@ func (p5x *p5xApi) TransferVolume(volume *p5xVolume, nodeName string) (*p5xVolum return vol, nil } -type MountVolumeRequest struct { - Mountpoint string `json:"mountpoint"` - Options map[string]string `json:"options"` -} - func (p5x *p5xApi) MountVolume(volume *p5xVolume, mountpoint string, options map[string]string) (*p5xVolume, error) { klog.Info("p5x.MountVolume: ", volume, mountpoint, options) - req := &MountVolumeRequest{ - Mountpoint: mountpoint, - Options: options, - } + volume.Mountpoint = mountpoint - body, err := json.Marshal(req) + body, err := json.Marshal(volume) if err != nil { return nil, err } - route := fmt.Sprintf("volumes/%s/mount", volume.Name) - resBody, err := p5x.MakeRequest(http.MethodPost, route, body) - if err != nil { - return nil, err - } - - vol := &p5xVolume{} - err = json.Unmarshal(resBody, vol) + _, err = p5x.MakeRequest(http.MethodPost, "volume/mount", body) if err != nil { return nil, err } klog.Info("p5x.MountVolume: Successfully mounted volume: ", volume.Name, mountpoint) - return vol, nil + return volume, nil } func (p5x *p5xApi) UnmountVolume(volume *p5xVolume) (*p5xVolume, error) { klog.Info("p5x.UnmountVolume: ", volume) - route := fmt.Sprintf("volumes/%s/unmount", volume.Name) - resBody, err := p5x.MakeRequest(http.MethodPost, route, []byte(`{}`)) + route := fmt.Sprintf("volume/unmount/%s", volume.Name) + _, err := p5x.MakeRequest(http.MethodPost, route, []byte(`{}`)) if err != nil { return nil, err } - vol := &p5xVolume{} - err = json.Unmarshal(resBody, vol) - if err != nil { - return nil, err - } + volume.Mountpoint = "" klog.Info("p5x.UnmountVolume: Successfully unmounted volume: ", volume.Name) - return vol, nil + return volume, nil } func (p5x *p5xApi) MakeRequest(method string, route string, body []byte) ([]byte, error) { - url := fmt.Sprintf("%s:%d/api/v1/%s", p5x.endpoint, p5x.port, route) + url := fmt.Sprintf("%s:%d/%s", p5x.endpoint, p5x.port, route) klog.Infof("p5x.MakeRequest: [%s] %s", method, url) var res *http.Response