Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for k8s ServiceAccount #121

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading