Skip to content

Commit

Permalink
fixed bug with requesting shares creation
Browse files Browse the repository at this point in the history
  • Loading branch information
mathis-marcotte committed Oct 8, 2024
1 parent 8f9e427 commit d9da853
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 64 deletions.
15 changes: 1 addition & 14 deletions components/centraldashboard/app/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,6 @@ export class Api {
}
res.json(filers);
})
.post(
'/create-requesting-shares/:namespace',
async (req: Request, res: Response) => {
try {
const cm = await this.k8sService.createRequestingSharesConfigMap(req.params.namespace, req.body, req.user.email);
res.json(cm.data);
}catch(e){
return apiError({
res, code: 500,
error: ERRORS.invalid_create_requesting_shares,
});
}
})
.get(
'/get-existing-shares/:namespace',
async (req: Request, res: Response) => {
Expand All @@ -163,7 +150,7 @@ export class Api {
});
}
})
.patch(
.post(
'/update-requesting-shares/:namespace',
async (req: Request, res: Response) => {
try {
Expand Down
63 changes: 25 additions & 38 deletions components/centraldashboard/app/k8s_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,29 +118,6 @@ export class KubernetesService {
}
}

/** Creates the requesting shares configmap for the central dashboard. */
async createRequestingSharesConfigMap(namespace: string, data: {[key:string]:string}, email: string): Promise<k8s.V1ConfigMap> {
try {
const config = {
metadata: {
name: REQUESTING_SHARES_CM_NAME,
labels: {
"for-ontap": "true"
},
annotations: {
"user-email": email
}
},
data
} as k8s.V1ConfigMap;
const { body } = await this.coreAPI.createNamespacedConfigMap(namespace, config);
return body;
} catch (err) {
console.error('Unable to create requesting shares ConfigMap:', err.response?.body || err.body || err);
throw err;
}
}

/** Retrieves the existing shares configmap data for the central dashboard. */
async getExistingSharesConfigMap(namespace: string): Promise<k8s.V1ConfigMap> {
try {
Expand All @@ -163,33 +140,43 @@ export class KubernetesService {
return body;
} catch (err) {
if(err.statusCode === 404){
//user has no user-filers yet
//user has no requesting-shares yet
return new k8s.V1ConfigMap();
}
console.error('Unable to fetch ConfigMap:', err.response?.body || err.body || err);
throw err;
}
}

/** Updates the requesting shares configmap for the central dashboard. */
/** Updates the requesting shares configmap for the central dashboard. Creates the configmap if it is not created.*/
async updateRequestingSharesConfigMap(namespace: string, data: {[key:string]:string}, email: string): Promise<k8s.V1ConfigMap> {
try {
const config = {
metadata: {
name: REQUESTING_SHARES_CM_NAME,
labels: {
"for-ontap": "true"
},
annotations: {
"user-email": email
}
const config = {
metadata: {
name: REQUESTING_SHARES_CM_NAME,
labels: {
"for-ontap": "true"
},
data
} as k8s.V1ConfigMap;
annotations: {
"user-email": email
}
},
data
} as k8s.V1ConfigMap;

try {
//try to get the configmap to see if it exists
await this.coreAPI.readNamespacedConfigMap(REQUESTING_SHARES_CM_NAME, namespace);

//if no error, it means the configmap exists already
const { body } = await this.coreAPI.replaceNamespacedConfigMap(REQUESTING_SHARES_CM_NAME, namespace, config);
return body;
} catch (err) {
console.error('Unable to patch ConfigMap:', err.response?.body || err.body || err);
if(err.statusCode === 404){
//user has no requesting-shares yet
const { body } = await this.coreAPI.createNamespacedConfigMap(namespace, config);
return body;
}
console.error('Unable to update ConfigMap:', err.response?.body || err.body || err);
throw err;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,7 @@ export class ManageFilersView extends mixinBehaviors([AppLocalizeBehavior], util
newRequestingData[filersSelectValue] =
JSON.stringify(newRequestingDataValue);

// if no requesting CM, create it
if (Object.keys(requestingData).length===0) {
// new configmap to create
const api = this.$.CreateRequestingSharesAjax;
api.body = newRequestingData;
api.generateRequest();
return;
}
// else update the config map
// updates the configmap if it exists. Creates it if it doesn't.
const api = this.$.UpdateRequestingSharesAjax;
api.body = newRequestingData;
api.generateRequest();
Expand Down Expand Up @@ -250,6 +242,8 @@ export class ManageFilersView extends mixinBehaviors([AppLocalizeBehavior], util
// updates the data
this.$.GetRequestingSharesAjax.generateRequest();
this.$.GetExistingSharesAjax.generateRequest();
// eslint-disable-next-line
console.log('here', this.requestingShares);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ iron-ajax#GetExistingSharesAjax(auto, url='/api/get-existing-shares/[[namespace]
last-response='{{existingShares}}', on-error='onHasFilersError', loading='{{existingSharesLoading}}')
iron-ajax#GetRequestingSharesAjax(auto, url='/api/get-requesting-shares/[[namespace]]', handle-as='json',
last-response='{{requestingShares}}', on-error='onHasFilersError', loading='{{requestingSharesLoading}}')
iron-ajax#CreateRequestingSharesAjax(method='POST', url='/api/create-requesting-shares/[[namespace]]',
on-response='handleUpdateShares', on-error='handleUpdateShares', handle-as='json', content-type='application/json')
iron-ajax#UpdateRequestingSharesAjax(method='PATCH', url='/api/update-requesting-shares/[[namespace]]',
iron-ajax#UpdateRequestingSharesAjax(method='POST', url='/api/update-requesting-shares/[[namespace]]',
on-response='handleUpdateShares', on-error='handleUpdateShares', handle-as='json', content-type='application/json')
iron-ajax#UpdateExistingSharesAjax(method='PATCH', url='/api/update-existing-shares/[[namespace]]',
on-response='handleUpdateShares', on-error='handleUpdateShares', handle-as='json', content-type='application/json')
Expand Down

0 comments on commit d9da853

Please sign in to comment.