diff --git a/.gitignore b/.gitignore index 8f8bba60..1c0e1779 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ .merge-chain +/tests/* +.idea/* +.pytest_cache +__pycache__/* \ No newline at end of file diff --git a/examples/csi-app-inline.yaml b/examples/csi-app-inline.yaml new file mode 100644 index 00000000..b5778b1c --- /dev/null +++ b/examples/csi-app-inline.yaml @@ -0,0 +1,16 @@ +kind: Pod +apiVersion: v1 +metadata: + name: my-csi-app-inline +spec: + containers: + - name: my-frontend + image: busybox + volumeMounts: + - mountPath: "/data" + name: my-csi-volume + command: [ "sleep", "1000000" ] + volumes: + - name: my-csi-volume + csi: + driver: csi.vastdata.com \ No newline at end of file diff --git a/examples/csi-clone.yaml b/examples/csi-clone.yaml new file mode 100644 index 00000000..222fae48 --- /dev/null +++ b/examples/csi-clone.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: hp-pvc-clone +spec: + storageClassName: csi-vast-sc + dataSource: + name: src-hp-pvc + kind: PersistentVolumeClaim + apiGroup: "" + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi diff --git a/examples/csi-pod-raw.yaml b/examples/csi-pod-raw.yaml new file mode 100644 index 00000000..4b7149ae --- /dev/null +++ b/examples/csi-pod-raw.yaml @@ -0,0 +1,20 @@ +apiVersion: v1 +kind: Pod +metadata: + name: pod-raw + labels: + name: busybox-test +spec: + restartPolicy: Always + containers: + - image: gcr.io/google_containers/busybox + command: ["/bin/sh", "-c"] + args: [ "tail -f /dev/null" ] + name: busybox + volumeDevices: + - name: vol + devicePath: /dev/loop3 # This device path needs to be replaced with the site specific + volumes: + - name: vol + persistentVolumeClaim: + claimName: pvc-raw diff --git a/examples/csi-pvc-raw.yaml b/examples/csi-pvc-raw.yaml new file mode 100644 index 00000000..b770c58d --- /dev/null +++ b/examples/csi-pvc-raw.yaml @@ -0,0 +1,12 @@ +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: pvc-raw +spec: + accessModes: + - ReadWriteOnce + storageClassName: csi-hostpath-sc + volumeMode: Block + resources: + requests: + storage: 1Gi diff --git a/examples/csi-raw-pv-snapshot.yaml b/examples/csi-raw-pv-snapshot.yaml new file mode 100644 index 00000000..70146526 --- /dev/null +++ b/examples/csi-raw-pv-snapshot.yaml @@ -0,0 +1,9 @@ +apiVersion: snapshot.storage.k8s.io/v1alpha1 +kind: VolumeSnapshot +metadata: + name: raw-pv-snapshot +spec: + snapshotClassName: csi-vast-snapclass + source: + name: pvc-raw + kind: PersistentVolumeClaim diff --git a/examples/csi-restore.yaml b/examples/csi-restore.yaml new file mode 100644 index 00000000..1186aa15 --- /dev/null +++ b/examples/csi-restore.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: hpvc-restore +spec: + storageClassName: csi-vast-sc + dataSource: + name: new-snapshot-demo + kind: VolumeSnapshot + apiGroup: snapshot.storage.k8s.io + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi diff --git a/examples/csi-snapshot.yaml b/examples/csi-snapshot.yaml new file mode 100644 index 00000000..d97569f4 --- /dev/null +++ b/examples/csi-snapshot.yaml @@ -0,0 +1,9 @@ +apiVersion: snapshot.storage.k8s.io/v1alpha1 +kind: VolumeSnapshot +metadata: + name: new-snapshot-demo +spec: + snapshotClassName: csi-vast-snapclass + source: + name: csi-pvc + kind: PersistentVolumeClaim diff --git a/future/csi-vast-resizer.yaml b/future/csi-vast-resizer.yaml new file mode 100644 index 00000000..70e2ab57 --- /dev/null +++ b/future/csi-vast-resizer.yaml @@ -0,0 +1,54 @@ +kind: Service +apiVersion: v1 +metadata: + name: csi-vast-resizer + labels: + app: csi-vast-resizer +spec: + selector: + app: csi-vast-resizer + ports: + - name: dummy + port: 12345 + +--- +kind: StatefulSet +apiVersion: apps/v1 +metadata: + name: csi-vast-resizer +spec: + serviceName: "csi-vast-resizer" + replicas: 1 + selector: + matchLabels: + app: csi-vast-resizer + template: + metadata: + labels: + app: csi-vast-resizer + spec: + affinity: + podAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchExpressions: + - key: app + operator: In + values: + - csi-vastplugin + topologyKey: kubernetes.io/hostname + serviceAccountName: csi-resizer + containers: + - name: csi-resizer + image: quay.io/k8scsi/csi-resizer:v0.3.0 + args: + - -v=5 + - -csi-address=/csi/csi.sock + volumeMounts: + - mountPath: /csi + name: socket-dir + volumes: + - hostPath: + path: /var/lib/kubelet/plugins/csi-vast + type: DirectoryOrCreate + name: socket-dir diff --git a/future/csi-vast-snapshotter.yaml b/future/csi-vast-snapshotter.yaml new file mode 100644 index 00000000..934f6e86 --- /dev/null +++ b/future/csi-vast-snapshotter.yaml @@ -0,0 +1,55 @@ +kind: Service +apiVersion: v1 +metadata: + name: csi-vast-snapshotter + labels: + app: csi-vast-snapshotter +spec: + selector: + app: csi-vast-snapshotter + ports: + - name: dummy + port: 12345 + +--- +kind: StatefulSet +apiVersion: apps/v1 +metadata: + name: csi-vast-snapshotter +spec: + serviceName: "csi-vast-snapshotter" + replicas: 1 + selector: + matchLabels: + app: csi-vast-snapshotter + template: + metadata: + labels: + app: csi-vast-snapshotter + spec: + affinity: + podAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchExpressions: + - key: app + operator: In + values: + - csi-vastplugin + topologyKey: kubernetes.io/hostname + serviceAccount: csi-snapshotter + containers: + - name: csi-snapshotter + image: quay.io/k8scsi/csi-snapshotter:v1.2.0 + args: + - -v=5 + - --csi-address=/csi/csi.sock + - --connection-timeout=15s + volumeMounts: + - mountPath: /csi + name: socket-dir + volumes: + - hostPath: + path: /var/lib/kubelet/plugins/csi-vast + type: DirectoryOrCreate + name: socket-dir diff --git a/vast_csi/server.py b/vast_csi/server.py index e64e890d..22288b24 100644 --- a/vast_csi/server.py +++ b/vast_csi/server.py @@ -436,40 +436,40 @@ def CreateVolume(self, name, volume_capabilities, capacity_range=None, parameter volume_name = volume_name[:64] # crop to Vast's max-length requested_capacity = capacity_range.required_bytes if capacity_range else 0 - existing_capacity = 0 volume_context = {} if CONF.mock_vast: volume = self._to_volume(volume_id) if volume: existing_capacity = volume.capacity_bytes + if existing_capacity != requested_capacity: + raise Abort( + ALREADY_EXISTS, + "Volume already exists with different capacity than requested" + f"({existing_capacity})") + vol_dir = self.root_mount[volume_id] + vol_dir.mkdir(exist_ok=True) + else: - quota = self.get_quota(volume_id) - if quota: + if quota := self.get_quota(volume_id): existing_capacity = quota.hard_limit + if existing_capacity and existing_capacity != requested_capacity: + raise Abort( + ALREADY_EXISTS, + "Volume already exists with different capacity than requested" + f"({existing_capacity})") - if not existing_capacity: - pass - elif existing_capacity != requested_capacity: - raise Abort( - ALREADY_EXISTS, - "Volume already exists with different capacity than requested" - f"({existing_capacity})") + else: + data = dict( + create_dir=True, + name=volume_name, + path=str(CONF.root_export[volume_id]), + ) + if requested_capacity: + data.update(hard_limit=requested_capacity) + quota = self.vms_session.post("quotas", data=data) - if CONF.mock_vast: - vol_dir = self.root_mount[volume_id] - vol_dir.mkdir() - else: - data = dict( - create_dir=True, - name=volume_name, - path=str(CONF.root_export[volume_id]), - ) - if requested_capacity: - data.update(hard_limit=requested_capacity) - quota = self.vms_session.post("quotas", data=data) volume_context.update(quota_id=quota.id) - volume = types.Volume( capacity_bytes=requested_capacity, volume_id=volume_id, volume_context={k: str(v) for k, v in volume_context.items()}) diff --git a/version.txt b/version.txt index 7059afe1..c2f6de90 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v2.0.4 \ No newline at end of file +v2.0.5