-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for k8s ServiceAccount
- Loading branch information
Showing
5 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
.../integration/kube_basic/expected_output/kube_serviceaccount-001-test-serviceaccount1.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: test-serviceaccount1 |
8 changes: 8 additions & 0 deletions
8
.../integration/kube_basic/expected_output/kube_serviceaccount-002-test-serviceaccount2.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |