mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 07:20:13 +00:00
two optimizations
- removed unnecessary return statements - optimized HTTP response code evaluations as numeric comparisons
This commit is contained in:
parent
c95af06154
commit
17f8dc53af
@ -17,9 +17,6 @@ limitations under the License.
|
||||
package azure
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
@ -153,19 +150,12 @@ func processRetryResponse(resp autorest.Response, err error) (bool, error) {
|
||||
|
||||
// shouldRetryAPIRequest determines if the response from an HTTP request suggests periodic retry behavior
|
||||
func shouldRetryAPIRequest(resp autorest.Response, err error) bool {
|
||||
// non-nil error from HTTP request suggests we should retry
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
// HTTP 429 suggests we should retry
|
||||
if resp.StatusCode == http.StatusTooManyRequests {
|
||||
return true
|
||||
}
|
||||
// HTTP 5xx suggests we should retry
|
||||
r, err := regexp.Compile(`^5\d\d$`)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if r.MatchString(strconv.Itoa(resp.StatusCode)) {
|
||||
// HTTP 4xx or 5xx suggests we should retry
|
||||
if 399 < resp.StatusCode && resp.StatusCode < 600 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
@ -174,11 +164,7 @@ func shouldRetryAPIRequest(resp autorest.Response, err error) bool {
|
||||
// isSuccessHTTPResponse determines if the response from an HTTP request suggests success
|
||||
func isSuccessHTTPResponse(resp autorest.Response) bool {
|
||||
// HTTP 2xx suggests a successful response
|
||||
r, err := regexp.Compile(`^2\d\d$`)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if r.MatchString(strconv.Itoa(resp.StatusCode)) {
|
||||
if 199 < resp.StatusCode && resp.StatusCode < 300 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
@ -326,7 +326,7 @@ func (az *Cloud) EnsureLoadBalancerDeleted(clusterName string, service *v1.Servi
|
||||
if shouldRetryAPIRequest(resp, err) {
|
||||
retryErr := az.CreateOrUpdateSGWithRetry(reconciledSg)
|
||||
if retryErr != nil {
|
||||
return retryErr
|
||||
err = retryErr
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
@ -361,7 +361,7 @@ func (az *Cloud) cleanupLoadBalancer(clusterName string, service *v1.Service, is
|
||||
if shouldRetryAPIRequest(resp, err) {
|
||||
retryErr := az.CreateOrUpdateLBWithRetry(lb)
|
||||
if retryErr != nil {
|
||||
return retryErr
|
||||
err = retryErr
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
@ -374,7 +374,7 @@ func (az *Cloud) cleanupLoadBalancer(clusterName string, service *v1.Service, is
|
||||
if shouldRetryAPIRequest(resp, err) {
|
||||
retryErr := az.DeleteLBWithRetry(lbName)
|
||||
if retryErr != nil {
|
||||
return retryErr
|
||||
err = retryErr
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
@ -891,7 +891,7 @@ func (az *Cloud) ensureHostInPool(serviceName string, nodeName types.NodeName, b
|
||||
if shouldRetryAPIRequest(resp, err) {
|
||||
retryErr := az.CreateOrUpdateInterfaceWithRetry(nic)
|
||||
if retryErr != nil {
|
||||
return retryErr
|
||||
err = retryErr
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -80,7 +80,7 @@ func (az *Cloud) CreateRoute(clusterName string, nameHint string, kubeRoute *clo
|
||||
if shouldRetryAPIRequest(resp, err) {
|
||||
retryErr := az.CreateOrUpdateRouteTableWithRetry(routeTable)
|
||||
if retryErr != nil {
|
||||
return retryErr
|
||||
err = retryErr
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
@ -113,7 +113,7 @@ func (az *Cloud) CreateRoute(clusterName string, nameHint string, kubeRoute *clo
|
||||
if shouldRetryAPIRequest(resp, err) {
|
||||
retryErr := az.CreateOrUpdateRouteWithRetry(route)
|
||||
if retryErr != nil {
|
||||
return retryErr
|
||||
err = retryErr
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
@ -134,7 +134,7 @@ func (az *Cloud) DeleteRoute(clusterName string, kubeRoute *cloudprovider.Route)
|
||||
if shouldRetryAPIRequest(resp, err) {
|
||||
retryErr := az.DeleteRouteWithRetry(routeName)
|
||||
if retryErr != nil {
|
||||
return retryErr
|
||||
err = retryErr
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -68,7 +68,7 @@ func (az *Cloud) AttachDisk(diskName, diskURI string, nodeName types.NodeName, l
|
||||
if shouldRetryAPIRequest(resp, err) {
|
||||
retryErr := az.CreateOrUpdateVMWithRetry(vmName, newVM)
|
||||
if retryErr != nil {
|
||||
return retryErr
|
||||
err = retryErr
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
@ -145,7 +145,7 @@ func (az *Cloud) DetachDiskByName(diskName, diskURI string, nodeName types.NodeN
|
||||
if shouldRetryAPIRequest(resp, err) {
|
||||
retryErr := az.CreateOrUpdateVMWithRetry(vmName, newVM)
|
||||
if retryErr != nil {
|
||||
return retryErr
|
||||
err = retryErr
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user