From d24192e96989b9f0f3282570d78c787fe17e03d8 Mon Sep 17 00:00:00 2001 From: hlts2 Date: Tue, 5 Mar 2024 11:52:23 +0900 Subject: [PATCH 1/7] fix: choose user given target address in priority Signed-off-by: hlts2 --- pkg/index/job/creation/service/indexer.go | 38 ++++------ .../job/creation/service/indexer_test.go | 56 +++++++-------- pkg/index/job/save/service/indexer.go | 45 +++++------- pkg/index/job/save/service/indexer_test.go | 69 +++++++++---------- 4 files changed, 89 insertions(+), 119 deletions(-) diff --git a/pkg/index/job/creation/service/indexer.go b/pkg/index/job/creation/service/indexer.go index 591c0c4074..986f036b3d 100644 --- a/pkg/index/job/creation/service/indexer.go +++ b/pkg/index/job/creation/service/indexer.go @@ -64,13 +64,23 @@ func New(opts ...Option) (Indexer, error) { log.Warn(oerr) } } - idx.targetAddrList = make(map[string]bool, len(idx.targetAddrs)) - for _, addr := range idx.targetAddrs { - idx.targetAddrList[addr] = true - } + idx.targetAddrs = delDuplicateAddrs(idx.targetAddrs) return idx, nil } +func delDuplicateAddrs(targetAddrs []string) []string { + addrs := make([]string, 0, len(targetAddrs)) + exist := make(map[string]bool) + + for _, addr := range targetAddrs { + if !exist[addr] { + addrs = append(addrs, addr) + exist[addr] = true + } + } + return addrs +} + // StartClient starts the gRPC client. func (idx *index) StartClient(ctx context.Context) (<-chan error, error) { return idx.client.Start(ctx) @@ -136,12 +146,7 @@ func (idx *index) doCreateIndex(ctx context.Context, fn func(_ context.Context, targetAddrs := idx.client.GetAddrs(ctx) if len(idx.targetAddrs) != 0 { - targetAddrs = idx.extractTargetAddrs(targetAddrs) - - // If targetAddrs is empty, an invalid target addresses may be registered in targetAddrList. - if len(targetAddrs) == 0 { - return errors.ErrGRPCTargetAddrNotFound - } + targetAddrs = idx.targetAddrs } log.Infof("target agent addrs: %v", targetAddrs) @@ -207,16 +212,3 @@ func (idx *index) doCreateIndex(ctx context.Context, fn func(_ context.Context, ) return errors.Join(err, errs) } - -// extractTargetAddresses filters and extracts target addresses registered in targetAddrList from the given address list. -func (idx *index) extractTargetAddrs(addrs []string) []string { - res := make([]string, 0, len(addrs)) - for _, addr := range addrs { - if !idx.targetAddrList[addr] { - log.Warnf("the gRPC target address not found: %s", addr) - } else { - res = append(res, addr) - } - } - return res -} diff --git a/pkg/index/job/creation/service/indexer_test.go b/pkg/index/job/creation/service/indexer_test.go index 3bca6048fc..77b3231cb5 100644 --- a/pkg/index/job/creation/service/indexer_test.go +++ b/pkg/index/job/creation/service/indexer_test.go @@ -36,7 +36,6 @@ func Test_index_Start(t *testing.T) { type fields struct { client discoverer.Client targetAddrs []string - targetAddrList map[string]bool creationPoolSize uint32 concurrency int } @@ -88,37 +87,30 @@ func Test_index_Start(t *testing.T) { } }(), func() test { - addrs := []string{ - "127.0.0.1:8080", - } return test{ - name: "Fail: when there is an error wrapped with gRPC status in the indexing request process", + name: "Success: when a target addresses (targetAddrs) is given and there are no errors in the indexing request process", args: args{ ctx: context.Background(), }, fields: fields{ + targetAddrs: []string{ + "127.0.0.1:8080", + }, client: &clientmock.DiscovererClientMock{ GetAddrsFunc: func(_ context.Context) []string { - return addrs + return nil }, GetClientFunc: func() grpc.Client { return &grpcmock.GRPCClientMock{ OrderedRangeConcurrentFunc: func(_ context.Context, _ []string, _ int, _ func(_ context.Context, _ string, _ *grpc.ClientConn, _ ...grpc.CallOption) error, ) error { - return status.WrapWithInternal( - agent.CreateIndexRPCName+" API connection not found", - errors.ErrGRPCClientConnNotFound("*"), - ) + return nil }, } }, }, }, - want: want{ - err: status.Error(codes.Internal, - agent.CreateIndexRPCName+" API connection not found"), - }, } }(), func() test { @@ -126,11 +118,10 @@ func Test_index_Start(t *testing.T) { "127.0.0.1:8080", } return test{ - name: "Fail: When the OrderedRangeConcurrent method returns a gRPC client conn not found error", + name: "Fail: when there is an error wrapped with gRPC status in the indexing request process", args: args{ ctx: context.Background(), }, - fields: fields{ client: &clientmock.DiscovererClientMock{ GetAddrsFunc: func(_ context.Context) []string { @@ -141,7 +132,10 @@ func Test_index_Start(t *testing.T) { OrderedRangeConcurrentFunc: func(_ context.Context, _ []string, _ int, _ func(_ context.Context, _ string, _ *grpc.ClientConn, _ ...grpc.CallOption) error, ) error { - return errors.ErrGRPCClientConnNotFound("*") + return status.WrapWithInternal( + agent.CreateIndexRPCName+" API connection not found", + errors.ErrGRPCClientConnNotFound("*"), + ) }, } }, @@ -154,29 +148,34 @@ func Test_index_Start(t *testing.T) { } }(), func() test { - targetAddrs := []string{ + addrs := []string{ "127.0.0.1:8080", } - targetAddrList := map[string]bool{ - targetAddrs[0]: true, - } return test{ - name: "Fail: when there is no address matching targetAddrList", + name: "Fail: When the OrderedRangeConcurrent method returns a gRPC client conn not found error", args: args{ ctx: context.Background(), }, + fields: fields{ client: &clientmock.DiscovererClientMock{ GetAddrsFunc: func(_ context.Context) []string { - return nil + return addrs + }, + GetClientFunc: func() grpc.Client { + return &grpcmock.GRPCClientMock{ + OrderedRangeConcurrentFunc: func(_ context.Context, _ []string, _ int, + _ func(_ context.Context, _ string, _ *grpc.ClientConn, _ ...grpc.CallOption) error, + ) error { + return errors.ErrGRPCClientConnNotFound("*") + }, + } }, }, - targetAddrs: targetAddrs, - targetAddrList: targetAddrList, }, want: want{ err: status.Error(codes.Internal, - agent.CreateIndexRPCName+" API connection target address \"127.0.0.1:8080\" not found"), + agent.CreateIndexRPCName+" API connection not found"), }, } }(), @@ -200,7 +199,6 @@ func Test_index_Start(t *testing.T) { idx := &index{ client: test.fields.client, targetAddrs: test.fields.targetAddrs, - targetAddrList: test.fields.targetAddrList, creationPoolSize: test.fields.creationPoolSize, concurrency: test.fields.concurrency, } @@ -312,7 +310,6 @@ func Test_index_Start(t *testing.T) { // type fields struct { // client discoverer.Client // targetAddrs []string -// targetAddrList map[string]bool // creationPoolSize uint32 // concurrency int // } @@ -349,7 +346,6 @@ func Test_index_Start(t *testing.T) { // fields: fields { // client:nil, // targetAddrs:nil, -// targetAddrList:nil, // creationPoolSize:0, // concurrency:0, // }, @@ -375,7 +371,6 @@ func Test_index_Start(t *testing.T) { // fields: fields { // client:nil, // targetAddrs:nil, -// targetAddrList:nil, // creationPoolSize:0, // concurrency:0, // }, @@ -410,7 +405,6 @@ func Test_index_Start(t *testing.T) { // idx := &index{ // client: test.fields.client, // targetAddrs: test.fields.targetAddrs, -// targetAddrList: test.fields.targetAddrList, // creationPoolSize: test.fields.creationPoolSize, // concurrency: test.fields.concurrency, // } diff --git a/pkg/index/job/save/service/indexer.go b/pkg/index/job/save/service/indexer.go index 7d8c9e4fbc..08465510ba 100644 --- a/pkg/index/job/save/service/indexer.go +++ b/pkg/index/job/save/service/indexer.go @@ -42,16 +42,15 @@ type Indexer interface { } type index struct { - client discoverer.Client - targetAddrs []string - targetAddrList map[string]bool + client discoverer.Client + targetAddrs []string concurrency int } // New returns Indexer object if no error occurs. func New(opts ...Option) (Indexer, error) { - idx := new(index) + idx := &index{} for _, opt := range append(defaultOpts, opts...) { if err := opt(idx); err != nil { oerr := errors.ErrOptionFailed(err, reflect.ValueOf(opt)) @@ -63,13 +62,23 @@ func New(opts ...Option) (Indexer, error) { log.Warn(oerr) } } - idx.targetAddrList = make(map[string]bool, len(idx.targetAddrs)) - for _, addr := range idx.targetAddrs { - idx.targetAddrList[addr] = true - } + idx.targetAddrs = delDuplicateAddrs(idx.targetAddrs) return idx, nil } +func delDuplicateAddrs(targetAddrs []string) []string { + addrs := make([]string, 0, len(targetAddrs)) + exist := make(map[string]bool) + + for _, addr := range targetAddrs { + if !exist[addr] { + addrs = append(addrs, addr) + exist[addr] = true + } + } + return addrs +} + // StartClient starts the gRPC client. func (idx *index) StartClient(ctx context.Context) (<-chan error, error) { return idx.client.Start(ctx) @@ -133,12 +142,7 @@ func (idx *index) doSaveIndex(ctx context.Context, fn func(_ context.Context, _ targetAddrs := idx.client.GetAddrs(ctx) if len(idx.targetAddrs) != 0 { - targetAddrs = idx.extractTargetAddrs(targetAddrs) - - // If targetAddrs is empty, an invalid target addresses may be registered in targetAddrList. - if len(targetAddrs) == 0 { - return errors.ErrGRPCTargetAddrNotFound - } + targetAddrs = idx.targetAddrs } log.Infof("target agent addrs: %v", targetAddrs) @@ -200,16 +204,3 @@ func (idx *index) doSaveIndex(ctx context.Context, fn func(_ context.Context, _ ) return errors.Join(err, errs) } - -// extractTargetAddresses filters and extracts target addresses registered in targetAddrList from the given address list. -func (idx *index) extractTargetAddrs(addrs []string) []string { - res := make([]string, 0, len(addrs)) - for _, addr := range addrs { - if !idx.targetAddrList[addr] { - log.Warnf("the gRPC target address not found: %s", addr) - } else { - res = append(res, addr) - } - } - return res -} diff --git a/pkg/index/job/save/service/indexer_test.go b/pkg/index/job/save/service/indexer_test.go index 67bdd94e76..efb5c37cae 100644 --- a/pkg/index/job/save/service/indexer_test.go +++ b/pkg/index/job/save/service/indexer_test.go @@ -33,10 +33,9 @@ func Test_index_Start(t *testing.T) { ctx context.Context } type fields struct { - client discoverer.Client - targetAddrs []string - targetAddrList map[string]bool - concurrency int + client discoverer.Client + targetAddrs []string + concurrency int } type want struct { err error @@ -86,37 +85,30 @@ func Test_index_Start(t *testing.T) { } }(), func() test { - addrs := []string{ - "127.0.0.1:8080", - } return test{ - name: "Fail: when there is an error wrapped with gRPC status in the save indexing request process", + name: "Success: when a target addresses (targetAddrs) is given and there are no errors in the save indexing request process", args: args{ ctx: context.Background(), }, fields: fields{ + targetAddrs: []string{ + "127.0.0.1:8080", + }, client: &clientmock.DiscovererClientMock{ GetAddrsFunc: func(_ context.Context) []string { - return addrs + return nil }, GetClientFunc: func() grpc.Client { return &grpcmock.GRPCClientMock{ OrderedRangeConcurrentFunc: func(_ context.Context, _ []string, _ int, _ func(_ context.Context, _ string, _ *grpc.ClientConn, _ ...grpc.CallOption) error, ) error { - return status.WrapWithInternal( - agent.SaveIndexRPCName+" API connection not found", - errors.ErrGRPCClientConnNotFound("*"), - ) + return nil }, } }, }, }, - want: want{ - err: status.Error(codes.Internal, - agent.SaveIndexRPCName+" API connection not found"), - }, } }(), func() test { @@ -124,11 +116,10 @@ func Test_index_Start(t *testing.T) { "127.0.0.1:8080", } return test{ - name: "Fail: When the OrderedRangeConcurrent method returns a gRPC client conn not found error", + name: "Fail: when there is an error wrapped with gRPC status in the save indexing request process", args: args{ ctx: context.Background(), }, - fields: fields{ client: &clientmock.DiscovererClientMock{ GetAddrsFunc: func(_ context.Context) []string { @@ -139,7 +130,10 @@ func Test_index_Start(t *testing.T) { OrderedRangeConcurrentFunc: func(_ context.Context, _ []string, _ int, _ func(_ context.Context, _ string, _ *grpc.ClientConn, _ ...grpc.CallOption) error, ) error { - return errors.ErrGRPCClientConnNotFound("*") + return status.WrapWithInternal( + agent.SaveIndexRPCName+" API connection not found", + errors.ErrGRPCClientConnNotFound("*"), + ) }, } }, @@ -152,30 +146,34 @@ func Test_index_Start(t *testing.T) { } }(), func() test { - targetAddrs := []string{ + addrs := []string{ "127.0.0.1:8080", } - targetAddrList := map[string]bool{ - targetAddrs[0]: true, - } return test{ - name: "Fail: when there is no address matching targetAddrList", + name: "Fail: When the OrderedRangeConcurrent method returns a gRPC client conn not found error", args: args{ ctx: context.Background(), }, + fields: fields{ client: &clientmock.DiscovererClientMock{ GetAddrsFunc: func(_ context.Context) []string { - // NOTE: This function returns nil, meaning that the targetAddrs stored in the field are invalid values. - return nil + return addrs + }, + GetClientFunc: func() grpc.Client { + return &grpcmock.GRPCClientMock{ + OrderedRangeConcurrentFunc: func(_ context.Context, _ []string, _ int, + _ func(_ context.Context, _ string, _ *grpc.ClientConn, _ ...grpc.CallOption) error, + ) error { + return errors.ErrGRPCClientConnNotFound("*") + }, + } }, }, - targetAddrs: targetAddrs, - targetAddrList: targetAddrList, }, want: want{ err: status.Error(codes.Internal, - agent.SaveIndexRPCName+" API connection target address \"127.0.0.1:8080\" not found"), + agent.SaveIndexRPCName+" API connection not found"), }, } }(), @@ -197,10 +195,9 @@ func Test_index_Start(t *testing.T) { checkFunc = defaultCheckFunc } idx := &index{ - client: test.fields.client, - targetAddrs: test.fields.targetAddrs, - targetAddrList: test.fields.targetAddrList, - concurrency: test.fields.concurrency, + client: test.fields.client, + targetAddrs: test.fields.targetAddrs, + concurrency: test.fields.concurrency, } err := idx.Start(test.args.ctx) @@ -310,7 +307,6 @@ func Test_index_Start(t *testing.T) { // type fields struct { // client discoverer.Client // targetAddrs []string -// targetAddrList map[string]bool // concurrency int // } // type want struct { @@ -346,7 +342,6 @@ func Test_index_Start(t *testing.T) { // fields: fields { // client:nil, // targetAddrs:nil, -// targetAddrList:nil, // concurrency:0, // }, // want: want{}, @@ -371,7 +366,6 @@ func Test_index_Start(t *testing.T) { // fields: fields { // client:nil, // targetAddrs:nil, -// targetAddrList:nil, // concurrency:0, // }, // want: want{}, @@ -405,7 +399,6 @@ func Test_index_Start(t *testing.T) { // idx := &index{ // client: test.fields.client, // targetAddrs: test.fields.targetAddrs, -// targetAddrList: test.fields.targetAddrList, // concurrency: test.fields.concurrency, // } // From 6acc8b1e4e85592eb09afb0cb07daf1994b7613f Mon Sep 17 00:00:00 2001 From: hlts2 Date: Tue, 5 Mar 2024 12:16:46 +0900 Subject: [PATCH 2/7] fix: deleted unnecessary code Signed-off-by: hlts2 --- pkg/index/job/creation/service/indexer.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/index/job/creation/service/indexer.go b/pkg/index/job/creation/service/indexer.go index 986f036b3d..898330e471 100644 --- a/pkg/index/job/creation/service/indexer.go +++ b/pkg/index/job/creation/service/indexer.go @@ -42,9 +42,8 @@ type Indexer interface { } type index struct { - client discoverer.Client - targetAddrs []string - targetAddrList map[string]bool + client discoverer.Client + targetAddrs []string creationPoolSize uint32 concurrency int From a42637d5087afc1dae346d6b03b28dc3794b27c9 Mon Sep 17 00:00:00 2001 From: hlts2 Date: Tue, 5 Mar 2024 12:34:19 +0900 Subject: [PATCH 3/7] fix: add logic to connect the user given target addresses Signed-off-by: hlts2 --- pkg/index/job/creation/service/indexer.go | 6 ++++++ pkg/index/job/creation/service/indexer_test.go | 8 ++++++-- pkg/index/job/save/service/indexer.go | 6 ++++++ pkg/index/job/save/service/indexer_test.go | 8 ++++++-- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/pkg/index/job/creation/service/indexer.go b/pkg/index/job/creation/service/indexer.go index 898330e471..3531f2790a 100644 --- a/pkg/index/job/creation/service/indexer.go +++ b/pkg/index/job/creation/service/indexer.go @@ -145,6 +145,12 @@ func (idx *index) doCreateIndex(ctx context.Context, fn func(_ context.Context, targetAddrs := idx.client.GetAddrs(ctx) if len(idx.targetAddrs) != 0 { + // If target addresses is specified, that addresses are used in priority. + for _, addr := range idx.targetAddrs { + if _, err := idx.client.GetClient().Connect(ctx, addr); err != nil { + return err + } + } targetAddrs = idx.targetAddrs } log.Infof("target agent addrs: %v", targetAddrs) diff --git a/pkg/index/job/creation/service/indexer_test.go b/pkg/index/job/creation/service/indexer_test.go index 77b3231cb5..aec44fdbc9 100644 --- a/pkg/index/job/creation/service/indexer_test.go +++ b/pkg/index/job/creation/service/indexer_test.go @@ -22,6 +22,7 @@ import ( "github.com/vdaas/vald/internal/errors" "github.com/vdaas/vald/internal/net/grpc" "github.com/vdaas/vald/internal/net/grpc/codes" + "github.com/vdaas/vald/internal/net/grpc/pool" "github.com/vdaas/vald/internal/net/grpc/status" "github.com/vdaas/vald/internal/test/goleak" clientmock "github.com/vdaas/vald/internal/test/mock/client" @@ -67,7 +68,6 @@ func Test_index_Start(t *testing.T) { args: args{ ctx: context.Background(), }, - fields: fields{ client: &clientmock.DiscovererClientMock{ GetAddrsFunc: func(_ context.Context) []string { @@ -95,6 +95,8 @@ func Test_index_Start(t *testing.T) { fields: fields{ targetAddrs: []string{ "127.0.0.1:8080", + "127.0.0.1:8081", + "127.0.0.1:8083", }, client: &clientmock.DiscovererClientMock{ GetAddrsFunc: func(_ context.Context) []string { @@ -107,6 +109,9 @@ func Test_index_Start(t *testing.T) { ) error { return nil }, + ConnectFunc: func(_ context.Context, _ string, _ ...grpc.DialOption) (pool.Conn, error) { + return nil, nil + }, } }, }, @@ -156,7 +161,6 @@ func Test_index_Start(t *testing.T) { args: args{ ctx: context.Background(), }, - fields: fields{ client: &clientmock.DiscovererClientMock{ GetAddrsFunc: func(_ context.Context) []string { diff --git a/pkg/index/job/save/service/indexer.go b/pkg/index/job/save/service/indexer.go index 08465510ba..cd34d9b268 100644 --- a/pkg/index/job/save/service/indexer.go +++ b/pkg/index/job/save/service/indexer.go @@ -142,6 +142,12 @@ func (idx *index) doSaveIndex(ctx context.Context, fn func(_ context.Context, _ targetAddrs := idx.client.GetAddrs(ctx) if len(idx.targetAddrs) != 0 { + // If target addresses is specified, that addresses are used in priority. + for _, addr := range idx.targetAddrs { + if _, err := idx.client.GetClient().Connect(ctx, addr); err != nil { + return err + } + } targetAddrs = idx.targetAddrs } log.Infof("target agent addrs: %v", targetAddrs) diff --git a/pkg/index/job/save/service/indexer_test.go b/pkg/index/job/save/service/indexer_test.go index efb5c37cae..8b389685dc 100644 --- a/pkg/index/job/save/service/indexer_test.go +++ b/pkg/index/job/save/service/indexer_test.go @@ -22,6 +22,7 @@ import ( "github.com/vdaas/vald/internal/errors" "github.com/vdaas/vald/internal/net/grpc" "github.com/vdaas/vald/internal/net/grpc/codes" + "github.com/vdaas/vald/internal/net/grpc/pool" "github.com/vdaas/vald/internal/net/grpc/status" "github.com/vdaas/vald/internal/test/goleak" clientmock "github.com/vdaas/vald/internal/test/mock/client" @@ -65,7 +66,6 @@ func Test_index_Start(t *testing.T) { args: args{ ctx: context.Background(), }, - fields: fields{ client: &clientmock.DiscovererClientMock{ GetAddrsFunc: func(_ context.Context) []string { @@ -93,6 +93,8 @@ func Test_index_Start(t *testing.T) { fields: fields{ targetAddrs: []string{ "127.0.0.1:8080", + "127.0.0.1:8081", + "127.0.0.1:8083", }, client: &clientmock.DiscovererClientMock{ GetAddrsFunc: func(_ context.Context) []string { @@ -105,6 +107,9 @@ func Test_index_Start(t *testing.T) { ) error { return nil }, + ConnectFunc: func(_ context.Context, _ string, _ ...grpc.DialOption) (pool.Conn, error) { + return nil, nil + }, } }, }, @@ -154,7 +159,6 @@ func Test_index_Start(t *testing.T) { args: args{ ctx: context.Background(), }, - fields: fields{ client: &clientmock.DiscovererClientMock{ GetAddrsFunc: func(_ context.Context) []string { From 905e16837a2c8070a28a5ad7da3c5b3ee780b85f Mon Sep 17 00:00:00 2001 From: hlts2 Date: Fri, 8 Mar 2024 17:18:02 +0900 Subject: [PATCH 4/7] fix: add info log about new connection target Signed-off-by: hlts2 --- pkg/index/job/creation/service/indexer.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/index/job/creation/service/indexer.go b/pkg/index/job/creation/service/indexer.go index 3531f2790a..98e2060a40 100644 --- a/pkg/index/job/creation/service/indexer.go +++ b/pkg/index/job/creation/service/indexer.go @@ -147,6 +147,7 @@ func (idx *index) doCreateIndex(ctx context.Context, fn func(_ context.Context, if len(idx.targetAddrs) != 0 { // If target addresses is specified, that addresses are used in priority. for _, addr := range idx.targetAddrs { + log.Infof("connect to target agent (%s)", addr) if _, err := idx.client.GetClient().Connect(ctx, addr); err != nil { return err } From 97e933bf50fbd66036a16bcf963985cb7c404bfd Mon Sep 17 00:00:00 2001 From: hlts2 Date: Fri, 8 Mar 2024 17:28:33 +0900 Subject: [PATCH 5/7] fix: indent of configuration data Signed-off-by: hlts2 --- charts/vald/templates/index/job/creation/configmap.yaml | 6 ++++++ charts/vald/templates/index/job/save/configmap.yaml | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/charts/vald/templates/index/job/creation/configmap.yaml b/charts/vald/templates/index/job/creation/configmap.yaml index b78887e9e6..16f83986dc 100644 --- a/charts/vald/templates/index/job/creation/configmap.yaml +++ b/charts/vald/templates/index/job/creation/configmap.yaml @@ -51,6 +51,12 @@ data: agent_namespace: {{ $creator.agent_namespace | quote }} node_name: {{ $creator.node_name | quote }} concurrency: {{ $creator.concurrency }} + {{- if $creator.target_addrs -}} + target_addrs: + {{ toYaml $creator.target_addrs | indent 8 }} + {{- else -}} + target_addrs: [] + {{- end -}} target_addrs: {{ $creator.target_addrs }} discoverer: duration: {{ $creator.discoverer.duration }} diff --git a/charts/vald/templates/index/job/save/configmap.yaml b/charts/vald/templates/index/job/save/configmap.yaml index 6813266e86..03107d71a4 100644 --- a/charts/vald/templates/index/job/save/configmap.yaml +++ b/charts/vald/templates/index/job/save/configmap.yaml @@ -51,7 +51,12 @@ data: agent_namespace: {{ $saver.agent_namespace | quote }} node_name: {{ $saver.node_name | quote }} concurrency: {{ $saver.concurrency }} - target_addrs: {{ $saver.target_addrs }} + {{- if $saver.target_addrs -}} + target_addrs: + {{ toYaml $saver.target_addrs | indent 8 }} + {{- else -}} + target_addrs: [] + {{- end -}} discoverer: duration: {{ $saver.discoverer.duration }} client: From 4e3131a1e285698dbc94e3ce0054650576cb659f Mon Sep 17 00:00:00 2001 From: hlts2 Date: Fri, 8 Mar 2024 18:08:32 +0900 Subject: [PATCH 6/7] fix: indent bug Signed-off-by: hlts2 --- charts/vald/templates/index/job/creation/configmap.yaml | 9 ++++----- charts/vald/templates/index/job/save/configmap.yaml | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/charts/vald/templates/index/job/creation/configmap.yaml b/charts/vald/templates/index/job/creation/configmap.yaml index 16f83986dc..fbd2850260 100644 --- a/charts/vald/templates/index/job/creation/configmap.yaml +++ b/charts/vald/templates/index/job/creation/configmap.yaml @@ -51,13 +51,12 @@ data: agent_namespace: {{ $creator.agent_namespace | quote }} node_name: {{ $creator.node_name | quote }} concurrency: {{ $creator.concurrency }} - {{- if $creator.target_addrs -}} + {{- if $creator.target_addrs }} target_addrs: - {{ toYaml $creator.target_addrs | indent 8 }} - {{- else -}} + {{- toYaml $creator.target_addrs | nindent 8 }} + {{- else }} target_addrs: [] - {{- end -}} - target_addrs: {{ $creator.target_addrs }} + {{- end }} discoverer: duration: {{ $creator.discoverer.duration }} client: diff --git a/charts/vald/templates/index/job/save/configmap.yaml b/charts/vald/templates/index/job/save/configmap.yaml index 03107d71a4..c1dc8b8d09 100644 --- a/charts/vald/templates/index/job/save/configmap.yaml +++ b/charts/vald/templates/index/job/save/configmap.yaml @@ -51,12 +51,12 @@ data: agent_namespace: {{ $saver.agent_namespace | quote }} node_name: {{ $saver.node_name | quote }} concurrency: {{ $saver.concurrency }} - {{- if $saver.target_addrs -}} + {{- if $saver.target_addrs }} target_addrs: - {{ toYaml $saver.target_addrs | indent 8 }} - {{- else -}} + {{- toYaml $saver.target_addrs | nindent 8 }} + {{- else }} target_addrs: [] - {{- end -}} + {{- end }} discoverer: duration: {{ $saver.discoverer.duration }} client: From 9e810f707c6833ccfc023c7506256e2f1ab825a0 Mon Sep 17 00:00:00 2001 From: hlts2 Date: Mon, 11 Mar 2024 12:30:12 +0900 Subject: [PATCH 7/7] fix: deepsource warning Signed-off-by: hlts2 --- pkg/index/job/creation/service/indexer.go | 1 + pkg/index/job/save/service/indexer.go | 1 + pkg/index/job/save/service/indexer_test.go | 1 + 3 files changed, 3 insertions(+) diff --git a/pkg/index/job/creation/service/indexer.go b/pkg/index/job/creation/service/indexer.go index 98e2060a40..83ac1eb4e8 100644 --- a/pkg/index/job/creation/service/indexer.go +++ b/pkg/index/job/creation/service/indexer.go @@ -135,6 +135,7 @@ func (idx *index) Start(ctx context.Context) error { return nil } +// skipcq: GO-R1005 func (idx *index) doCreateIndex(ctx context.Context, fn func(_ context.Context, _ agent.AgentClient, _ ...grpc.CallOption) (*payload.Empty, error)) (errs error) { ctx, span := trace.StartSpan(grpc.WrapGRPCMethod(ctx, grpcMethodName), apiName+"/service/index.doCreateIndex") defer func() { diff --git a/pkg/index/job/save/service/indexer.go b/pkg/index/job/save/service/indexer.go index cd34d9b268..a3e8325ba4 100644 --- a/pkg/index/job/save/service/indexer.go +++ b/pkg/index/job/save/service/indexer.go @@ -132,6 +132,7 @@ func (idx *index) Start(ctx context.Context) error { return nil } +// skipcq: GO-R1005 func (idx *index) doSaveIndex(ctx context.Context, fn func(_ context.Context, _ agent.AgentClient, _ ...grpc.CallOption) (*payload.Empty, error)) (errs error) { ctx, span := trace.StartSpan(grpc.WrapGRPCMethod(ctx, grpcMethodName), apiName+"/service/index.doSaveIndex") defer func() { diff --git a/pkg/index/job/save/service/indexer_test.go b/pkg/index/job/save/service/indexer_test.go index 8b389685dc..ed05353bbe 100644 --- a/pkg/index/job/save/service/indexer_test.go +++ b/pkg/index/job/save/service/indexer_test.go @@ -30,6 +30,7 @@ import ( ) func Test_index_Start(t *testing.T) { + t.Parallel() type args struct { ctx context.Context }