Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate Quantity helper methods for dies
Dies that have fields of resource.Quantity or corev1.ResourceList often have setter methods to parse a string formatted quantity into the structured value. Rather than the user defining these values, we can generate them when we see a field of the type. for resource.Quantity: ``` func (d *MyResourceDie) CapacityString(quantity string) *MyResourceDie { q := resource.MustParse(quantity) return d.Capacity(q) } ``` for corev1.ResourceList: ``` func (d *MyResourceDie) AddLimit(name corev1.ResourceName, quantity resource.Quantity) *MyResourceDie { return d.DieStamp(func(r *corev1.ResourceQuotaSpec) { if r.Limits == nil { r.Limits = corev1.ResourceList{} } r.Limits[name] = quantity }) } func (d *MyResourceDie) AddLimitString(name corev1.ResourceName, quantity string) *MyResourceDie { q := resource.MustParse(quantity) return d.AddLimit(name, q) } ``` Signed-off-by: Scott Andrews <scott@andrews.me>
- Loading branch information