Skip to content

Commit

Permalink
feat: remove deprecation warnings from openshift rest client (#398)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The api for the openshift rest client has changed slightly, but there should be no nodeshift api changes

While this doesn't have to be a semver-major release, there might be some unexpected bugs.  One known issue, is we are no longer passing a custom config to the rest client.  If this removal causes issues we can work on a way to put it back in

fixes #377

* test(nodeshift-config): update tests to work with the new client

* squash: remove those tmp files
  • Loading branch information
lholmquist committed Jan 15, 2020
1 parent cb62bf8 commit 2b97f49
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 157 deletions.
2 changes: 1 addition & 1 deletion lib/build-watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = async function watchBuildLog (config, build) {
await pingEndpoint(config, build);
// Then do the follow endpoint

const response = config.openshiftRestClient.api.v1.ns(config.namespace.name).pods(`${build}-build`).log.getStream({ qs: { follow: true, pretty: false } });
const response = await config.openshiftRestClient.api.v1.ns(config.namespace.name).pods(`${build}-build`).log.getByteStream({ qs: { follow: true, pretty: false } });

response.on('data', (chunk) => {
logger.trace(chunk.toString('utf8').trim());
Expand Down
16 changes: 11 additions & 5 deletions lib/nodeshift-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'use strict';

const logger = require('./common-log')();
const { OpenshiftClient: restClient, config: k8sConfig } = require('openshift-rest-client');
const { OpenshiftClient: openshiftRestClient } = require('openshift-rest-client');
const fs = require('fs');
const { promisify } = require('util');
const readFile = promisify(fs.readFile);
Expand All @@ -32,10 +32,16 @@ async function setup (options = {}) {
const projectPackage = JSON.parse(await readFile(`${options.projectLocation}/package.json`, { encoding: 'utf8' }));
// const config = await openshiftConfigLoader(Object.assign({}, { tryServiceAccount: options.tryServiceAccount, configLocation: options.configLocation }));
// TODO: pass in different configs like in the openshift-rest-client
const kubeConfig = k8sConfig.fromKubeconfig(options.config);
const restClient = await openshiftRestClient(/* TODO: pass custom configs */);
const kubeConfig = restClient.kubeconfig;

const currentContext = kubeConfig.getCurrentContext();
const contexts = kubeConfig.getContexts();

const currentCluster = contexts.find(context => context.name === currentContext);
const config = {
namespace: {
name: kubeConfig.namespace
name: currentCluster.namespace
}
};

Expand All @@ -54,7 +60,7 @@ async function setup (options = {}) {
delete options.namespace;
}

logger.info(`using namespace ${config.namespace.name} at ${kubeConfig.url}`);
logger.info(`using namespace ${config.namespace.name} at ${kubeConfig.getCurrentCluster().server}`);

if (!projectPackage.name.match(/^[a-z][0-9a-z-]+[0-9a-z]$/)) {
throw new Error('"name" in package.json can only consist lower-case letters, numbers, and dashes. It must start with a letter and can\'t end with a -.');
Expand All @@ -73,7 +79,7 @@ async function setup (options = {}) {
// Since we are only doing s2i builds(atm), append the s2i bit to the end
buildName: `${projectPackage.name}-s2i`,
// Load an instance of the Openshift Rest Client, https://www.npmjs.com/package/openshift-rest-client
openshiftRestClient: await restClient({ config: kubeConfig })
openshiftRestClient: restClient
}, options);
}

Expand Down
104 changes: 54 additions & 50 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"js-yaml": "~3.13.1",
"lodash": "^4.17.4",
"mkdirp": "^0.5.1",
"openshift-rest-client": "~2.3.0",
"openshift-rest-client": "~3.1.0",
"rimraf": "^3.0.0",
"tar": "~5.0.5",
"yargs": "^15.0.2"
Expand Down

0 comments on commit 2b97f49

Please sign in to comment.