in pkg/controllers/hub/trafficmanagerprofile/controller.go [268:329]
func (r *Reconciler) updateProfileStatus(ctx context.Context, profile *fleetnetv1beta1.TrafficManagerProfile, atmProfile *armtrafficmanager.Profile, armErr error) (ctrl.Result, error) {
profileKObj := klog.KObj(profile)
if armErr == nil {
// atmProfile.Properties.DNSConfig.Fqdn should not be nil
if atmProfile.Properties != nil && atmProfile.Properties.DNSConfig != nil {
profile.Status.DNSName = atmProfile.Properties.DNSConfig.Fqdn
} else {
err := fmt.Errorf("got nil DNSConfig for Azure Traffic Manager profile")
klog.ErrorS(controller.NewUnexpectedBehaviorError(err), "Unexpected value returned by the Azure Traffic Manager", "trafficManagerProfile", profileKObj, "resourceGroup", profile.Spec.ResourceGroup, "atmProfileName", atmProfile.Name)
profile.Status.DNSName = nil // reset the DNS name
}
if atmProfile.ID != nil {
profile.Status.ResourceID = *atmProfile.ID
} else {
profile.Status.ResourceID = "" // reset the resource ID
err := controller.NewUnexpectedBehaviorError(fmt.Errorf("got nil ID for Azure Traffic Manager profile"))
klog.ErrorS(err, "Unexpected value returned by the Azure Traffic Manager", "trafficManagerProfile", profileKObj, "resourceGroup", profile.Spec.ResourceGroup, "atmProfileName", atmProfile.Name)
}
} else {
profile.Status.DNSName = nil // reset the DNS name
profile.Status.ResourceID = "" // reset the resource ID
}
cond := metav1.Condition{
Type: string(fleetnetv1beta1.TrafficManagerProfileConditionProgrammed),
Status: metav1.ConditionTrue,
ObservedGeneration: profile.Generation,
Reason: string(fleetnetv1beta1.TrafficManagerProfileReasonProgrammed),
Message: "Successfully configured the Azure Traffic Manager profile",
}
if azureerrors.IsConflict(armErr) {
cond = metav1.Condition{
Type: string(fleetnetv1beta1.TrafficManagerProfileConditionProgrammed),
Status: metav1.ConditionFalse,
ObservedGeneration: profile.Generation,
Reason: string(fleetnetv1beta1.TrafficManagerProfileReasonDNSNameNotAvailable),
Message: "Domain name is not available. Please choose a different profile name or namespace",
}
} else if azureerrors.IsClientError(armErr) && !azureerrors.IsThrottled(armErr) {
cond = metav1.Condition{
Type: string(fleetnetv1beta1.TrafficManagerProfileConditionProgrammed),
Status: metav1.ConditionFalse,
ObservedGeneration: profile.Generation,
Reason: string(fleetnetv1beta1.TrafficManagerProfileReasonInvalid),
Message: fmt.Sprintf("Invalid profile: %v", armErr),
}
} else if armErr != nil {
cond = metav1.Condition{
Type: string(fleetnetv1beta1.TrafficManagerProfileConditionProgrammed),
Status: metav1.ConditionUnknown,
ObservedGeneration: profile.Generation,
Reason: string(fleetnetv1beta1.TrafficManagerProfileReasonPending),
Message: fmt.Sprintf("Failed to configure profile and retrying: %v", armErr),
}
}
meta.SetStatusCondition(&profile.Status.Conditions, cond)
if err := r.Client.Status().Update(ctx, profile); err != nil {
klog.ErrorS(err, "Failed to update trafficManagerProfile status", "trafficManagerProfile", profileKObj)
return ctrl.Result{}, controller.NewUpdateIgnoreConflictError(err)
}
klog.V(2).InfoS("Updated the trafficProfile status", "trafficManagerProfile", profileKObj, "status", profile.Status)
return ctrl.Result{}, armErr // return the error to retry the reconciliation
}