diff --git a/pkg/wekafs/apiclient/nfs.go b/pkg/wekafs/apiclient/nfs.go index e1b889a48..170efc94f 100644 --- a/pkg/wekafs/apiclient/nfs.go +++ b/pkg/wekafs/apiclient/nfs.go @@ -223,10 +223,10 @@ func EnsureNfsPermission(ctx context.Context, fsName string, group string, apiCl } type NfsClientGroup struct { - Uid *uuid.UUID `json:"uid,omitempty" url:"-"` - Rules *[]NfsClientGroupRule `json:"rules,omitempty" url:"-"` - Id string `json:"id" url:"-"` - Name string `json:"name,omitempty" url:"name,omitempty"` + Uid uuid.UUID `json:"uid,omitempty" url:"-"` + Rules []NfsClientGroupRule `json:"rules,omitempty" url:"-"` + Id string `json:"id" url:"-"` + Name string `json:"name,omitempty" url:"name,omitempty"` } func (g *NfsClientGroup) GetType() string { @@ -250,11 +250,11 @@ func (g *NfsClientGroup) EQ(other ApiObject) bool { } func (g *NfsClientGroup) getImmutableFields() []string { - return []string{"Name", "Id", "Uid"} + return []string{"Name"} } func (g *NfsClientGroup) String() string { - return fmt.Sprintln("NfsClientGroup name:", g.Name, "Uid:", g.Uid.String()) + return fmt.Sprintln("NfsClientGroup name:", g.Name) } func (a *ApiClient) GetNfsClientGroups(ctx context.Context, clientGroups *[]NfsClientGroup) error { @@ -292,8 +292,10 @@ func (a *ApiClient) GetNfsClientGroupByFilter(ctx context.Context, query *NfsCli 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) rs := &[]NfsClientGroup{} err := a.FindNfsClientGroupsByFilter(ctx, query, rs) + logger.Trace().Str("client_group", query.String()).Msg("Getting client group by filter") if err != nil { return &NfsClientGroup{}, err } @@ -313,7 +315,7 @@ func (a *ApiClient) GetNfsClientGroupByName(ctx context.Context, name string) (* } func (a *ApiClient) GetNfsClientGroupByUid(ctx context.Context, uid uuid.UUID) (*NfsClientGroup, error) { - query := &NfsClientGroup{Uid: &uid} + query := &NfsClientGroup{Uid: uid} return a.GetNfsClientGroupByFilter(ctx, query) } @@ -347,9 +349,10 @@ func (a *ApiClient) EnsureCsiPluginNfsClientGroup(ctx context.Context) (*NfsClie if err != ObjectNotFoundError { logger.Error().Err(err).Msg("Failed to get client group by name") return ret, err + } else { + logger.Trace().Str("client_group_name", NfsClientGroupName).Msg("Existing client group not found, creating client group") + err = a.CreateNfsClientGroup(ctx, NewNfsClientGroupCreateRequest(NfsClientGroupName), ret) } - logger.Trace().Str("client_group_name", NfsClientGroupName).Msg("Existing client group not found, creating client group") - err = a.CreateNfsClientGroup(ctx, NewNfsClientGroupCreateRequest(NfsClientGroupName), ret) } return ret, nil } @@ -385,10 +388,10 @@ func NewNfsClientGroupCreateRequest(name string) *NfsClientGroupCreateRequest { type NfsClientGroupRule struct { NfsClientGroupUid uuid.UUID `json:"-" url:"-"` - Type NfsClientGroupRuleType `json:"type" url:"-"` - Uid uuid.UUID `json:"uid" url:"-"` - Rule string `json:"rule" url:"-"` - Id string `json:"id" url:"-"` + Type NfsClientGroupRuleType `json:"type,omitempty" url:"-"` + Uid uuid.UUID `json:"uid,omitempty" url:"-"` + Rule string `json:"rule,omitempty" url:"-"` + Id string `json:"id,omitempty" url:"-"` } func (r *NfsClientGroupRule) GetType() string { @@ -396,7 +399,7 @@ func (r *NfsClientGroupRule) GetType() string { } func (r *NfsClientGroupRule) GetBasePath(a *ApiClient) string { - ncgUrl := (&NfsClientGroup{Uid: &r.Uid}).GetApiUrl(a) + ncgUrl := (&NfsClientGroup{Uid: r.Uid}).GetApiUrl(a) url, err := urlutil.URLJoin(ncgUrl, r.GetType()) if err != nil { return "" @@ -461,7 +464,7 @@ func (a *ApiClient) GetNfsClientGroupRules(ctx context.Context, rules *[]NfsClie if err != nil { return err } - rules = cg.Rules + rules = &cg.Rules return nil } @@ -479,7 +482,7 @@ func (a *ApiClient) FindNfsClientGroupRulesByFilter(ctx context.Context, query * if cg == nil || err != nil { return err } - ret := *cg.Rules + ret := cg.Rules for _, r := range ret { if r.EQ(query) { @@ -537,7 +540,7 @@ func (r *NfsClientGroupRuleCreateRequest) hasRequiredFields() bool { } func (r *NfsClientGroupRuleCreateRequest) getRelatedObject() ApiObject { - return &NfsClientGroup{Uid: &r.NfsClientGroupUid} + return &NfsClientGroup{Uid: r.NfsClientGroupUid} } func (r *NfsClientGroupRuleCreateRequest) String() string { @@ -579,12 +582,12 @@ func (a *ApiClient) EnsureNfsClientGroupRuleForIp(ctx context.Context, cg *NfsCl if cg == nil { return errors.New("NfsClientGroup is nil") } - q := &NfsClientGroupRule{Type: NfsClientGroupRuleTypeIP, Rule: ip, NfsClientGroupUid: *cg.Uid} + q := &NfsClientGroupRule{Type: NfsClientGroupRuleTypeIP, Rule: ip, NfsClientGroupUid: cg.Uid} rule, err := a.GetNfsClientGroupRuleByFilter(ctx, q) if err != nil { if err == ObjectNotFoundError { - req := NewNfsClientGroupRuleCreateRequest(*cg.Uid, rule.Type, rule.Rule) + req := NewNfsClientGroupRuleCreateRequest(cg.Uid, rule.Type, rule.Rule) return a.CreateNfsClientGroupRule(ctx, req, rule) } }