Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kubernetes Environment Check #18588

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions ui/app/adapters/kubernetes/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { encodePath } from 'vault/utils/path-encoding-helpers';
export default class KubernetesConfigAdapter extends ApplicationAdapter {
namespace = 'v1';

getURL(backend) {
return `${this.buildURL()}/${encodePath(backend)}/config`;
getURL(backend, path = 'config') {
return `${this.buildURL()}/${encodePath(backend)}/${path}`;
}
urlForUpdateRecord(name, modelName, snapshot) {
return this.getURL(snapshot.attr('backend'));
Expand Down Expand Up @@ -33,7 +33,6 @@ export default class KubernetesConfigAdapter extends ApplicationAdapter {
return this.ajax(url, 'POST', { data }).then(() => data);
}
checkConfigVars(backend) {
// this endpoint has yet to be created so this url is a mock for now and wired up in the mirage handler
return this.ajax(`${this.getURL(backend)}/vars`, 'GET');
return this.ajax(`${this.getURL(backend, 'check')}`, 'GET');
}
}
16 changes: 9 additions & 7 deletions ui/mirage/handlers/kubernetes.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { Response } from 'miragejs';

// yet to be defined endpoint
// exporting to use in tests in case it changes
export const configVarUri = '/:path/config/vars';

export default function (server) {
const getRecord = (schema, req, dbKey) => {
const { path, name } = req.params;
Expand Down Expand Up @@ -41,10 +37,16 @@ export default function (server) {
server.delete('/:path/config', (schema, req) => {
return deleteRecord(schema, req, 'kubernetesConfigs');
});
// to be defined endpoint for checking for environment variables necessary for inferred config
server.get(configVarUri, () => {
// endpoint for checking for environment variables necessary for inferred config
server.get('/:path/check', () => {
const response = {};
const status = Math.random() > 0.5 ? 204 : 404;
return new Response(status, {});
if (status === 404) {
response.errors = [
'Missing environment variables: KUBERNETES_SERVICE_HOST, KUBERNETES_SERVICE_PORT_HTTPS',
];
}
return new Response(status, response);
});
server.get('/:path/roles', (schema) => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { setupEngine } from 'ember-engines/test-support';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { render, click, waitUntil, find, fillIn } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { configVarUri } from '../../../../../mirage/handlers/kubernetes';
import { Response } from 'miragejs';
import sinon from 'sinon';

Expand Down Expand Up @@ -58,7 +57,7 @@ module('Integration | Component | kubernetes | Page::Configure', function (hooks
assert.expect(8);

let status = 404;
this.server.get(configVarUri, () => {
this.server.get('/:path/check', () => {
assert.ok(
waitUntil(() => find('[data-test-config] button').disabled),
'Button is disabled while request is in flight'
Expand Down