Skip to content

Commit 8b00ec2

Browse files
committed
Added namespacing support, admin updates, now all are isolated a bit better
1 parent 2d5874c commit 8b00ec2

File tree

3 files changed

+48
-40
lines changed

3 files changed

+48
-40
lines changed

wrongsecrets-balancer/src/admin/admin.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ async function listInstances(req, res) {
3939

4040
return res.json({
4141
instances: instances.map((instance) => {
42-
const team = instance.metadata.labels.team;
42+
let team = instance.metadata.labels.team;
43+
if (team === '') {
44+
team = 'kubelet-ignore-this';
45+
}
4346
return {
4447
team,
4548
name: instance.metadata.name,

wrongsecrets-balancer/src/kubernetes.js

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@ const k8sCoreApi = kc.makeApiClient(CoreV1Api);
77

88
const { get } = require('./config');
99

10-
const lodashGet = require('lodash/get');
11-
const once = require('lodash/once');
10+
//used for owner ref, not used now:
11+
// const lodashGet = require('lodash/get');
12+
// const once = require('lodash/once');
1213

14+
//used for owner ref, not used now:
1315
// Gets the Deployment uid for the JuiceBalancer
1416
// This is required to set the JuiceBalancer as owner of the created JuiceShop Instances
15-
const getJuiceBalancerDeploymentUid = once(async () => {
16-
const deployment = await k8sAppsApi.readNamespacedDeployment(
17-
'wrongsecrets-balancer',
18-
get('namespace')
19-
);
20-
return lodashGet(deployment, ['body', 'metadata', 'uid'], null);
21-
});
17+
// const getJuiceBalancerDeploymentUid = once(async () => {
18+
// const deployment = await k8sAppsApi.readNamespacedDeployment(
19+
// 'wrongsecrets-balancer',
20+
// get('namespace')
21+
// );
22+
// return lodashGet(deployment, ['body', 'metadata', 'uid'], null);
23+
// });
2224

2325
const createNameSpaceForTeam = async (team) => {
2426
const namedNameSpace = {
@@ -349,23 +351,24 @@ const createDesktopServiceForTeam = async (teamname) =>
349351
});
350352
module.exports.createDesktopServiceForTeam = createDesktopServiceForTeam;
351353

352-
async function getOwnerReference() {
353-
if (get('skipOwnerReference') === true) {
354-
return {};
355-
}
356-
return {
357-
ownerReferences: [
358-
{
359-
apiVersion: 'apps/v1',
360-
blockOwnerDeletion: true,
361-
controller: true,
362-
kind: 'Deployment',
363-
name: 'wrongsecrets-balancer',
364-
uid: await getJuiceBalancerDeploymentUid(),
365-
},
366-
],
367-
};
368-
}
354+
//used for owner ref, not used now as we cannot do clusterwide owning of namespaced items:
355+
// async function getOwnerReference() {
356+
// if (get('skipOwnerReference') === true) {
357+
// return {};
358+
// }
359+
// return {
360+
// ownerReferences: [
361+
// {
362+
// apiVersion: 'apps/v1',
363+
// blockOwnerDeletion: true,
364+
// controller: true,
365+
// kind: 'Deployment',
366+
// name: 'wrongsecrets-balancer',
367+
// uid: await getJuiceBalancerDeploymentUid(),
368+
// },
369+
// ],
370+
// };
371+
// }
369372

370373
// TODO fix!
371374
const getJuiceShopInstances = () =>
@@ -378,16 +381,9 @@ const getJuiceShopInstances = () =>
378381
// undefined, //labelSelector
379382
// undefined, //limit
380383
// `app=wrongsecrets,deployment-context=${get('deploymentContext')}`
381-
.listDeploymentForAllNamespaces(
382-
true,
383-
false,
384-
undefined,
385-
undefined,
386-
undefined,
387-
`app=wrongsecrets,deployment-context=${get('deploymentContext')}`
388-
)
384+
.listDeploymentForAllNamespaces()
389385
.catch((error) => {
390-
throw new Error(error.response.body.message);
386+
throw new Error(error);
391387
});
392388
module.exports.getJuiceShopInstances = getJuiceShopInstances;
393389

wrongsecrets-balancer/ui/src/pages/AdminPage.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ const messages = defineMessages({
6767
id: 'admin_table.teamname',
6868
defaultMessage: 'Teamname',
6969
},
70+
name: {
71+
id: 'admin_table.name',
72+
defaultMessage: 'Name',
73+
},
7074
ready: {
7175
id: 'admin_table.ready',
7276
defaultMessage: 'Ready',
@@ -102,7 +106,7 @@ function RestartInstanceButton({ team }) {
102106
{restarting ? (
103107
<FormattedMessage id="admin_table.restarting" defaultMessage="Restarting..." />
104108
) : (
105-
<FormattedMessage id="admin_table.restart" defaultMessage="Restart" />
109+
<FormattedMessage id="admin_table.restart" defaultMessage="Restart-WS" />
106110
)}
107111
</SmallSecondary>
108112
);
@@ -122,7 +126,7 @@ function RestartDesktopInstanceButton({ team }) {
122126
{restarting ? (
123127
<FormattedMessage id="admin_table.restarting" defaultMessage="Restarting..." />
124128
) : (
125-
<FormattedMessage id="admin_table.restart" defaultMessage="Restart" />
129+
<FormattedMessage id="admin_table.restart" defaultMessage="Restart-VD" />
126130
)}
127131
</SmallSecondary>
128132
);
@@ -184,6 +188,11 @@ export default function AdminPage() {
184188
selector: 'team',
185189
sortable: true,
186190
},
191+
{
192+
name: formatMessage(messages.name),
193+
selector: 'name',
194+
sortable: true,
195+
},
187196
{
188197
name: formatMessage(messages.ready),
189198
selector: 'ready',
@@ -226,8 +235,8 @@ export default function AdminPage() {
226235
cell: ({ team }) => {
227236
return (
228237
<>
229-
<DeleteInstanceButton team={team} />
230-
<RestartInstanceButton team={team} />
238+
<DeleteInstanceButton team={team} /><br/>
239+
<RestartInstanceButton team={team} /><br/>
231240
<RestartDesktopInstanceButton team={team} />
232241
</>
233242
);

0 commit comments

Comments
 (0)