Skip to content

Commit 875a156

Browse files
authored
Wdt 414 k8s filter (#628)
* rename method to reflect intention * Add support for preparing a domain for k8s during discovery * add comments * remove obsolete code * add command for preparing models for operator * refactor method * Fix code if no -variable_file is passed * cleanup * JIRA WDT-414 - Don't include single-unpredictable tokens in model path * fix bug * fix password formating * refactor code * Fix multiple models problem * Add documentation * Fix initialization error * various fixes for review * Fix PR review * python version requirment * update to avoid duplicate create secrets * change target file final name * update doc * doc update
1 parent c3875da commit 875a156

File tree

22 files changed

+1195
-89
lines changed

22 files changed

+1195
-89
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ Currently, the project provides five single-purpose tools, all exposed as shell
8686
- The [Encrypt Model Tool](site/encrypt.md) (`encryptModel`) encrypts the passwords in a model (or its variable file) using a user-provided passphrase.
8787
- The [Validate Model Tool](site/validate.md) (`validateModel`) provides both standalone validation of a model as well as model usage information to help users write or edit their models.
8888
- The [Compare Model Tool](site/compare.md) (`compareModel`) compares two model files.
89+
- The [Prepare Model Tool](site/compare.md) (`prepareModel`) prepare model files for deploying to WebLogic Kubernetes Operator environment.
8990
- The [Extract Domain Resource Tool](site/kubernetes.md) (`extractDomainResource`) generates a domain resource YAML for use with the Oracle WebLogic Server Kubernetes Operator.
9091

9192
As new use cases are discovered, new tools will likely be added to cover those operations but all will use the metadata model to describe what needs to be done.

core/src/main/python/compare_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
]
5959

6060
__optional_arguments = [
61-
CommandLineArgUtil.COMPARE_MODEL_OUTPUT_DIR_SWITCH,
61+
CommandLineArgUtil.OUTPUT_DIR_SWITCH,
6262
CommandLineArgUtil.VARIABLE_FILE_SWITCH
6363
]
6464

core/src/main/python/discover.py

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
from wlsdeploy.util.cla_utils import CommandLineArgUtil
5151
from wlsdeploy.util.model import Model
5252
from wlsdeploy.util.weblogic_helper import WebLogicHelper
53+
from wlsdeploy.util import target_configuration_helper
5354

5455
wlst_helper.wlst_functions = globals()
5556

@@ -73,7 +74,9 @@
7374
CommandLineArgUtil.ADMIN_URL_SWITCH,
7475
CommandLineArgUtil.ADMIN_USER_SWITCH,
7576
CommandLineArgUtil.ADMIN_PASS_SWITCH,
76-
CommandLineArgUtil.TARGET_MODE_SWITCH
77+
CommandLineArgUtil.TARGET_MODE_SWITCH,
78+
CommandLineArgUtil.OUTPUT_DIR_SWITCH,
79+
CommandLineArgUtil.TARGET_SWITCH
7780
]
7881

7982

@@ -90,6 +93,8 @@ def __process_args(args):
9093

9194
cla_helper.verify_required_args_present(_program_name, __required_arguments, required_arg_map)
9295
__wlst_mode = cla_helper.process_online_args(optional_arg_map)
96+
97+
__process_target_arg(optional_arg_map)
9398
__process_archive_filename_arg(required_arg_map)
9499
__process_variable_filename_arg(optional_arg_map)
95100
__process_java_home(optional_arg_map)
@@ -98,6 +103,24 @@ def __process_args(args):
98103
combined_arg_map.update(required_arg_map)
99104
return model_context_helper.create_context(_program_name, combined_arg_map)
100105

106+
def __process_target_arg(optional_arg_map):
107+
108+
_method_name = '__process_target_arg'
109+
110+
if CommandLineArgUtil.TARGET_SWITCH in optional_arg_map:
111+
# if -target is specified -output_dir is required
112+
output_dir = optional_arg_map[CommandLineArgUtil.OUTPUT_DIR_SWITCH]
113+
if output_dir is None or os.path.isdir(output_dir) is False:
114+
if not os.path.isdir(output_dir):
115+
ex = exception_helper.create_cla_exception('WLSDPLY-01642', output_dir)
116+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
117+
raise ex
118+
119+
# Set the -variable_file parameter if not present with default
120+
121+
if CommandLineArgUtil.VARIABLE_FILE_SWITCH not in optional_arg_map:
122+
optional_arg_map[CommandLineArgUtil.VARIABLE_FILE_SWITCH] = os.path.join(output_dir,
123+
"k8s_variable.properties")
101124

102125
def __process_archive_filename_arg(required_arg_map):
103126
"""
@@ -399,15 +422,25 @@ def __check_and_customize_model(model, model_context, aliases, injector):
399422
_method_name = '__check_and_customize_model'
400423
__logger.entering(class_name=_class_name, method_name=_method_name)
401424

402-
if filter_helper.apply_filters(model.get_model(), "discover"):
425+
if filter_helper.apply_filters(model.get_model(), "discover", model_context):
403426
__logger.info('WLSDPLY-06014', _class_name=_class_name, method_name=_method_name)
404427

405428
cache = None
406429
if injector is not None:
407430
cache = injector.get_variable_cache()
431+
# Generate k8s create secret script, after that clear the dictionary to avoid showing up in the variable file
432+
if model_context.is_targetted_config():
433+
validation_method = model_context.get_target_configuration()['validation_method']
434+
model_context.set_validation_method(validation_method)
435+
target_configuration_helper.generate_k8s_script(model_context.get_kubernetes_variable_file(), cache)
436+
cache.clear()
437+
438+
variable_injector = VariableInjector(_program_name, model.get_model(), model_context,
439+
WebLogicHelper(__logger).get_actual_weblogic_version(), cache)
440+
408441
inserted, variable_model, variable_file_name = \
409-
VariableInjector(_program_name, model.get_model(), model_context,
410-
WebLogicHelper(__logger).get_actual_weblogic_version(), cache).inject_variables_keyword_file()
442+
variable_injector.inject_variables_keyword_file()
443+
411444
if inserted:
412445
model = Model(variable_model)
413446
try:

0 commit comments

Comments
 (0)