Skip to content

Commit

Permalink
handle client org and openshift for restore form
Browse files Browse the repository at this point in the history
Signed-off-by: SamiulSourav <[email protected]>
  • Loading branch information
SamiulSourav authored and ArnobKumarSaha committed Jan 3, 2025
1 parent 4e0d5ea commit 561d133
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ steps:
text: Repository
onChange: onRepoChange
refresh: true
required: true
schema:
$ref: discriminator#/properties/repository
type: select
Expand Down Expand Up @@ -72,6 +73,9 @@ steps:
schema:
$ref: discriminator#/properties/params
type: textarea
- computed: setSecurityContext
if: returnFalse
type: input
schema:
$ref: schema#/properties/spec/properties/addon
type: single-step-form
Expand Down Expand Up @@ -105,6 +109,8 @@ steps:
if: isConsole
label:
text: Target
schema:
$ref: schema#/properties/spec/properties/target
show_label: true
type: single-step-form
schema:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,16 @@ function initTarget({ getValue, discriminator, commit }) {
async function getRepositories({ getValue, model, storeGet, axios }) {
const user = storeGet('/route/params/user') || ''
const cluster = storeGet('/route/params/cluster') || ''
const url = `/clusters/${user}/${cluster}/proxy/storage.kubestash.com/v1alpha1/repositories`
const namespace = storeGet('/route/query/namespace') || ''
const activeOrg = storeGet('/activeOrganization') || ''
const orgList = storeGet('/organizations') || []
const activeOrgObj = orgList.find((item) => item.username === activeOrg)
const orgType = activeOrgObj?.orgType

let url = `/clusters/${user}/${cluster}/proxy/storage.kubestash.com/v1alpha1/repositories`
if (orgType === 3) {
url = `/clusters/${user}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${namespace}/repositories`
}

try {
const resp = await axios.get(url)
Expand Down Expand Up @@ -315,6 +324,53 @@ function databaseSelected({ storeGet, watchDependency, getValue, discriminator }
return !!target.name
}

const securityContextMap = {
MongoDB: 999,
Postgres: 70,
Elasticsearch: 1000,
MSSQLServer: 10001,
MySQL: 999,
MariaDB: 999,
Redis: 999,
Singlestore: 999,
ZooKeeper: 999,
}

async function setSecurityContext({ storeGet, commit, axios }) {
const namespace = storeGet('/route/query/namespace') || ''
const user = storeGet('/route/params/user') || ''
const cluster = storeGet('/route/params/cluster') || ''
if (namespace) {
const url = `clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}`
try {
const resp = await axios.get(url)
console.log(resp.data)
const annotations = resp.data?.metadata?.annotations || {}
const uidRange = annotations['openshift.io/sa.scc.uid-range']
if (uidRange) {
const val = uidRange.split('/')[0]
commit('wizard/model$update', {
path: '/spec/addon/jobTemplate/securityContext',
value: val,
force: true,
})
} else {
const kind = storeGet('/resource/layout/result/resource/kind') || ''
const context = securityContextMap[kind]
console.log(kind, context)

commit('wizard/model$update', {
path: '/spec/addon/jobTemplate/securityContext',
value: context,
force: true,
})
}
} catch (e) {
console.log(e)
}
}
}

function returnFalse() {
return false
}
Expand Down Expand Up @@ -467,4 +523,5 @@ return {
databaseSelected,
returnFalse,
onParameterChange,
setSecurityContext,
}

0 comments on commit 561d133

Please sign in to comment.