Enable custom project-level resource quotas #16550
Enable custom project-level resource quotas #16550rak-phillip merged 15 commits intorancher:masterfrom
Conversation
Signed-off-by: Phillip Rak <rak.phillip@gmail.com>
Signed-off-by: Phillip Rak <rak.phillip@gmail.com>
Signed-off-by: Phillip Rak <rak.phillip@gmail.com>
Signed-off-by: Phillip Rak <rak.phillip@gmail.com>
This updates existing tests so that a new wrapper is initialized for each test. I encountered issues with tests mutating the wrapper. This update is a more idiomatic style for testing Vue components. Signed-off-by: Phillip Rak <rak.phillip@gmail.com>
Signed-off-by: Phillip Rak <rak.phillip@gmail.com>
Signed-off-by: Phillip Rak <rak.phillip@gmail.com>
Signed-off-by: Phillip Rak <rak.phillip@gmail.com>
Signed-off-by: Phillip Rak <rak.phillip@gmail.com>
Signed-off-by: Phillip Rak <rak.phillip@gmail.com>
| const limit = this.value.spec.resourceQuota.limit; | ||
| const extendedKeys = Object.keys(limit.extended || {}); | ||
|
|
||
| this.typeValues = Object.keys(limit).flatMap((k) => { | ||
| if (k !== TYPES.EXTENDED) { | ||
| return k; | ||
| } | ||
|
|
||
| return extendedKeys.map((ek) => `extended.${ ek }`); | ||
| }); |
There was a problem hiding this comment.
typeValues was originally an array of selected values:
[
"configMaps",
"extended",
"limitsCpu"
]
This pattern needed to be modified to work with multiple extended values, so we now produce an array that appends the custom types to extended:
[
"configMaps",
"extended.test1",
"extended.test2",
"extended.test3",
"limitsCpu"
]
| :mode="mode" | ||
| :types="remainingTypes(typeValues[props.i])" | ||
| :type="typeValues[props.i]" | ||
| :index="props.i" |
There was a problem hiding this comment.
It was just easier for me to think about the indexing by passing a prop and emitting the event along with the index.
| created() { | ||
| if (this.type.startsWith(TYPES.EXTENDED)) { | ||
| this.customType = this.type.split('.')[1]; | ||
| } else { | ||
| this.customType = this.type; |
There was a problem hiding this comment.
This is a side-effect of the updated typeValues pattern[^1]. Custom types will be strings formatted as extended.{ customType }..
edit: thinking about this more, this pattern needs some updating. This will break down with types like requests.nvidia.com/gpu.
| EXTENDED: 'extended', | ||
| CONFIG_MAPS: 'configMaps', |
There was a problem hiding this comment.
I originally had a string constant for EXTENDED, but added CONFIG_MAPS to fix failing unit tests that were relying on specific order in the RANCHER_TYPES array. After I decided to migrate the rest after I added these.
Signed-off-by: Phillip Rak <rak.phillip@gmail.com>
|
The remove behavior is inaccurate.. this stems from the design of the ArrayList component and its usage array indexes as v-for keys #14742. I'm working on an alternative approach that will work for quotas. |
codyrancher
left a comment
There was a problem hiding this comment.
The only reservation that I really had was the split between resource type and resourceIdentifier.
In my mind I think the UX I would've preferred would be just have a Resource Identifier with a taggable labeled select where the user could type in the custom identifier if needed.
Signed-off-by: Phillip Rak <rak.phillip@gmail.com>
Signed-off-by: Phillip Rak <rak.phillip@gmail.com>
Signed-off-by: Phillip Rak <rak.phillip@gmail.com>
Adding a key to the ResourceQuota component will force it to re-render when the key is incremented. This resolves issues with the ArrayList component rendering incorrect rows because it uses an index as key in its v-for. This approach can incur a performance penalty, but I expect the number of rows to remain reasonably small; the added reliability of this approach is more important. Signed-off-by: Phillip Rak <rak.phillip@gmail.com>
Summary
This updates the Project Resource Quotas tab so that custom resource quotas can now be specified.
Fixes #14797
Occurred changes and/or fixed issues
extendedwith computed props and constsTechnical notes summary
The following changes were made to enable custom quotas:
The relationship between the Project and ProjectRow components gets a little complicated with the custom quotas. The components are designed in such a way that "Resource Type" is expected to be unique, but this is no longer the case with multiple "Custom" quotas. I'll call out some code snippets to highlight where special consideration needs to be made.
Areas or cases that should be tested
Project resource quotas should behave as they did before, in addition to being able to add new custom quotas.
Areas which could experience regressions
Existing resource quotas should still behave the same with these changes in place.
Screenshot/Video
Checklist
Admin,Standard UserandUser Base