Skip to content

Commit e4ac851

Browse files
authored
Bring back manual manifest specification for attaching storage (#427)
* return manual manifest specification for attaching storage * fix I/O operation on empty file error
1 parent 9904a8e commit e4ac851

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ Parameters:
467467
- `--readonly` - if set to true, workload can only read from storage.
468468
- `--size` - size of the storage in Gb.
469469
- `--bucket` - name of the storage bucket. If not set then the name of the storage is used as a bucket name.
470+
- `--manifest` - path to the manifest file containing PersistentVolume and PresistentVolumeClaim definitions. If set, then values from manifest override the following parameters: `--size` and `--bucket`.
470471
471472
### Filestore
472473
@@ -502,6 +503,7 @@ Commands `xpk storage create` and `xpk storage attach` with `--type=gcpfilestore
502503
- `--access-mode` - access mode of the Filestore instance that will be created. Possible values are: `[ReadWriteOnce, ReadOnlyMany, ReadWriteMany]`
503504
- `--vol` - file share name of the Filestore instance that will be created.
504505
- `--instance` - the name of the Filestore instance. If not set then the name parameter is used as an instance name. Useful when connecting multiple volumes from the same Filestore instance.
506+
- `--manifest` - path to the manifest file containing PersistentVolume, PresistentVolumeClaim and StorageClass definitions. If set, then values from manifest override the following parameters: `--access-mode`, `--size` and `--volume`.
505507
506508
### List attached storages
507509

src/xpk/commands/storage.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from argparse import Namespace
1818

19+
import yaml
1920
from kubernetes import client as k8s_client
2021
from kubernetes.client import ApiClient
2122
from kubernetes.client.rest import ApiException
@@ -72,9 +73,13 @@ def storage_create(args: Namespace) -> None:
7273
filestore_client.create_instance(
7374
vol=args.vol, size=args.size, tier=args.tier, network=filestore_network
7475
)
75-
manifest = filestore_client.manifest(
76-
args.name, args.vol, args.access_mode, filestore_network
77-
)
76+
if args.manifest is not None:
77+
with open(args.manifest, "r", encoding="utf-8") as f:
78+
manifest = list(yaml.safe_load_all(f))
79+
else:
80+
manifest = filestore_client.manifest(
81+
args.name, args.vol, args.access_mode, filestore_network
82+
)
7883

7984
k8s_api_client = setup_k8s_env(args)
8085
create_storage_crds(k8s_api_client, args, manifest)
@@ -137,22 +142,30 @@ def storage_attach(args: Namespace) -> None:
137142
xpk_print(f"Filestore instance {args.instance} does not exists.")
138143
xpk_exit(1)
139144

140-
filestore_network = get_cluster_network(args)
141-
manifest = filestore_client.manifest(
142-
args.name, args.vol, args.access_mode, filestore_network
143-
)
145+
if args.manifest is not None:
146+
with open(args.manifest, "r", encoding="utf-8") as f:
147+
manifest = list(yaml.safe_load_all(f))
148+
else:
149+
filestore_network = get_cluster_network(args)
150+
manifest = filestore_client.manifest(
151+
args.name, args.vol, args.access_mode, filestore_network
152+
)
144153

145154
else: # args.type == GCS_FUSE_TYPE:
146-
if args.size is None:
155+
if args.manifest is None and args.size is None:
147156
xpk_print("--size is required when attaching gcsfuse storage.")
148157
xpk_exit(1)
149158

150159
if args.bucket is None:
151160
args.bucket = args.name
152161

153-
manifest = gcsfuse.manifest(
154-
name=args.name, bucket=args.bucket, size=args.size
155-
)
162+
if args.manifest is not None:
163+
with open(args.manifest, "r", encoding="utf-8") as f:
164+
manifest = list(yaml.safe_load_all(f))
165+
else:
166+
manifest = gcsfuse.manifest(
167+
name=args.name, bucket=args.bucket, size=args.size
168+
)
156169

157170
k8s_api_client = setup_k8s_env(args)
158171
create_storage_crds(k8s_api_client, args, manifest)

src/xpk/parser/storage.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ def add_storage_attach_parser(
148148
'Optional Arguments',
149149
'Optional arguments for storage create.',
150150
)
151+
opt_args.add_argument(
152+
'--manifest',
153+
type=str,
154+
help='Path to manifest file containing volume definitions',
155+
)
151156
add_kind_cluster_arguments(opt_args)
152157

153158

@@ -238,6 +243,11 @@ def add_storage_create_parser(
238243
help='Access mode of created filestore instance',
239244
default='ReadWriteMany',
240245
)
246+
opt_args.add_argument(
247+
'--manifest',
248+
type=str,
249+
help='Path to manifest file containing volume definitions',
250+
)
241251

242252
add_kind_cluster_arguments(opt_args)
243253

0 commit comments

Comments
 (0)