Skip to content

Commit

Permalink
Add option to skip ownerReferences on JuiceShop Deployment and Services
Browse files Browse the repository at this point in the history
This lets MultiJuicer run in older kubernetes cluster which don't support the reference type or the app/v1 deployment type

Related to #51
  • Loading branch information
J12934 committed May 7, 2020
1 parent 4893b1d commit 88b91f9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
1 change: 1 addition & 0 deletions helm/multi-juicer/templates/juice-balancer-config-map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ data:
"namespace": {{ .Release.Namespace | quote }},
"deploymentContext": {{ .Release.Name | quote }},
"maxJuiceShopInstances": {{ .Values.juiceShop.maxInstances}},
"skipOwnerReference": {{ .Values.balancer.skipOwnerReference }},
"cookieParser": {
"cookieName": {{ include "multi-juicer.cookieName" . | quote }},
"secure": {{ .Values.balancer.cookie.secure }}
Expand Down
3 changes: 3 additions & 0 deletions helm/multi-juicer/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ balancer:
cpu: 400m
affinity: {}
tolerations: []
# If set to true this skips setting ownerReferences on the teams JuiceShop Deployment and Services
# This lets MultiJuicer run in older kubernetes cluster which don't support the reference type or the app/v1 deployment type
skipOwnerReference: false
metrics:
# enables prometheus metrics for the balancer
# if set to true you should change the prometheus-scraper password
Expand Down
1 change: 1 addition & 0 deletions juice-balancer/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"namespace": "default",
"deploymentContext": "multi-juicer",
"maxJuiceShopInstances": 10,
"skipOwnerReference": false,
"admin": {
"username": "admin",
"password": "12345678"
Expand Down
40 changes: 20 additions & 20 deletions juice-balancer/src/kubernetes.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,7 @@ const createDeploymentForTeam = async ({ team, passcodeHash }) => {
'multi-juicer.iteratec.dev/challengesSolved': '0',
'multi-juicer.iteratec.dev/continueCode': '',
},
ownerReferences: [
{
apiVersion: 'apps/v1',
blockOwnerDeletion: true,
controller: true,
kind: 'Deployment',
name: 'juice-balancer',
uid: await getJuiceBalancerDeploymentUid(),
},
],
...(await getOwnerReference()),
},
spec: {
selector: {
Expand Down Expand Up @@ -139,16 +130,7 @@ const createServiceForTeam = async teamname =>
team: teamname,
'deployment-context': get('deploymentContext'),
},
ownerReferences: [
{
apiVersion: 'apps/v1',
blockOwnerDeletion: true,
controller: true,
kind: 'Deployment',
name: 'juice-balancer',
uid: await getJuiceBalancerDeploymentUid(),
},
],
...(await getOwnerReference()),
},
spec: {
selector: {
Expand All @@ -168,6 +150,24 @@ const createServiceForTeam = async teamname =>
});
module.exports.createServiceForTeam = createServiceForTeam;

async function getOwnerReference() {
if (get('skipOwnerReference') === true) {
return {};
}
return {
ownerReferences: [
{
apiVersion: 'apps/v1',
blockOwnerDeletion: true,
controller: true,
kind: 'Deployment',
name: 'juice-balancer',
uid: await getJuiceBalancerDeploymentUid(),
},
],
};
}

const getJuiceShopInstances = () =>
k8sAppsApi
.listNamespacedDeployment(
Expand Down

0 comments on commit 88b91f9

Please sign in to comment.