-
Story
-
Resolution: Unresolved
-
Minor
-
None
-
None
-
Quality / Stability / Reliability
-
False
-
-
False
-
None
-
None
-
None
-
None
-
None
I think we can DRY the following:
- [decodeAWSMachineProviderSpec|https://github.com/openshift/hive/blob/5931ef9ae7169749016e006d71fa5612ab3ee603/pkg/controller/machinepool/awsactuator.go#L311
- part of getGCPImageID
- decodeOvirtMachineProviderSpec (maybe?)
- part of getVSphereOSImage
- The forthcoming decodeNutanixMachineProviderSpec
...with a generic like:
func decodeMachineProviderSpec[T any](rawExtension *runtime.RawExtension) (*T, error) {
if rawExtension == nil {
return new(T), nil
}
spec := new(T)
if err := json.Unmarshal(rawExtension.Raw, &spec); err != nil {
return nil, fmt.Errorf("error unmarshalling providerSpec: %v", err)
}
return spec, nil
}
Called as e.g.:
nuxProviderSpec := decodeMachineProviderSpec[machinev1.NutanixMachineProviderConfig](rawExtension)
That said, we seem to have upstream renditions of some of these funcs – better to try to find/use them for all, or replace with a local (albeit mostly logically duplicated) func that can be called from all places?