Skip to content

Commit

Permalink
updated template PVC name and namespace to use parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacov committed Aug 25, 2020
1 parent 88eaea3 commit 2f26c05
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@ import {
} from '../../../../selectors/config-map/sc-defaults';
import { toShallowJS, iGetIn } from '../../../../utils/immutable';
import { generateDataVolumeName } from '../../../../utils';
import { DUMMY_VM_NAME, TEMPLATE_DATAVOLUME_ANNOTATION } from '../../../../constants/vm';
import {
DUMMY_VM_NAME,
TEMPLATE_DATAVOLUME_NAME_PARAMETER,
TEMPLATE_DATAVOLUME_NAMESPACE_PARAMETER,
} from '../../../../constants/vm';
import {
iGetVmSettingValue,
iGetProvisionSource,
iGetRelevantTemplateSelectors,
} from '../../selectors/immutable/vm-settings';
import { iGetLoadedCommonData, iGetName } from '../../selectors/immutable/selectors';
import { iGetRelevantTemplate } from '../../../../selectors/immutable/template/combined';
import { iGetAnnotation } from '../../../../selectors/immutable/common';
import { iGetPrameter } from '../../../../selectors/immutable/common';

const ROOT_DISK_NAME = 'rootdisk';
const WINTOOLS_DISK_NAME = 'windows-guest-tools';
Expand Down Expand Up @@ -186,11 +190,8 @@ export const getNewProvisionSourceStorage = (state: any, id: string): VMWizardSt
const iCommonTemplates = iGetLoadedCommonData(state, id, VMWizardProps.commonTemplates);
const iTemplate =
iCommonTemplates && iGetRelevantTemplate(null, iCommonTemplates, relevantOptions);
const pvcName = iGetAnnotation(
iTemplate,
`${TEMPLATE_DATAVOLUME_ANNOTATION}/${relevantOptions.os}`,
);
const pvcNamespace = iGetAnnotation(iTemplate, `${TEMPLATE_DATAVOLUME_ANNOTATION}/namespace`);
const pvcName = iGetPrameter(iTemplate, TEMPLATE_DATAVOLUME_NAME_PARAMETER).value;
const pvcNamespace = iGetPrameter(iTemplate, TEMPLATE_DATAVOLUME_NAMESPACE_PARAMETER).value;

const iBaseImage = iGetLoadedCommonData(state, id, VMWizardProps.openshiftCNVBaseImages)
.valueSeq()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import {
iGetName,
} from '../../selectors/immutable/selectors';
import { iGetRelevantTemplate } from '../../../../selectors/immutable/template/combined';
import { CUSTOM_FLAVOR, TEMPLATE_DATAVOLUME_ANNOTATION } from '../../../../constants/vm';
import { CUSTOM_FLAVOR, TEMPLATE_DATAVOLUME_NAME_PARAMETER } from '../../../../constants/vm';
import { ProvisionSource } from '../../../../constants/vm/provision-source';
import { prefillVmTemplateUpdater } from './prefill-vm-template-state-update';
import { iGetAnnotation } from '../../../../selectors/immutable/common';
import { iGetPrameter } from '../../../../selectors/immutable/common';

const selectUserTemplateOnLoadedUpdater = (options: UpdateOptions) => {
const { id, dispatch, getState } = options;
Expand Down Expand Up @@ -129,10 +129,7 @@ const baseImageUpdater = ({ id, prevState, dispatch, getState }: UpdateOptions)
const iCommonTemplates = iGetLoadedCommonData(state, id, VMWizardProps.commonTemplates);
const iTemplate =
iCommonTemplates && iGetRelevantTemplate(null, iCommonTemplates, relevantOptions);
const pvcName = iGetAnnotation(
iTemplate,
`${TEMPLATE_DATAVOLUME_ANNOTATION}/${relevantOptions?.os}`,
);
const pvcName = iGetPrameter(iTemplate, TEMPLATE_DATAVOLUME_NAME_PARAMETER).value;

const iBaseImages = iGetLoadedCommonData(state, id, VMWizardProps.openshiftCNVBaseImages);
iBaseImage =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export const TEMPLATE_TYPE_BASE = 'base';
export const TEMPLATE_WORKLOAD_LABEL = 'workload.template.kubevirt.io';
export const TEMPLATE_VM_NAME_LABEL = 'vm.kubevirt.io/name';
export const TEMPLATE_OS_NAME_ANNOTATION = 'name.os.template.kubevirt.io';
export const TEMPLATE_DATAVOLUME_ANNOTATION = 'datavolume.template.kubevirt.io';
export const TEMPLATE_DATAVOLUME_NAME_PARAMETER = 'SRC_PVC_NAME';
export const TEMPLATE_DATAVOLUME_NAMESPACE_PARAMETER = 'SRC_PVC_NAMESPACE';
export const TEMPLATE_VM_DOMAIN_LABEL = 'kubevirt.io/domain';
export const TEMPLATE_VM_SIZE_LABEL = 'kubevirt.io/size';
export const TEMPLATE_VM_GOLDEN_OS_NAMESPACE = 'openshift-cnv-base-images';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { iGetIn } from '../../utils/immutable';
import { ILabels } from '../../types/template';
import { TemplateParameter } from '@console/internal/module/k8s';

export const iGetLabels = (obj): ILabels => iGetIn(obj, ['metadata', 'labels']);
export const iGetCreationTimestamp = (obj): string =>
iGetIn(obj, ['metadata', 'creationTimestamp']);
export const iGetAnnotation = (obj, key: string, defaultValue = undefined): string =>
iGetIn(obj, ['metadata', 'annotations', key], defaultValue);
export const iGetPrameter = (obj, name: string, defaultValue = {}): TemplateParameter =>
iGetIn(obj, ['parameters'])
?.valueSeq()
.find((parameter) => parameter.name === name) || defaultValue;
5 changes: 4 additions & 1 deletion frontend/packages/kubevirt-plugin/src/selectors/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as _ from 'lodash';
import { K8sResourceKind } from '@console/internal/module/k8s';
import { K8sResourceKind, TemplateParameter } from '@console/internal/module/k8s';
import { VMGenericLikeEntityKind } from '../types/vmLike';

export const getKind = (value) => _.get(value, 'kind') as K8sResourceKind['kind'];
Expand Down Expand Up @@ -36,6 +36,9 @@ export const getAnnotation = (
defaultValue?: string,
): string => _.get(entity, ['metadata', 'annotations', annotationName], defaultValue);

export const getParameter = (obj, name: string, defaultValue = {}): TemplateParameter =>
_.get(obj, ['parameters'], []).find((parameter) => parameter.name === name) || defaultValue;

export const getAnnotationKeySuffix = (
entity: K8sResourceKind,
annotationPrefix: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@ import {
CloudInitDataHelper,
CloudInitDataFormKeys,
} from '../../k8s/wrapper/vm/cloud-init-data-helper';
import { getAnnotation, getAnnotations, getLabels } from '../selectors';
import { getAnnotation, getAnnotations, getLabels, getParameter } from '../selectors';
import {
TEMPLATE_FLAVOR_LABEL,
TEMPLATE_OS_LABEL,
TEMPLATE_OS_NAME_ANNOTATION,
TEMPLATE_TYPE_LABEL,
TEMPLATE_TYPE_VM,
TEMPLATE_WORKLOAD_LABEL,
TEMPLATE_DATAVOLUME_NAME_PARAMETER,
TEMPLATE_DATAVOLUME_NAMESPACE_PARAMETER,
} from '../../constants/vm';
import {
getCloudInitVolume,
getOperatingSystemDataVolumeAnnotation,
getOperatingSystemDataVolumeNamespaceAnnotation,
} from '../vm/selectors';
import { getCloudInitVolume } from '../vm/selectors';
import { VolumeWrapper } from '../../k8s/wrapper/vm/volume-wrapper';
import { selectVM } from './basic';
import { removeOSDups } from '../../utils/sort';
Expand Down Expand Up @@ -83,11 +81,12 @@ export const getTemplateOperatingSystems = (templates: TemplateKind[]) => {
(t) =>
!!Object.keys(getAnnotations(t, {})).find((annotation) => annotation === nameAnnotation),
);

return {
id: osId,
name: getAnnotation(template, nameAnnotation),
dataVolumeName: getOperatingSystemDataVolumeAnnotation(template, osId),
dataVolumeNamespace: getOperatingSystemDataVolumeNamespaceAnnotation(template),
dataVolumeName: getParameter(template, TEMPLATE_DATAVOLUME_NAME_PARAMETER)?.value,
dataVolumeNamespace: getParameter(template, TEMPLATE_DATAVOLUME_NAMESPACE_PARAMETER)?.value,
};
}),
);
Expand Down
13 changes: 0 additions & 13 deletions frontend/packages/kubevirt-plugin/src/selectors/vm/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as _ from 'lodash';
import { getName } from '@console/shared/src/selectors/common';
import { createBasicLookup } from '@console/shared/src/utils/utils';
import {
TEMPLATE_DATAVOLUME_ANNOTATION,
TEMPLATE_FLAVOR_LABEL,
TEMPLATE_OS_LABEL,
TEMPLATE_OS_NAME_ANNOTATION,
Expand Down Expand Up @@ -182,15 +181,3 @@ export const getIsGraphicsConsoleAttached = (vm: VMKind) =>

export const getIsSerialConsoleAttached = (vm: VMKind) =>
vm?.spec?.template?.spec?.domain?.devices?.autoattachSerialConsole;

export const getOperatingSystemDataVolumeAnnotation = (
vmLike: VMGenericLikeEntityKind,
osId?: string,
) =>
getValueByPrefix(
getAnnotations(vmLike),
`${TEMPLATE_DATAVOLUME_ANNOTATION}/${osId || getOperatingSystem(vmLike)}`,
);

export const getOperatingSystemDataVolumeNamespaceAnnotation = (vmLike: VMGenericLikeEntityKind) =>
getValueByPrefix(getAnnotations(vmLike), `${TEMPLATE_DATAVOLUME_ANNOTATION}/namespace`);

0 comments on commit 2f26c05

Please sign in to comment.