Uploaded image for project: 'OpenShift Hive'
  1. OpenShift Hive
  2. HIVE-2794

Tech Debt: Generic decodeMachineProviderSpec()

XMLWordPrintable

    • Icon: Story Story
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • None
    • Quality / Stability / Reliability
    • False
    • Hide

      None

      Show
      None
    • False
    • None
    • None
    • None
    • None

      I think we can DRY the following:

      ...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?

              Unassigned Unassigned
              efried.openshift Eric Fried
              None
              None
              None
              None
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: