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

Fix nil pointer exception when deleting MachinePools #4019

Merged
merged 1 commit into from
Sep 21, 2023
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
30 changes: 17 additions & 13 deletions azure/scope/machinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,7 @@
ctx, log, done := tele.StartSpanWithLogger(ctx, "scope.MachinePoolScope.ScaleSetSpec")
defer done()

shouldPatchCustomData := false
if m.HasReplicasExternallyManaged(ctx) {
shouldPatchCustomData = m.cache.HasBootstrapDataChanges
log.V(4).Info("has bootstrap data changed?", "shouldPatchCustomData", shouldPatchCustomData)
}

return &scalesets.ScaleSetSpec{
spec := &scalesets.ScaleSetSpec{

Check warning on line 180 in azure/scope/machinepool.go

View check run for this annotation

Codecov / codecov/patch

azure/scope/machinepool.go#L180

Added line #L180 was not covered by tests
Name: m.Name(),
ResourceGroup: m.ResourceGroup(),
Size: m.AzureMachinePool.Spec.Template.VMSize,
Expand All @@ -209,16 +203,26 @@
OrchestrationMode: m.AzureMachinePool.Spec.OrchestrationMode,
Location: m.AzureMachinePool.Spec.Location,
SubscriptionID: m.SubscriptionID(),
VMSSExtensionSpecs: m.VMSSExtensionSpecs(),
HasReplicasExternallyManaged: m.HasReplicasExternallyManaged(ctx),
ClusterName: m.ClusterName(),
AdditionalTags: m.AzureMachinePool.Spec.AdditionalTags,
SKU: m.cache.VMSKU,
VMImage: m.cache.VMImage,
BootstrapData: m.cache.BootstrapData,
ShouldPatchCustomData: shouldPatchCustomData,
MaxSurge: m.cache.MaxSurge,
}

if m.cache != nil {
if m.HasReplicasExternallyManaged(ctx) {
spec.ShouldPatchCustomData = m.cache.HasBootstrapDataChanges
log.V(4).Info("has bootstrap data changed?", "shouldPatchCustomData", spec.ShouldPatchCustomData)
}
spec.VMSSExtensionSpecs = m.VMSSExtensionSpecs()
spec.SKU = m.cache.VMSKU
spec.VMImage = m.cache.VMImage
spec.BootstrapData = m.cache.BootstrapData
spec.MaxSurge = m.cache.MaxSurge
} else {
log.V(4).Info("machinepool cache is nil, this is only expected when deleting a machinepool")
}

Check warning on line 223 in azure/scope/machinepool.go

View check run for this annotation

Codecov / codecov/patch

azure/scope/machinepool.go#L210-L223

Added lines #L210 - L223 were not covered by tests

return spec

Check warning on line 225 in azure/scope/machinepool.go

View check run for this annotation

Codecov / codecov/patch

azure/scope/machinepool.go#L225

Added line #L225 was not covered by tests
}

// Name returns the Azure Machine Pool Name.
Expand Down