Skip to content

Commit

Permalink
Merge pull request #4191 from cyril-ui-developer/res-reqs-specdescrip…
Browse files Browse the repository at this point in the history
…tor-missing

Bug-1794844: specDescriptor - "resourceRequirements" - Missing 'Limits and Requests' fields for "Storage (ephemeral storage)" resource
  • Loading branch information
openshift-merge-robot committed Feb 25, 2020
2 parents ff06fbf + 96579c5 commit 7bac664
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ const defaultValueFor = <C extends SpecCapability | StatusCapability>(capability
case SpecCapability.label:
return 'app=openshift';
case SpecCapability.resourceRequirements:
return { limits: { cpu: '500m', memory: '50Mi' }, requests: { cpu: '500m', memory: '50Mi' } };
return {
limits: { cpu: '500m', memory: '50Mi', 'ephemeral-storage': '50Mi' },
requests: { cpu: '500m', memory: '50Mi', 'ephemeral-storage': '50Mi' },
};
case SpecCapability.namespaceSelector:
return { matchNames: ['default'] };
case SpecCapability.booleanSwitch:
Expand Down Expand Up @@ -92,15 +95,23 @@ const inputValueFor = (capability: SpecCapability) => async (el: any) => {
.$$('input')
.get(1)
.getAttribute('value'),
'ephemeral-storage': await el
.$$('input')
.get(2)
.getAttribute('value'),
},
requests: {
cpu: await el
.$$('input')
.get(2)
.get(3)
.getAttribute('value'),
memory: await el
.$$('input')
.get(3)
.get(4)
.getAttribute('value'),
'ephemeral-storage': await el
.$$('input')
.get(5)
.getAttribute('value'),
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,14 @@ export const CreateOperandForm: React.FC<CreateOperandFormProps> = ({
<ResourceRequirements
cpu={_.get(formValues, [field.path, 'limits', 'cpu'])}
memory={_.get(formValues, [field.path, 'limits', 'memory'])}
storage={_.get(formValues, [field.path, 'limits', 'ephemeral-storage'])}
onChangeCPU={(cpu) => updateFormValues([field.path, 'limits', 'cpu'], cpu)}
onChangeMemory={(memory) =>
updateFormValues([field.path, 'limits', 'memory'], memory)
}
onChangeStorage={(storage) =>
updateFormValues([field.path, 'limits', 'ephemeral-storage'], storage)
}
path={`${field.path}.limits`}
/>
</dd>
Expand All @@ -506,10 +510,14 @@ export const CreateOperandForm: React.FC<CreateOperandFormProps> = ({
<ResourceRequirements
cpu={_.get(formValues, [field.path, 'requests', 'cpu'])}
memory={_.get(formValues, [field.path, 'requests', 'memory'])}
storage={_.get(formValues, [field.path, 'requests', 'ephemeral-storage'])}
onChangeCPU={(cpu) => updateFormValues([field.path, 'requests', 'cpu'], cpu)}
onChangeMemory={(memory) =>
updateFormValues([field.path, 'requests', 'memory'], memory)
}
onChangeStorage={(storage) =>
updateFormValues([field.path, 'requests', 'ephemeral-storage'], storage)
}
path={`${field.path}.requests`}
/>
</dd>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,18 @@ describe(ResourceRequirementsModal.name, () => {
it('calls function to update resource instance when form is submitted', (done) => {
wrapper.find('input[name="cpu"]').simulate('change', { target: { value: '200m' } });
wrapper.find('input[name="memory"]').simulate('change', { target: { value: '20Mi' } });
wrapper
.find('input[name="ephemeral-storage"]')
.simulate('change', { target: { value: '50Mi' } });

spyAndExpect(spyOn(k8s, 'k8sUpdate'))(Promise.resolve())
.then(([model, newObj]: [k8s.K8sKind, k8s.K8sResourceKind]) => {
expect(model).toEqual(testModel);
expect(newObj.spec.resources.requests).toEqual({ cpu: '200m', memory: '20Mi' });
expect(newObj.spec.resources.requests).toEqual({
cpu: '200m',
memory: '20Mi',
'ephemeral-storage': '50Mi',
});
done();
})
.catch((err) => fail(err));
Expand All @@ -82,8 +89,8 @@ describe(ResourceRequirementsModalLink.displayName, () => {
beforeEach(() => {
obj = _.cloneDeep(testResourceInstance);
obj.spec.resources = {
limits: { memory: '50Mi', cpu: '500m' },
requests: { memory: '50Mi', cpu: '500m' },
limits: { memory: '50Mi', cpu: '500m', 'ephemeral-storage': '50Mi' },
requests: { memory: '50Mi', cpu: '500m', 'ephemeral-storage': '50Mi' },
};
wrapper = shallow(
<ResourceRequirementsModalLink.WrappedComponent
Expand All @@ -96,25 +103,25 @@ describe(ResourceRequirementsModalLink.displayName, () => {
});

it('renders a button link with the resource requests limits', () => {
const { memory, cpu } = obj.spec.resources.limits;
const { memory, cpu, 'ephemeral-storage': storage } = obj.spec.resources.limits;
wrapper = wrapper.setProps({ type: 'requests' });

expect(
wrapper
.find('button')
.childAt(0)
.text(),
).toEqual(`CPU: ${cpu}, Memory: ${memory}`);
).toEqual(`CPU: ${cpu}, Memory: ${memory}, Storage: ${storage}`);
});

it('renders a button link with the resource limits', () => {
const { memory, cpu } = obj.spec.resources.requests;
const { memory, cpu, 'ephemeral-storage': storage } = obj.spec.resources.requests;
expect(
wrapper
.find('button')
.childAt(0)
.text(),
).toEqual(`CPU: ${cpu}, Memory: ${memory}`);
).toEqual(`CPU: ${cpu}, Memory: ${memory}, Storage: ${storage}`);
});

it('renders default values if undefined', () => {
Expand All @@ -126,7 +133,7 @@ describe(ResourceRequirementsModalLink.displayName, () => {
.find('button')
.childAt(0)
.text(),
).toEqual('CPU: none, Memory: none');
).toEqual('CPU: none, Memory: none, Storage: none');
});

it('opens resource requirements modal when clicked', (done) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import {
import { RootState } from '@console/internal/redux';

export const ResourceRequirements: React.FC<ResourceRequirementsProps> = (props) => {
const { cpu, memory, onChangeCPU, onChangeMemory, path = '' } = props;
const { cpu, memory, storage, onChangeCPU, onChangeMemory, onChangeStorage, path = '' } = props;

return (
<div className="row co-m-form-row">
<div className="col-xs-5">
<div className="col-xs-4">
<label
style={{ fontWeight: 300 }}
className="text-muted text-uppercase"
Expand All @@ -36,7 +36,7 @@ export const ResourceRequirements: React.FC<ResourceRequirementsProps> = (props)
placeholder="500m"
/>
</div>
<div className="col-xs-5">
<div className="col-xs-4">
<label
style={{ fontWeight: 300 }}
className="text-muted text-uppercase"
Expand All @@ -54,6 +54,24 @@ export const ResourceRequirements: React.FC<ResourceRequirementsProps> = (props)
placeholder="50Mi"
/>
</div>
<div className="col-xs-4">
<label
style={{ fontWeight: 300 }}
className="text-muted text-uppercase"
htmlFor={`${path}.ephemeral-storage`}
>
Storage
</label>
<input
value={storage}
onChange={(e) => onChangeStorage(e.target.value)}
id={`${path}.ephemeral-storage`}
name="ephemeral-storage"
type="text"
className="pf-c-form-control"
placeholder="50Mi"
/>
</div>
</div>
);
};
Expand All @@ -65,13 +83,20 @@ export const ResourceRequirementsModal = withHandlePromise(
const [memory, setMemory] = React.useState<string>(
_.get(obj.spec, `${path}.${type}.memory`, ''),
);
const [storage, setStorage] = React.useState<string>(
_.get(obj.spec, `${path}.${type}.ephemeral-storage`),
);

const submit = (e) => {
e.preventDefault();

let newObj = _.cloneDeep(obj);
if (cpu !== '' || memory !== '') {
newObj = _.set(newObj, `spec.${path}.${type}`, { cpu, memory });
if (cpu !== '' || memory !== '' || storage !== '') {
newObj = _.set(newObj, `spec.${path}.${type}`, {
cpu,
memory,
'ephemeral-storage': storage,
});
}

return props.handlePromise(k8sUpdate(model, newObj)).then(props.close);
Expand All @@ -87,8 +112,10 @@ export const ResourceRequirementsModal = withHandlePromise(
<ResourceRequirements
cpu={cpu}
memory={memory}
storage={storage}
onChangeCPU={setCPU}
onChangeMemory={setMemory}
onChangeStorage={setStorage}
path={path}
/>
</ModalBody>
Expand Down Expand Up @@ -156,8 +183,10 @@ export type ResourceRequirementsModalProps = {
export type ResourceRequirementsProps = {
cpu: string;
memory: string;
storage: string;
onChangeCPU: (value: string) => void;
onChangeMemory: (value: string) => void;
onChangeStorage: (value: string) => void;
path?: string;
};

Expand Down

0 comments on commit 7bac664

Please sign in to comment.