-
Notifications
You must be signed in to change notification settings - Fork 592
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove hard coded model versions from kubevirt
- Loading branch information
Showing
3 changed files
with
49 additions
and
43 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
37 changes: 11 additions & 26 deletions
37
frontend/packages/kubevirt-plugin/src/models/kubevirtReferenceForModel.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 |
---|---|---|
@@ -1,33 +1,18 @@ | ||
import * as _ from 'lodash'; | ||
import { modelFor, referenceForGroupVersionKind } from '@console/internal/module/k8s'; | ||
import { | ||
apiVersionForModel, | ||
modelForGroupKind, | ||
referenceForModel, | ||
} from '@console/internal/module/k8s'; | ||
import { K8sKind } from '@console/internal/module/k8s/types'; | ||
|
||
const VERSIONS = ['v1', 'v1alpha3', 'v1beta1', 'v1alpha1']; | ||
|
||
export const getKubevirtModelAvailableVersion = (model: K8sKind): string => | ||
_.uniq([model.apiVersion, ...VERSIONS]).find( | ||
(v) => !!modelFor(referenceForGroupVersionKind(model.apiGroup)(v)(model.kind)), | ||
); | ||
|
||
export const kubevirtReferenceForModel = (model: K8sKind): string => { | ||
const version = getKubevirtModelAvailableVersion(model); | ||
|
||
if (version) { | ||
return referenceForGroupVersionKind(model.apiGroup)(version)(model.kind); | ||
} | ||
|
||
return model.kind; | ||
}; | ||
|
||
export const getKubevirtAvailableModel = (model: K8sKind): K8sKind => { | ||
const version = getKubevirtModelAvailableVersion(model); | ||
modelForGroupKind(model.apiGroup, model.kind)?.apiVersion || model.apiVersion; | ||
|
||
if (version) { | ||
return modelFor(referenceForGroupVersionKind(model.apiGroup)(version)(model.kind)); | ||
} | ||
export const kubevirtReferenceForModel = (model: K8sKind): string => | ||
referenceForModel(modelForGroupKind(model.apiGroup, model.kind) || model); | ||
|
||
return model; | ||
}; | ||
export const getKubevirtAvailableModel = (model: K8sKind): K8sKind => | ||
modelForGroupKind(model.apiGroup, model.kind) || model; | ||
|
||
export const getKubevirtModelAvailableAPIVersion = (model: K8sKind): string => | ||
`${model.apiGroup}/${getKubevirtModelAvailableVersion(model) || model.apiVersion}`; | ||
apiVersionForModel(modelForGroupKind(model.apiGroup, model.kind) || model); |