Skip to content

Commit

Permalink
vpcagent: ClaimVpcGuestDnsRecords: guard against pending_deleted guests
Browse files Browse the repository at this point in the history
  • Loading branch information
yousong committed Jul 6, 2020
1 parent 4bd60cc commit 8212839
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions pkg/vpcagent/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (el *Network) Copy() *Network {
type Guestnetwork struct {
compute_models.SGuestnetwork

// Guest could be nil for when the guest is pending_deleted
Guest *Guest `json:"-"`
Network *Network `json:"-"`
Elasticip *Elasticip `json:"-"`
Expand Down
19 changes: 13 additions & 6 deletions pkg/vpcagent/ovn/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ func (keeper *OVNNorthboundKeeper) ClaimVpcEipgw(ctx context.Context, vpc *agent

func (keeper *OVNNorthboundKeeper) ClaimGuestnetwork(ctx context.Context, guestnetwork *agentmodels.Guestnetwork) error {
var (
// Callers assure that guestnetwork.Guest is not nil
guest = guestnetwork.Guest
network = guestnetwork.Network
vpc = network.Vpc
Expand Down Expand Up @@ -517,14 +518,20 @@ func (keeper *OVNNorthboundKeeper) ClaimVpcGuestDnsRecords(ctx context.Context,
has = map[string]struct{}{}
)
for _, network := range vpc.Networks {
hasValid := false
for _, guestnetwork := range network.Guestnetworks {
var (
guest = guestnetwork.Guest
ip = guestnetwork.IpAddr
)
grs[guest.Name] = append(grs[guest.Name], ip)
if guest := guestnetwork.Guest; guest != nil {
var (
name = guest.Name
ip = guestnetwork.IpAddr
)
grs[name] = append(grs[name], ip)
if !hasValid {
hasValid = true
}
}
}
if len(network.Guestnetworks) > 0 {
if hasValid {
has[network.Id] = struct{}{}
}
}
Expand Down

0 comments on commit 8212839

Please sign in to comment.