forked from opendatahub-io/odh-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add enablement of Partner Managed ISVs (#52)
* Add enablement of Partner Managed ISVs * update permissions for dev installed user
- Loading branch information
1 parent
afed0f4
commit 4ce1fb0
Showing
25 changed files
with
458 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const { DEV_MODE } = require('../../../utils/constants'); | ||
const responseUtils = require('../../../utils/responseUtils'); | ||
const validateISV = require('./validateISV'); | ||
|
||
module.exports = async (fastify, opts) => { | ||
fastify.get('/', async (request, reply) => { | ||
return validateISV | ||
.createValidationJob({ fastify, opts, request, reply }) | ||
.then((res) => { | ||
if (DEV_MODE) { | ||
responseUtils.addCORSHeader(request, reply); | ||
} | ||
return res; | ||
}) | ||
.catch((res) => { | ||
if (DEV_MODE) { | ||
responseUtils.addCORSHeader(request, reply); | ||
} | ||
fastify.log.error(`Failed to create validation job: ${res.response?.body?.message}`); | ||
reply.send(res); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
const componentUtils = require('../components/componentUtils'); | ||
const createError = require('http-errors'); | ||
|
||
const getApplicationDef = (appName) => { | ||
const appDefs = componentUtils.getApplicationDefs(); | ||
return appDefs.find((appDef) => appDef.metadata.name === appName); | ||
}; | ||
|
||
const createAccessSecret = async (appDef, namespace, stringData, coreV1Api) => { | ||
const { enable } = appDef.spec; | ||
if (!enable) { | ||
return Promise.resolve(); | ||
} | ||
|
||
stringData.configMapName = enable.validationConfigMap; | ||
const name = enable.validationSecret; | ||
const secret = { | ||
apiVersion: 'v1', | ||
metadata: { name, namespace }, | ||
type: 'Opaque', | ||
stringData, | ||
}; | ||
return coreV1Api | ||
.readNamespacedSecret(name, namespace) | ||
.then(() => { | ||
return coreV1Api.replaceNamespacedSecret(name, namespace, secret); | ||
}) | ||
.catch(() => { | ||
return coreV1Api.createNamespacedSecret(namespace, secret); | ||
}); | ||
}; | ||
|
||
const createValidationJob = async ({ fastify, request }) => { | ||
const namespace = fastify.kube.namespace; | ||
const appName = request.query?.appName; | ||
const stringData = JSON.parse(request.query?.values ?? {}); | ||
const batchV1beta1Api = fastify.kube.batchV1beta1Api; | ||
const batchV1Api = fastify.kube.batchV1Api; | ||
const coreV1Api = fastify.kube.coreV1Api; | ||
const appDef = getApplicationDef(appName); | ||
const { enable } = appDef.spec; | ||
|
||
const cronjobName = enable?.validationJob; | ||
if (!cronjobName) { | ||
const error = createError(500, 'failed to validate'); | ||
error.explicitInternalServerError = true; | ||
error.error = 'failed to find application definition file'; | ||
error.message = 'Unable to validate the application.'; | ||
throw error; | ||
} | ||
|
||
return createAccessSecret(appDef, namespace, stringData, coreV1Api).then(() => { | ||
return batchV1beta1Api.readNamespacedCronJob(cronjobName, namespace).then(async (res) => { | ||
const cronJob = res.body; | ||
const jobSpec = cronJob.spec.jobTemplate.spec; | ||
const jobName = `${cronjobName}-job-custom-run`; | ||
const job = { | ||
apiVersion: 'batch/v1', | ||
metadata: { | ||
name: jobName, | ||
namespace, | ||
annotations: { | ||
'cronjob.kubernetes.io/instantiate': 'manual', | ||
}, | ||
}, | ||
spec: jobSpec, | ||
}; | ||
// Flag the cronjob as no longer suspended | ||
cronJob.spec.suspend = false; | ||
await batchV1beta1Api.replaceNamespacedCronJob(cronjobName, namespace, cronJob).catch((e) => { | ||
fastify.log.error(`failed to unsuspend cronjob: ${e.response.body.message}`); | ||
}); | ||
|
||
// If there was a manual job already, delete it | ||
await batchV1Api.deleteNamespacedJob(jobName, namespace).catch(() => {}); | ||
|
||
// Some delay to allow job to delete | ||
return new Promise((resolve) => setTimeout(resolve, 1000)).then(() => | ||
batchV1Api.createNamespacedJob(namespace, job), | ||
); | ||
}); | ||
}); | ||
}; | ||
|
||
module.exports = { createAccessSecret, createValidationJob }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.