Skip to content

Commit

Permalink
Merge pull request #122 from ApplauseOSS/feat/pv
Browse files Browse the repository at this point in the history
feat: add support for PersistentVolume
  • Loading branch information
verbotenj authored Feb 12, 2024
2 parents c32a640 + fd7c009 commit f397acf
Show file tree
Hide file tree
Showing 7 changed files with 226 additions and 10 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@ Utility for generating deployment configs for a service
The below command will generate the required deployment config files for the specified service in the current directory.

```bash
$ deploy-config-generator path/to/service/repo
deploy-config-generator path/to/service/repo
```

You can specify the environment to generate configuration for.

```bash
$ deploy-config-generator path/to/service/repo -e stage
deploy-config-generator path/to/service/repo -e stage
```

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

```bash
$ deploy-config-generator path/to/service/repo --output-dir /tmp
deploy-config-generator path/to/service/repo --output-dir /tmp
```

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

```bash
$ deploy-config-generator path/to/service/repo -vvv
deploy-config-generator path/to/service/repo -vvv
```

You can specify the path to a site config file.

```bash
$ deploy-config-generator path/to/service/repo --config path/to/site/config.yml
deploy-config-generator path/to/service/repo --config path/to/site/config.yml
```

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

```bash
$ python setup.py test
$ python setup.py integration
python setup.py test
python setup.py integration
```

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

```bash
$ tox
tox
```

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

```bash
$ scripts/gen-plugin-docs.py
scripts/gen-plugin-docs.py
```
91 changes: 91 additions & 0 deletions deploy_config_generator/output/kube_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,97 @@
),
)

PERSISTENT_VOLUME_FIELD_SPEC = dict(
access_modes=dict(
type='list',
required=True,
subtype='str',
),
capacity=dict(
type='dict',
required=True,
fields=dict(
storage=dict(
type='str',
),
),
),
persistent_volume_reclaim_policy=dict(
type='str',
),
storage_class_name=dict(
type='str',
),
volume_mode=dict(
type='str',
),
mount_options=dict(
type='list',
subtype='str',
),
claim_ref=dict(
type='dict',
fields=dict(
api_version=dict(
type='str',
),
kind=dict(
type='str',
),
namespace=dict(
type='str',
),
name=dict(
type='str',
),
),
),
node_affinity=dict(
type='dict',
fields=dict(
required=dict(
type='dict',
fields=dict(
node_selector_terms=dict(
type='list',
subtype='dict',
),
),
),
),
),
csi=dict(
type='dict',
fields=dict(
driver=dict(type='str'),
volume_handle=dict(type='str'),
read_only=dict(
type='bool',
),
fs_type=dict(
type='str',
),
volume_attributes=dict(
type='dict',
subtype='str',
),
),
),
nfs=dict(
type='dict',
fields=dict(
path=dict(
type='str',
required=True
),
server=dict(
type='str',
required=True
),
),
),
)


class OutputPlugin(OutputPluginBase):

Expand Down
42 changes: 42 additions & 0 deletions deploy_config_generator/output/kube_pv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import copy

from deploy_config_generator.utils import yaml_dump
from deploy_config_generator.output import kube_common


class OutputPlugin(kube_common.OutputPlugin):

NAME = 'kube_pv'
DESCR = 'Kubernetes PersistentVolume output plugin'
FILE_EXT = '.yaml'

DEFAULT_CONFIG = {
'fields': {
'kube_pvs': dict(
metadata=dict(
type='dict',
required=True,
fields=copy.deepcopy(kube_common.METADATA_FIELD_SPEC),
),
spec=dict(
type='dict',
required=True,
fields=copy.deepcopy(kube_common.PERSISTENT_VOLUME_FIELD_SPEC),
),
),
}
}

def generate_output(self, app_vars):
# Basic structure
data = {
'apiVersion': 'v1',
'kind': 'PersistentVolume',
'spec': dict(),
}
data['metadata'] = self.build_metadata(app_vars['APP']['metadata'])
data['spec'] = self.build_generic(app_vars['APP']['spec'], self._plugin_config['fields']['kube_pvs']['spec']['fields'])

data = self._template.render_template(data, app_vars)
output = yaml_dump(data)
return (output, self.get_output_filename_suffix(data))
46 changes: 46 additions & 0 deletions docs/plugin_kube_pv.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!--
NOTE: this document is automatically generated. Any manual changes will get overwritten.
-->
# kube_pv

Kubernetes PersistentVolume output plugin

### Parameters


#### Deploy config section: kube_pvs

Name | Type | Required | Default | Description
--- | --- | --- | --- | ---
`metadata`|`dict`|yes||
`metadata . annotations`|`dict`|no||
`metadata . labels`|`dict`|no||
`metadata . name`|`str`|no||
`metadata . namespace`|`str`|no||
`spec`|`dict`|yes||
`spec . access_modes`|`list` (of `str`)|yes||
`spec . capacity`|`dict`|yes||
`spec . capacity . storage`|`str`|no||
`spec . claim_ref`|`dict`|no||
`spec . claim_ref . api_version`|`str`|no||
`spec . claim_ref . kind`|`str`|no||
`spec . claim_ref . name`|`str`|no||
`spec . claim_ref . namespace`|`str`|no||
`spec . csi`|`dict`|no||
`spec . csi . driver`|`str`|no||
`spec . csi . fs_type`|`str`|no||
`spec . csi . read_only`|`bool`|no||
`spec . csi . volume_attributes`|`dict` (of `str`)|no||
`spec . csi . volume_handle`|`str`|no||
`spec . mount_options`|`list` (of `str`)|no||
`spec . nfs`|`dict`|no||
`spec . nfs . path`|`str`|yes||
`spec . nfs . server`|`str`|yes||
`spec . node_affinity`|`dict`|no||
`spec . node_affinity . required`|`dict`|no||
`spec . node_affinity . required . node_selector_terms`|`list` (of `dict`)|no||
`spec . persistent_volume_reclaim_policy`|`str`|no||
`spec . storage_class_name`|`str`|no||
`spec . volume_mode`|`str`|no||


2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def run(self):

setup(
name='deploy-config-generator',
version='2.27.0',
version='2.28.0',
url='https://github.com/ApplauseOSS/deploy-config-generator',
license='MIT',
description='Utility to generate service deploy configurations',
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/kube_basic/deploy/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,24 @@ kube_pvcs:
match_expressions:
- {key: environment, operator: In, values: [dev]}

kube_pvs:
- metadata:
name: test-pv
spec:
capacity:
storage: 8Gi
volume_mode: Filesystem
access_modes:
- ReadWriteOnce
persistent_volume_reclaim_policy: Recycle
storage_class_name: slow
mount_options:
- hard
- nfsvers=4.1
nfs:
path: /tmp
server: 172.17.0.2

kube_configmaps:
- metadata:
name: test-configmap
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: test-pv
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 8Gi
mountOptions:
- hard
- nfsvers=4.1
nfs:
path: /tmp
server: 172.17.0.2
persistentVolumeReclaimPolicy: Recycle
storageClassName: slow
volumeMode: Filesystem

0 comments on commit f397acf

Please sign in to comment.