Skip to content

Commit f397acf

Browse files
authored
Merge pull request #122 from ApplauseOSS/feat/pv
feat: add support for PersistentVolume
2 parents c32a640 + fd7c009 commit f397acf

File tree

7 files changed

+226
-10
lines changed

7 files changed

+226
-10
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,31 @@ Utility for generating deployment configs for a service
1818
The below command will generate the required deployment config files for the specified service in the current directory.
1919

2020
```bash
21-
$ deploy-config-generator path/to/service/repo
21+
deploy-config-generator path/to/service/repo
2222
```
2323

2424
You can specify the environment to generate configuration for.
2525

2626
```bash
27-
$ deploy-config-generator path/to/service/repo -e stage
27+
deploy-config-generator path/to/service/repo -e stage
2828
```
2929

3030
You can specify the output directory using the `--output-dir` option.
3131

3232
```bash
33-
$ deploy-config-generator path/to/service/repo --output-dir /tmp
33+
deploy-config-generator path/to/service/repo --output-dir /tmp
3434
```
3535

3636
You can increase the verbosity level to see what the script is doing.
3737

3838
```bash
39-
$ deploy-config-generator path/to/service/repo -vvv
39+
deploy-config-generator path/to/service/repo -vvv
4040
```
4141

4242
You can specify the path to a site config file.
4343

4444
```bash
45-
$ deploy-config-generator path/to/service/repo --config path/to/site/config.yml
45+
deploy-config-generator path/to/service/repo --config path/to/site/config.yml
4646
```
4747

4848
## The dirty details
@@ -134,6 +134,7 @@ The following output plugins are available:
134134
* [`kube_kong_plugin`](docs/plugin_kube_kong_plugin.md)
135135
* [`kube_namespace`](docs/plugin_kube_namespace.md)
136136
* [`kube_pdb`](docs/plugin_kube_pdb.md)
137+
* [`kube_pv`](docs/plugin_kube_pv.md)
137138
* [`kube_pvc`](docs/plugin_kube_pvc.md)
138139
* [`kube_secret`](docs/plugin_kube_secret.md)
139140
* [`kube_service`](docs/plugin_kube_service.md)
@@ -149,14 +150,14 @@ The following output plugins are available:
149150
This tool comes with unit and integration test suites, which can be run with the commands:
150151

151152
```bash
152-
$ python setup.py test
153-
$ python setup.py integration
153+
python setup.py test
154+
python setup.py integration
154155
```
155156

156157
You can run the full test suite in multiple python versions using `tox` by running:
157158

158159
```bash
159-
$ tox
160+
tox
160161
```
161162

162163
### Regenerating plugin docs
@@ -165,5 +166,5 @@ The docs for the individual plugins are generated from the code of the plugins.
165166
with the following command:
166167

167168
```bash
168-
$ scripts/gen-plugin-docs.py
169+
scripts/gen-plugin-docs.py
169170
```

deploy_config_generator/output/kube_common.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,97 @@
667667
),
668668
)
669669

670+
PERSISTENT_VOLUME_FIELD_SPEC = dict(
671+
access_modes=dict(
672+
type='list',
673+
required=True,
674+
subtype='str',
675+
),
676+
capacity=dict(
677+
type='dict',
678+
required=True,
679+
fields=dict(
680+
storage=dict(
681+
type='str',
682+
),
683+
),
684+
),
685+
persistent_volume_reclaim_policy=dict(
686+
type='str',
687+
),
688+
storage_class_name=dict(
689+
type='str',
690+
),
691+
volume_mode=dict(
692+
type='str',
693+
),
694+
mount_options=dict(
695+
type='list',
696+
subtype='str',
697+
),
698+
claim_ref=dict(
699+
type='dict',
700+
fields=dict(
701+
api_version=dict(
702+
type='str',
703+
),
704+
kind=dict(
705+
type='str',
706+
),
707+
namespace=dict(
708+
type='str',
709+
),
710+
name=dict(
711+
type='str',
712+
),
713+
),
714+
),
715+
node_affinity=dict(
716+
type='dict',
717+
fields=dict(
718+
required=dict(
719+
type='dict',
720+
fields=dict(
721+
node_selector_terms=dict(
722+
type='list',
723+
subtype='dict',
724+
),
725+
),
726+
),
727+
),
728+
),
729+
csi=dict(
730+
type='dict',
731+
fields=dict(
732+
driver=dict(type='str'),
733+
volume_handle=dict(type='str'),
734+
read_only=dict(
735+
type='bool',
736+
),
737+
fs_type=dict(
738+
type='str',
739+
),
740+
volume_attributes=dict(
741+
type='dict',
742+
subtype='str',
743+
),
744+
),
745+
),
746+
nfs=dict(
747+
type='dict',
748+
fields=dict(
749+
path=dict(
750+
type='str',
751+
required=True
752+
),
753+
server=dict(
754+
type='str',
755+
required=True
756+
),
757+
),
758+
),
759+
)
760+
670761

671762
class OutputPlugin(OutputPluginBase):
672763

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import copy
2+
3+
from deploy_config_generator.utils import yaml_dump
4+
from deploy_config_generator.output import kube_common
5+
6+
7+
class OutputPlugin(kube_common.OutputPlugin):
8+
9+
NAME = 'kube_pv'
10+
DESCR = 'Kubernetes PersistentVolume output plugin'
11+
FILE_EXT = '.yaml'
12+
13+
DEFAULT_CONFIG = {
14+
'fields': {
15+
'kube_pvs': dict(
16+
metadata=dict(
17+
type='dict',
18+
required=True,
19+
fields=copy.deepcopy(kube_common.METADATA_FIELD_SPEC),
20+
),
21+
spec=dict(
22+
type='dict',
23+
required=True,
24+
fields=copy.deepcopy(kube_common.PERSISTENT_VOLUME_FIELD_SPEC),
25+
),
26+
),
27+
}
28+
}
29+
30+
def generate_output(self, app_vars):
31+
# Basic structure
32+
data = {
33+
'apiVersion': 'v1',
34+
'kind': 'PersistentVolume',
35+
'spec': dict(),
36+
}
37+
data['metadata'] = self.build_metadata(app_vars['APP']['metadata'])
38+
data['spec'] = self.build_generic(app_vars['APP']['spec'], self._plugin_config['fields']['kube_pvs']['spec']['fields'])
39+
40+
data = self._template.render_template(data, app_vars)
41+
output = yaml_dump(data)
42+
return (output, self.get_output_filename_suffix(data))

docs/plugin_kube_pv.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!--
2+
NOTE: this document is automatically generated. Any manual changes will get overwritten.
3+
-->
4+
# kube_pv
5+
6+
Kubernetes PersistentVolume output plugin
7+
8+
### Parameters
9+
10+
11+
#### Deploy config section: kube_pvs
12+
13+
Name | Type | Required | Default | Description
14+
--- | --- | --- | --- | ---
15+
`metadata`|`dict`|yes||
16+
`metadata . annotations`|`dict`|no||
17+
`metadata . labels`|`dict`|no||
18+
`metadata . name`|`str`|no||
19+
`metadata . namespace`|`str`|no||
20+
`spec`|`dict`|yes||
21+
`spec . access_modes`|`list` (of `str`)|yes||
22+
`spec . capacity`|`dict`|yes||
23+
`spec . capacity . storage`|`str`|no||
24+
`spec . claim_ref`|`dict`|no||
25+
`spec . claim_ref . api_version`|`str`|no||
26+
`spec . claim_ref . kind`|`str`|no||
27+
`spec . claim_ref . name`|`str`|no||
28+
`spec . claim_ref . namespace`|`str`|no||
29+
`spec . csi`|`dict`|no||
30+
`spec . csi . driver`|`str`|no||
31+
`spec . csi . fs_type`|`str`|no||
32+
`spec . csi . read_only`|`bool`|no||
33+
`spec . csi . volume_attributes`|`dict` (of `str`)|no||
34+
`spec . csi . volume_handle`|`str`|no||
35+
`spec . mount_options`|`list` (of `str`)|no||
36+
`spec . nfs`|`dict`|no||
37+
`spec . nfs . path`|`str`|yes||
38+
`spec . nfs . server`|`str`|yes||
39+
`spec . node_affinity`|`dict`|no||
40+
`spec . node_affinity . required`|`dict`|no||
41+
`spec . node_affinity . required . node_selector_terms`|`list` (of `dict`)|no||
42+
`spec . persistent_volume_reclaim_policy`|`str`|no||
43+
`spec . storage_class_name`|`str`|no||
44+
`spec . volume_mode`|`str`|no||
45+
46+

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def run(self):
5353

5454
setup(
5555
name='deploy-config-generator',
56-
version='2.27.0',
56+
version='2.28.0',
5757
url='https://github.com/ApplauseOSS/deploy-config-generator',
5858
license='MIT',
5959
description='Utility to generate service deploy configurations',

tests/integration/kube_basic/deploy/config.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,24 @@ kube_pvcs:
171171
match_expressions:
172172
- {key: environment, operator: In, values: [dev]}
173173

174+
kube_pvs:
175+
- metadata:
176+
name: test-pv
177+
spec:
178+
capacity:
179+
storage: 8Gi
180+
volume_mode: Filesystem
181+
access_modes:
182+
- ReadWriteOnce
183+
persistent_volume_reclaim_policy: Recycle
184+
storage_class_name: slow
185+
mount_options:
186+
- hard
187+
- nfsvers=4.1
188+
nfs:
189+
path: /tmp
190+
server: 172.17.0.2
191+
174192
kube_configmaps:
175193
- metadata:
176194
name: test-configmap
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: v1
2+
kind: PersistentVolume
3+
metadata:
4+
name: test-pv
5+
spec:
6+
accessModes:
7+
- ReadWriteOnce
8+
capacity:
9+
storage: 8Gi
10+
mountOptions:
11+
- hard
12+
- nfsvers=4.1
13+
nfs:
14+
path: /tmp
15+
server: 172.17.0.2
16+
persistentVolumeReclaimPolicy: Recycle
17+
storageClassName: slow
18+
volumeMode: Filesystem

0 commit comments

Comments
 (0)