Skip to content

Commit bdfc270

Browse files
Merge pull request #51 from oracle/actions-refactor
Actions refactor
2 parents b22056f + 62cc3b6 commit bdfc270

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+4180
-2638
lines changed

electron/app/js/appUpdater.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const i18n = require('./i18next.config');
1111
const { getLogger } = require('./wktLogging');
1212
const errorUtils = require('./errorUtils');
1313
const { sendToWindow } = require('./windowUtils');
14-
const osUtils = require('./osUtils');
1514

1615
let _isDevMode;
1716
let _downloadWindow;
@@ -35,22 +34,8 @@ function registerAutoUpdateListeners() {
3534
autoUpdater.logger.info('Download complete, install type: ' + _installType);
3635
// quit and install in this handler so MacOS updater can process the event first
3736
if(_installType === 'now') {
38-
// Working around https://github.com/electron-userland/electron-builder/issues/6418.
39-
//
40-
// This issue is fixed in [email protected] but that version suffers from
41-
// https://github.com/electron-userland/electron-builder/issues/6425, which causes
42-
// a Windows installer regression.
43-
//
44-
if (osUtils.isMac()) {
45-
autoUpdater.autoInstallOnAppQuit = false;
46-
}
4737
autoUpdater.quitAndInstall();
4838
}
49-
// On Windows, when _installType = 'onExit' and the app is installed for all users, [email protected]
50-
// doesn't work. This is fixed in [email protected] but that version suffers from
51-
// https://github.com/electron-userland/electron-builder/issues/6425, which causes
52-
// a Windows installer regression.
53-
//
5439
});
5540
}
5641

electron/app/js/fsUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ async function verifyFilesExist(baseDirectory, ...files) {
221221
const invalidFiles = [];
222222
for (const file of files) {
223223
let absolutePath = file;
224-
if (!path.isAbsolute(file)) {
224+
if (baseDirectory && !path.isAbsolute(file)) {
225225
absolutePath = path.join(baseDirectory, file);
226226
}
227227
const fileExists = await exists(absolutePath);

electron/app/js/helmUtils.js

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ async function addOrUpdateHelmChart(helmExe, repoName, repoUrl, helmOptions) {
7272
});
7373
}
7474

75-
async function installIngressController(helmExe, ingressControllerName, ingressChartName, ingressControllerNamespace, valuesData, helmChartValues, helmOptions) {
75+
async function installIngressController(helmExe, ingressControllerName, ingressChartName, ingressControllerNamespace,
76+
helmChartValues, helmOptions) {
77+
const args = [ 'install', ingressControllerName, ingressChartName, '--namespace', ingressControllerNamespace ];
78+
processHelmChartValues(args, helmChartValues);
79+
processHelmOptions(args, helmOptions);
80+
args.push('--wait');
7681

7782
const httpsProxyUrl = getHttpsProxyUrl();
7883
const bypassProxyHosts = getBypassProxyHosts();
@@ -81,28 +86,39 @@ async function installIngressController(helmExe, ingressControllerName, ingressC
8186
isSuccess: true
8287
};
8388
return new Promise(resolve => {
84-
fsUtils.writeTempFile(valuesData, { baseName: 'values', extension: '.yaml' }).then(fileName => {
85-
let args = [ 'install', ingressControllerName, ingressChartName, '--namespace', ingressControllerNamespace, '--values', fileName];
86-
processHelmChartValues(args, helmChartValues);
87-
processHelmOptions(args, helmOptions);
88-
executeFileCommand(helmExe, args, env).then(() => resolve(results)).catch(err => {
89-
results.isSuccess = false;
90-
results.reason = i18n.t('helm-install-ingress-controller-failed-error-message',
91-
{ namespace: ingressControllerNamespace, controllerName: ingressControllerName, error: getErrorMessage(err) });
92-
getLogger().error(results.reason);
93-
getLogger().error(err);
94-
resolve(results);
95-
});
96-
}).catch(err => {
89+
executeFileCommand(helmExe, args, env).then(() => resolve(results)).catch(err => {
9790
results.isSuccess = false;
98-
results.reason = i18n.t('helm-write-values-file-failed-error-message', { error: getErrorMessage(err) });
91+
results.reason = i18n.t('helm-install-ingress-controller-failed-error-message',
92+
{ namespace: ingressControllerNamespace, controllerName: ingressControllerName, error: getErrorMessage(err) });
9993
getLogger().error(results.reason);
10094
getLogger().error(err);
10195
resolve(results);
10296
});
103-
10497
});
98+
}
99+
100+
async function uninstallIngressController(helmExe, ingressName, ingressNamespace, helmOptions) {
101+
const args = [ 'uninstall', ingressName, '--namespace', ingressNamespace ];
102+
const httpsProxyUrl = getHttpsProxyUrl();
103+
const bypassProxyHosts = getBypassProxyHosts();
104+
const env = getHelmEnv(httpsProxyUrl, bypassProxyHosts, helmOptions);
105+
106+
processHelmOptions(args, helmOptions);
107+
const results = {
108+
isSuccess: true
109+
};
105110

111+
return new Promise(resolve => {
112+
executeFileCommand(helmExe, args, env).then(stdout => {
113+
getLogger().debug(stdout);
114+
resolve(results);
115+
}).catch(err => {
116+
results.isSuccess = false;
117+
results.reason = i18n.t('helm-uninstall-ingress-failed-error-message',
118+
{ controllerName: ingressName, namespace: ingressNamespace, error: getErrorMessage(err) });
119+
resolve(results);
120+
});
121+
});
106122
}
107123

108124
async function installWko(helmExe, name, namespace, helmChartValues, helmOptions) {
@@ -114,7 +130,7 @@ async function installWko(helmExe, name, namespace, helmChartValues, helmOptions
114130
return _runHelmWko(helmExe, name, namespace, args, helmOptions, 'helm-install-wko-failed-error-message');
115131
}
116132

117-
async function upgradeWko(helmExe, name, namespace, helmChartValues, helmOptions) {
133+
async function updateWko(helmExe, name, namespace, helmChartValues, helmOptions) {
118134
const args = [ 'upgrade', name, _wkoHelmChartName, '--namespace', namespace, '--reuse-values' ];
119135
processHelmChartValues(args, helmChartValues);
120136
processHelmOptions(args, helmOptions);
@@ -123,6 +139,14 @@ async function upgradeWko(helmExe, name, namespace, helmChartValues, helmOptions
123139
return _runHelmWko(helmExe, name, namespace, args, helmOptions, 'helm-upgrade-wko-failed-error-message');
124140
}
125141

142+
async function uninstallWko(helmExe, name, namespace, helmOptions) {
143+
const args = [ 'uninstall', name, '--namespace', namespace ];
144+
processHelmOptions(args, helmOptions);
145+
146+
return _runHelmWko(helmExe, name, namespace, args, helmOptions, 'helm-uninstall-wko-failed-error-message');
147+
}
148+
149+
126150
async function helmListAllNamespaces(helmExe, helmOptions) {
127151
const args = [ 'list', '--all-namespaces' ];
128152
processHelmOptions(args, helmOptions);
@@ -245,9 +269,11 @@ function formatArrayOfObjectsSetArgument(name, objectArray) {
245269
module.exports = {
246270
addOrUpdateWkoHelmChart,
247271
installWko,
248-
upgradeWko,
272+
uninstallWko,
273+
updateWko,
249274
helmListAllNamespaces,
250275
installIngressController,
276+
uninstallIngressController,
251277
addOrUpdateHelmChart,
252278
validateHelmExe
253279
};

electron/app/js/ipcRendererPreload.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,14 @@ contextBridge.exposeInMainWorld(
7070
'start-push-aux-image',
7171
'start-k8s-verify-connection',
7272
'start-wko-install',
73+
'start-wko-uninstall',
74+
'start-wko-update',
7375
'start-ingress-install',
76+
'start-ingress-uninstall',
7477
'add-ingress-routes',
7578
'app-download-progress',
7679
'start-k8s-domain-deploy',
80+
'start-k8s-domain-undeploy',
7781
'get-wko-domain-status',
7882
'start-app-quit',
7983
'start-window-close'
@@ -164,28 +168,31 @@ contextBridge.exposeInMainWorld(
164168
'k8s-apply',
165169
'k8s-label-namespace',
166170
'k8s-get-service-details',
167-
'k8s-get-operator-version-from-dm',
171+
'k8s-get-operator-version-from-domain-config-map',
168172
'k8s-get-k8s-config',
169173
'k8s-get-k8s-cluster-info',
170174
'k8s-get-wko-domain-status',
171175
'k8s-get-operator-status',
172176
'k8s-get-operator-log',
173177
'helm-add-wko-chart',
174178
'helm-install-wko',
175-
'helm-upgrade-wko',
179+
'helm-uninstall-wko',
180+
'helm-update-wko',
176181
'get-ingress-tlskeyfile',
177182
'get-ingress-tlscertfile',
178183
'helm-list-all-namespaces',
179184
'helm-add-update-repo',
180185
'helm-install-ingress-controller',
186+
'helm-uninstall-ingress-controller',
181187
'validate-openssl-exe',
182188
'k8s-create-tls-secret',
183189
'get-tls-keyfile',
184190
'get-tls-certfile',
185191
'k8s-delete-object',
186192
'openssl-generate-certs',
187193
'validate-k8s-namespaces-exist',
188-
'validate-wko-domain-exist'
194+
'validate-wko-domain-exist',
195+
'domain-undeploy-scope-prompt'
189196
];
190197
return new Promise((resolve, reject) => {
191198
if (validChannels.includes(channel)) {
@@ -211,6 +218,7 @@ contextBridge.exposeInMainWorld(
211218
getDockerFilePath: () => fsUtils.getExecutableFilePath('docker', exeMode),
212219
getPodmanFilePath: () => fsUtils.getExecutableFilePath('podman', exeMode),
213220
getKubeConfig: () => k8sUtils.getKubeConfig(),
221+
getImageTagComponents: (imageTag) => k8sUtils.splitImageNameAndVersion(imageTag),
214222
getKubectlFilePath: () => fsUtils.getExecutableFilePath('kubectl'),
215223
getHelmFilePath: () => fsUtils.getExecutableFilePath('helm', exeMode),
216224
getOpenSSLFilePath: () => fsUtils.getExecutableFilePath('openssl'),

electron/app/js/k8sUtils.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,45 @@ function getRegistryAddressFromImageTag(tag) {
3939
return result;
4040
}
4141

42+
// Need to handle all possible flavors of the tag:
43+
//
44+
// - my-registry/foo/image
45+
// - my-registry/foo/image:1.0
46+
// - 2001:0db8:85a3:0000:0000:8a2e:0370:7334/foo/image
47+
// - 2001:0db8:85a3:0000:0000:8a2e:0370:7334/foo/image:1.0
48+
// - my-registry:8888/foo/image
49+
// - my-registry:8888/foo/image:1.0
50+
//
51+
function splitImageNameAndVersion(imageTag) {
52+
let imageName = imageTag;
53+
let imageVersion = 'latest';
54+
if (imageTag) {
55+
const lastColon = imageTag.lastIndexOf(':');
56+
const firstSlash = imageTag.indexOf('/');
57+
58+
// If no colon, then the imageTag is the imageName...
59+
if (lastColon !== -1) {
60+
// There may or may not be a slash in the image tag. The important
61+
// thing we have to check is if the first slash (if there is one)
62+
// is before or after the last colon.
63+
//
64+
// If before, the colon found is separating the image name from the version.
65+
//
66+
// If after, the colon found is part of the registry address. It could be
67+
// separating the port number from the DNS name/IP address, or it could be
68+
// part of an IPv6 address. Either way, there is no version specified.
69+
//
70+
if (firstSlash < lastColon) {
71+
imageName = imageTag.slice(0, lastColon);
72+
imageVersion = imageTag.slice(lastColon + 1);
73+
}
74+
}
75+
}
76+
return { name: imageName, version: imageVersion };
77+
}
78+
4279
module.exports = {
4380
getKubeConfig,
44-
getRegistryAddressFromImageTag
81+
getRegistryAddressFromImageTag,
82+
splitImageNameAndVersion
4583
};

electron/app/js/kubectlUtils.js

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const { getLogger } = require('./wktLogging');
1414
const { getHttpsProxyUrl, getBypassProxyHosts } = require('./userSettings');
1515
const { getErrorMessage } = require('./errorUtils');
1616
const osUtils = require('./osUtils');
17+
const k8sUtils = require('./k8sUtils');
1718

1819
/* global process */
1920
async function validateKubectlExe(kubectlExe) {
@@ -80,8 +81,7 @@ async function setCurrentContext(kubectlExe, context, options) {
8081
resolve(results);
8182
}).catch(err => {
8283
results.isSuccess = false;
83-
results.reason = i18n.t('kubectl-use-context-error-message',
84-
{ context: context, error: getErrorMessage(err) });
84+
results.reason = i18n.t('kubectl-use-context-error-message', { context: context, error: getErrorMessage(err) });
8585
resolve(results);
8686
});
8787
});
@@ -103,7 +103,7 @@ async function getK8sConfigView(kubectlExe, options) {
103103
}).catch(err => {
104104
results.isSuccess = false;
105105
results.reason =
106-
i18n.t('kubectl-config-view-error-message',{ error: getErrorMessage(err) });
106+
i18n.t('kubectl-config-view-error-message', { error: getErrorMessage(err) });
107107
resolve(results);
108108
});
109109
});
@@ -125,7 +125,7 @@ async function getK8sClusterInfo(kubectlExe, options) {
125125
}).catch(err => {
126126
results.isSuccess = false;
127127
results.reason =
128-
i18n.t('kubectl-config-view-error-message',{ error: getErrorMessage(err) });
128+
i18n.t('kubectl-cluster-info-error-message', { error: getErrorMessage(err) });
129129
resolve(results);
130130
});
131131
});
@@ -147,7 +147,7 @@ async function getWkoDomainStatus(kubectlExe, domainUID, domainNamespace, option
147147
}).catch(err => {
148148
results.isSuccess = false;
149149
results.reason =
150-
i18n.t('kubectl-get-wko-domain-status-error-message',{ error: getErrorMessage(err) });
150+
i18n.t('kubectl-get-wko-domain-status-error-message', { error: getErrorMessage(err) });
151151
resolve(results);
152152
});
153153
});
@@ -169,7 +169,7 @@ async function getOperatorStatus(kubectlExe, operatorNamespace, options) {
169169
}).catch(err => {
170170
results.isSuccess = false;
171171
results.reason =
172-
i18n.t('kubectl-get-operator-status-error-message',{ error: getErrorMessage(err) });
172+
i18n.t('kubectl-get-operator-status-error-message', { error: getErrorMessage(err) });
173173
resolve(results);
174174
});
175175
});
@@ -192,13 +192,13 @@ async function getOperatorLogs(kubectlExe, operatorNamespace, options) {
192192
}).catch(err => {
193193
results.isSuccess = false;
194194
results.reason =
195-
i18n.t('kubectl-get-operator-logs-error-message',{ error: getErrorMessage(err) });
195+
i18n.t('kubectl-get-operator-logs-error-message', { error: getErrorMessage(err) });
196196
resolve(results);
197197
});
198198
});
199199
}
200200

201-
async function getOperatorVersionFromDomainCM(kubectlExe, domainNamespace, options) {
201+
async function getOperatorVersionFromDomainConfigMap(kubectlExe, domainNamespace, options) {
202202
const args = [ 'get', 'configmap', 'weblogic-scripts-cm', '-n', domainNamespace, '-o', 'jsonpath={.metadata.labels.weblogic\\.operatorVersion}'];
203203

204204
const httpsProxyUrl = getHttpsProxyUrl();
@@ -222,7 +222,6 @@ async function getOperatorVersionFromDomainCM(kubectlExe, domainNamespace, optio
222222
});
223223
}
224224

225-
226225
async function verifyClusterConnectivity(kubectlExe, options) {
227226
const args = [ 'version', '--short' ];
228227
const httpsProxyUrl = getHttpsProxyUrl();
@@ -388,8 +387,16 @@ async function createNamespaceIfNotExists(kubectlExe, namespace, options) {
388387
}
389388

390389
async function deleteObjectIfExists(kubectlExe, namespace, object, kind, options) {
391-
const getArgs = [ 'get', '-n', namespace, kind, object, '--output=json' ];
392-
const deleteArgs = [ 'delete', kind, object, '-n', namespace ];
390+
let getArgs;
391+
let deleteArgs;
392+
if (kind === 'namespace') {
393+
getArgs = [ 'get', kind, object, '--output=json' ];
394+
deleteArgs = [ 'delete', kind, object ];
395+
} else {
396+
getArgs = [ 'get', '-n', namespace, kind, object, '--output=json' ];
397+
deleteArgs = [ 'delete', kind, object, '-n', namespace ];
398+
}
399+
393400
const httpsProxyUrl = getHttpsProxyUrl();
394401
const bypassProxyHosts = getBypassProxyHosts();
395402

@@ -644,23 +651,13 @@ function getOperatorImageTag(operatorDeployment) {
644651
}
645652

646653
function getOperatorImageWithoutVersion(imageTag) {
647-
let imageName = imageTag;
648-
if (imageTag) {
649-
imageName = imageTag.split(':')[0];
650-
}
651-
return imageName;
654+
const imageComponents = k8sUtils.splitImageNameAndVersion(imageTag);
655+
return imageComponents.name;
652656
}
653657

654658
function getOperatorImageVersion(imageTag) {
655-
let version;
656-
if (imageTag) {
657-
if (imageTag.indexOf(':') !== -1) {
658-
version = imageTag.split(':')[1];
659-
} else {
660-
version = 'latest';
661-
}
662-
}
663-
return version;
659+
const imageComponents = k8sUtils.splitImageNameAndVersion(imageTag);
660+
return imageComponents.version;
664661
}
665662

666663
function doesNamedObjectExist(objectListJson, name) {
@@ -777,7 +774,7 @@ module.exports = {
777774
getK8sClusterInfo,
778775
getWkoDomainStatus,
779776
getOperatorStatus,
780-
getOperatorVersionFromDomainCM,
777+
getOperatorVersionFromDomainConfigMap,
781778
getOperatorLogs,
782779
validateNamespacesExist,
783780
validateDomainExist,

0 commit comments

Comments
 (0)