Merge pull request #120087 from divyasri537/incorporating-feedback-PR-119341
Incorporating feedback on 119341
This commit is contained in:
		| @@ -20,6 +20,7 @@ package mutating | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"time" | ||||
|  | ||||
| @@ -168,13 +169,12 @@ func (a *mutatingDispatcher) Dispatch(ctx context.Context, attr admission.Attrib | ||||
| 		if err != nil { | ||||
| 			switch err := err.(type) { | ||||
| 			case *webhookutil.ErrCallingWebhook: | ||||
| 				if ctx.Err() == context.Canceled { | ||||
| 					klog.Warningf("Context Canceled when calling webhook %v", hook.Name) | ||||
| 					return err | ||||
| 				} | ||||
| 				if !ignoreClientCallFailures { | ||||
| 					rejected = true | ||||
| 					admissionmetrics.Metrics.ObserveWebhookRejection(ctx, hook.Name, "admit", string(versionedAttr.Attributes.GetOperation()), admissionmetrics.WebhookRejectionCallingWebhookError, int(err.Status.ErrStatus.Code)) | ||||
| 					// Ignore context cancelled from webhook metrics | ||||
| 					if !errors.Is(err.Reason, context.Canceled) { | ||||
| 						admissionmetrics.Metrics.ObserveWebhookRejection(ctx, hook.Name, "admit", string(versionedAttr.Attributes.GetOperation()), admissionmetrics.WebhookRejectionCallingWebhookError, int(err.Status.ErrStatus.Code)) | ||||
| 					} | ||||
| 				} | ||||
| 				admissionmetrics.Metrics.ObserveWebhook(ctx, hook.Name, time.Since(t), rejected, versionedAttr.Attributes, "admit", int(err.Status.ErrStatus.Code)) | ||||
| 			case *webhookutil.ErrWebhookRejection: | ||||
| @@ -203,10 +203,14 @@ func (a *mutatingDispatcher) Dispatch(ctx context.Context, attr admission.Attrib | ||||
|  | ||||
| 		if callErr, ok := err.(*webhookutil.ErrCallingWebhook); ok { | ||||
| 			if ignoreClientCallFailures { | ||||
| 				klog.Warningf("Failed calling webhook, failing open %v: %v", hook.Name, callErr) | ||||
| 				admissionmetrics.Metrics.ObserveWebhookFailOpen(ctx, hook.Name, "admit") | ||||
| 				annotator.addFailedOpenAnnotation() | ||||
|  | ||||
| 				// Ignore context cancelled from webhook metrics | ||||
| 				if errors.Is(callErr.Reason, context.Canceled) { | ||||
| 					klog.Warningf("Context canceled when calling webhook %v", hook.Name) | ||||
| 				} else { | ||||
| 					klog.Warningf("Failed calling webhook, failing open %v: %v", hook.Name, callErr) | ||||
| 					admissionmetrics.Metrics.ObserveWebhookFailOpen(ctx, hook.Name, "admit") | ||||
| 					annotator.addFailedOpenAnnotation() | ||||
| 				} | ||||
| 				utilruntime.HandleError(callErr) | ||||
|  | ||||
| 				select { | ||||
|   | ||||
| @@ -18,6 +18,7 @@ package validating | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"sync" | ||||
| 	"time" | ||||
| @@ -173,13 +174,12 @@ func (d *validatingDispatcher) Dispatch(ctx context.Context, attr admission.Attr | ||||
| 			if err != nil { | ||||
| 				switch err := err.(type) { | ||||
| 				case *webhookutil.ErrCallingWebhook: | ||||
| 					if ctx.Err() == context.Canceled { | ||||
| 						klog.Warningf("Context Canceled when calling webhook %v", hook.Name) | ||||
| 						return | ||||
| 					} | ||||
| 					if !ignoreClientCallFailures { | ||||
| 						rejected = true | ||||
| 						admissionmetrics.Metrics.ObserveWebhookRejection(ctx, hook.Name, "validating", string(versionedAttr.Attributes.GetOperation()), admissionmetrics.WebhookRejectionCallingWebhookError, int(err.Status.ErrStatus.Code)) | ||||
| 						// Ignore context cancelled from webhook metrics | ||||
| 						if !errors.Is(err.Reason, context.Canceled) { | ||||
| 							admissionmetrics.Metrics.ObserveWebhookRejection(ctx, hook.Name, "validating", string(versionedAttr.Attributes.GetOperation()), admissionmetrics.WebhookRejectionCallingWebhookError, int(err.Status.ErrStatus.Code)) | ||||
| 						} | ||||
| 					} | ||||
| 					admissionmetrics.Metrics.ObserveWebhook(ctx, hook.Name, time.Since(t), rejected, versionedAttr.Attributes, "validating", int(err.Status.ErrStatus.Code)) | ||||
| 				case *webhookutil.ErrWebhookRejection: | ||||
| @@ -198,12 +198,17 @@ func (d *validatingDispatcher) Dispatch(ctx context.Context, attr admission.Attr | ||||
|  | ||||
| 			if callErr, ok := err.(*webhookutil.ErrCallingWebhook); ok { | ||||
| 				if ignoreClientCallFailures { | ||||
| 					klog.Warningf("Failed calling webhook, failing open %v: %v", hook.Name, callErr) | ||||
| 					admissionmetrics.Metrics.ObserveWebhookFailOpen(ctx, hook.Name, "validating") | ||||
| 					key := fmt.Sprintf("%sround_0_index_%d", ValidatingAuditAnnotationFailedOpenKeyPrefix, idx) | ||||
| 					value := hook.Name | ||||
| 					if err := versionedAttr.Attributes.AddAnnotation(key, value); err != nil { | ||||
| 						klog.Warningf("Failed to set admission audit annotation %s to %s for validating webhook %s: %v", key, value, hook.Name, err) | ||||
| 					// Ignore context cancelled from webhook metrics | ||||
| 					if errors.Is(callErr.Reason, context.Canceled) { | ||||
| 						klog.Warningf("Context canceled when calling webhook %v", hook.Name) | ||||
| 					} else { | ||||
| 						klog.Warningf("Failed calling webhook, failing open %v: %v", hook.Name, callErr) | ||||
| 						admissionmetrics.Metrics.ObserveWebhookFailOpen(ctx, hook.Name, "validating") | ||||
| 						key := fmt.Sprintf("%sround_0_index_%d", ValidatingAuditAnnotationFailedOpenKeyPrefix, idx) | ||||
| 						value := hook.Name | ||||
| 						if err := versionedAttr.Attributes.AddAnnotation(key, value); err != nil { | ||||
| 							klog.Warningf("Failed to set admission audit annotation %s to %s for validating webhook %s: %v", key, value, hook.Name, err) | ||||
| 						} | ||||
| 					} | ||||
| 					utilruntime.HandleError(callErr) | ||||
| 					return | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Kubernetes Prow Robot
					Kubernetes Prow Robot