From 4d65097afa526883a99d1820c67c2d8e05bcb0fd Mon Sep 17 00:00:00 2001 From: Manuel Alejandro de Brito Fontes Date: Mon, 26 Oct 2020 16:08:55 -0300 Subject: [PATCH] Improve log messages --- internal/admission/controller/main.go | 6 ++--- internal/ingress/annotations/annotations.go | 6 ++--- .../annotations/sessionaffinity/main.go | 14 +++++------ internal/ingress/controller/store/store.go | 24 +++++++++---------- 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/internal/admission/controller/main.go b/internal/admission/controller/main.go index b6b663e8a..7c59cdd9e 100644 --- a/internal/admission/controller/main.go +++ b/internal/admission/controller/main.go @@ -63,7 +63,7 @@ func (ia *IngressAdmission) HandleAdmission(obj runtime.Object) (runtime.Object, outputVersion = admissionv1beta1.SchemeGroupVersion reviewv1beta1, isv1beta1 := obj.(*admissionv1beta1.AdmissionReview) if !isv1beta1 { - return nil, fmt.Errorf("request is not of type apiextensions v1 or v1beta1") + return nil, fmt.Errorf("request is not of type AdmissionReview v1 or v1beta1") } review = &admissionv1.AdmissionReview{} @@ -98,7 +98,7 @@ func (ia *IngressAdmission) HandleAdmission(obj runtime.Object) (runtime.Object, } if err := ia.Checker.CheckIngress(&ingress); err != nil { - klog.ErrorS(err, "invalid ingress configuration", "ingress", review.Request.Name, "namespace", review.Request.Namespace) + klog.ErrorS(err, "invalid ingress configuration", "ingress", fmt.Sprintf("%v/%v", review.Request.Name, review.Request.Namespace)) status.Allowed = false status.Result = &metav1.Status{ Status: metav1.StatusFailure, Code: http.StatusBadRequest, Reason: metav1.StatusReasonBadRequest, @@ -109,7 +109,7 @@ func (ia *IngressAdmission) HandleAdmission(obj runtime.Object) (runtime.Object, return convertResponse(review, outputVersion), nil } - klog.InfoS("successfully validated configuration, accepting", "ingress", review.Request.Name, "namespace", review.Request.Namespace) + klog.InfoS("successfully validated configuration, accepting", "ingress", fmt.Sprintf("%v/%v", review.Request.Name, review.Request.Namespace)) status.Allowed = true review.Response = status diff --git a/internal/ingress/annotations/annotations.go b/internal/ingress/annotations/annotations.go index 87bb8a2c4..0e9b7f214 100644 --- a/internal/ingress/annotations/annotations.go +++ b/internal/ingress/annotations/annotations.go @@ -175,7 +175,7 @@ func (e Extractor) Extract(ing *networking.Ingress) *Ingress { data := make(map[string]interface{}) for name, annotationParser := range e.annotations { val, err := annotationParser.Parse(ing) - klog.V(5).InfoS("Parsing Ingress annotation", "name", name, "namespace", ing.GetNamespace(), "ingress", ing.GetName(), "value", val) + klog.V(5).InfoS("Parsing Ingress annotation", "name", name, "ingress", klog.KObj(ing), "value", val) if err != nil { if errors.IsMissingAnnotations(err) { continue @@ -197,11 +197,11 @@ func (e Extractor) Extract(ing *networking.Ingress) *Ingress { if !alreadyDenied { errString := err.Error() data[DeniedKeyName] = &errString - klog.ErrorS(err, "error reading Ingress annotation", "name", name, "namespace", ing.GetNamespace(), "ingress", ing.GetName()) + klog.ErrorS(err, "error reading Ingress annotation", "name", name, "ingress", klog.KObj(ing)) continue } - klog.V(5).ErrorS(err, "error reading Ingress annotation", "name", name, "namespace", ing.GetNamespace(), "ingress", ing.GetName()) + klog.V(5).ErrorS(err, "error reading Ingress annotation", "name", name, "ingress", klog.KObj(ing)) } if val != nil { diff --git a/internal/ingress/annotations/sessionaffinity/main.go b/internal/ingress/annotations/sessionaffinity/main.go index db4f399b4..5765cf537 100644 --- a/internal/ingress/annotations/sessionaffinity/main.go +++ b/internal/ingress/annotations/sessionaffinity/main.go @@ -96,40 +96,40 @@ func (a affinity) cookieAffinityParse(ing *networking.Ingress) *Cookie { cookie.Name, err = parser.GetStringAnnotation(annotationAffinityCookieName, ing) if err != nil { - klog.V(3).InfoS("Invalid or no annotation value found. Ignoring", "ingress", ing.Name, "annotation", annotationAffinityCookieExpires, "default", defaultAffinityCookieName) + klog.V(3).InfoS("Invalid or no annotation value found. Ignoring", "ingress", klog.KObj(ing), "annotation", annotationAffinityCookieExpires, "default", defaultAffinityCookieName) cookie.Name = defaultAffinityCookieName } cookie.Expires, err = parser.GetStringAnnotation(annotationAffinityCookieExpires, ing) if err != nil || !affinityCookieExpiresRegex.MatchString(cookie.Expires) { - klog.V(3).InfoS("Invalid or no annotation value found. Ignoring", "ingress", ing.Name, "annotation", annotationAffinityCookieExpires) + klog.V(3).InfoS("Invalid or no annotation value found. Ignoring", "ingress", klog.KObj(ing), "annotation", annotationAffinityCookieExpires) cookie.Expires = "" } cookie.MaxAge, err = parser.GetStringAnnotation(annotationAffinityCookieMaxAge, ing) if err != nil || !affinityCookieExpiresRegex.MatchString(cookie.MaxAge) { - klog.V(3).InfoS("Invalid or no annotation value found. Ignoring", "ingress", ing.Name, "annotation", annotationAffinityCookieMaxAge) + klog.V(3).InfoS("Invalid or no annotation value found. Ignoring", "ingress", klog.KObj(ing), "annotation", annotationAffinityCookieMaxAge) cookie.MaxAge = "" } cookie.Path, err = parser.GetStringAnnotation(annotationAffinityCookiePath, ing) if err != nil { - klog.V(3).InfoS("Invalid or no annotation value found. Ignoring", "ingress", ing.Name, "annotation", annotationAffinityCookieMaxAge) + klog.V(3).InfoS("Invalid or no annotation value found. Ignoring", "ingress", klog.KObj(ing), "annotation", annotationAffinityCookieMaxAge) } cookie.SameSite, err = parser.GetStringAnnotation(annotationAffinityCookieSameSite, ing) if err != nil { - klog.V(3).InfoS("Invalid or no annotation value found. Ignoring", "ingress", ing.Name, "annotation", annotationAffinityCookieSameSite) + klog.V(3).InfoS("Invalid or no annotation value found. Ignoring", "ingress", klog.KObj(ing), "annotation", annotationAffinityCookieSameSite) } cookie.ConditionalSameSiteNone, err = parser.GetBoolAnnotation(annotationAffinityCookieConditionalSameSiteNone, ing) if err != nil { - klog.V(3).InfoS("Invalid or no annotation value found. Ignoring", "ingress", ing.Name, "annotation", annotationAffinityCookieConditionalSameSiteNone) + klog.V(3).InfoS("Invalid or no annotation value found. Ignoring", "ingress", klog.KObj(ing), "annotation", annotationAffinityCookieConditionalSameSiteNone) } cookie.ChangeOnFailure, err = parser.GetBoolAnnotation(annotationAffinityCookieChangeOnFailure, ing) if err != nil { - klog.V(3).InfoS("Invalid or no annotation value found. Ignoring", "ingress", ing.Name, "annotation", annotationAffinityCookieChangeOnFailure) + klog.V(3).InfoS("Invalid or no annotation value found. Ignoring", "ingress", klog.KObj(ing), "annotation", annotationAffinityCookieChangeOnFailure) } return cookie diff --git a/internal/ingress/controller/store/store.go b/internal/ingress/controller/store/store.go index 584a1c7e7..814142a3d 100644 --- a/internal/ingress/controller/store/store.go +++ b/internal/ingress/controller/store/store.go @@ -328,12 +328,10 @@ func New( } if isCatchAllIngress(ing.Spec) && disableCatchAll { - klog.InfoS("Ignoring delete for catch-all because of --disable-catch-all", "namespace", ing.Namespace, "ingress", ing.Name) + klog.InfoS("Ignoring delete for catch-all because of --disable-catch-all", "ingress", klog.KObj(ing)) return } - recorder.Eventf(ing, corev1.EventTypeNormal, "DELETE", fmt.Sprintf("Ingress %s/%s", ing.Namespace, ing.Name)) - store.listers.IngressWithAnnotation.Delete(ing) key := k8s.MetaNamespaceKey(ing) @@ -350,14 +348,14 @@ func New( ing, _ := toIngress(obj) if !class.IsValid(ing) { a, _ := parser.GetStringAnnotation(class.IngressKey, ing) - klog.InfoS("Ignoring add for ingress based on annotation", "namespace", ing.Namespace, "ingress", ing.Name, "annotation", a) + klog.InfoS("Ignoring add for ingress based on annotation", "ingress", klog.KObj(ing), "annotation", a) return } if isCatchAllIngress(ing.Spec) && disableCatchAll { - klog.InfoS("Ignoring add for catch-all ingress because of --disable-catch-all", "namespace", ing.Namespace, "ingress", ing.Name) + klog.InfoS("Ignoring add for catch-all ingress because of --disable-catch-all", "ingress", klog.KObj(ing)) return } - recorder.Eventf(ing, corev1.EventTypeNormal, "CREATE", fmt.Sprintf("Ingress %s/%s", ing.Namespace, ing.Name)) + recorder.Eventf(ing, corev1.EventTypeNormal, "Sync", "Scheduled for sync") store.syncIngress(ing) store.updateSecretIngressMap(ing) @@ -377,26 +375,26 @@ func New( validCur := class.IsValid(curIng) if !validOld && validCur { if isCatchAllIngress(curIng.Spec) && disableCatchAll { - klog.InfoS("ignoring update for catch-all ingress because of --disable-catch-all", "namespace", curIng.Namespace, "ingress", curIng.Name) + klog.InfoS("ignoring update for catch-all ingress because of --disable-catch-all", "ingress", klog.KObj(curIng)) return } - klog.InfoS("creating ingress", "namespace", curIng.Namespace, "ingress", curIng.Name, "class", class.IngressKey) - recorder.Eventf(curIng, corev1.EventTypeNormal, "CREATE", fmt.Sprintf("Ingress %s/%s", curIng.Namespace, curIng.Name)) + klog.InfoS("creating ingress", "ingress", klog.KObj(curIng), "class", class.IngressKey) + recorder.Eventf(curIng, corev1.EventTypeNormal, "Sync", "Scheduled for sync") } else if validOld && !validCur { - klog.InfoS("removing ingress", "namespace", curIng.Namespace, "ingress", curIng.Name, "class", class.IngressKey) + klog.InfoS("removing ingress", "ingress", klog.KObj(curIng), "class", class.IngressKey) ingDeleteHandler(old) return } else if validCur && !reflect.DeepEqual(old, cur) { if isCatchAllIngress(curIng.Spec) && disableCatchAll { - klog.InfoS("ignoring update for catch-all ingress and delete old one because of --disable-catch-all", "namespace", curIng.Namespace, "ingress", curIng.Name) + klog.InfoS("ignoring update for catch-all ingress and delete old one because of --disable-catch-all", "ingress", klog.KObj(curIng)) ingDeleteHandler(old) return } - recorder.Eventf(curIng, corev1.EventTypeNormal, "UPDATE", fmt.Sprintf("Ingress %s/%s", curIng.Namespace, curIng.Name)) + recorder.Eventf(curIng, corev1.EventTypeNormal, "Sync", "Scheduled for sync") } else { - klog.V(3).InfoS("No changes on ingress. Skipping update", "namespace", curIng.Namespace, "ingress", curIng.Name) + klog.V(3).InfoS("No changes on ingress. Skipping update", "ingress", klog.KObj(curIng)) return }