Skip to content

Commit 06a4c0b

Browse files
authored
Changes for Verrazzano (#713)
* added new target type, wko * added execute permissions to generated shell script from vz target * corrected weblogic credential secret name for models targeted to WebLogic Operator * changed generated Verrazzano binding defaults for DNS name to "*" * changed generated Verrazzano binding namepace from default to {domainUid}-ns * corrected log folder name from jcslcm-logs to wdt-logs
1 parent 8114227 commit 06a4c0b

File tree

13 files changed

+245
-28
lines changed

13 files changed

+245
-28
lines changed

core/src/main/java/oracle/weblogic/deploy/logging/WLSDeployLoggingConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ private static File findLoggingDirectory(String programName) {
344344

345345
if (!found && tmpDir.canWrite()) {
346346
try {
347-
File parentDir = tmpDir.getCanonicalFile().getParentFile();
348-
logDir = FileUtils.createTempDirectory(parentDir, "jcslcm-logs");
347+
File parentDir = tmpDir.getCanonicalFile();
348+
logDir = FileUtils.createTempDirectory(parentDir, "wdt-logs");
349349
found = true;
350350
} catch (IOException ioe) {
351351
String message = MessageFormat.format("{0} failed to create temporary logs directory in {1}: {2}",

core/src/main/java/oracle/weblogic/deploy/util/FileUtils.java

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@
1313
import java.io.InputStream;
1414
import java.nio.file.Files;
1515
import java.nio.file.Paths;
16+
import java.nio.file.attribute.PosixFilePermission;
1617
import java.security.MessageDigest;
1718
import java.security.NoSuchAlgorithmException;
1819
import java.util.ArrayList;
1920
import java.util.Arrays;
21+
import java.util.HashSet;
2022
import java.util.List;
2123
import java.util.Locale;
24+
import java.util.Set;
2225
import java.util.zip.ZipEntry;
2326
import java.util.zip.ZipInputStream;
24-
2527
import javax.xml.bind.DatatypeConverter;
2628

2729
import oracle.weblogic.deploy.exception.ExceptionHelper;
@@ -783,4 +785,52 @@ public boolean accept(File dir, String name) {
783785
}
784786

785787

788+
/**
789+
* Convert an octal number into Posix File Permisions.
790+
* @param octals 3 octal digits representing posix file permissions rwxrwxrwx
791+
* @return a set of Posix file permissions
792+
*/
793+
@SuppressWarnings("OctalInteger")
794+
static Set<PosixFilePermission> getPermissions(int octals) {
795+
Set<PosixFilePermission> result = new HashSet<>();
796+
if ( (0400 & octals) > 0) {
797+
result.add(PosixFilePermission.OWNER_READ);
798+
}
799+
if ( (0200 & octals) > 0) {
800+
result.add(PosixFilePermission.OWNER_WRITE);
801+
}
802+
if ( (0100 & octals) > 0) {
803+
result.add(PosixFilePermission.OWNER_EXECUTE);
804+
}
805+
if ( (0040 & octals) > 0) {
806+
result.add(PosixFilePermission.GROUP_READ);
807+
}
808+
if ( (0020 & octals) > 0) {
809+
result.add(PosixFilePermission.GROUP_WRITE);
810+
}
811+
if ( (0010 & octals) > 0) {
812+
result.add(PosixFilePermission.GROUP_EXECUTE);
813+
}
814+
if ( (0004 & octals) > 0) {
815+
result.add(PosixFilePermission.OTHERS_READ);
816+
}
817+
if ( (0002 & octals) > 0) {
818+
result.add(PosixFilePermission.OTHERS_WRITE);
819+
}
820+
if ( (0001 & octals) > 0) {
821+
result.add(PosixFilePermission.OTHERS_EXECUTE);
822+
}
823+
return result;
824+
}
825+
826+
/**
827+
* Set OS file permissions given an Octal permission set.
828+
* Needed due to Jython 2.2 did not offer a os.chmod function.
829+
* @param path file name to be changed
830+
* @param octals octal number set like OS chmod permissions
831+
* @throws IOException if permissions update fails
832+
*/
833+
public static void chmod(String path, int octals) throws IOException {
834+
Files.setPosixFilePermissions(Paths.get(path), getPermissions(octals));
835+
}
786836
}

core/src/main/python/prepare_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ def __substitute_password_with_token(self, model_path, attribute_name, validatio
310310

311311
# for normal secrets, assign the secret name to the attribute
312312
if credentials_method == SECRETS_METHOD:
313-
model_value = target_configuration_helper.format_as_secret_token(cache_key)
313+
model_value = target_configuration_helper.format_as_secret_token(cache_key,
314+
self.model_context.get_target_configuration())
314315
self.cache[cache_key] = ''
315316

316317
# for config override secrets, assign a placeholder password to the attribute.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@ def _process_attribute(self, model, attribute, location, injector_values):
400400
# for credentials_method: secrets, assign a secret token to the attribute
401401
if credentials_method == SECRETS_METHOD \
402402
and variable_value == alias_constants.PASSWORD_TOKEN:
403-
model[attribute] = target_configuration_helper.format_as_secret_token(variable_name)
403+
model[attribute] = target_configuration_helper.format_as_secret_token(variable_name,
404+
self.__model_context.get_target_configuration())
404405

405406
# for config_override_secrets, assign a placeholder value to the attribute
406407
elif credentials_method == CONFIG_OVERRIDES_SECRETS_METHOD \

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
# types for credential method
99
CREDENTIALS_METHOD = "credentials_method"
1010

11+
# Overrides the Kubernetes secret name for the WebLogic admin user credential
12+
WLS_CREDENTIALS_NAME = "wls_credentials_name"
13+
1114
# put secret tokens in the model, and build a script to create the secrets.
1215
SECRETS_METHOD = 'secrets'
1316

@@ -43,6 +46,13 @@ def get_credentials_method(self):
4346
"""
4447
return dictionary_utils.get_element(self.config_dictionary, CREDENTIALS_METHOD)
4548

49+
def get_wls_credentials_name(self):
50+
"""
51+
Returns the method for handling credentials in the model.
52+
:return: the method for handling credentials
53+
"""
54+
return dictionary_utils.get_element(self.config_dictionary, WLS_CREDENTIALS_NAME)
55+
4656
def get_additional_output_types(self):
4757
"""
4858
Return the additional output types for this target environment.

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

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
# Shared methods for using target environments (-target abc).
55
# Used by discoverDomain and prepareModel.
66
import re
7-
87
import os
98

9+
from oracle.weblogic.deploy.util import FileUtils
10+
1011
from wlsdeploy.aliases.model_constants import DEFAULT_WLS_DOMAIN_NAME
1112
from wlsdeploy.aliases.model_constants import JDBC_DRIVER_PARAMS
1213
from wlsdeploy.aliases.model_constants import JDBC_RESOURCE
@@ -152,36 +153,31 @@ def generate_k8s_script(model_context, token_dictionary, model_dictionary):
152153
k8s_script.write(command_string + nl)
153154

154155
k8s_script.close()
156+
FileUtils.chmod(k8s_file, 0750)
155157

156-
157-
def format_as_secret_token(variable_name):
158+
def format_as_secret_token(variable_name, target_config):
158159
"""
159160
Format the variable as a secret name token for use in a model.
160161
:param variable_name: variable name in dot separated format
161162
:return: formatted name
162163
"""
164+
normal_secret_format = '@@SECRET:@@ENV:DOMAIN_UID@@-%s:%s@@'
163165
name_lower_tokens = variable_name.lower().split('.')
164166
if len(name_lower_tokens) == 1:
165167
admin_lower_token = name_lower_tokens[0]
166168
if admin_lower_token in ['adminusername', 'adminpassword']:
167-
# these should just be 'username' and 'password', to match secrets script
169+
# substring removes "admin" and keeps just 'username' or 'password', to match secrets script
168170
admin_token = admin_lower_token[5:]
169-
return get_secret_model_token(WEBLOGIC_CREDENTIALS_SECRET_NAME, admin_token)
171+
secret_name = target_config.get_wls_credentials_name()
172+
if secret_name == None:
173+
return normal_secret_format % (WEBLOGIC_CREDENTIALS_SECRET_NAME, admin_token)
174+
else:
175+
# if the target configuration declares a special name for the WebLogic credential secret
176+
return '@@SECRET:%s:%s@@' % (secret_name, admin_token)
170177

171178
# for paired and single secrets, password key is always named "password"
172179
secret_name = "password"
173-
174-
return get_secret_model_token('-'.join(name_lower_tokens[:-1]), secret_name)
175-
176-
177-
def get_secret_model_token(name, key):
178-
"""
179-
Returns the substitution string to be put in the model for a secret value.
180-
:param name: the name of the secret
181-
:param key: the key of the secret
182-
:return: the substitution string
183-
"""
184-
return '@@SECRET:@@ENV:DOMAIN_UID@@-%s:%s@@' % (name, key)
180+
return normal_secret_format % ('-'.join(name_lower_tokens[:-1]), secret_name)
185181

186182

187183
def get_secret_name_for_location(location, domain_uid, aliases):

core/src/main/resources/oracle/weblogic/deploy/targets/vz/binding.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ spec:
1111
placement:
1212
- name: local
1313
namespaces:
14-
- name: default
14+
- name: "{{{domainUid}}}-ns"
1515
components:
1616
- name: {{{domainName}}}
1717
ingressBindings:
1818
- name: "{{{domainPrefix}}}-ingress"
19-
dnsName: "todo.vz.oracledx.com"
19+
dnsName: "*"
2020
{{#hasDatabases}}
2121
databaseBindings:
2222
{{/hasDatabases}}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
},
77
"variable_injectors" : {"PORT": {},"HOST": {},"URL": {}},
88
"validation_method" : "lax",
9-
"credentials_method" : "config_override_secrets",
9+
"credentials_method" : "secrets",
10+
"wls_credentials_name" : "__weblogic-credentials__",
1011
"additional_output" : "vz"
1112
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"model_filters" : {
3+
"discover": [
4+
{ "name": "wko_prep", "path": "@@TARGET_CONFIG_DIR@@/wko_operator_filter.py" }
5+
]
6+
},
7+
"variable_injectors" : {"PORT": {},"HOST": {},"URL": {}},
8+
"validation_method" : "lax",
9+
"credentials_method" : "secrets",
10+
"wls_credentials_name" : "__weblogic-credentials__"
11+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright (c) 2020, Oracle Corporation and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
#
4+
# ------------
5+
# Description:
6+
# ------------
7+
# This is a WDT filter for primordial domain creation. It filters out all resources and
8+
# apps deployments, leaving only the domainInfo and admin server in topology.
9+
#
10+
def filter_model(model):
11+
__cleanup_topology(model)
12+
__cleanup_resources(model)
13+
14+
def __cleanup_resources(model):
15+
if model and 'resources' in model:
16+
resources = model['resources']
17+
18+
for delthis in [ 'PartitionWorkManager', 'Partition', 'ResourceGroup', 'ResourceGroupTemplate', 'VirtualHost',
19+
'ResourceManager', 'ResourceManagement' ]:
20+
if resources.has_key(delthis):
21+
del resources[delthis]
22+
23+
def __cleanup_topology(model):
24+
if model and 'topology' in model:
25+
topology = model['topology']
26+
for delthis in [ 'NMProperties', 'VirtualTarget', 'Machine']:
27+
if topology.has_key(delthis):
28+
del topology[delthis]
29+
30+
if topology.has_key('Cluster'):
31+
clusters = topology['Cluster']
32+
for cluster in clusters:
33+
for delthis in ['MigrationBasis', 'CandidateMachinesForMigratableServer', 'DatabaseLessLeasingBasis',
34+
'ClusterMessagingMode']:
35+
if clusters[cluster].has_key(delthis):
36+
del clusters[cluster][delthis]
37+
38+
if topology.has_key('Server'):
39+
servers = topology['Server']
40+
for server in servers:
41+
for delthis in ['Machine', 'CandidateMachine', 'AutoMigrationEnabled']:
42+
if servers[server].has_key(delthis):
43+
del servers[server][delthis]
44+
45+
if topology.has_key('SecurityConfiguration'):
46+
for delthis in ['NodeManagerPasswordEncrypted', 'NodeManagerUsername' ]:
47+
if topology['SecurityConfiguration'].has_key(delthis):
48+
del topology['SecurityConfiguration'][delthis]
49+
if len(topology['SecurityConfiguration'].keys()) == 0:
50+
del topology['SecurityConfiguration']
51+
52+
if topology.has_key('ServerTemplate'):
53+
server_templates = topology['ServerTemplate']
54+
for server_template in server_templates:
55+
server_templates[server_template]['AutoMigrationEnabled'] = False
56+
else:
57+
topology['ServerTemplate'] = {}
58+
server_templates = topology['ServerTemplate']
59+
if topology.has_key('Cluster'):
60+
clusters = topology['Cluster']
61+
for cluster in clusters:
62+
server_templates[cluster] = {}
63+
server_template = server_templates[cluster]
64+
server_template['Cluster'] = cluster
65+
server_template['AutoMigrationEnabled'] = False
66+
67+

0 commit comments

Comments
 (0)