Skip to content

Commit 5b77626

Browse files
authored
Merge pull request #294 from microsoft/user/matthewchen/fix-pnf
Add Generic Not Found case
2 parents ee43ea7 + 7f8b105 commit 5b77626

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

api/v1beta1/conditions_consts.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ const (
3838
OutOfNodeCapacityReason = "OutOfNodeCapacity"
3939
// PathNotFoundReason used when the AzureStackHCI GalleryImage is not found.
4040
PathNotFoundReason = "PathNotFound"
41+
// NotFoundReason used as a generic error reason when a resource is not found.
42+
NotFoundReason = "NotFound"
4143
)
4244

4345
// Conditions and condition Reasons for the AzureStackHCICluster object

controllers/azurestackhcivirtualmachine_controller.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/microsoft/cluster-api-provider-azurestackhci/cloud/scope"
2525
infrav1util "github.com/microsoft/cluster-api-provider-azurestackhci/pkg/util"
2626
mocerrors "github.com/microsoft/moc/pkg/errors"
27+
moccodes "github.com/microsoft/moc/pkg/errors/codes"
2728
"github.com/pkg/errors"
2829

2930
corev1 "k8s.io/api/core/v1"
@@ -209,9 +210,16 @@ func (r *AzureStackHCIVirtualMachineReconciler) getOrCreate(virtualMachineScope
209210
case mocerrors.OutOfCapacity.Error():
210211
conditions.MarkFalse(virtualMachineScope.AzureStackHCIVirtualMachine, infrav1.VMRunningCondition, infrav1.OutOfCapacityReason, clusterv1.ConditionSeverityError, err.Error())
211212
case mocerrors.OutOfNodeCapacity.Error():
212-
conditions.MarkFalse(virtualMachineScope.AzureStackHCIVirtualMachine, infrav1.VMRunningCondition, infrav1.OutOfNodeCapacityReason, clusterv1.ConditionSeverityWarning, err.Error())
213-
case mocerrors.PathNotFound.Error():
214-
conditions.MarkFalse(virtualMachineScope.AzureStackHCIVirtualMachine, infrav1.VMRunningCondition, infrav1.PathNotFoundReason, clusterv1.ConditionSeverityError, err.Error())
213+
conditions.MarkFalse(virtualMachineScope.AzureStackHCIVirtualMachine, infrav1.VMRunningCondition, infrav1.OutOfNodeCapacityReason, clusterv1.ConditionSeverityWarning, err.Error())
214+
case mocerrors.NotFound.Error(): // "NotFound"
215+
fallthrough
216+
// Internally, NotFound is a legacy error and returns the error string instead.
217+
case moccodes.NotFound.String(): // "Not Found"
218+
if mocerrors.IsPathNotFound(err) {
219+
conditions.MarkFalse(virtualMachineScope.AzureStackHCIVirtualMachine, infrav1.VMRunningCondition, infrav1.PathNotFoundReason, clusterv1.ConditionSeverityError, err.Error())
220+
} else {
221+
conditions.MarkFalse(virtualMachineScope.AzureStackHCIVirtualMachine, infrav1.VMRunningCondition, infrav1.NotFoundReason, clusterv1.ConditionSeverityError, err.Error())
222+
}
215223
default:
216224
conditions.MarkFalse(virtualMachineScope.AzureStackHCIVirtualMachine, infrav1.VMRunningCondition, infrav1.VMProvisionFailedReason, clusterv1.ConditionSeverityError, err.Error())
217225
}

0 commit comments

Comments
 (0)