Skip to content

Commit 5b83d5c

Browse files
committed
hotwired admin mostly, updated k8s for deployment naming for challenge53
1 parent 3f1d19d commit 5b83d5c

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

wrongsecrets-balancer/src/admin/admin.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const {
77
deletePodForTeam,
88
deleteNamespaceForTeam,
99
deleteDesktopPodForTeam,
10+
deleteChallenge53DeploymentForTeam,
1011
} = require('../kubernetes');
1112

1213
const { get } = require('../config');
@@ -88,6 +89,18 @@ async function restartDesktopInstance(req, res) {
8889
}
8990
}
9091

92+
async function restartChallenge53Deployment(req, res) {
93+
try {
94+
const teamname = req.params.team;
95+
logger.info(`Restarting challenge53 for team: '${teamname}'`);
96+
await deleteChallenge53DeploymentForTeam(teamname);
97+
res.send();
98+
} catch (error) {
99+
logger.error(error);
100+
res.status(500).send();
101+
}
102+
}
103+
91104
/**
92105
* @param {import("express").Request} req
93106
* @param {import("express").Response} res
@@ -110,5 +123,6 @@ router.all('*', ensureAdminLogin);
110123
router.get('/all', listInstances);
111124
router.post('/teams/:team/restart', restartInstance);
112125
router.post('/teams/:team/restartdesktop', restartDesktopInstance);
126+
router.post('/teams/:team/restartchallenge53', restartChallenge53Deployment);
113127
router.delete('/teams/:team/delete', deleteInstance);
114128
module.exports = router;

wrongsecrets-balancer/src/kubernetes.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ const createK8sChallenge53DeploymentForTeam = async ({ team, passcodeHash }) =>
379379
apiVersion: 'apps/v1',
380380
kind: 'Deployment',
381381
metadata: {
382-
name: 'secret-challenge-53',
382+
name: `t-${team}-secret-challenge-53`,
383383
namespace: `t-${team}`,
384384
labels: {
385385
app: 'secret-challenge-53',
@@ -485,10 +485,11 @@ const createK8sChallenge53DeploymentForTeam = async ({ team, passcodeHash }) =>
485485

486486
try {
487487
logger.info(`Deploying Challenge 53 to namespace t-${team}`);
488-
const response = await k8sAppsApi.createNamespacedDeployment(
489-
`t-${team}`,
490-
deploymentChallenge53Config
491-
);
488+
const response = await k8sAppsApi.createNamespacedDeployment({
489+
namespace: `t-${team}`,
490+
body: deploymentChallenge53Config,
491+
});
492+
492493
logger.info(`Successfully created Challenge 53 deployment for team ${team}`);
493494
return response;
494495
} catch (error) {
@@ -503,13 +504,13 @@ const getChallenge53InstanceForTeam = async (team) => {
503504

504505
try {
505506
const validatedTeamName = validateTeamName(team);
506-
const deploymentName = 'secret-challenge-53';
507+
const deploymentName = `t-${validatedTeamName}-secret-challenge-53`;
507508
const namespace = `t-${validatedTeamName}`;
508509

509510
logger.info(`Checking Challenge 53 deployment ${deploymentName} in namespace ${namespace}`);
510511

511512
const res = await safeApiCall(
512-
() => k8sAppsApi.readNamespacedDeployment(deploymentName, namespace),
513+
() => k8sAppsApi.readNamespacedDeployment({ name: deploymentName, namespace: namespace }),
513514
`Check Challenge 53 deployment for team ${team}`
514515
);
515516

@@ -540,7 +541,9 @@ const deleteChallenge53DeploymentForTeam = async (team) => {
540541
logger.info(`Deleting Challenge 53 deployment for team ${team}`);
541542

542543
try {
543-
await k8sAppsApi.deleteNamespacedDeployment('secret-challenge-53', `t-${team}`);
544+
const validatedTeamName = validateTeamName(team);
545+
const deploymentName = `t-${validatedTeamName}-secret-challenge-53`;
546+
await k8sAppsApi.deleteNamespacedDeployment({ name: deploymentName, namespace: `t-${team}` });
544547
logger.info(`Successfully deleted Challenge 53 deployment for team ${team}`);
545548
} catch (error) {
546549
if (error.statusCode === 404) {
@@ -2055,7 +2058,7 @@ const getJuiceShopInstances = () => {
20552058
allowWatchBookmarks: true,
20562059
_continue: undefined,
20572060
fieldSelector: undefined,
2058-
labelSelector: 'app in (wrongsecrets, virtualdesktop)',
2061+
labelSelector: 'app in (wrongsecrets, virtualdesktop, secret-challenge-53)',
20592062
limit: 200,
20602063
})
20612064
.catch((error) => {

0 commit comments

Comments
 (0)