Skip to content

Commit

Permalink
fix: prefer extraConfig over OVF env, skip empty config
Browse files Browse the repository at this point in the history
Some users reported that OVF env takes precedence over extraConfig.
Combined with the fact that `talos.config` is mandatory in the OVA spec,
this causes two problems:
- when you don't supply the mandatory OVF env, it will cause an empty
  Talos config to be retrieved, which is unparsable;
- when you deploy a VM, you cannot override the built in Talos config,
  as OVF env takes precedence over extraConfig.

This patch fixes this in two ways:
- config from OVF env needs to be non-empty.
- the order in which OVF env/extraConfig are probed is reversed.

Signed-off-by: Jorik Jonker <[email protected]>
  • Loading branch information
jonkerj authored and talos-bot committed Jun 7, 2021
1 parent 5ad314f commit 5aede1a
Showing 1 changed file with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ func readConfigFromExtraConfig(extraConfig *rpcvmx.Config, key string) ([]byte,
return nil, fmt.Errorf("failed to decode extraConfig %s: %w", key, err)
}

if len(decoded) == 0 {
log.Printf("skipping zero-length config in extraConfig")

return nil, nil
}

return decoded, nil
}

Expand Down Expand Up @@ -90,6 +96,12 @@ func readConfigFromOvf(extraConfig *rpcvmx.Config, key string) ([]byte, error) {
return nil, fmt.Errorf("failed to decode OVF property %s: %w", property.Key, err)
}

if len(decoded) == 0 {
log.Printf("skipping zero-length config in OVF")

return nil, nil
}

return decoded, nil
}
}
Expand Down Expand Up @@ -119,10 +131,10 @@ func (v *VMware) Configuration(context.Context) ([]byte, error) {

extraConfig := rpcvmx.NewConfig()

// try to fetch `talos.config` from OVF
log.Printf("trying to find '%s' in OVF env", constants.VMwareGuestInfoConfigKey)
// try to fetch `talos.config` from plain extraConfig (ie, the old behavior)
log.Printf("trying to find '%s' in extraConfig", constants.VMwareGuestInfoConfigKey)

config, err := readConfigFromOvf(extraConfig, constants.VMwareGuestInfoConfigKey)
config, err := readConfigFromExtraConfig(extraConfig, constants.VMwareGuestInfoConfigKey)
if err != nil {
return nil, err
}
Expand All @@ -131,10 +143,10 @@ func (v *VMware) Configuration(context.Context) ([]byte, error) {
return config, nil
}

// try to fetch `userdata` from OVF
log.Printf("trying to find '%s' in OVF env", constants.VMwareGuestInfoFallbackKey)
// try to fetch `userdata` from plain extraConfig (ie, the old behavior)
log.Printf("trying to find '%s' in extraConfig", constants.VMwareGuestInfoFallbackKey)

config, err = readConfigFromOvf(extraConfig, constants.VMwareGuestInfoFallbackKey)
config, err = readConfigFromExtraConfig(extraConfig, constants.VMwareGuestInfoFallbackKey)
if err != nil {
return nil, err
}
Expand All @@ -143,10 +155,10 @@ func (v *VMware) Configuration(context.Context) ([]byte, error) {
return config, nil
}

// try to fetch `talos.config` from plain extraConfig (ie, the old behavior)
log.Printf("trying to find '%s' in extraConfig", constants.VMwareGuestInfoConfigKey)
// try to fetch `talos.config` from OVF
log.Printf("trying to find '%s' in OVF env", constants.VMwareGuestInfoConfigKey)

config, err = readConfigFromExtraConfig(extraConfig, constants.VMwareGuestInfoConfigKey)
config, err = readConfigFromOvf(extraConfig, constants.VMwareGuestInfoConfigKey)
if err != nil {
return nil, err
}
Expand All @@ -155,10 +167,10 @@ func (v *VMware) Configuration(context.Context) ([]byte, error) {
return config, nil
}

// try to fetch `userdata` from plain extraConfig (ie, the old behavior)
log.Printf("trying to find '%s' in extraConfig", constants.VMwareGuestInfoFallbackKey)
// try to fetch `userdata` from OVF
log.Printf("trying to find '%s' in OVF env", constants.VMwareGuestInfoFallbackKey)

config, err = readConfigFromExtraConfig(extraConfig, constants.VMwareGuestInfoFallbackKey)
config, err = readConfigFromOvf(extraConfig, constants.VMwareGuestInfoFallbackKey)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 5aede1a

Please sign in to comment.