Skip to content

Commit 1d0de57

Browse files
authored
Target type cleanup (#1090)
* Only include runtime encryption secret for MII targets * Only add secrets to domain resource if target uses credential secrets * Combine similar domain resource templates and customize using target configuration
1 parent 856202b commit 1d0de57

File tree

12 files changed

+44
-457
lines changed

12 files changed

+44
-457
lines changed

core/src/main/python/wlsdeploy/tool/util/targets/additional_output_helper.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
2+
Copyright (c) 2020, 2022, Oracle and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
55
Methods for creating Kubernetes resource configuration files for Verrazzano.
@@ -49,6 +49,7 @@
4949
NAMESPACE = 'namespace'
5050
REPLICAS = 'replicas'
5151
RUNTIME_ENCRYPTION_SECRET = "runtimeEncryptionSecret"
52+
USE_PERSISTENT_VOLUME = "usePersistentVolume"
5253
WEBLOGIC_CREDENTIALS_SECRET = 'webLogicCredentialsSecret'
5354

5455

@@ -85,7 +86,7 @@ def _create_file(template_name, template_hash, model_context, output_dir, except
8586
_method_name = '_create_file'
8687

8788
target_key = model_context.get_target()
88-
template_subdir = "targets/" + target_key + "/" + template_name
89+
template_subdir = "targets/templates/" + template_name
8990
template_path = path_utils.find_config_path(template_subdir)
9091
output_file = File(output_dir, template_name)
9192

@@ -104,6 +105,7 @@ def _build_template_hash(model, model_context, aliases, credential_injector):
104105
:return: the hash dictionary
105106
"""
106107
template_hash = dict()
108+
target_configuration = model_context.get_target_configuration()
107109

108110
# actual domain name
109111

@@ -130,9 +132,15 @@ def _build_template_hash(model, model_context, aliases, credential_injector):
130132

131133
# runtime encryption secret
132134

133-
runtime_secret = domain_uid + target_configuration_helper.RUNTIME_ENCRYPTION_SECRET_SUFFIX
134-
declared_secrets.append(runtime_secret)
135-
template_hash[RUNTIME_ENCRYPTION_SECRET] = runtime_secret
135+
additional_secrets = target_configuration.get_additional_secrets()
136+
if target_configuration_helper.RUNTIME_ENCRYPTION_SECRET_NAME in additional_secrets:
137+
runtime_secret = domain_uid + target_configuration_helper.RUNTIME_ENCRYPTION_SECRET_SUFFIX
138+
declared_secrets.append(runtime_secret)
139+
template_hash[RUNTIME_ENCRYPTION_SECRET] = runtime_secret
140+
141+
# use persistent_volume
142+
143+
template_hash[USE_PERSISTENT_VOLUME] = target_configuration.use_persistent_volume()
136144

137145
# configuration / model
138146
template_hash[DOMAIN_TYPE] = model_context.get_domain_type()
@@ -212,11 +220,13 @@ def _build_template_hash(model, model_context, aliases, credential_injector):
212220

213221
# combine user/password properties to get a single list
214222
secrets = []
215-
for property_name in credential_injector.get_variable_cache():
216-
halves = property_name.split(':', 1)
217-
name = halves[0]
218-
if name not in secrets:
219-
secrets.append(name)
223+
224+
if target_configuration.uses_credential_secrets():
225+
for property_name in credential_injector.get_variable_cache():
226+
halves = property_name.split(':', 1)
227+
name = halves[0]
228+
if name not in secrets:
229+
secrets.append(name)
220230

221231
for secret in secrets:
222232
secrets_hash = dict()

core/src/main/python/wlsdeploy/util/target_configuration.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
# Determines whether the domainBin contents should be excluded
1919
EXCLUDE_DOMAIN_BIN_CONTENTS = "exclude_domain_bin_contents"
2020

21+
# Determines whether a persistent volume is used
22+
USE_PERSISTENT_VOLUME = "use_persistent_volume"
23+
2124
# put secret tokens in the model, and build a script to create the secrets.
2225
SECRETS_METHOD = 'secrets'
2326

@@ -149,3 +152,13 @@ def exclude_domain_bin_contents(self):
149152
if result is None:
150153
result = False
151154
return result
155+
156+
def use_persistent_volume(self):
157+
"""
158+
Determine if this configuration uses a persistent volume for the domain home.
159+
:return: True if persistent volume is used, False otherwise
160+
"""
161+
result = dictionary_utils.get_element(self.config_dictionary, USE_PERSISTENT_VOLUME)
162+
if result is None:
163+
result = False
164+
return result

core/src/main/targetconfigs/vz-pv/vz-application.yaml renamed to core/src/main/targetconfigs/templates/vz-application.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ spec:
6868

6969
# WebLogic Image Tool provides modelHome
7070
modelHome: {{{modelHome}}}
71+
{{#runtimeEncryptionSecret}}
7172

7273
# encryption for the WDT model and the SystemSerializedIni.data file.
7374
# used only for model-in-image deployment, can be removed for other types.
7475
runtimeEncryptionSecret: {{{runtimeEncryptionSecret}}}
76+
{{/runtimeEncryptionSecret}}
7577
{{#hasAdditionalSecrets}}
7678

7779
secrets:
@@ -107,6 +109,7 @@ spec:
107109
value: "-Dweblogic.StdoutDebugEnabled=false"
108110
- name: USER_MEM_ARGS
109111
value: "-Djava.security.egd=file:/dev/./urandom -Xms64m -Xmx256m "
112+
{{#usePersistentVolume}}
110113

111114
# volume information for persistent volume
112115
volumes:
@@ -116,6 +119,7 @@ spec:
116119
volumeMounts:
117120
- mountPath: /shared
118121
name: weblogic-domain-storage-volume
122+
{{/usePersistentVolume}}
119123
---
120124
apiVersion: core.oam.dev/v1alpha2
121125
kind: Component

core/src/main/targetconfigs/wko-pv/wko-domain.yaml renamed to core/src/main/targetconfigs/templates/wko-domain.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ spec:
3434
value: "-Dweblogic.StdoutDebugEnabled=false"
3535
- name: USER_MEM_ARGS
3636
value: "-Djava.security.egd=file:/dev/./urandom -Xms64m -Xmx256m "
37+
{{#usePersistentVolume}}
3738

3839
# volume information for persistent volume
3940
volumes:
@@ -43,8 +44,9 @@ spec:
4344
volumeMounts:
4445
- mountPath: /shared
4546
name: weblogic-domain-storage-volume
46-
47+
{{/usePersistentVolume}}
4748
{{#hasClusters}}
49+
4850
# clusters is used to configure the desired behavior for starting member servers of a cluster.
4951
# If you use this entry, then the rules will be applied to ALL servers that are members of the named clusters.
5052
clusters:
@@ -80,10 +82,12 @@ spec:
8082

8183
# WebLogic Image Tool provides modelHome
8284
modelHome: {{{modelHome}}}
85+
{{#runtimeEncryptionSecret}}
8386

8487
# encryption for the WDT model and the SystemSerializedIni.data file.
8588
# used only for model-in-image deployment, can be removed for other types.
8689
runtimeEncryptionSecret: {{{runtimeEncryptionSecret}}}
90+
{{/runtimeEncryptionSecret}}
8791
{{#hasAdditionalSecrets}}
8892

8993
# Secrets that are referenced by model yaml macros

core/src/main/targetconfigs/vz-dii/target.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@
88
"validation_method" : "lax",
99
"credentials_output_method" : "script",
1010
"exclude_domain_bin_contents": true,
11-
"additional_secrets": "runtime-encryption-secret",
1211
"additional_output" : "vz-application.yaml"
1312
}

core/src/main/targetconfigs/vz-dii/vz-application.yaml

Lines changed: 0 additions & 135 deletions
This file was deleted.

core/src/main/targetconfigs/vz-pv/target.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"validation_method" : "lax",
99
"credentials_output_method" : "script",
1010
"exclude_domain_bin_contents": true,
11-
"additional_secrets": "runtime-encryption-secret",
11+
"use_persistent_volume" : true,
1212
"additional_output" : "vz-application.yaml"
1313
}

0 commit comments

Comments
 (0)