Skip to content

Commit 96c8c16

Browse files
committed
Merge branch 'filter-model-opss-secrets' into 'main'
Filter model OPSS secrets for MII and PV domain home source types See merge request weblogic-cloud/weblogic-deploy-tooling!1483
2 parents 37b0bd5 + d4a8d2b commit 96c8c16

File tree

16 files changed

+65
-32
lines changed

16 files changed

+65
-32
lines changed

core/src/main/python/wlsdeploy/tool/util/filter_helper.py

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
'wko_filter': wko_filter.filter_model_for_wko,
2727

2828
# individual filters for custom target environments
29+
'domain_info_filter': wko_filter.filter_domain_info,
2930
'online_attributes_filter': wko_filter.filter_online_attributes,
3031
'resources_filter': wko_filter.filter_resources,
3132
'topology_filter': wko_filter.filter_topology,

core/src/main/python/wlsdeploy/tool/util/filters/wko_filter.py

+25
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
# ------------
77
# WDT filters to prepare a model for use a target environment, using the createDomain or prepareModel tools.
88
# These operations can be invoked as a single call, or independently of each other.
9+
910
from oracle.weblogic.deploy.util import PyRealBoolean
11+
1012
from wlsdeploy.aliases import alias_utils
1113
from wlsdeploy.aliases.model_constants import AUTO_MIGRATION_ENABLED
1214
from wlsdeploy.aliases.model_constants import CALCULATED_LISTEN_PORTS
@@ -15,13 +17,15 @@
1517
from wlsdeploy.aliases.model_constants import CLUSTER
1618
from wlsdeploy.aliases.model_constants import CLUSTER_MESSAGING_MODE
1719
from wlsdeploy.aliases.model_constants import DATABASE_LESS_LEASING_BASIS
20+
from wlsdeploy.aliases.model_constants import DOMAIN_INFO
1821
from wlsdeploy.aliases.model_constants import DYNAMIC_SERVERS
1922
from wlsdeploy.aliases.model_constants import LISTEN_PORT
2023
from wlsdeploy.aliases.model_constants import MACHINE
2124
from wlsdeploy.aliases.model_constants import MIGRATION_BASIS
2225
from wlsdeploy.aliases.model_constants import NM_PROPERTIES
2326
from wlsdeploy.aliases.model_constants import NODE_MANAGER_PW_ENCRYPTED
2427
from wlsdeploy.aliases.model_constants import NODE_MANAGER_USER_NAME
28+
from wlsdeploy.aliases.model_constants import OPSS_SECRETS
2529
from wlsdeploy.aliases.model_constants import PARTITION
2630
from wlsdeploy.aliases.model_constants import PARTITION_WORK_MANAGER
2731
from wlsdeploy.aliases.model_constants import RESOURCES
@@ -57,6 +61,7 @@ def filter_model(model, model_context):
5761
:param model: the model to be filtered
5862
:param model_context: used by nested filters
5963
"""
64+
filter_domain_info(model, model_context)
6065
filter_topology(model, model_context)
6166
filter_resources(model, model_context)
6267
filter_online_attributes(model, model_context)
@@ -143,6 +148,26 @@ def check_clustered_server_ports(model, _model_context):
143148
server_port_map[server_cluster] = {"firstServer": server_name, "serverPort": server_port_text}
144149

145150

151+
def filter_domain_info(model, _model_context):
152+
"""
153+
Remove elements from the domainInfo section of the model that are not relevant in a Kubernetes environment.
154+
This may include references to OPSS secret elements.
155+
:param model: the model to be updated
156+
:param _model_context: used to get target configuration
157+
"""
158+
_method_name = 'filter_domain_info'
159+
160+
target_configuration = _model_context.get_target_configuration()
161+
if not target_configuration.uses_opss_secrets():
162+
domain_info = dictionary_utils.get_dictionary_element(model, DOMAIN_INFO)
163+
for delete_key in [OPSS_SECRETS]:
164+
if delete_key in domain_info:
165+
source_name = target_configuration.get_domain_home_source_name()
166+
_logger.info('WLSDPLY-20208', OPSS_SECRETS, DOMAIN_INFO, source_name, class_name=_class_name,
167+
method_name=_method_name)
168+
del domain_info[delete_key]
169+
170+
146171
def filter_topology(model, _model_context):
147172
"""
148173
Remove elements from the topology section of the model that are not relevant in a Kubernetes environment.

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,8 @@ def get_target_configuration(self):
674674
:return: target configuration object
675675
"""
676676
if self._target_configuration is None:
677-
configuration_dict = {}
677+
# if no target declared, construct TargetConfiguration with None
678+
configuration_dict = None
678679

679680
if self._target:
680681
target_configuration_file = self.get_target_configuration_file()

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

+25-8
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ def __init__(self, config_dictionary):
8383
"""
8484
if config_dictionary is None:
8585
self.config_dictionary = {}
86+
self.is_targeted = False # no target was declared, methods are still usable
8687
else:
8788
self.config_dictionary = config_dictionary
89+
self.is_targeted = True
8890

8991
def get_credentials_method(self):
9092
"""
@@ -96,10 +98,11 @@ def get_credentials_method(self):
9698
def get_results_output_method(self):
9799
"""
98100
Returns the method for generating results output.
99-
:return: "default" (script and additional files) or "json" (single results file)
101+
:return: "default" (script and additional files) or "json" (single results file), or None if not
102+
using a targeted configuration
100103
"""
101104
result = dictionary_utils.get_element(self.config_dictionary, RESULTS_OUTPUT_METHOD)
102-
if result is None:
105+
if not result and self.is_targeted:
103106
result = DEFAULT_RESULTS_OUTPUT_METHOD
104107
return result
105108

@@ -219,15 +222,26 @@ def uses_wdt_model(self):
219222
:return: True if a model is included, False otherwise
220223
"""
221224
source_type = self._get_domain_home_source_type()
222-
return source_type == MODEL_IN_IMAGE_SOURCE_TYPE
225+
return source_type in [None, MODEL_IN_IMAGE_SOURCE_TYPE]
226+
227+
def uses_opss_secrets(self):
228+
"""
229+
Determine if OPSS secrets are applicable to this target configuration.
230+
They are applicable for non-targeted scenarios.
231+
:return: True if a model is included, False otherwise
232+
"""
233+
source_type = self._get_domain_home_source_type()
234+
return source_type not in [MODEL_IN_IMAGE_SOURCE_TYPE, PERSISTENT_VOLUME_SOURCE_TYPE]
223235

224236
def get_domain_home_source_name(self):
225237
"""
226238
Return the name associated with the domain home source type key.
227239
:return: the domain home source name
228240
"""
229241
source_type = self._get_domain_home_source_type()
230-
return SOURCE_TYPE_NAMES[source_type]
242+
if source_type:
243+
return SOURCE_TYPE_NAMES[source_type]
244+
return None
231245

232246
def sets_cluster_replicas(self):
233247
"""
@@ -272,11 +286,11 @@ def validate_configuration(self, exit_code, target_configuration_file):
272286
self._validate_enumerated_field(PRODUCT_VERSION, product_version, valid_product_versions, exit_code,
273287
target_configuration_file)
274288

275-
source_type = self._get_domain_home_source_type()
289+
source_type = dictionary_utils.get_element(self.config_dictionary, DOMAIN_HOME_SOURCE_TYPE)
276290
self._validate_enumerated_field(DOMAIN_HOME_SOURCE_TYPE, source_type, SOURCE_TYPE_NAMES.keys(), exit_code,
277291
target_configuration_file)
278292

279-
output_method = self.get_results_output_method()
293+
output_method = dictionary_utils.get_element(self.config_dictionary, RESULTS_OUTPUT_METHOD)
280294
self._validate_enumerated_field(RESULTS_OUTPUT_METHOD, output_method, RESULTS_OUTPUT_METHODS, exit_code,
281295
target_configuration_file)
282296

@@ -287,10 +301,13 @@ def validate_configuration(self, exit_code, target_configuration_file):
287301
def _get_domain_home_source_type(self):
288302
"""
289303
Get the domain home source type (private method).
290-
:return: the domain home source type key, or the default MODEL_IN_IMAGE_SOURCE_TYPE
304+
:return: the configured domain home source type key, or MODEL_IN_IMAGE_SOURCE_TYPE. If not using a
305+
targeted configuration, None is returned.
291306
"""
292307
source_type = dictionary_utils.get_element(self.config_dictionary, DOMAIN_HOME_SOURCE_TYPE)
293-
return source_type or MODEL_IN_IMAGE_SOURCE_TYPE
308+
if not source_type and self.is_targeted:
309+
source_type = MODEL_IN_IMAGE_SOURCE_TYPE
310+
return source_type
294311

295312
def _validate_enumerated_field(self, key, value, valid_values, exit_code, target_configuration_file):
296313
method_name = '_validate_enumerated_field'

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

+10-11
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,19 @@ def generate_all_output_files(model, aliases, credential_injector, model_context
112112
:param model_context: used to determine location and content for the output
113113
:param exception_type: the type of exception to throw if needed
114114
"""
115-
if model_context.is_targetted_config():
116-
target_config = model_context.get_target_configuration()
117-
credential_cache = credential_injector.get_variable_cache()
115+
target_config = model_context.get_target_configuration()
116+
credential_cache = credential_injector.get_variable_cache()
118117

119-
if target_config.generate_results_file():
120-
generate_results_json(model_context, credential_cache, model.get_model(), exception_type)
118+
if target_config.generate_results_file():
119+
generate_results_json(model_context, credential_cache, model.get_model(), exception_type)
121120

122-
if target_config.generate_output_files():
123-
# Generate k8s create secret script
124-
generate_k8s_script(model_context, credential_cache, model.get_model(), exception_type)
121+
if target_config.generate_output_files():
122+
# Generate k8s create secret script
123+
generate_k8s_script(model_context, credential_cache, model.get_model(), exception_type)
125124

126-
# create additional output files
127-
additional_output_helper.create_additional_output(model, model_context, aliases, credential_injector,
128-
exception_type)
125+
# create additional output files
126+
additional_output_helper.create_additional_output(model, model_context, aliases, credential_injector,
127+
exception_type)
129128

130129

131130
def _prepare_k8s_secrets(model_context, token_dictionary, model_dictionary):

core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties

+1
Original file line numberDiff line numberDiff line change
@@ -1819,6 +1819,7 @@ WLSDPLY-20204=Adding {0} "{1}" to dynamic cluster "{2}" for compatibility with {
18191819
WLSDPLY-20205=The {0} value "{1}" is used by multiple dynamic clusters, which will cause deployment to fail
18201820
WLSDPLY-20206=Adding {0} value "{1}" to model for compatibility with {2} target
18211821
WLSDPLY-20207=Adding {0} "{1}" to model for compatibility with {2} target
1822+
WLSDPLY-20208=Removing {0} from {1} for domain home source type {2}
18221823

18231824
# Common messages used for tool exit and clean-up
18241825
WLSDPLY-21000={0} Messages:

core/src/main/targetconfigs/k8s/target.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@
1010
],
1111
"variable_injectors" : {"PORT": {},"HOST": {},"URL": {}},
1212
"validation_method" : "lax",
13-
"credentials_method" : "secrets",
14-
"credentials_output_method" : "script"
13+
"credentials_method" : "secrets"
1514
}

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

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"validation_method" : "lax",
1212
"product_key": "vz",
1313
"domain_home_source_type" : "dii",
14-
"credentials_output_method" : "script",
1514
"exclude_domain_bin_contents": true,
1615
"additional_output" : "vz-application.yaml"
1716
}

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

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"validation_method" : "lax",
1212
"product_key": "vz",
1313
"domain_home_source_type" : "pv",
14-
"credentials_output_method" : "script",
1514
"exclude_domain_bin_contents": true,
1615
"use_persistent_volume" : true,
1716
"additional_output" : "vz-application.yaml"

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

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"product_key": "vz",
1414
"domain_home_source_type" : "mii",
1515
"credentials_method" : "secrets",
16-
"credentials_output_method" : "script",
1716
"exclude_domain_bin_contents": true,
1817
"wls_credentials_name" : "__weblogic-credentials__",
1918
"additional_secrets": "runtime-encryption-secret",

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

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"variable_injectors" : {"PORT": {},"HOST": {},"URL": {}},
1111
"validation_method" : "lax",
1212
"domain_home_source_type" : "dii",
13-
"credentials_output_method" : "script",
1413
"exclude_domain_bin_contents": true,
1514
"additional_output" : "wko-domain.yaml"
1615
}

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

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"variable_injectors" : {"PORT": {},"HOST": {},"URL": {}},
1111
"validation_method" : "lax",
1212
"domain_home_source_type" : "pv",
13-
"credentials_output_method" : "script",
1413
"exclude_domain_bin_contents": true,
1514
"use_persistent_volume" : true,
1615
"additional_output" : "wko-domain.yaml"

core/src/main/targetconfigs/wko/target.json

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
"validation_method" : "lax",
1313
"domain_home_source_type" : "mii",
1414
"credentials_method" : "secrets",
15-
"-- results_output_method" : "json",
16-
"credentials_output_method" : "script",
1715
"exclude_domain_bin_contents": true,
1816
"wls_credentials_name" : "__weblogic-credentials__",
1917
"additional_secrets": "runtime-encryption-secret",

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

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"variable_injectors" : {"PORT": {},"HOST": {},"URL": {}},
1111
"validation_method" : "lax",
1212
"domain_home_source_type" : "dii",
13-
"credentials_output_method" : "script",
1413
"exclude_domain_bin_contents": true,
1514
"product_version" : "v4",
1615
"additional_output" : "wko-domain.yaml"

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

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"variable_injectors" : {"PORT": {},"HOST": {},"URL": {}},
1111
"validation_method" : "lax",
1212
"domain_home_source_type" : "pv",
13-
"credentials_output_method" : "script",
1413
"exclude_domain_bin_contents": true,
1514
"use_persistent_volume" : true,
1615
"product_version" : "v4",

core/src/main/targetconfigs/wko4/target.json

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"validation_method" : "lax",
1212
"domain_home_source_type" : "mii",
1313
"credentials_method" : "secrets",
14-
"credentials_output_method" : "script",
1514
"exclude_domain_bin_contents": true,
1615
"product_version" : "v4",
1716
"wls_credentials_name" : "__weblogic-credentials__",

0 commit comments

Comments
 (0)