feat(castellum): Add castellum and Manila share resources#250
feat(castellum): Add castellum and Manila share resources#250munchtoast wants to merge 3 commits into
Conversation
|
Hi, thanks for the PR. Could you please explain what is the reason for adding the
these resources will be removed within #248 PR |
- Add sci_castellum_resource_v1 resource for managing Castellum autoscaling configuration on a per-project, per-resource-type basis. - Register castellum client via gophercloud-sapcc/v2 v2.1.0.
sci_share removed as openstack_sharedfilesystem_share_v2 accomplishes the same thing upstream.. I have also rebased the branch with the new deprecation changes. |
| @@ -0,0 +1,5 @@ | |||
| // SPDX-FileCopyrightText: 2020-2026 SAP SE or an SAP affiliate company | |||
| return opts | ||
| } | ||
|
|
||
| func castellumSCICastellumResourceV1ExpandThreshold(raw any) *castellum.Threshold { |
There was a problem hiding this comment.
This function (and other functions like it) should return Option[T] instead of *T to avoid useless legwork converting between both formats at the callsite.
| if v, ok := sc.Minimum.Unpack(); ok { | ||
| m["minimum"] = int(v) | ||
| } else { | ||
| m["minimum"] = 0 | ||
| } |
There was a problem hiding this comment.
This, and other instance of this pattern, can be simplified into:
| if v, ok := sc.Minimum.Unpack(); ok { | |
| m["minimum"] = int(v) | |
| } else { | |
| m["minimum"] = 0 | |
| } | |
| m["minimum"] = int(sc.Minimum.UnwrapOr(0)) |
| if v, ok := sc.Maximum.Unpack(); ok { | ||
| m["maximum"] = int(v) | ||
| } else { | ||
| m["maximum"] = 0 | ||
| } |
There was a problem hiding this comment.
This is an incorrect default value. maximum = None is wildly different from maximum = 0. In fact, it's the polar opposite.
| parts := strings.SplitN(id, "/", 2) | ||
| if len(parts) != 2 || parts[0] == "" || parts[1] == "" { | ||
| return "", "", fmt.Errorf("invalid sci_castellum_resource_v1 ID %q: expected <project_id>/<resource_type>", id) | ||
| } | ||
| return parts[0], parts[1], nil |
| if t, ok := resource.LowThreshold.Unpack(); ok { | ||
| _ = d.Set("low_threshold", castellumSCICastellumResourceV1FlattenThreshold(t)) | ||
| } else { | ||
| _ = d.Set("low_threshold", []map[string]any{}) | ||
| } |
There was a problem hiding this comment.
| if t, ok := resource.LowThreshold.Unpack(); ok { | |
| _ = d.Set("low_threshold", castellumSCICastellumResourceV1FlattenThreshold(t)) | |
| } else { | |
| _ = d.Set("low_threshold", []map[string]any{}) | |
| } | |
| _ = d.Set("low_threshold", options.Map(resource.LowThreshold, castellumSCICastellumResourceV1FlattenThreshold).UnwrapOr([]map[string]any{})) |
Same for the other similar instances below.
| m, ok := list[0].(map[string]any) | ||
| if !ok { | ||
| return nil | ||
| } | ||
| return &castellum.Threshold{ | ||
| UsagePercent: castellum.UsageValues{ | ||
| castellum.SingularUsageMetric: m["usage_percent"].(float64), | ||
| }, | ||
| DelaySeconds: uint32(m["delay_seconds"].(int)), | ||
| } |
There was a problem hiding this comment.
This implementation only works for resources that have a single usage metric (like Manila shares), but not for ones with multiple usage metrics (e.g. server groups that scale both on CPU and RAM usage). I'm not asking that this functionality be included in this PR, but the structure of the threshold configuration should be declared in a way that allows the natural expansion to multidimensional usage thresholds later.
For example, we could check m["metric"]here and, instead of pickinglist[0], pick an element from listthat has the key"metric": castellum.SingularUsageMetric`.
|
Uh oh!
There was an error while loading. Please reload this page.