Skip to content
This repository has been archived by the owner on Feb 28, 2020. It is now read-only.

Commit

Permalink
fix(test): Look for kube secrets in bindings.yaml
Browse files Browse the repository at this point in the history
Kube secrets for provisioned services were moved out of deployment.yaml into a bindings.yaml file.
Tests need to look for those attributes there.

ibm-developer/generator-ibm-cloud-enablement#275
  • Loading branch information
Erin Schnabel committed May 23, 2018
1 parent a74b3e2 commit 5f65e3f
Show file tree
Hide file tree
Showing 9 changed files with 5,014 additions and 3,115 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ jdk:
before_install:
- wget http://services.gradle.org/distributions/gradle-3.5-bin.zip
- wget https://github.com/github/hub/releases/download/v2.2.9/hub-linux-386-2.2.9.tgz
- wget https://kubernetes-helm.storage.googleapis.com/helm-v2.7.2-linux-amd64.tar.gz
- shasum -a 256 -c ./sha256.txt
- unzip -qq gradle-3.5-bin.zip
- tar -xvzf hub-linux-386-2.2.9.tgz
- export GRADLE_HOME=$PWD/gradle-3.5
- export PATH=$GRADLE_HOME/bin:$PWD/hub-linux-386-2.2.9/bin/:$PATH
- tar -xvf helm-v2.7.2-linux-amd64.tar.gz
- export PATH=$GRADLE_HOME/bin:$PWD/hub-linux-386-2.2.9/bin/:$PWD/linux-amd64:$PATH
- gradle -v
- nvm install 6.9.1
- cd ./generator-java
Expand Down
25 changes: 25 additions & 0 deletions generator-java/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space

[*.{md}]
indent_size = 2
trim_trailing_whitespace = false

[*.java]
indent_size = 4

[*.js]
indent_size = 2

[*.{html,rb,css,xml,sh,yaml,yml}]
indent_size = 2
3 changes: 2 additions & 1 deletion generator-java/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules/
# If eslint goes into this dir it will read package.json as a config file
# We either rename the package.json template, or we don't lint this dir
test/resources/*
generators/app/templates/*
generators/app/templates/*
coverage/
3 changes: 1 addition & 2 deletions .eslintrc.yml → generator-java/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ env:
mocha: true

rules:
strict: 2
strict: 0
no-var: 2
no-console: 0
indent: ["error", 2, { "SwitchCase": 1}]

extends: eslint:recommended
2 changes: 1 addition & 1 deletion generator-java/lib/assert/internal/assert.core.bx.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class AssertBx extends Assert {
})
it('should create file ' + constant.LOCALDEV_FILE + ' with Object Storage credentials', function () {
assert.fileContent(constant.LOCALDEV_FILE, '"object_storage_project": "objectStorage-project"')
assert.fileContent(constant.LOCALDEV_FILE, '"object_storage_user_id": "objectStorage-userId"')
assert.fileContent(constant.LOCALDEV_FILE, '"object_storage_userId": "objectStorage-userId"')
assert.fileContent(constant.LOCALDEV_FILE, '"object_storage_password": "objectStorage-password"')
assert.fileContent(constant.LOCALDEV_FILE, '"object_storage_auth_url": "objectStorage-url"')
assert.fileContent(constant.LOCALDEV_FILE, '"object_storage_domainName": "objectStorage-domainName"')
Expand Down
37 changes: 23 additions & 14 deletions generator-java/lib/assert/internal/assert.kube.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ test_kube.test = function(appName, exists, framework, createType, cloudantExists
const prefix = exists ? 'generates ' : 'does not generate ';
const check = exists ? assert.file : assert.noFile;
const VALUES_YML = 'chart/' + appName.toLowerCase() + '/values.yaml';
const BINDINGS_YML = 'chart/' + appName.toLowerCase() + '/bindings.yaml';
const CHART_YML = 'chart/' + appName.toLowerCase() + '/Chart.yaml';
const DEPLOYMENT_YML = 'chart/' + appName.toLowerCase() + '/templates/deployment.yaml';
const SERVICE_YML = 'chart/' + appName.toLowerCase() + '/templates/service.yaml';
Expand Down Expand Up @@ -76,24 +77,29 @@ test_kube.test = function(appName, exists, framework, createType, cloudantExists
check(CHART_YML);
check(DEPLOYMENT_YML);
check(SERVICE_YML);

if(exists) {
const valuesyml = yml.safeLoad(fs.readFileSync(VALUES_YML, 'utf8'));
const chartyml = yml.safeLoad(fs.readFileSync(CHART_YML, 'utf8'));
const bindingsyml = yml.safeLoad(fs.readFileSync(BINDINGS_YML, 'utf8'));

const rawdeploymentyml = fs.readFileSync(DEPLOYMENT_YML, 'utf8');
//comment out helm conditionals so it can be parsed by js-yaml
const newdeploymentyml = rawdeploymentyml.replace('{{ if', '#').replace('{{ else', '#').replace('{{ end', '#');
const newdeploymentyml = rawdeploymentyml
.replace('{{ if', '#').replace('{{ else', '#').replace('{{ end', '#')
.replace('{{- if', '#').replace('{{- end', '#').replace('{{.File','#');
const deploymentyml = yml.safeLoad(newdeploymentyml);

const rawserviceyml = fs.readFileSync(SERVICE_YML, 'utf8');
const newserviceyml = rawserviceyml.replace('"+" "_"', '\\"+\\" \\"_\\"');
const serviceyml = yml.safeLoad(newserviceyml);

// values.yaml
assertYmlContent(valuesyml.image.repository, appName.toLowerCase(), 'valuesyml.image.repository');

// Chart.yaml
assertYmlContent(chartyml.name, appName.toLowerCase(), 'chartyml.name');

// deployment.yaml
if(framework === LIBERTY) {
if(createType === 'basicweb') {
Expand All @@ -105,6 +111,7 @@ test_kube.test = function(appName, exists, framework, createType, cloudantExists
if(framework === SPRING) {
assertYmlContent(deploymentyml.spec.template.spec.containers[0].readinessProbe.httpGet.path, '/health', 'deploymentyml.spec.template.spec.containers[0].readinessProbe.httpGet.path');
}

assertYmlContent(deploymentyml.metadata.name, '{{ .Chart.Name }}-deployment', 'deploymentyml.metadata.name');
assertYmlContent(deploymentyml.metadata.labels.chart, '{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}', 'deploymentyml.metadata.labels.chart');
assert.fileContent(DEPLOYMENT_YML, ' replicas: {{ .Values.replicaCount }}');
Expand All @@ -113,24 +120,26 @@ test_kube.test = function(appName, exists, framework, createType, cloudantExists
assert.fileContent(DEPLOYMENT_YML, ' - name: "{{ .Chart.Name }}"');
assertYmlContent(deploymentyml.spec.template.spec.containers[0].image, '{{ .Values.image.repository }}:{{ .Values.image.tag }}', 'deploymentyml.spec.template.spec.containers[0].image');
assert.fileContent(DEPLOYMENT_YML, ' imagePullPolicy: {{ .Values.image.pullPolicy }}');

// There should be bindings (for secrets) in the deployment.yml
const cloudantBinding = deploymentyml.spec.template.spec.containers[0].env.filter(element => element.name === "service_cloudant");
assert.equal(cloudantBinding.length > 0, cloudantExists,
DEPLOYMENT_YML + ' should' +(cloudantExists ? '' : ' not') + ' contain cloudant credentials');

// There should be bindings (for secrets) in the bindings.yml
if ( cloudantExists ) {
const cloudantBinding = bindingsyml.filter(element => element.name === "service_cloudant");
assert.equal(cloudantBinding.length > 0, cloudantExists,
BINDINGS_YML + ' should' +(cloudantExists ? '' : ' not') + ' contain cloudant credentials: \n' + JSON.stringify(bindingsyml));

assert.ok(cloudantBinding[0].valueFrom, 'Cloudant binding should have a valueFrom element: ' + JSON.stringify(cloudantBinding));
assert.ok(cloudantBinding[0].valueFrom.secretKeyRef, 'Cloudant valueFrom should have secretKeyRef element: ' + JSON.stringify(cloudantBinding));
}

const osBinding = deploymentyml.spec.template.spec.containers[0].env.filter(element => element.name === "service_object_storage");
assert.equal(osBinding.length > 0, objectStorageExists,
DEPLOYMENT_YML + ' should' +(cloudantExists ? '' : ' not') + ' contain object storage credentials');
if ( objectStorageExists ) {
const osBinding = bindingsyml.filter(element => element.name === "service_object_storage");
assert.equal(osBinding.length > 0, objectStorageExists,
BINDINGS_YML + ' should' +(objectStorageExists ? '' : ' not') + ' contain object storage credentials: \n' + JSON.stringify(bindingsyml));

assert.ok(osBinding[0].valueFrom, 'Object Storage binding should have a valueFrom element: ' + JSON.stringify(osBinding));
assert.ok(osBinding[0].valueFrom.secretKeyRef, 'Object Storage valueFrom should have secretKeyRef element: ' + JSON.stringify(osBinding));
}

// service.yaml
assertYmlContent(serviceyml.metadata.name, '{{ .Chart.Name }}-service', 'serviceyml.metadata.name');
assertYmlContent(serviceyml.metadata.labels.chart, '{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}');
Expand Down

0 comments on commit 5f65e3f

Please sign in to comment.