fix: nil pointer exception in syncLink

If link has no `Info` field we can't do anything meaningful, so we'll just log and skip.
Also fix race in test.

For #6956

Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
This commit is contained in:
Dmitriy Matrenichev 2023-03-16 16:55:58 +03:00 committed by Andrey Smirnov
parent cf101e56fb
commit a14a0aba04
No known key found for this signature in database
GPG Key ID: 7B26396447AB6DFD
2 changed files with 11 additions and 0 deletions

View File

@ -225,6 +225,16 @@ func (ctrl *LinkSpecController) syncLink(ctx context.Context, r controller.Runti
if existing != nil && link.TypedSpec().Logical {
replace := false
if existing.Attributes.Info == nil {
logger.Warn("requested logical link has no info, skipping sync",
zap.String("name", existing.Attributes.Name),
zap.Stringer("type", nethelpers.LinkType(existing.Type)),
zap.Uint32("index", existing.Index),
)
return nil
}
// if type/kind doesn't match, recreate the link to change it
if existing.Type != uint16(link.TypedSpec().Type) || existing.Attributes.Info.Kind != link.TypedSpec().Kind {
logger.Info("replacing logical link",

View File

@ -290,6 +290,7 @@ func (ctrl *LinkStatusController) reconcile(
status.DriverVersion = driverInfo.Version
status.FirmwareVersion = driverInfo.FwVersion
// link.Attributes.Info will be non-nil, because we set status.Kind above using link.Attributes.Info.Kind
switch status.Kind {
case network.LinkKindVLAN:
if err = networkadapter.VLANSpec(&status.VLAN).Decode(link.Attributes.Info.Data); err != nil {