Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not exit NSG monitor when unable to get subnet #3372

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions pkg/monitor/azure/nsg/nsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,23 @@ func (n *NSGMonitor) toSubnetConfig(ctx context.Context, subnetID string) (subne
func (n *NSGMonitor) Monitor(ctx context.Context) []error {
defer n.wg.Done()

errors := []error{}

// to make sure each NSG is processed only once
nsgSet := map[string]*armnetwork.SecurityGroup{}

masterSubnet, err := n.toSubnetConfig(ctx, n.oc.Properties.MasterProfile.SubnetID)
if err != nil {
// FP has no access to the subnet
return []error{err}
errors = append(errors, err)
} else {
if masterSubnet.nsg != nil && masterSubnet.nsg.ID != nil {
nsgSet[*masterSubnet.nsg.ID] = masterSubnet.nsg
}
}

// need this to get the right workerProfiles
workerProfiles, _ := api.GetEnrichedWorkerProfiles(n.oc.Properties)
workerSubnets := make([]subnetNSGConfig, 0, len(workerProfiles))
workerPrefixes := make([]netip.Prefix, 0, len(workerProfiles))
// To minimize the possibility of NRP throttling, we only retrieve a subnet's info only once.
subnetsToMonitor := map[string]struct{}{}
Expand All @@ -139,20 +147,12 @@ func (n *NSGMonitor) Monitor(ctx context.Context) []error {
s, err := n.toSubnetConfig(ctx, subnetID)
if err != nil {
// FP has no access to the subnet
return []error{err}
}
workerSubnets = append(workerSubnets, s)
workerPrefixes = append(workerPrefixes, s.prefix...)
}

// to make sure each NSG is processed only once
nsgSet := map[string]*armnetwork.SecurityGroup{}
if masterSubnet.nsg != nil && masterSubnet.nsg.ID != nil {
nsgSet[*masterSubnet.nsg.ID] = masterSubnet.nsg
}
for _, w := range workerSubnets {
if w.nsg != nil && w.nsg.ID != nil {
nsgSet[*w.nsg.ID] = w.nsg
errors = append(errors, err)
} else {
workerPrefixes = append(workerPrefixes, s.prefix...)
if s.nsg != nil && s.nsg.ID != nil {
nsgSet[*s.nsg.ID] = s.nsg
}
}
}

Expand All @@ -166,6 +166,7 @@ func (n *NSGMonitor) Monitor(ctx context.Context) []error {
nsgResource, err := arm.ParseResourceID(nsgID)
if err != nil {
n.log.Errorf("Unable to parse NSG resource ID: %s. %s", nsgID, err)
errors = append(errors, err)
continue
}

Expand All @@ -185,5 +186,5 @@ func (n *NSGMonitor) Monitor(ctx context.Context) []error {
}
}
}
return []error{}
return errors
}
Loading