forked from opendatahub-io/odh-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'opendatahub-io:main' into main
- Loading branch information
Showing
29 changed files
with
780 additions
and
121 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { FastifyReply, FastifyRequest } from 'fastify'; | ||
import { StorageClassConfig, KubeFastifyInstance } from '../../../types'; | ||
import { secureAdminRoute } from '../../../utils/route-security'; | ||
import { updateStorageClassConfig } from './utils'; | ||
|
||
export default async (fastify: KubeFastifyInstance): Promise<void> => { | ||
fastify.put( | ||
'/:storageClassName/config', | ||
secureAdminRoute(fastify)( | ||
async ( | ||
request: FastifyRequest<{ | ||
Body: StorageClassConfig; | ||
Params: { storageClassName: string }; | ||
}>, | ||
reply: FastifyReply, | ||
) => { | ||
return updateStorageClassConfig(fastify, request) | ||
.then((res) => { | ||
return res; | ||
}) | ||
.catch((res) => { | ||
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,63 @@ | ||
import { FastifyRequest } from 'fastify'; | ||
import { | ||
K8sResourceCommon, | ||
KubeFastifyInstance, | ||
ResponseStatus, | ||
StorageClassConfig, | ||
} from '../../../types'; | ||
import { isHttpError } from '../../../utils'; | ||
import { errorHandler } from '../../../utils'; | ||
|
||
export async function updateStorageClassConfig( | ||
fastify: KubeFastifyInstance, | ||
request: FastifyRequest<{ Body: StorageClassConfig; Params: { storageClassName: string } }>, | ||
): Promise<ResponseStatus> { | ||
const params = request.params; | ||
const body = request.body; | ||
|
||
try { | ||
// Fetch the existing custom object for the StorageClass | ||
const storageClass = await fastify.kube.customObjectsApi.getClusterCustomObject( | ||
'storage.k8s.io', | ||
'v1', | ||
'storageclasses', | ||
params.storageClassName, | ||
); | ||
|
||
// Extract and update the annotations | ||
const annotations = (storageClass.body as K8sResourceCommon).metadata.annotations || {}; | ||
annotations['opendatahub.io/sc-config'] = JSON.stringify(body); | ||
|
||
// Patch the StorageClass with the new annotations | ||
await fastify.kube.customObjectsApi.patchClusterCustomObject( | ||
'storage.k8s.io', | ||
'v1', | ||
'storageclasses', | ||
params.storageClassName, | ||
{ | ||
metadata: { | ||
annotations, | ||
}, | ||
}, | ||
undefined, | ||
undefined, | ||
undefined, | ||
{ | ||
headers: { | ||
'Content-Type': 'application/merge-patch+json', | ||
}, | ||
}, | ||
); | ||
|
||
return { success: true, error: '' }; | ||
} catch (e) { | ||
if (!isHttpError(e) || e.statusCode !== 404) { | ||
fastify.log.error(e, 'Unable to update storage class metadata.'); | ||
return { | ||
success: false, | ||
error: `Unable to update storage class metadata: ${errorHandler(e)}`, | ||
}; | ||
} | ||
throw e; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as React from 'react'; | ||
import { ExpandableSection, ExpandableSectionProps, FormSection } from '@patternfly/react-core'; | ||
|
||
type ExpandableFormSectionProps = Omit<ExpandableSectionProps, 'ref'> & { | ||
initExpanded?: boolean; | ||
}; | ||
|
||
const ExpandableFormSection: React.FC<ExpandableFormSectionProps> = ({ | ||
children, | ||
initExpanded = false, | ||
isIndented = true, | ||
...props | ||
}) => { | ||
const [expanded, setExpanded] = React.useState<boolean>(initExpanded); | ||
|
||
return ( | ||
<ExpandableSection | ||
isIndented={isIndented} | ||
isExpanded={expanded} | ||
onToggle={(_ev, isExpanded) => setExpanded(isExpanded)} | ||
{...props} | ||
> | ||
<FormSection>{children}</FormSection> | ||
</ExpandableSection> | ||
); | ||
}; | ||
|
||
export default ExpandableFormSection; |
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,15 @@ | ||
.odh-number-input-wrapper { | ||
&.m-full-width { | ||
width: 100%; | ||
display: flex; | ||
.pf-v5-c-input-group__item:where(:not(:first-child)):where(:not(:last-child)) { | ||
flex: 1; | ||
.pf-v5-c-form-control { | ||
width: 100%; | ||
} | ||
} | ||
.pf-v5-c-number-input__unit { | ||
white-space: nowrap; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.