Skip to content

Commit deb88ea

Browse files
authored
Fix nil pointer dereference in getSubnetKey (#1516)
1 parent 8ffcab2 commit deb88ea

1 file changed

Lines changed: 12 additions & 18 deletions

File tree

pkg/controller/infrastructure/infraflow/reconcile.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,58 +1966,52 @@ func (c *FlowContext) getSubnetZoneChild(zoneName string) Whiteboard {
19661966
return c.state.GetChild(ChildIdZones).GetChild(zoneName)
19671967
}
19681968

1969-
func (c *FlowContext) getSubnetKey(item *awsclient.Subnet) (zoneName, subnetKey string, err error) {
1969+
func (c *FlowContext) getSubnetKey(item *awsclient.Subnet) (string, string, error) {
19701970
zone := c.getZone(item)
19711971
// With IPv6 we don't have configuration for zone.Workers and zone.Internal.
19721972
// In that case, we get the subnetKey comparing the name tag.
19731973
if zone == nil || !isIPv4(c.getIpFamilies()) {
19741974
// zone may have been deleted from spec, need to find subnetKey on other ways
1975-
zoneName = item.AvailabilityZone
1975+
zoneName := item.AvailabilityZone
19761976
if item.SubnetId != "" {
19771977
zoneChild := c.getSubnetZoneChild(zoneName)
19781978
for _, key := range []string{IdentifierZoneSubnetWorkers, IdentifierZoneSubnetPublic, IdentifierZoneSubnetPrivate} {
19791979
if s := zoneChild.Get(key); s != nil && *s == item.SubnetId {
1980-
subnetKey = key
1981-
return
1980+
return zoneName, key, nil
19821981
}
19831982
}
19841983
}
19851984
if item.Tags != nil && item.Tags[TagKeyName] != "" {
19861985
value := item.Tags[TagKeyName]
1987-
helper := c.zoneSuffixHelpers(zone.Name)
1986+
helper := c.zoneSuffixHelpers(zoneName)
19881987
for _, key := range []string{IdentifierZoneSubnetWorkers, IdentifierZoneSubnetPublic, IdentifierZoneSubnetPrivate} {
19891988
switch key {
19901989
case IdentifierZoneSubnetWorkers:
19911990
if value == fmt.Sprintf("%s-%s", c.namespace, helper.GetSuffixSubnetWorkers()) {
1992-
subnetKey = key
1993-
return
1991+
return zoneName, key, nil
19941992
}
19951993
case IdentifierZoneSubnetPublic:
19961994
if value == fmt.Sprintf("%s-%s", c.namespace, helper.GetSuffixSubnetPublic()) {
1997-
subnetKey = key
1998-
return
1995+
return zoneName, key, nil
19991996
}
20001997
case IdentifierZoneSubnetPrivate:
20011998
if value == fmt.Sprintf("%s-%s", c.namespace, helper.GetSuffixSubnetPrivate()) {
2002-
subnetKey = key
2003-
return
1999+
return zoneName, key, nil
20042000
}
20052001
}
20062002
}
20072003
}
2008-
err = fmt.Errorf("subnetKey could not calculated from subnet item")
2009-
return
2004+
return "", "", fmt.Errorf("could not determine subnet key for subnet %s", item.SubnetId)
20102005
}
2011-
zoneName = zone.Name
20122006
switch item.CidrBlock {
20132007
case zone.Workers:
2014-
subnetKey = IdentifierZoneSubnetWorkers
2008+
return zone.Name, IdentifierZoneSubnetWorkers, nil
20152009
case zone.Public:
2016-
subnetKey = IdentifierZoneSubnetPublic
2010+
return zone.Name, IdentifierZoneSubnetPublic, nil
20172011
case zone.Internal:
2018-
subnetKey = IdentifierZoneSubnetPrivate
2012+
return zone.Name, IdentifierZoneSubnetPrivate, nil
20192013
}
2020-
return
2014+
return "", "", fmt.Errorf("could not determine subnet key for subnet %s", item.SubnetId)
20212015
}
20222016

20232017
func (c *FlowContext) getZone(item *awsclient.Subnet) *aws.Zone {

0 commit comments

Comments
 (0)