-
Notifications
You must be signed in to change notification settings - Fork 613
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kubevirt: take storageClassConfigMap into account when creating disks
- Loading branch information
Showing
5 changed files
with
66 additions
and
7 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
3 changes: 3 additions & 0 deletions
3
frontend/packages/kubevirt-plugin/src/k8s/requests/config-map/storage-class/constants.ts
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,3 @@ | ||
export const STORAGE_CLASS_CONFIG_MAP_NAME = 'kubevirt-storage-class-defaults'; | ||
// Different releases, different locations. Respect the order when resolving. Otherwise the configMap name/namespace is considered as well-known. | ||
export const STORAGE_CLASS_CONFIG_MAP_NAMESPACES = ['openshift-cnv', 'openshift']; |
1 change: 1 addition & 0 deletions
1
frontend/packages/kubevirt-plugin/src/k8s/requests/config-map/storage-class/index.ts
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 @@ | ||
export * from './storageClassConfigMap'; |
44 changes: 44 additions & 0 deletions
44
...ckages/kubevirt-plugin/src/k8s/requests/config-map/storage-class/storageClassConfigMap.ts
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,44 @@ | ||
import { ConfigMapModel } from '@console/internal/models'; | ||
import { ConfigMapKind } from '@console/internal/module/k8s'; | ||
import { STORAGE_CLASS_CONFIG_MAP_NAME, STORAGE_CLASS_CONFIG_MAP_NAMESPACES } from './constants'; | ||
|
||
const { warn } = console; | ||
|
||
const getStorageClassConfigMapInNamespace = async ({ | ||
k8sGet, | ||
namespace, | ||
}: { | ||
namespace: string; | ||
k8sGet: (...opts: any) => Promise<any>; | ||
}): Promise<ConfigMapKind> => { | ||
try { | ||
return await k8sGet(ConfigMapModel, STORAGE_CLASS_CONFIG_MAP_NAME, namespace, null, { | ||
disableHistory: true, | ||
}); | ||
} catch (e) { | ||
return null; | ||
} | ||
}; | ||
|
||
export const getStorageClassConfigMap = async (props: { | ||
k8sGet: (...opts: any[]) => Promise<any>; | ||
}): Promise<ConfigMapKind> => { | ||
// query namespaces sequentially to respect order | ||
// eslint-disable-next-line @typescript-eslint/prefer-for-of | ||
for (let index = 0; index < STORAGE_CLASS_CONFIG_MAP_NAMESPACES.length; index++) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const configMap = await getStorageClassConfigMapInNamespace({ | ||
namespace: STORAGE_CLASS_CONFIG_MAP_NAMESPACES[index], | ||
...props, | ||
}); | ||
if (configMap) { | ||
return configMap; | ||
} | ||
} | ||
warn( | ||
`The ${STORAGE_CLASS_CONFIG_MAP_NAME} can not be found in none of following namespaces: `, | ||
JSON.stringify(STORAGE_CLASS_CONFIG_MAP_NAMESPACES), | ||
'. The PVCs will be created with default values.', | ||
); | ||
return null; | ||
}; |