From 0d3a993c1051aa7bf0aa5ce30624a22cade391c0 Mon Sep 17 00:00:00 2001 From: Damian Sawicki Date: Thu, 11 May 2023 16:52:23 +0000 Subject: [PATCH] Do not emit an Event on THC annotation typos --- pkg/controller/translator/translator.go | 13 ++++-------- pkg/controller/translator/translator_test.go | 22 +------------------- 2 files changed, 5 insertions(+), 30 deletions(-) diff --git a/pkg/controller/translator/translator.go b/pkg/controller/translator/translator.go index b8769971d6..b0d8346be3 100644 --- a/pkg/controller/translator/translator.go +++ b/pkg/controller/translator/translator.go @@ -209,17 +209,9 @@ func (t *Translator) maybeEnableBackendConfig(sp *utils.ServicePort, svc *api_v1 // setEnableTHC sets the THCEnabled for the service port as true or false depending on whether // Transparent Health Checks should be enabled. func (t *Translator) setEnableTHC(sp *utils.ServicePort, svc *api_v1.Service) (flagWarning bool) { - var THCEnabled bool - defer func() { //TODO(DamianSawicki): remove defer and move the following to the end of the function. - klog.Infof("Is THC enabled for the sevice %v with service port (%v, %v)? %v", svc.Name, sp.Port, sp.PortName, THCEnabled) - sp.THCConfiguration.THCEnabled = THCEnabled - }() - THCEnabled, err := annotations.FromService(svc).ShouldEnableTHC() if err != nil { - message := fmt.Sprintf("Parsing THC annotation failed: %+v.", err) - t.recorderGetter.Recorder(sp.ID.Service.Namespace).Event(svc, api_v1.EventTypeWarning, "THCAnnotationParsingFailed", message) - klog.Warning(message) + klog.Warningf("Parsing THC annotation failed: %+v.", err) } if THCEnabled && !t.enableTHC { @@ -242,6 +234,9 @@ func (t *Translator) setEnableTHC(sp *utils.ServicePort, svc *api_v1.Service) (f sp.THCConfiguration.THCEvents.THCConfigured = true } + klog.Infof("Is THC enabled for the sevice %v with service port (%v, %v)? %v", svc.Name, sp.Port, sp.PortName, THCEnabled) + sp.THCConfiguration.THCEnabled = THCEnabled + return } diff --git a/pkg/controller/translator/translator_test.go b/pkg/controller/translator/translator_test.go index b5305a9d70..c8ce4cdf54 100644 --- a/pkg/controller/translator/translator_test.go +++ b/pkg/controller/translator/translator_test.go @@ -21,7 +21,6 @@ import ( "fmt" "io/ioutil" "reflect" - "strings" "testing" "time" @@ -1322,9 +1321,7 @@ func TestSetEnableTHC(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { translator := fakeTranslator() - bufferSize := 1 - fakeSingletonRecorderGetter := healthchecks.NewFakeSingletonRecorderGetter(bufferSize) - translator.recorderGetter = fakeSingletonRecorderGetter + translator.recorderGetter = healthchecks.NewFakeRecorderGetter(0) translator.enableTHC = tc.enableTHC sp := *tc.sp @@ -1332,23 +1329,6 @@ func TestSetEnableTHC(t *testing.T) { if !reflect.DeepEqual(&sp, tc.want) { t.Errorf("setEnableTHC, %s\ngot %s,\nwant %s", tc.name, pretty.Sprint(&sp), pretty.Sprint(tc.want)) } - fakeRecorder := fakeSingletonRecorderGetter.FakeRecorder() - if tc.wantEvent { - select { - case output := <-fakeRecorder.Events: - if !strings.HasPrefix(output, tc.eventPrefix) { - t.Fatalf("Incorrect event emitted: %s.", output) - } - case <-time.After(10 * time.Second): - t.Fatalf("Timeout when expecting Event.") - } - } else { - select { - case output := <-fakeRecorder.Events: - t.Fatalf("Unexpected event emitted: %s.", output) - case <-time.After(100 * time.Millisecond): - } - } }) } }