From 2a10bbc0e440f37da5afa6ed1c2c788b21095f47 Mon Sep 17 00:00:00 2001 From: Sergey Berezansky Date: Sat, 10 Aug 2024 15:48:33 +0300 Subject: [PATCH] chore(CSI-213): fix EnsureCsiPluginNfsClientGroup logic --- pkg/wekafs/apiclient/nfs.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/pkg/wekafs/apiclient/nfs.go b/pkg/wekafs/apiclient/nfs.go index bcf93044e..e1b889a48 100644 --- a/pkg/wekafs/apiclient/nfs.go +++ b/pkg/wekafs/apiclient/nfs.go @@ -339,16 +339,19 @@ func (a *ApiClient) EnsureCsiPluginNfsClientGroup(ctx context.Context) (*NfsClie ctx, span := otel.Tracer(TracerName).Start(ctx, op) defer span.End() ctx = log.With().Str("trace_id", span.SpanContext().TraceID().String()).Str("span_id", span.SpanContext().SpanID().String()).Str("op", op).Logger().WithContext(ctx) + logger := log.Ctx(ctx) var ret *NfsClientGroup + logger.Trace().Str("client_group_name", NfsClientGroupName).Msg("Getting client group by name") ret, err := a.GetNfsClientGroupByName(ctx, NfsClientGroupName) - if err == nil { - return ret, nil - } - if err != ObjectNotFoundError { - return ret, err + if err != nil { + if err != ObjectNotFoundError { + logger.Error().Err(err).Msg("Failed to get client group by name") + return ret, err + } + logger.Trace().Str("client_group_name", NfsClientGroupName).Msg("Existing client group not found, creating client group") + err = a.CreateNfsClientGroup(ctx, NewNfsClientGroupCreateRequest(NfsClientGroupName), ret) } - err = a.CreateNfsClientGroup(ctx, NewNfsClientGroupCreateRequest(NfsClientGroupName), ret) - return ret, err + return ret, nil } type NfsClientGroupCreateRequest struct { @@ -579,11 +582,12 @@ func (a *ApiClient) EnsureNfsClientGroupRuleForIp(ctx context.Context, cg *NfsCl q := &NfsClientGroupRule{Type: NfsClientGroupRuleTypeIP, Rule: ip, NfsClientGroupUid: *cg.Uid} rule, err := a.GetNfsClientGroupRuleByFilter(ctx, q) - if err == ObjectNotFoundError { - req := NewNfsClientGroupRuleCreateRequest(*cg.Uid, rule.Type, rule.Rule) - err = a.CreateNfsClientGroupRule(ctx, req, rule) + if err != nil { + if err == ObjectNotFoundError { + req := NewNfsClientGroupRuleCreateRequest(*cg.Uid, rule.Type, rule.Rule) + return a.CreateNfsClientGroupRule(ctx, req, rule) + } } - return err }