Skip to content

Commit

Permalink
feat: support for k8s ServiceAccount
Browse files Browse the repository at this point in the history
  • Loading branch information
agaffney committed Feb 2, 2024
1 parent 940e334 commit be42e35
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
59 changes: 59 additions & 0 deletions deploy_config_generator/output/kube_serviceaccount.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import copy

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


class OutputPlugin(kube_common.OutputPlugin):

NAME = 'kube_serviceaccount'
DESCR = 'Kubernetes service account output plugin'
FILE_EXT = '.yaml'

DEFAULT_CONFIG = {
'fields': {
'kube_serviceaccounts': dict(
metadata=dict(
type='dict',
required=True,
fields=copy.deepcopy(kube_common.METADATA_FIELD_SPEC),
),
automount_service_account_token=dict(
type='bool',
),
secrets=dict(
type='list',
subtype='dict',
fields=dict(
name=dict(
type='str',
),
),
),
image_pull_secrets=dict(
type='list',
subtype='dict',
fields=dict(
name=dict(
type='str',
),
),
),
),
}
}

def generate_output(self, app_vars):
# Basic structure
data = {
'apiVersion': 'v1',
'kind': 'ServiceAccount',
}
data['metadata'] = self.build_metadata(app_vars['APP']['metadata'])
for field in ('automount_service_account_token', 'secrets', 'image_pull_secrets'):
if app_vars['APP'].get(field, None) is not None and app_vars['APP'][field]:
data[underscore_to_camelcase(field)] = app_vars['APP'][field]

data = self._template.render_template(data, app_vars)
output = yaml_dump(data)
return (output, self.get_output_filename_suffix(data))
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.26.0',
version='2.27.0',
url='https://github.com/ApplauseOSS/deploy-config-generator',
license='MIT',
description='Utility to generate service deploy configurations',
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/kube_basic/deploy/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,14 @@ kube_configmaps:
test1
test2
test3
kube_serviceaccounts:
- metadata:
name: test-serviceaccount1
- metadata:
name: test-serviceaccount2
automount_service_account_token: false
secrets:
- name: foo-bar
image_pull_secrets:
- name: bar-baz
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: test-serviceaccount1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
imagePullSecrets:
- name: bar-baz
kind: ServiceAccount
metadata:
name: test-serviceaccount2
secrets:
- name: foo-bar

0 comments on commit be42e35

Please sign in to comment.