Skip to content

Commit c6d55b9

Browse files
authored
Remove cluster replica count from domain resource file by default (#1147)
* Remove cluster replica count by default, provide target switch to enable * Add comment for adding cluster replica count to domain resource file * Revised unit test to set and test cluster replica count
1 parent a5b7248 commit c6d55b9

File tree

7 files changed

+41
-6
lines changed

7 files changed

+41
-6
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
NAMESPACE = 'namespace'
5555
REPLICAS = 'replicas'
5656
RUNTIME_ENCRYPTION_SECRET = "runtimeEncryptionSecret"
57+
SET_CLUSTER_REPLICAS = "setClusterReplicas"
5758
USE_PERSISTENT_VOLUME = "usePersistentVolume"
5859
WEBLOGIC_CREDENTIALS_SECRET = 'webLogicCredentialsSecret'
5960

@@ -195,6 +196,7 @@ def _build_template_hash(model, model_context, aliases, credential_injector):
195196
cluster_values = dictionary_utils.get_dictionary_element(cluster_list, cluster_name)
196197
server_count = k8s_helper.get_server_count(cluster_name, cluster_values, model.get_model())
197198
cluster_hash[REPLICAS] = str(server_count)
199+
cluster_hash[SET_CLUSTER_REPLICAS] = target_configuration.sets_cluster_replicas()
198200
clusters.append(cluster_hash)
199201

200202
template_hash[CLUSTERS] = clusters

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
SPEC = 'spec'
2929

3030
WKO_DOMAIN_KIND = 'Domain'
31+
CLUSTERS = 'clusters'
3132
DOMAIN_HOME = 'domainHome'
3233
IMAGE_PULL_SECRETS = 'imagePullSecrets'
34+
REPLICAS = 'replicas'
3335

3436
# specific to Verrazzano
3537
COMPONENT_KIND = 'Component'
@@ -264,12 +266,19 @@ def _add_comments(wko_dictionary):
264266
Add relevant comments to the output dictionary to provide additional information.
265267
:param wko_dictionary: the top-level WKO dictionary containing metadata, spec, etc.
266268
"""
267-
spec = dictionary_utils.get_element(wko_dictionary, SPEC)
268-
if spec:
269-
image_pull_secrets = dictionary_utils.get_element(spec, IMAGE_PULL_SECRETS)
270-
if image_pull_secrets is not None and not len(image_pull_secrets):
271-
message = exception_helper.get_message('WLSDPLY-01679')
272-
spec.addComment(IMAGE_PULL_SECRETS, message)
269+
spec = dictionary_utils.get_dictionary_element(wko_dictionary, SPEC)
270+
image_pull_secrets = dictionary_utils.get_element(spec, IMAGE_PULL_SECRETS)
271+
if image_pull_secrets is not None and not len(image_pull_secrets):
272+
message = exception_helper.get_message('WLSDPLY-01679')
273+
spec.addComment(IMAGE_PULL_SECRETS, message)
274+
275+
clusters = dictionary_utils.get_dictionary_element(spec, CLUSTERS)
276+
for cluster in clusters:
277+
cluster_replicas = dictionary_utils.get_element(cluster, REPLICAS)
278+
if cluster_replicas is None and len(cluster):
279+
last_key = cluster.keys()[-1]
280+
message = exception_helper.get_message('WLSDPLY-01680')
281+
cluster.addComment(last_key, REPLICAS + ': 99 # ' + message)
273282

274283

275284
def _get_or_create_dictionary(dictionary, key):

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
# Determines the type of domain used
2727
DOMAIN_HOME_SOURCE_TYPE = "domain_home_source_type"
2828

29+
# Determines if replica count is applied at the cluster level
30+
SET_CLUSTER_REPLICAS = "set_cluster_replicas"
31+
2932
# put secret tokens in the model, and build a script to create the secrets.
3033
SECRETS_METHOD = 'secrets'
3134

@@ -197,6 +200,14 @@ def get_domain_home_source_name(self):
197200
source_type = self._get_domain_home_source_type()
198201
return SOURCE_TYPE_NAMES[source_type]
199202

203+
def sets_cluster_replicas(self):
204+
"""
205+
Return True if this configuration will calculate and apply replica counts at the cluster level.
206+
:return: True if a replica counts are applied, False otherwise
207+
"""
208+
result = dictionary_utils.get_element(self.config_dictionary, SET_CLUSTER_REPLICAS)
209+
return result or False
210+
200211
def validate_configuration(self, exit_code, target_configuration_file):
201212
validation_method = self.get_validation_method()
202213
self._validate_enumerated_field(VALIDATION_METHOD, validation_method, VALIDATION_METHODS, exit_code,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ WLSDPLY-01676=Unable to find section for update in target output file "{0}"
321321
WLSDPLY-01677=Expected a map value for {0} in the target output file {1}, skipping update
322322
WLSDPLY-01678=Expected a list value for {0} in the target output file {1}, skipping update
323323
WLSDPLY-01679=Add any credential secrets that are required to pull the image
324+
WLSDPLY-01680=Set a specific replica count for this cluster
324325

325326
# wlsdeploy/util/enum.py
326327
WLSDPLY-01700=The value {0} is not a valid value of the Enum type {1}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ spec:
102102
values:
103103
- $(CLUSTER_NAME)
104104
topologyKey: "kubernetes.io/hostname"
105+
{{#setClusterReplicas}}
105106
replicas: {{{replicas}}}
107+
{{/setClusterReplicas}}
106108
{{/clusters}}
107109

108110
serverPod:

core/src/main/targetconfigs/templates/wko-domain.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ spec:
6767
values:
6868
- $(CLUSTER_NAME)
6969
topologyKey: "kubernetes.io/hostname"
70+
{{#setClusterReplicas}}
7071

7172
# The number of cluster member Managed Server instances to start for this WebLogic cluster
7273
replicas: {{{replicas}}}
74+
{{/setClusterReplicas}}
7375
{{/clusters}}
7476

7577
configuration:

core/src/test/python/wlsdeploy/tool/extract/extract_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from base_test import BaseTestCase
99
from wlsdeploy.aliases.aliases import Aliases
1010
from wlsdeploy.aliases.wlst_modes import WlstModes
11+
from wlsdeploy.json.json_translator import JsonToPython
12+
from wlsdeploy.json.json_translator import PythonToJson
1113
from wlsdeploy.logging.platform_logger import PlatformLogger
1214
from wlsdeploy.tool.extract.domain_resource_extractor import DomainResourceExtractor
1315
from wlsdeploy.util.model import Model
@@ -61,6 +63,12 @@ def testDefaultModel(self):
6163
Test that default values and information from the model
6264
are incorporated into the resulting domain resource file.
6365
"""
66+
# Configure the target to set cluster replicas
67+
target_path = os.path.join(self.TEST_OUTPUT_DIR, 'config', 'targets', 'wko', 'target.json')
68+
config = JsonToPython(target_path).parse()
69+
config['set_cluster_replicas'] = True
70+
PythonToJson(config).write_to_json_file(target_path)
71+
6472
resource = self._extract_domain_resource('1')
6573

6674
# clusters from topology should be in the domain resource file

0 commit comments

Comments
 (0)