fix: don't panic if the machine config doesn't have network (EM)

This handles the case if the machine config doesn't contain
`.machine.network` (I got hit by that today).

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
This commit is contained in:
Andrey Smirnov 2021-08-18 20:34:47 +03:00
parent 8bef41e4ba
commit 0b86edab80
No known key found for this signature in database
GPG Key ID: 7B26396447AB6DFD

View File

@ -76,7 +76,7 @@ func (p *Packet) Name() string {
}
// Configuration implements the platform.Platform interface.
//nolint:gocyclo
//nolint:gocyclo,cyclop
func (p *Packet) Configuration(ctx context.Context) ([]byte, error) {
// Fetch and unmarshal both the talos machine config and the
// metadata about the instance from packet's metadata server
@ -199,6 +199,14 @@ func (p *Packet) Configuration(ctx context.Context) ([]byte, error) {
}
}
if machineConfig.MachineConfig == nil {
machineConfig.MachineConfig = &v1alpha1.MachineConfig{}
}
if machineConfig.MachineConfig.MachineNetwork == nil {
machineConfig.MachineConfig.MachineNetwork = &v1alpha1.NetworkConfig{}
}
machineConfig.MachineConfig.MachineNetwork.NetworkInterfaces = append(
machineConfig.MachineConfig.MachineNetwork.NetworkInterfaces,
&bondDev,