From d7aa5002f0d7bee2c566478448cc38b6482592b3 Mon Sep 17 00:00:00 2001 From: Rohit Arora <49132604+ntap-arorar@users.noreply.github.com> Date: Wed, 13 Dec 2023 11:03:08 -0500 Subject: [PATCH] Trident liveness probe should check for ACP only if it is enabled The purpose of this change is to ensure Trident's liveness probe does not spam logs if ACP is not enabled. --- acp/client.go | 10 +++++++--- acp/types.go | 1 + frontend/rest/controller_handlers.go | 4 ++++ mocks/mock_acp/mock_acp.go | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/acp/client.go b/acp/client.go index 39f2eb535..b3f69323d 100644 --- a/acp/client.go +++ b/acp/client.go @@ -55,10 +55,14 @@ func newClient(restAPI REST, acpEnabled bool) TridentACP { return &client{restAPI, acpEnabled} } +func (c *client) Enabled() bool { + return c.acpEnabled +} + func (c *client) GetVersion(ctx context.Context) (*version.Version, error) { Logc(ctx).Debug("Getting Trident-ACP version.") - if !c.acpEnabled { + if !c.Enabled() { Logc(ctx).Debug("ACP is not enabled.") return nil, errors.UnsupportedError("ACP is not enabled") } @@ -83,7 +87,7 @@ func (c *client) GetVersionWithBackoff(ctx context.Context) (*version.Version, e var v *version.Version var err error - if !c.acpEnabled { + if !c.Enabled() { Logc(ctx).Debug("ACP is not enabled.") return nil, errors.UnsupportedError("ACP is not enabled") } @@ -123,7 +127,7 @@ func (c *client) IsFeatureEnabled(ctx context.Context, feature string) error { fields := LogFields{"feature": feature} Logc(ctx).WithFields(fields).Debug("Checking if feature is enabled.") - if !c.acpEnabled { + if !c.Enabled() { Logc(ctx).WithFields(fields).Warning("Feature requires Trident-ACP to be enabled.") return errors.UnsupportedConfigError("acp is not enabled") } diff --git a/acp/types.go b/acp/types.go index 37277657e..2c08c9452 100644 --- a/acp/types.go +++ b/acp/types.go @@ -13,6 +13,7 @@ import ( // TridentACP is a set of methods for exposing Trident-ACP REST APIs to Trident. type TridentACP interface { + Enabled() bool GetVersion(context.Context) (*version.Version, error) GetVersionWithBackoff(context.Context) (*version.Version, error) IsFeatureEnabled(context.Context, string) error diff --git a/frontend/rest/controller_handlers.go b/frontend/rest/controller_handlers.go index f93bae7a2..30950aa16 100644 --- a/frontend/rest/controller_handlers.go +++ b/frontend/rest/controller_handlers.go @@ -271,6 +271,10 @@ func GetVersion(w http.ResponseWriter, r *http.Request) { } func GetACPVersion(ctx context.Context) string { + if !acp.API().Enabled() { + return "" + } + version, err := acp.API().GetVersion(ctx) if err != nil { if !errors.IsUnsupportedError(err) { diff --git a/mocks/mock_acp/mock_acp.go b/mocks/mock_acp/mock_acp.go index 8b0a141b2..b83d13554 100644 --- a/mocks/mock_acp/mock_acp.go +++ b/mocks/mock_acp/mock_acp.go @@ -35,6 +35,20 @@ func (m *MockTridentACP) EXPECT() *MockTridentACPMockRecorder { return m.recorder } +// Enabled mocks base method. +func (m *MockTridentACP) Enabled() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Enabled") + ret0, _ := ret[0].(bool) + return ret0 +} + +// Enabled indicates an expected call of Enabled. +func (mr *MockTridentACPMockRecorder) Enabled() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Enabled", reflect.TypeOf((*MockTridentACP)(nil).Enabled)) +} + // GetVersion mocks base method. func (m *MockTridentACP) GetVersion(arg0 context.Context) (*version.Version, error) { m.ctrl.T.Helper()