From 04d336b2d43fbc8da828b768be7f2dac7ba94de3 Mon Sep 17 00:00:00 2001 From: jonesyang12 <130545229+jonesyang12@users.noreply.github.com> Date: Thu, 28 Sep 2023 17:40:46 +0800 Subject: [PATCH] nodegroup lint (#2652) --- .../cmd/client/client.go | 15 ++++--- .../cmd/client/cmd/apply.go | 17 ++++---- .../cmd/client/cmd/create.go | 14 +++--- .../cmd/client/cmd/delete.go | 22 +++++----- .../cmd/client/cmd/get.go | 14 +++--- .../cmd/client/cmd/printer/careview.go | 19 ++++---- .../cmd/client/cmd/printer/strategy.go | 23 ++++++---- .../cmd/client/cmd/printer/utils.go | 14 +++--- .../cmd/client/cmd/root.go | 14 +++--- .../cmd/client/pkg/client.go | 15 ++++--- .../bcs-nodegroup-manager/cmd/server/cmd.go | 2 +- .../cmd/server/options.go | 3 +- .../cmd/server/server.go | 21 +++++---- .../bcs-nodegroup-manager/generate.go | 3 +- .../handler/bcs-nodegroup-manager.go | 15 ++++--- .../handler/bcs-nodegroup-manager_test.go | 34 +++++++++------ bcs-services/bcs-nodegroup-manager/main.go | 14 +++--- .../pkg/cluster/client.go | 15 ++++--- .../pkg/cluster/client_test.go | 27 +++++++----- .../pkg/cluster/mock/requester.go | 0 .../pkg/cluster/requester/requester.go | 16 +++---- .../pkg/cluster/types.go | 14 +++--- .../pkg/controller/balancer.go | 4 +- .../pkg/controller/balancer_test.go | 2 +- .../pkg/controller/nodegroup.go | 15 +++++-- .../pkg/controller/nodegroup_test.go | 21 ++++++--- .../pkg/controller/options.go | 2 +- .../pkg/controller/strategy/buffer.go | 21 ++++----- .../pkg/controller/strategy/buffer_test.go | 24 ++++++----- .../pkg/controller/strategy/factory.go | 14 +++--- .../pkg/controller/strategy/hierarchical.go | 16 +++---- .../controller/strategy/hierarchical_test.go | 22 +++++----- .../pkg/controller/task.go | 35 +++++++-------- .../pkg/controller/task_test.go | 18 +++++--- .../pkg/resourcemgr/mocks/Client.go | 6 ++- .../pkg/resourcemgr/resource.go | 22 +++++----- .../pkg/storage/interface.go | 15 ++++--- .../pkg/storage/mongo/action.go | 21 ++++----- .../pkg/storage/mongo/action_test.go | 27 ++++++------ .../pkg/storage/mongo/event.go | 19 ++++---- .../pkg/storage/mongo/event_test.go | 22 +++++----- .../pkg/storage/mongo/group.go | 20 ++++----- .../pkg/storage/mongo/group_test.go | 26 ++++++----- .../pkg/storage/mongo/mongo.go | 14 +++--- .../pkg/storage/mongo/strategy.go | 21 ++++----- .../pkg/storage/mongo/strategy_test.go | 42 +++++++++++------- .../pkg/storage/mongo/task.go | 18 ++++---- .../pkg/storage/mongo/task_test.go | 43 +++++++++++-------- .../pkg/storage/mongo/utils.go | 14 +++--- .../pkg/storage/mongo/utils_test.go | 14 +++--- .../pkg/storage/types.go | 11 +++-- 51 files changed, 485 insertions(+), 395 deletions(-) delete mode 100644 bcs-services/bcs-nodegroup-manager/pkg/cluster/mock/requester.go diff --git a/bcs-services/bcs-nodegroup-manager/cmd/client/client.go b/bcs-services/bcs-nodegroup-manager/cmd/client/client.go index 30532c1628..1113e63108 100644 --- a/bcs-services/bcs-nodegroup-manager/cmd/client/client.go +++ b/bcs-services/bcs-nodegroup-manager/cmd/client/client.go @@ -1,15 +1,16 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ +// Package main client main package main import "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/cmd/client/cmd" diff --git a/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/apply.go b/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/apply.go index a3d27f4706..65d5787849 100644 --- a/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/apply.go +++ b/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/apply.go @@ -1,26 +1,27 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ +// Package cmd xxx package cmd import ( "encoding/json" "fmt" - "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/cmd/client/pkg" "os" "github.com/spf13/cobra" "github.com/spf13/viper" + "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/cmd/client/pkg" nodegroupmanager "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/proto" ) diff --git a/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/create.go b/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/create.go index bca86c4e8e..aac4a95b68 100644 --- a/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/create.go +++ b/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/create.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ diff --git a/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/delete.go b/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/delete.go index ead717ccda..3f8bfdb506 100644 --- a/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/delete.go +++ b/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/delete.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ @@ -14,11 +14,13 @@ package cmd import ( "fmt" - "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/cmd/client/pkg" - nodegroupmanager "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/proto" + "os" + "github.com/spf13/cobra" "github.com/spf13/viper" - "os" + + "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/cmd/client/pkg" + nodegroupmanager "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/proto" ) // NewDeleteCmd new delete cmd diff --git a/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/get.go b/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/get.go index 562a65df58..eaeb3321a6 100644 --- a/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/get.go +++ b/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/get.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ diff --git a/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/printer/careview.go b/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/printer/careview.go index 96335d4e8d..d9539933b7 100644 --- a/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/printer/careview.go +++ b/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/printer/careview.go @@ -1,21 +1,24 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ +// Package printer xxx package printer import ( "fmt" - nodegroupmanager "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/proto" + "github.com/tidwall/pretty" + + nodegroupmanager "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/proto" ) // PrintCaReviewInJSON print caReview in json diff --git a/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/printer/strategy.go b/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/printer/strategy.go index c23ed15aef..11ab550d72 100644 --- a/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/printer/strategy.go +++ b/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/printer/strategy.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ @@ -15,11 +15,12 @@ package printer import ( "encoding/json" "fmt" - "github.com/tidwall/pretty" "os" - nodegroupmanager "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/proto" "github.com/olekukonko/tablewriter" + "github.com/tidwall/pretty" + + nodegroupmanager "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/proto" ) // PrintStrategyInTable print strategy in table by default @@ -31,6 +32,8 @@ func PrintStrategyInTable(wide bool, strategies []*nodegroupmanager.NodeGroupStr table.SetHeader(func() []string { r := []string{"NAME", "RESOURCE_POOL", "LABELS"} if wide { + // no-op append call, 源码如此(append是否缺少参数,wide是否有意义) + // nolint r = append(r) } return r @@ -42,6 +45,8 @@ func PrintStrategyInTable(wide bool, strategies []*nodegroupmanager.NodeGroupStr strategy.Name, strategy.ResourcePool, string(label), } if wide { + // no-op append call, 源码如此(append是否缺少参数,wide是否有意义) + // nolint r = append(r) } return r diff --git a/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/printer/utils.go b/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/printer/utils.go index 1b2cb646c8..031fd6a56c 100644 --- a/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/printer/utils.go +++ b/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/printer/utils.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ diff --git a/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/root.go b/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/root.go index 727cd11ed6..0d4f1e8b8e 100644 --- a/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/root.go +++ b/bcs-services/bcs-nodegroup-manager/cmd/client/cmd/root.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ diff --git a/bcs-services/bcs-nodegroup-manager/cmd/client/pkg/client.go b/bcs-services/bcs-nodegroup-manager/cmd/client/pkg/client.go index ecf28329cf..3fa94df41f 100644 --- a/bcs-services/bcs-nodegroup-manager/cmd/client/pkg/client.go +++ b/bcs-services/bcs-nodegroup-manager/cmd/client/pkg/client.go @@ -1,15 +1,16 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ +// Package pkg xxx package pkg import ( diff --git a/bcs-services/bcs-nodegroup-manager/cmd/server/cmd.go b/bcs-services/bcs-nodegroup-manager/cmd/server/cmd.go index a80a13a5f3..a628c84a55 100644 --- a/bcs-services/bcs-nodegroup-manager/cmd/server/cmd.go +++ b/bcs-services/bcs-nodegroup-manager/cmd/server/cmd.go @@ -4,7 +4,7 @@ * Licensed under the MIT License (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under, + * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions and * limitations under the License. diff --git a/bcs-services/bcs-nodegroup-manager/cmd/server/options.go b/bcs-services/bcs-nodegroup-manager/cmd/server/options.go index da595a2cb6..650e9d5a9f 100644 --- a/bcs-services/bcs-nodegroup-manager/cmd/server/options.go +++ b/bcs-services/bcs-nodegroup-manager/cmd/server/options.go @@ -4,7 +4,7 @@ * Licensed under the MIT License (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under, + * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions and * limitations under the License. @@ -45,6 +45,7 @@ type Storage struct { } // ServerConfig option for server +// nolint type ServerConfig struct { Address string `json:"address"` IPv6Address string `json:"ipv6address"` diff --git a/bcs-services/bcs-nodegroup-manager/cmd/server/server.go b/bcs-services/bcs-nodegroup-manager/cmd/server/server.go index ad3050c482..04221b6398 100644 --- a/bcs-services/bcs-nodegroup-manager/cmd/server/server.go +++ b/bcs-services/bcs-nodegroup-manager/cmd/server/server.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ @@ -23,7 +23,10 @@ import ( "syscall" "time" + "github.com/Tencent/bk-bcs/bcs-common/common/blog" "github.com/Tencent/bk-bcs/bcs-common/common/encrypt" + "github.com/Tencent/bk-bcs/bcs-common/common/version" + "github.com/Tencent/bk-bcs/bcs-common/pkg/odm/drivers/mongo" grpccli "github.com/asim/go-micro/plugins/client/grpc/v4" "github.com/asim/go-micro/plugins/registry/etcd/v4" grpcsvr "github.com/asim/go-micro/plugins/server/grpc/v4" @@ -35,10 +38,6 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials" - "github.com/Tencent/bk-bcs/bcs-common/common/blog" - "github.com/Tencent/bk-bcs/bcs-common/common/version" - "github.com/Tencent/bk-bcs/bcs-common/pkg/odm/drivers/mongo" - "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/handler" "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/pkg/cluster" "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/pkg/cluster/requester" diff --git a/bcs-services/bcs-nodegroup-manager/generate.go b/bcs-services/bcs-nodegroup-manager/generate.go index e4835bc634..6fca7bec21 100644 --- a/bcs-services/bcs-nodegroup-manager/generate.go +++ b/bcs-services/bcs-nodegroup-manager/generate.go @@ -4,12 +4,13 @@ * Licensed under the MIT License (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under, + * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ +// Package main xxx package main //go:generate make proto diff --git a/bcs-services/bcs-nodegroup-manager/handler/bcs-nodegroup-manager.go b/bcs-services/bcs-nodegroup-manager/handler/bcs-nodegroup-manager.go index 650764431c..9d6e273680 100644 --- a/bcs-services/bcs-nodegroup-manager/handler/bcs-nodegroup-manager.go +++ b/bcs-services/bcs-nodegroup-manager/handler/bcs-nodegroup-manager.go @@ -1,15 +1,16 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ +// Package handler xxx package handler import ( diff --git a/bcs-services/bcs-nodegroup-manager/handler/bcs-nodegroup-manager_test.go b/bcs-services/bcs-nodegroup-manager/handler/bcs-nodegroup-manager_test.go index 46b3d81701..37b57124e1 100644 --- a/bcs-services/bcs-nodegroup-manager/handler/bcs-nodegroup-manager_test.go +++ b/bcs-services/bcs-nodegroup-manager/handler/bcs-nodegroup-manager_test.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ @@ -18,11 +18,10 @@ import ( "testing" "time" + "github.com/Tencent/bk-bcs/bcs-common/common" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" - "github.com/Tencent/bk-bcs/bcs-common/common" - "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/pkg/storage" "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/pkg/storage/mocks" nodegroupmanager "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/proto" @@ -81,7 +80,10 @@ func Test_CreateNodePoolMgrStrategy(t *testing.T) { }, wantErr: false, on: func(storageCli *mocks.Storage) { - storageCli.On("CreateNodeGroupStrategy", mock.Anything, &storage.CreateOptions{OverWriteIfExist: false}).Return(fmt.Errorf("exist")) + storageCli.On("CreateNodeGroupStrategy", + mock.Anything, + &storage.CreateOptions{OverWriteIfExist: false}). + Return(fmt.Errorf("exist")) }, }, } @@ -126,7 +128,10 @@ func Test_GetNodePoolMgrStrategy(t *testing.T) { }, wantErr: false, on: func(storageCli *mocks.Storage) { - storageCli.On("GetNodeGroupStrategy", "normal", &storage.GetOptions{}).Return(&storage.NodeGroupMgrStrategy{Name: "normal"}, nil) + storageCli.On("GetNodeGroupStrategy", + "normal", + &storage.GetOptions{}). + Return(&storage.NodeGroupMgrStrategy{Name: "normal"}, nil) }, }, { @@ -360,7 +365,10 @@ func Test_DeleteNodePoolMgrStrategy(t *testing.T) { }, wantErr: false, on: func(storageCli *mocks.Storage) { - storageCli.On("DeleteNodeGroupStrategy", "normal", &storage.DeleteOptions{}).Return(&storage.NodeGroupMgrStrategy{}, nil) + storageCli.On("DeleteNodeGroupStrategy", + "normal", + &storage.DeleteOptions{}). + Return(&storage.NodeGroupMgrStrategy{}, nil) }, }, { @@ -412,6 +420,8 @@ func Test_DeleteNodePoolMgrStrategy(t *testing.T) { } } +// NOCC:golint/funlen(设计如此) +// nolint func Test_GetClusterAutoscalerReview(t *testing.T) { tests := []struct { name string diff --git a/bcs-services/bcs-nodegroup-manager/main.go b/bcs-services/bcs-nodegroup-manager/main.go index fc9593aa2f..2b25a469c7 100644 --- a/bcs-services/bcs-nodegroup-manager/main.go +++ b/bcs-services/bcs-nodegroup-manager/main.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ diff --git a/bcs-services/bcs-nodegroup-manager/pkg/cluster/client.go b/bcs-services/bcs-nodegroup-manager/pkg/cluster/client.go index 5bf1e4477b..e7c0a46bbb 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/cluster/client.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/cluster/client.go @@ -1,15 +1,16 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ +// Package cluster xxx package cluster import ( diff --git a/bcs-services/bcs-nodegroup-manager/pkg/cluster/client_test.go b/bcs-services/bcs-nodegroup-manager/pkg/cluster/client_test.go index 434e0ca113..7fc2502be1 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/cluster/client_test.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/cluster/client_test.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ @@ -23,6 +23,7 @@ import ( ) func TestClient_ListClusterNodes(t *testing.T) { + // nolint rawNodeList := []byte("{\"items\":[{\"metadata\":{\"name\":\"1.1.1.1\",\"labels\":{\"beta.kubernetes.io/arch\":\"amd64\"}},\"spec\":{\"podCIDR\":\"1.1.1.1/27\",\"podCIDRs\":[\"1.1.1.1/27\"],\"providerID\":\"qcloud:///330001/ins-d3cwxd6w\"},\"status\":{\"capacity\":{\"cpu\":\"4\",\"ephemeral-storage\":\"103079844Ki\",\"hugepages-1Gi\":\"0\",\"hugepages-2Mi\":\"0\",\"memory\":\"16128872Ki\",\"pods\":\"29\"},\"conditions\":[],\"addresses\":[{\"type\":\"InternalIP\",\"address\":\"1.1.1.1\"},{\"type\":\"Hostname\",\"address\":\"1.1.1.1\"}],\"nodeInfo\":{},\"images\":[]}},{\"metadata\":{\"name\":\"2.2.2.2\",\"labels\":{\"beta.kubernetes.io/arch\":\"amd64\"}},\"status\":{\"capacity\":{\"cpu\":\"8\",\"ephemeral-storage\":\"103079844Ki\",\"hugepages-1Gi\":\"0\",\"hugepages-2Mi\":\"0\",\"memory\":\"64567304Ki\",\"pods\":\"29\"},\"conditions\":[],\"addresses\":[{\"type\":\"InternalIP\",\"address\":\"2.2.2.2\"},{\"type\":\"Hostname\",\"address\":\"2.2.2.2\"}],\"daemonEndpoints\":{\"kubeletEndpoint\":{\"Port\":10250}},\"nodeInfo\":{},\"images\":[]}}]}\n") tests := []struct { name string @@ -38,7 +39,8 @@ func TestClient_ListClusterNodes(t *testing.T) { wantErr: false, on: func(f *MockFields) { f.requester.On("DoGetRequest", - fmt.Sprintf("/clusters/%s/api/v1/nodes?labelSelector=node-role.kubernetes.io/master!=true", "BCS-K8S-15202"), mock.Anything).Return(rawNodeList, nil) + fmt.Sprintf("/clusters/%s/api/v1/nodes?labelSelector=node-role.kubernetes.io/master!=true", "BCS-K8S-15202"), + mock.Anything).Return(rawNodeList, nil) }, }, { @@ -48,7 +50,8 @@ func TestClient_ListClusterNodes(t *testing.T) { wantErr: true, on: func(f *MockFields) { f.requester.On("DoGetRequest", - fmt.Sprintf("/clusters/%s/api/v1/nodes?labelSelector=node-role.kubernetes.io/master!=true", "BCS-K8S-15202"), mock.Anything). + fmt.Sprintf("/clusters/%s/api/v1/nodes?labelSelector=node-role.kubernetes.io/master!=true", "BCS-K8S-15202"), + mock.Anything). Return(nil, fmt.Errorf("request err")) }, }, @@ -125,6 +128,7 @@ func TestClient_UpdateNodeLabels(t *testing.T) { } func TestClient_ListNodesByLabel(t *testing.T) { + // nolint rawNodeList := []byte("{\"items\":[{\"metadata\":{\"name\":\"1.1.1.1\",\"labels\":{\"beta.kubernetes.io/arch\":\"amd64\"}},\"spec\":{\"podCIDR\":\"1.1.1.1/27\",\"podCIDRs\":[\"1.1.1.1/27\"],\"providerID\":\"qcloud:///330001/ins-d3cwxd6w\"},\"status\":{\"capacity\":{\"cpu\":\"4\",\"ephemeral-storage\":\"103079844Ki\",\"hugepages-1Gi\":\"0\",\"hugepages-2Mi\":\"0\",\"memory\":\"16128872Ki\",\"pods\":\"29\"},\"conditions\":[],\"addresses\":[{\"type\":\"InternalIP\",\"address\":\"1.1.1.1\"},{\"type\":\"Hostname\",\"address\":\"1.1.1.1\"}],\"nodeInfo\":{},\"images\":[]}},{\"metadata\":{\"name\":\"2.2.2.2\",\"labels\":{\"beta.kubernetes.io/arch\":\"amd64\"}},\"status\":{\"capacity\":{\"cpu\":\"8\",\"ephemeral-storage\":\"103079844Ki\",\"hugepages-1Gi\":\"0\",\"hugepages-2Mi\":\"0\",\"memory\":\"64567304Ki\",\"pods\":\"29\"},\"conditions\":[],\"addresses\":[{\"type\":\"InternalIP\",\"address\":\"2.2.2.2\"},{\"type\":\"Hostname\",\"address\":\"2.2.2.2\"}],\"daemonEndpoints\":{\"kubeletEndpoint\":{\"Port\":10250}},\"nodeInfo\":{},\"images\":[]}}]}\n") tests := []struct { name string @@ -142,7 +146,9 @@ func TestClient_ListNodesByLabel(t *testing.T) { wantErr: false, on: func(f *MockFields) { f.requester.On("DoGetRequest", - fmt.Sprintf("/clusters/%s/api/v1/nodes?labelSelector=node-role.kubernetes.io/master!=true,test=test", "BCS-K8S-15202"), mock.Anything).Return(rawNodeList, nil) + // nolint + fmt.Sprintf("/clusters/%s/api/v1/nodes?labelSelector=node-role.kubernetes.io/master!=true,test=test", "BCS-K8S-15202"), + mock.Anything).Return(rawNodeList, nil) }, }, { @@ -153,6 +159,7 @@ func TestClient_ListNodesByLabel(t *testing.T) { wantErr: true, on: func(f *MockFields) { f.requester.On("DoGetRequest", + // nolint fmt.Sprintf("/clusters/%s/api/v1/nodes?labelSelector=node-role.kubernetes.io/master!=true,test=test", "BCS-K8S-15202"), mock.Anything). Return(nil, fmt.Errorf("request err")) }, diff --git a/bcs-services/bcs-nodegroup-manager/pkg/cluster/mock/requester.go b/bcs-services/bcs-nodegroup-manager/pkg/cluster/mock/requester.go deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/bcs-services/bcs-nodegroup-manager/pkg/cluster/requester/requester.go b/bcs-services/bcs-nodegroup-manager/pkg/cluster/requester/requester.go index ac7549eb9c..a863543bc0 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/cluster/requester/requester.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/cluster/requester/requester.go @@ -1,22 +1,22 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ +// Package requester xxx package requester import ( "fmt" "github.com/Tencent/bk-bcs/bcs-common/common/blog" - "github.com/go-resty/resty/v2" ) diff --git a/bcs-services/bcs-nodegroup-manager/pkg/cluster/types.go b/bcs-services/bcs-nodegroup-manager/pkg/cluster/types.go index 8cdfb2a4cc..64329e09f3 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/cluster/types.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/cluster/types.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ diff --git a/bcs-services/bcs-nodegroup-manager/pkg/controller/balancer.go b/bcs-services/bcs-nodegroup-manager/pkg/controller/balancer.go index 6277c0f73b..4e042349af 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/controller/balancer.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/controller/balancer.go @@ -4,12 +4,13 @@ * Licensed under the MIT License (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under, + * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ +// Package controller xxx package controller import ( @@ -136,6 +137,7 @@ func (balance *weightBalancer) distribute(n int) []*nodeGroup { // all scaleDown resources are partitioned into nodeGroups break } + // nolint selected := rand.Intn(balance.max) + 1 index := sort.SearchInts(balance.ruler, selected) node := balance.nodes[index] diff --git a/bcs-services/bcs-nodegroup-manager/pkg/controller/balancer_test.go b/bcs-services/bcs-nodegroup-manager/pkg/controller/balancer_test.go index 5d31cc6d3b..fecd9ea0f6 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/controller/balancer_test.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/controller/balancer_test.go @@ -4,7 +4,7 @@ * Licensed under the MIT License (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under, + * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions and * limitations under the License. diff --git a/bcs-services/bcs-nodegroup-manager/pkg/controller/nodegroup.go b/bcs-services/bcs-nodegroup-manager/pkg/controller/nodegroup.go index 22ec5ac59c..eca1985308 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/controller/nodegroup.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/controller/nodegroup.go @@ -4,7 +4,7 @@ * Licensed under the MIT License (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under, + * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions and * limitations under the License. @@ -114,6 +114,8 @@ func (c *control) controllerLoops() { // handleStrategy handle one strategy for specified ResourcePool // make decision that elasticNodeGroup need to ScaleUp or ScaleDown +// NOCC:golint/funlen(设计如此) +// nolint func (c *control) handleStrategy(strategy *storage.NodeGroupMgrStrategy) { var msg, status string var globalErr error @@ -280,6 +282,8 @@ func (c *control) handleStrategy(strategy *storage.NodeGroupMgrStrategy) { } // tracingScaleDownAction track exist nodegroup scaledown action +// NOCC:golint/funlen(设计如此) +// nolint func (c *control) tracingScaleDownAction(strategy *storage.NodeGroupMgrStrategy, scaleDownNum int, actions []*storage.NodeGroupAction) error { // check exist nodegroup action is suitable for tracing @@ -385,6 +389,8 @@ func (c *control) tracingScaleDownAction(strategy *storage.NodeGroupMgrStrategy, } // tracingScaleUpAction track +// NOCC:golint/funlen(设计如此) +// nolint func (c *control) tracingScaleUpAction(strategy *storage.NodeGroupMgrStrategy, scaleUpNum int, actions []*storage.NodeGroupAction) error { // check exist nodegroup action is suitable for tracing @@ -489,8 +495,9 @@ func (c *control) tracingScaleUpAction(strategy *storage.NodeGroupMgrStrategy, // cleanUnexpectedNodeGroupActions 清理掉操作方向不一致的记录. // return: -// bool, true if nodegroupAction was delete, otherwise false -// error, if any error happened +// +// bool, true if nodegroupAction was delete, otherwise false +// error, if any error happened func (c *control) cleanUnexpectedNodeGroupActions(action *storage.NodeGroupAction, expectedState string) (bool, error) { if action.Event != expectedState { blog.Infof("[nodegroupController] exist %s/%s nodegroup action is not %s, clean outdated action. details: %+v", @@ -549,7 +556,7 @@ func (c *control) handleElasticNodeGroupScaleUp(strategy *storage.NodeGroupMgrSt // for next tick to confirm progress. for _, ng := range nodegrps { nodegroup := nodegroups[ng.NodeGroupID] - //original := nodegroup.DesiredSize + // original := nodegroup.DesiredSize original := nodegroup.CmDesiredSize nodegroup.DesiredSize = original + ng.partition nodegroup.LastScaleUpTime = time.Now() diff --git a/bcs-services/bcs-nodegroup-manager/pkg/controller/nodegroup_test.go b/bcs-services/bcs-nodegroup-manager/pkg/controller/nodegroup_test.go index 8e8cab4fe6..f20a7fe8b6 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/controller/nodegroup_test.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/controller/nodegroup_test.go @@ -4,7 +4,7 @@ * Licensed under the MIT License (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under, + * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions and * limitations under the License. @@ -136,7 +136,9 @@ func TestScaleUp_updateNodeGroupErr(t *testing.T) { // storage return failure store.On("GetNodeGroup", nodeGroups[0].NodeGroupID, &storage.GetOptions{}).Return(nodeGroups[0], nil) store.On("GetNodeGroup", nodeGroups[1].NodeGroupID, &storage.GetOptions{}).Return(nodeGroups[1], nil) - store.On("UpdateNodeGroup", nodeGroups[0], &storage.UpdateOptions{}).Return(nodeGroups[0], fmt.Errorf("data storage failure")) + store.On("UpdateNodeGroup", + nodeGroups[0], &storage.UpdateOptions{}). + Return(nodeGroups[0], fmt.Errorf("data storage failure")) err := ctl.handleElasticNodeGroupScaleUp(strategy, scaleUpNum) assertion.NotNil(err, "UpdateNodeGroup met any failure must stop testcase") @@ -293,7 +295,8 @@ func TestScaleDown_updateNodeGroupErr(t *testing.T) { // storage return failure store.On("GetNodeGroup", nodeGroups[0].NodeGroupID, &storage.GetOptions{}).Return(nodeGroups[0], nil) store.On("GetNodeGroup", nodeGroups[1].NodeGroupID, &storage.GetOptions{}).Return(nodeGroups[1], nil) - store.On("UpdateNodeGroup", nodeGroups[0], &storage.UpdateOptions{}).Return(nodeGroups[0], fmt.Errorf("data storage failure")) + store.On("UpdateNodeGroup", nodeGroups[0], &storage.UpdateOptions{}). + Return(nodeGroups[0], fmt.Errorf("data storage failure")) err := ctl.handleElasticNodeGroupScaleUp(strategy, scaleDownNum) assertion.NotNil(err, "UpdateNodeGroup met any failure must stop testcase") @@ -329,7 +332,8 @@ func TestScaleDown_createActionErr(t *testing.T) { store.On("GetNodeGroup", nodeGroups[0].NodeGroupID, &storage.GetOptions{}).Return(nodeGroups[0], nil) store.On("GetNodeGroup", nodeGroups[1].NodeGroupID, &storage.GetOptions{}).Return(nodeGroups[1], nil) - store.On("UpdateNodeGroup", nodeGroups[0], &storage.UpdateOptions{OverwriteZeroOrEmptyStr: true}).Return(nodeGroups[0], nil) + store.On("UpdateNodeGroup", nodeGroups[0], &storage.UpdateOptions{OverwriteZeroOrEmptyStr: true}). + Return(nodeGroups[0], nil) // store.On("UpdateNodeGroup", nodeGroups[1], &storage.UpdateOptions{}).Return(nodeGroups[1], nil) store.On("CreateNodeGroupAction", basemock.MatchedBy(func(action *storage.NodeGroupAction) bool { @@ -375,7 +379,8 @@ func TestScaleDown_createNodeGroupEvent(t *testing.T) { store.On("GetNodeGroup", nodeGroups[0].NodeGroupID, &storage.GetOptions{}).Return(nodeGroups[0], nil) store.On("GetNodeGroup", nodeGroups[1].NodeGroupID, &storage.GetOptions{}).Return(nodeGroups[1], nil) // !first loop, create Event failure but still go on - store.On("UpdateNodeGroup", nodeGroups[0], &storage.UpdateOptions{OverwriteZeroOrEmptyStr: true}).Return(nodeGroups[0], nil) + store.On("UpdateNodeGroup", nodeGroups[0], &storage.UpdateOptions{OverwriteZeroOrEmptyStr: true}). + Return(nodeGroups[0], nil) store.On("CreateNodeGroupAction", basemock.MatchedBy(func(action *storage.NodeGroupAction) bool { return action.NodeGroupID == expectedActions[0].NodeGroupID && @@ -389,7 +394,8 @@ func TestScaleDown_createNodeGroupEvent(t *testing.T) { &storage.CreateOptions{}, ).Return(fmt.Errorf("database connection lost")) // !second loop - store.On("UpdateNodeGroup", nodeGroups[1], &storage.UpdateOptions{OverwriteZeroOrEmptyStr: true}).Return(nodeGroups[1], nil) + store.On("UpdateNodeGroup", nodeGroups[1], &storage.UpdateOptions{OverwriteZeroOrEmptyStr: true}). + Return(nodeGroups[1], nil) store.On("CreateNodeGroupAction", basemock.MatchedBy(func(action *storage.NodeGroupAction) bool { return action.NodeGroupID == expectedActions[1].NodeGroupID && @@ -536,7 +542,8 @@ func TestTracingDown_releaseResNotEnough(t *testing.T) { // expected create NodeGroupEvent, no matter what error store.On("CreateNodeGroupEvent", basemock.MatchedBy(func(event *storage.NodeGroupEvent) bool { - t.Logf("create new NodeGroup Event, %s, Desired, %d, message: %s", event.NodeGroupID, event.DesiredNum, event.Message) + t.Logf("create new NodeGroup Event, %s, Desired, %d, message: %s", + event.NodeGroupID, event.DesiredNum, event.Message) return true }), &storage.CreateOptions{}, diff --git a/bcs-services/bcs-nodegroup-manager/pkg/controller/options.go b/bcs-services/bcs-nodegroup-manager/pkg/controller/options.go index b02676046c..ccd063e446 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/controller/options.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/controller/options.go @@ -4,7 +4,7 @@ * Licensed under the MIT License (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under, + * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions and * limitations under the License. diff --git a/bcs-services/bcs-nodegroup-manager/pkg/controller/strategy/buffer.go b/bcs-services/bcs-nodegroup-manager/pkg/controller/strategy/buffer.go index 3f79fd2315..7d52db51a6 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/controller/strategy/buffer.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/controller/strategy/buffer.go @@ -1,15 +1,16 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ +// Package strategy xxx package strategy import ( @@ -56,12 +57,12 @@ func (e *BufferStrategyExecutor) IsAbleToScaleDown(strategy *storage.NodeGroupMg blog.Infof("strategy %s, resourcePool:%s: total:%d, idleNum:%d, warnBuffer:%d, reservedNum:%d", strategy.Name, pool.ID, int(total), idleNum, int(warnBuffer), reservedNum) if idleNum >= reservedNum { - //resource is enough, do nothing + // resource is enough, do nothing blog.Infof("ResourcePool %s resource is idle %d >= reserved %d, elasticNodeGroup don't scaleDown", pool.ID, idleNum, reservedNum) return 0, false, nil } - //buffer resource is not enough, calculate necessary number for scale down + // buffer resource is not enough, calculate necessary number for scale down scaleDownNum := reservedNum - idleNum blog.Infof("strategy:%s, scaleDownNum:%d", strategy.Name, scaleDownNum) return scaleDownNum, true, nil @@ -90,7 +91,7 @@ func (e *BufferStrategyExecutor) IsAbleToScaleUp(strategy *storage.NodeGroupMgrS blog.Infof("strategy %s, resourcePool:%s: total:%d, idleNum:%d, warnBuffer:%d, reservedNum:%d", strategy.Name, pool.ID, int(total), idleNum, int(warnBuffer), reservedNum) if idleNum <= reservedNum { - //resource is not idle enough + // resource is not idle enough blog.Infof("ResourcePool %s idle resource %d <= reserved %d, elasticNodeGroup don't scaleUp", pool.ID, idleNum, reservedNum) return 0, false, nil diff --git a/bcs-services/bcs-nodegroup-manager/pkg/controller/strategy/buffer_test.go b/bcs-services/bcs-nodegroup-manager/pkg/controller/strategy/buffer_test.go index 099e3a49ff..0dd1e96ce1 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/controller/strategy/buffer_test.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/controller/strategy/buffer_test.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ @@ -35,7 +35,7 @@ func TestIsAbleToScaleDown(t *testing.T) { message string on func(f *MockFields) }{ - { //resource is not idle + { // resource is not idle name: "scaleDown", strategy: &storage.NodeGroupMgrStrategy{ Name: "test", @@ -65,7 +65,7 @@ func TestIsAbleToScaleDown(t *testing.T) { }, nil) }, }, - { //resource is idle + { // resource is idle name: "notScaleDown", strategy: &storage.NodeGroupMgrStrategy{ ResourcePool: "testpool", @@ -116,6 +116,8 @@ func TestIsAbleToScaleDown(t *testing.T) { } } +// NOCC:golint/funlen(设计如此) +// nolint func TestIsAbleToScaleUp(t *testing.T) { // construct test data testcases := []struct { @@ -126,7 +128,7 @@ func TestIsAbleToScaleUp(t *testing.T) { message string on func(f *MockFields) }{ - { //resource is not idle enough + { // resource is not idle enough name: "notScaleUp", strategy: &storage.NodeGroupMgrStrategy{ ResourcePool: "testpool", @@ -157,7 +159,7 @@ func TestIsAbleToScaleUp(t *testing.T) { }, nil) }, }, - { //resource is not idle enough time + { // resource is not idle enough time name: "notEnoughTime", strategy: &storage.NodeGroupMgrStrategy{ ResourcePool: "testpool", diff --git a/bcs-services/bcs-nodegroup-manager/pkg/controller/strategy/factory.go b/bcs-services/bcs-nodegroup-manager/pkg/controller/strategy/factory.go index 3801556f3c..7e039b75b9 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/controller/strategy/factory.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/controller/strategy/factory.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ diff --git a/bcs-services/bcs-nodegroup-manager/pkg/controller/strategy/hierarchical.go b/bcs-services/bcs-nodegroup-manager/pkg/controller/strategy/hierarchical.go index 76e9d1f414..c4e7b7ca24 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/controller/strategy/hierarchical.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/controller/strategy/hierarchical.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ @@ -71,7 +71,7 @@ func (e *HierarchicalStrategyExecutor) IsAbleToScaleUp(strategy *storage.NodeGro blog.Infof("strategy %s, consumer id :%s: total:%d, idleNum:%d, warnBuffer:%d, reservedNum:%d", strategy.Name, consumerID, int(total), idleNum, int(warnBuffer), reservedNum) if idleNum <= reservedNum { - //resource is not idle enough + // resource is not idle enough blog.Infof("the device group of consumer id %s idle resource %d <= reserved %d, elasticNodeGroup don't scaleUp", consumerID, idleNum, reservedNum) return 0, false, nil diff --git a/bcs-services/bcs-nodegroup-manager/pkg/controller/strategy/hierarchical_test.go b/bcs-services/bcs-nodegroup-manager/pkg/controller/strategy/hierarchical_test.go index f2f85c13aa..05af868949 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/controller/strategy/hierarchical_test.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/controller/strategy/hierarchical_test.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ @@ -51,7 +51,7 @@ func TestHierarchical_IsAbleToScaleUp(t *testing.T) { TotalNum: 2, NodeGroupStrategy: "test-strategy", Deadline: time.Now(), - IsDelete: false, + IsDeleted: false, IsExecuted: true, }}, nil) }, @@ -69,7 +69,7 @@ func TestHierarchical_IsAbleToScaleUp(t *testing.T) { TotalNum: 2, NodeGroupStrategy: "test-strategy", Deadline: time.Now().Add(24 * time.Hour), - IsDelete: false, + IsDeleted: false, IsExecuted: false, }}, nil) f.resourceCli.On("GetResourcePoolByCondition", "test-resource-pool", "consumer1", "", mock.Anything). @@ -137,7 +137,7 @@ func Test_checkIfTaskExecuting(t *testing.T) { TotalNum: 2, NodeGroupStrategy: "test", Deadline: time.Now().Add(5 * time.Minute), - IsDelete: false, + IsDeleted: false, IsExecuted: false, }}, nil) }, @@ -154,7 +154,7 @@ func Test_checkIfTaskExecuting(t *testing.T) { TotalNum: 2, NodeGroupStrategy: "test", Deadline: time.Now().Add(-1 * time.Minute), - IsDelete: false, + IsDeleted: false, IsExecuted: true, }}, nil) }, diff --git a/bcs-services/bcs-nodegroup-manager/pkg/controller/task.go b/bcs-services/bcs-nodegroup-manager/pkg/controller/task.go index 831cac4960..e80201ef90 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/controller/task.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/controller/task.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ @@ -19,9 +19,8 @@ import ( "time" "github.com/Tencent/bk-bcs/bcs-common/common/blog" - v1 "k8s.io/api/core/v1" - "github.com/panjf2000/ants/v2" + v1 "k8s.io/api/core/v1" "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/pkg/storage" ) @@ -47,11 +46,11 @@ func NewTaskController(option *Options) Controller { // Init task controller func (c *taskController) Init(opts ...Option) error { - //init all custom Option + // init all custom Option for _, opt := range opts { opt(c.opt) } - //init all dependent resource, such as storage, client and etc. + // init all dependent resource, such as storage, client and etc. if c.opt.ResourceManager == nil { blog.Errorf("[taskController] Controller lost resource-manager interface in Init Stage") return fmt.Errorf("controller lost resource-manager instance") @@ -78,7 +77,7 @@ func (c *taskController) Run(cxt context.Context) { for { select { case now := <-tick.C: - //main loops + // main loops blog.Infof("[taskController] ############## task controller ticker: %s################", now.Format(time.RFC3339)) c.controllerLoops() case <-cxt.Done(): @@ -98,7 +97,7 @@ func (c *taskController) controllerLoops() { c.handleNormalTask() // handleTerminatedTask c.handleTerminatedTask() - //handleExpiredTask + // handleExpiredTask c.handleExpiredTask() // traceExecutingTask c.traceExecutingTask() @@ -128,6 +127,7 @@ func (c *taskController) handleNormalTask() { blog.Errorf("[taskController] get strategy %s tasks err:%s", strategy.Name, listErr.Error()) return } + // nolint if task != nil && len(task) != 0 { for _, oneTask := range task { oneTask.NodeGroupStrategy = strategy.Name @@ -194,9 +194,9 @@ func (c *taskController) handleOneNormalTask(task *storage.ScaleDownTask) { blog.Infof("[taskController] originalTotal:%d", originTotal) // 如果ip数量和任务的数量一致,说明上一轮没有ip被剔除,此时检查节点状态 if originTotal == task.TotalNum { - //先检查ScaleDownGroups里的节点状态是否都是ready,如果不是,从切片里删除 - //检查nodegroup里带标签的节点跟切片里的是否一致,不在切片里但有标签的,去掉 - //如果执行时间在1小时内,不操作? + // 先检查ScaleDownGroups里的节点状态是否都是ready,如果不是,从切片里删除 + // 检查nodegroup里带标签的节点跟切片里的是否一致,不在切片里但有标签的,去掉 + // 如果执行时间在1小时内,不操作? wg := sync.WaitGroup{} pool, initErr := ants.NewPool(c.opt.Concurrency) if err != nil { @@ -370,12 +370,13 @@ func (c *taskController) handleOneExpiredTask(task *storage.ScaleDownTask) error if err != nil { return fmt.Errorf("get nodegroup %s error:%s", scaleDownDetail.NodeGroupID, getErr.Error()) } - nodegroupInfo.DesiredSize = nodegroupInfo.DesiredSize - scaleDownDetail.NodeNum + nodegroupInfo.DesiredSize -= scaleDownDetail.NodeNum nodegroupInfo.UpdatedTime = time.Now() nodegroupInfo.LastStatus = nodegroupInfo.Status nodegroupInfo.Status = storage.ScaleDownByTaskState nodegroupInfo.HookConfirm = false nodegroupInfo.Message = fmt.Sprintf("scale down %d nodes by task %s", scaleDownDetail.NodeNum, task.TaskID) + // nolint if _, err = c.opt.Storage.UpdateNodeGroup(nodegroupInfo, &storage.UpdateOptions{OverwriteZeroOrEmptyStr: true}); err != nil { return fmt.Errorf("update nodegroup %s desire size error:%s", scaleDownDetail.NodeGroupID, err.Error()) } diff --git a/bcs-services/bcs-nodegroup-manager/pkg/controller/task_test.go b/bcs-services/bcs-nodegroup-manager/pkg/controller/task_test.go index 2b867a8b63..c9bd63acb0 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/controller/task_test.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/controller/task_test.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ @@ -147,6 +147,8 @@ func Test_filterAvailableNodes(t *testing.T) { } } +// NOCC:golint/funlen(设计如此) +// nolint func Test_removeNotReadyNodes(t *testing.T) { allReadyNodes := map[string]*cluster.Node{"test1": { Name: "test1", @@ -325,6 +327,8 @@ func Test_removeLabel(t *testing.T) { } } +// NOCC:golint/funlen(设计如此) +// nolint func Test_nodeSelector(t *testing.T) { nodes1 := map[string]*cluster.Node{"test1": { Name: "test1", diff --git a/bcs-services/bcs-nodegroup-manager/pkg/resourcemgr/mocks/Client.go b/bcs-services/bcs-nodegroup-manager/pkg/resourcemgr/mocks/Client.go index 299b0ac011..fada790177 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/resourcemgr/mocks/Client.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/resourcemgr/mocks/Client.go @@ -60,7 +60,7 @@ func (_m *Client) GetResourcePoolByCondition(poolID string, consumerID string, d } // GetTask provides a mock function with given fields: poolID, consumerID, option -func (_m *Client) GetTask(poolID string, consumerID string, option *resourcemgr.ListOptions) ([]*storage.ScaleDownTask, error) { +func (_m *Client) ListTasks(poolID string, consumerID string, option *resourcemgr.ListOptions) ([]*storage.ScaleDownTask, error) { ret := _m.Called(poolID, consumerID, option) var r0 []*storage.ScaleDownTask @@ -82,6 +82,10 @@ func (_m *Client) GetTask(poolID string, consumerID string, option *resourcemgr. return r0, r1 } +func (_m *Client) GetTaskByID(recordID string, opt *resourcemgr.GetOptions) (*storage.ScaleDownTask, error){ + panic("not impleted") +} + // ListResourcePools provides a mock function with given fields: option func (_m *Client) ListResourcePools(option *resourcemgr.ListOptions) ([]*storage.ResourcePool, error) { ret := _m.Called(option) diff --git a/bcs-services/bcs-nodegroup-manager/pkg/resourcemgr/resource.go b/bcs-services/bcs-nodegroup-manager/pkg/resourcemgr/resource.go index b61bb341de..f4069fea56 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/resourcemgr/resource.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/resourcemgr/resource.go @@ -1,15 +1,16 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ +// Package resourcemgr xxx package resourcemgr import ( @@ -18,13 +19,12 @@ import ( "fmt" "time" + "github.com/Tencent/bk-bcs/bcs-common/common/blog" grpc "github.com/asim/go-micro/plugins/client/grpc/v4" etcd "github.com/asim/go-micro/plugins/registry/etcd/v4" "go-micro.dev/v4/client" "go-micro.dev/v4/registry" - "github.com/Tencent/bk-bcs/bcs-common/common/blog" - impl "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/pkg/resourcemgr/proto" "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/pkg/storage" ) @@ -164,7 +164,7 @@ func (c *innerClient) GetResourcePoolByCondition(poolID, consumerID, deviceRecor blog.Errorf("get resource pool details failed, resource-manager logic err: %s", resp.GetMessage()) return nil, fmt.Errorf("resource-manager logic failure, %s", resp.GetMessage()) } - //convert details to local ResourcePool definition + // convert details to local ResourcePool definition if len(resp.Data) == 0 { blog.Errorf("resource-manager response empty Resource from ResourcePool %s, consumerID:%s, "+ "deviceRecord:%s", poolID, consumerID, deviceRecord) @@ -188,7 +188,7 @@ func (c *innerClient) ListTasks(poolID, consumerID string, opt *ListOptions) ([] blog.Errorf("get device records failed, resource-manager logic err: %s", resp.GetMessage()) return nil, fmt.Errorf("resource-manager logic failure, %s", resp.GetMessage()) } - //convert details to local ResourcePool definition + // convert details to local ResourcePool definition if len(resp.Data) == 0 { blog.Infof("resource-manager response empty device records from ResourcePool %s", poolID) return nil, fmt.Errorf("empty resources response") diff --git a/bcs-services/bcs-nodegroup-manager/pkg/storage/interface.go b/bcs-services/bcs-nodegroup-manager/pkg/storage/interface.go index 21835af3b3..492f88118e 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/storage/interface.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/storage/interface.go @@ -1,15 +1,16 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ +// Package storage xxx package storage // ListOptions for list operation diff --git a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/action.go b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/action.go index 8cadca2c1c..adda4e9b2d 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/action.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/action.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ @@ -19,10 +19,9 @@ import ( "fmt" "time" - "go.mongodb.org/mongo-driver/bson" - "github.com/Tencent/bk-bcs/bcs-common/pkg/odm/drivers" "github.com/Tencent/bk-bcs/bcs-common/pkg/odm/operator" + "go.mongodb.org/mongo-driver/bson" "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/pkg/storage" ) @@ -80,6 +79,7 @@ func (m *ModelAction) ListNodeGroupAction(nodeGroupID string, isDeletedKey: opt.ReturnSoftDeletedItems, })) if !opt.DoPagination && opt.Limit == 0 { + // nolint count, err := m.DB.Table(m.TableName).Find(operator.NewBranchCondition(operator.And, cond...)).Count(ctx) if err != nil { return nil, fmt.Errorf("get action count err:%v", err) @@ -179,7 +179,7 @@ func (m *ModelAction) UpdateNodeGroupAction(action *storage.NodeGroupAction, isDeletedKey: false, }) retAction := &storage.NodeGroupAction{} - if err := m.DB.Table(m.TableName).Find(cond).One(ctx, retAction); err != nil { + if err = m.DB.Table(m.TableName).Find(cond).One(ctx, retAction); err != nil { // 如果找不到且opt.CreateIfNotExist,创建新的 if errors.Is(err, drivers.ErrTableRecordNotFound) && opt.CreateIfNotExist { _, err = m.DB.Table(m.TableName).Insert(ctx, []interface{}{action}) @@ -271,6 +271,7 @@ func (m *ModelAction) ListNodeGroupActionByTaskID(taskID string, isDeletedKey: opt.ReturnSoftDeletedItems, })) if !opt.DoPagination && opt.Limit == 0 { + // nolint count, err := m.DB.Table(m.TableName).Find(operator.NewBranchCondition(operator.And, cond...)).Count(ctx) if err != nil { return nil, fmt.Errorf("get action count err:%v", err) diff --git a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/action_test.go b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/action_test.go index 9dc3abd105..810d073a37 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/action_test.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/action_test.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ @@ -18,11 +18,10 @@ import ( "testing" "time" + "github.com/Tencent/bk-bcs/bcs-common/pkg/odm/drivers" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" - "github.com/Tencent/bk-bcs/bcs-common/pkg/odm/drivers" - "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/pkg/storage" "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/mocks" ) @@ -110,6 +109,7 @@ func Test_CreateNodeGroupAction(t *testing.T) { } } +// nolint func TestModelAction_GetNodeGroupActions(t *testing.T) { action := &storage.NodeGroupAction{ NodeGroupID: "nodegroup1", @@ -244,9 +244,11 @@ func TestModelAction_ListNodeGroupAction(t *testing.T) { mockFields.find.On("WithSort", mock.Anything).Return(mockFields.find) mockFields.find.On("WithStart", mock.Anything).Return(mockFields.find) mockFields.find.On("WithLimit", mock.Anything).Return(mockFields.find) - mockFields.find.On("All", context.Background(), mock.Anything).Return(func(ctx context.Context, result interface{}) error { - return reflectInterface(result, []*storage.NodeGroupAction{action}) - }) + mockFields.find.On("All", + context.Background(), mock.Anything). + Return(func(ctx context.Context, result interface{}) error { + return reflectInterface(result, []*storage.NodeGroupAction{action}) + }) }, }, { @@ -379,6 +381,7 @@ func Test_UpdateNodeGroupAction(t *testing.T) { } } +// nolint func Test_DeleteNodeGroupAction(t *testing.T) { action := &storage.NodeGroupAction{ NodeGroupID: "nodegroup1", diff --git a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/event.go b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/event.go index dc05ff9ac4..127f0dceb5 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/event.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/event.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ @@ -16,10 +16,10 @@ import ( "context" "fmt" - "go.mongodb.org/mongo-driver/bson" - "github.com/Tencent/bk-bcs/bcs-common/pkg/odm/drivers" "github.com/Tencent/bk-bcs/bcs-common/pkg/odm/operator" + "go.mongodb.org/mongo-driver/bson" + "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/pkg/storage" ) @@ -96,6 +96,7 @@ func (m *ModelEvent) ListNodeGroupEvent(nodeGroupID string, opt *storage.ListOpt isDeletedKey: opt.ReturnSoftDeletedItems, })) if !opt.DoPagination && opt.Limit == 0 { + // nolint count, err := m.DB.Table(m.TableName).Find(operator.NewBranchCondition(operator.And, cond...)).Count(ctx) if err != nil { return nil, fmt.Errorf("get event count err:%v", err) diff --git a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/event_test.go b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/event_test.go index 540ff5794d..f4fb93f6c8 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/event_test.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/event_test.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ @@ -129,9 +129,11 @@ func TestModelEvent_ListNodeGroupEvent(t *testing.T) { mockFields.find.On("WithSort", mock.Anything).Return(mockFields.find) mockFields.find.On("WithStart", mock.Anything).Return(mockFields.find) mockFields.find.On("WithLimit", mock.Anything).Return(mockFields.find) - mockFields.find.On("All", context.Background(), mock.Anything).Return(func(ctx context.Context, result interface{}) error { - return reflectInterface(result, []*storage.NodeGroupEvent{event}) - }) + mockFields.find.On("All", + context.Background(), mock.Anything). + Return(func(ctx context.Context, result interface{}) error { + return reflectInterface(result, []*storage.NodeGroupEvent{event}) + }) }, }, { diff --git a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/group.go b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/group.go index 489d1186a4..b2fb26a5d8 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/group.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/group.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ @@ -19,10 +19,9 @@ import ( "fmt" "time" - "go.mongodb.org/mongo-driver/bson" - "github.com/Tencent/bk-bcs/bcs-common/pkg/odm/drivers" "github.com/Tencent/bk-bcs/bcs-common/pkg/odm/operator" + "go.mongodb.org/mongo-driver/bson" "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/pkg/storage" ) @@ -77,6 +76,7 @@ func (m *ModelGroup) ListNodeGroups(opt *storage.ListOptions) ([]*storage.NodeGr isDeletedKey: opt.ReturnSoftDeletedItems, })) if !opt.DoPagination && opt.Limit == 0 { + // nolint count, err := m.DB.Table(m.TableName).Find(operator.NewBranchCondition(operator.And, cond...)).Count(ctx) if err != nil { return nil, fmt.Errorf("get group count err:%v", err) @@ -174,7 +174,7 @@ func (m *ModelGroup) UpdateNodeGroup(nodegroup *storage.NodeGroup, opt *storage. isDeletedKey: false, }) retNodeGroup := &storage.NodeGroup{} - if err := m.DB.Table(m.TableName).Find(cond).One(ctx, retNodeGroup); err != nil { + if err = m.DB.Table(m.TableName).Find(cond).One(ctx, retNodeGroup); err != nil { // 如果找不到且opt.CreateIfNotExist,创建新的 if errors.Is(err, drivers.ErrTableRecordNotFound) && opt.CreateIfNotExist { _, err = m.DB.Table(m.TableName).Insert(ctx, []interface{}{nodegroup}) diff --git a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/group_test.go b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/group_test.go index 752379d026..2999827b55 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/group_test.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/group_test.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ @@ -18,10 +18,10 @@ import ( "testing" "time" + "github.com/Tencent/bk-bcs/bcs-common/pkg/odm/drivers" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" - "github.com/Tencent/bk-bcs/bcs-common/pkg/odm/drivers" "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/pkg/storage" "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/mocks" ) @@ -243,9 +243,11 @@ func TestModelGroup_ListNodeGroups(t *testing.T) { mockFields.find.On("WithSort", mock.Anything).Return(mockFields.find) mockFields.find.On("WithStart", mock.Anything).Return(mockFields.find) mockFields.find.On("WithLimit", mock.Anything).Return(mockFields.find) - mockFields.find.On("All", context.Background(), mock.Anything).Return(func(ctx context.Context, result interface{}) error { - return reflectInterface(result, []*storage.NodeGroup{group}) - }) + mockFields.find.On("All", + context.Background(), mock.Anything). + Return(func(ctx context.Context, result interface{}) error { + return reflectInterface(result, []*storage.NodeGroup{group}) + }) }, }, { @@ -284,6 +286,7 @@ func TestModelGroup_ListNodeGroups(t *testing.T) { } } +// nolint func TestModelGroup_UpdateNodeGroup(t *testing.T) { group := &storage.NodeGroup{ NodeGroupID: "nodegroup1", @@ -379,6 +382,7 @@ func TestModelGroup_UpdateNodeGroup(t *testing.T) { } } +// nolint func TestModelGroup_DeleteNodeGroup(t *testing.T) { group := &storage.NodeGroup{ NodeGroupID: "nodegroup1", diff --git a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/mongo.go b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/mongo.go index c9c8cbdf3d..929b035fd6 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/mongo.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/mongo.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ diff --git a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/strategy.go b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/strategy.go index 047e43e9d7..521407a5f8 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/strategy.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/strategy.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ @@ -18,11 +18,10 @@ import ( "errors" "fmt" - "go.mongodb.org/mongo-driver/bson" - "github.com/Tencent/bk-bcs/bcs-common/common/blog" "github.com/Tencent/bk-bcs/bcs-common/pkg/odm/drivers" "github.com/Tencent/bk-bcs/bcs-common/pkg/odm/operator" + "go.mongodb.org/mongo-driver/bson" "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/pkg/storage" ) @@ -72,6 +71,7 @@ func (m *ModelStrategy) ListNodeGroupStrategies(opt *storage.ListOptions) ([]*st isDeletedKey: opt.ReturnSoftDeletedItems, })) if !opt.DoPagination && opt.Limit == 0 { + // nolint count, err := m.DB.Table(m.TableName).Find(operator.NewBranchCondition(operator.And, cond...)).Count(ctx) if err != nil { return nil, fmt.Errorf("get strategy count err:%v", err) @@ -110,6 +110,7 @@ func (m *ModelStrategy) ListNodeGroupStrategiesByType(strategyType string, isDeletedKey: opt.ReturnSoftDeletedItems, })) if !opt.DoPagination && opt.Limit == 0 { + // nolint count, err := m.DB.Table(m.TableName).Find(operator.NewBranchCondition(operator.And, cond...)).Count(ctx) if err != nil { return nil, fmt.Errorf("get strategy count err:%v", err) @@ -205,7 +206,7 @@ func (m *ModelStrategy) UpdateNodeGroupStrategy(strategy *storage.NodeGroupMgrSt isDeletedKey: false, }) retStrategy := &storage.NodeGroupMgrStrategy{} - if err := m.DB.Table(m.TableName).Find(cond).One(ctx, retStrategy); err != nil { + if err = m.DB.Table(m.TableName).Find(cond).One(ctx, retStrategy); err != nil { // 如果找不到且opt.CreateIfNotExist,创建新的 if errors.Is(err, drivers.ErrTableRecordNotFound) && opt.CreateIfNotExist { _, err = m.DB.Table(m.TableName).Insert(ctx, []interface{}{strategy}) diff --git a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/strategy_test.go b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/strategy_test.go index 5d46359412..b7a589ef4d 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/strategy_test.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/strategy_test.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ @@ -20,15 +20,15 @@ import ( "testing" "time" + "github.com/Tencent/bk-bcs/bcs-common/pkg/odm/drivers" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" - "github.com/Tencent/bk-bcs/bcs-common/pkg/odm/drivers" - "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/pkg/storage" "github.com/Tencent/bk-bcs/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/mocks" ) +// nolint func Test_CreateNodeGroupStrategy(t *testing.T) { strategy := &storage.NodeGroupMgrStrategy{ Name: "testStrategy1", @@ -143,6 +143,7 @@ func Test_CreateNodeGroupStrategy(t *testing.T) { } } +// nolint func Test_GetNodeGroupStrategy(t *testing.T) { strategy := &storage.NodeGroupMgrStrategy{ Name: "testStrategy1", @@ -265,6 +266,7 @@ func Test_GetNodeGroupStrategy(t *testing.T) { } } +// nolint func Test_ListNodeGroupStrategies(t *testing.T) { strategy := &storage.NodeGroupMgrStrategy{ Name: "testStrategy1", @@ -333,9 +335,11 @@ func Test_ListNodeGroupStrategies(t *testing.T) { mockFields.find.On("WithSort", mock.Anything).Return(mockFields.find) mockFields.find.On("WithStart", mock.Anything).Return(mockFields.find) mockFields.find.On("WithLimit", mock.Anything).Return(mockFields.find) - mockFields.find.On("All", context.Background(), mock.Anything).Return(func(ctx context.Context, result interface{}) error { - return reflectInterface(result, []*storage.NodeGroupMgrStrategy{strategy}) - }) + mockFields.find.On("All", + context.Background(), mock.Anything). + Return(func(ctx context.Context, result interface{}) error { + return reflectInterface(result, []*storage.NodeGroupMgrStrategy{strategy}) + }) }, }, { @@ -374,6 +378,7 @@ func Test_ListNodeGroupStrategies(t *testing.T) { } } +// nolint func Test_UpdateNodeGroupStrategy(t *testing.T) { strategy := &storage.NodeGroupMgrStrategy{ Name: "testStrategy1", @@ -461,7 +466,8 @@ func Test_UpdateNodeGroupStrategy(t *testing.T) { mockFields.db.On("Table", tableNamePrefix+strategyTableName).Return(mockFields.table) mockFields.table.On("HasIndex", context.Background(), "strategy_1").Return(true, nil) mockFields.table.On("Find", mock.Anything).Return(mockFields.find) - mockFields.find.On("One", context.Background(), &storage.NodeGroupMgrStrategy{}).Return(drivers.ErrTableRecordNotFound) + mockFields.find.On("One", context.Background(), &storage.NodeGroupMgrStrategy{}). + Return(drivers.ErrTableRecordNotFound) mockFields.table.On("Insert", context.Background(), mock.Anything).Return(1, nil) }, }, @@ -479,7 +485,8 @@ func Test_UpdateNodeGroupStrategy(t *testing.T) { mockFields.db.On("Table", tableNamePrefix+strategyTableName).Return(mockFields.table) mockFields.table.On("HasIndex", context.Background(), "strategy_1").Return(true, nil) mockFields.table.On("Find", mock.Anything).Return(mockFields.find) - mockFields.find.On("One", context.Background(), &storage.NodeGroupMgrStrategy{}).Return(drivers.ErrTableRecordNotFound) + mockFields.find.On("One", context.Background(), &storage.NodeGroupMgrStrategy{}). + Return(drivers.ErrTableRecordNotFound) }, }, } @@ -498,6 +505,7 @@ func Test_UpdateNodeGroupStrategy(t *testing.T) { } } +// nolint func Test_DeleteNodeGroupStrategy(t *testing.T) { strategy := &storage.NodeGroupMgrStrategy{ Name: "testStrategy1", @@ -578,7 +586,8 @@ func Test_DeleteNodeGroupStrategy(t *testing.T) { mockFields.db.On("Table", tableNamePrefix+strategyTableName).Return(mockFields.table) mockFields.table.On("HasIndex", context.Background(), "strategy_1").Return(true, nil) mockFields.table.On("Find", mock.Anything).Return(mockFields.find) - mockFields.find.On("One", context.Background(), &storage.NodeGroupMgrStrategy{}).Return(drivers.ErrTableRecordNotFound) + mockFields.find.On("One", context.Background(), &storage.NodeGroupMgrStrategy{}). + Return(drivers.ErrTableRecordNotFound) }, }, { @@ -604,7 +613,8 @@ func Test_DeleteNodeGroupStrategy(t *testing.T) { mockFields.db.On("Table", tableNamePrefix+strategyTableName).Return(mockFields.table) mockFields.table.On("HasIndex", context.Background(), "strategy_1").Return(true, nil) mockFields.table.On("Find", mock.Anything).Return(mockFields.find) - mockFields.find.On("One", context.Background(), &storage.NodeGroupMgrStrategy{}).Return(drivers.ErrTableRecordNotFound) + mockFields.find.On("One", context.Background(), &storage.NodeGroupMgrStrategy{}). + Return(drivers.ErrTableRecordNotFound) }, }, } diff --git a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/task.go b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/task.go index 6d40490038..a80b2a6797 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/task.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/task.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ @@ -114,7 +114,7 @@ func (m *ModelTask) UpdateTask(task *storage.ScaleDownTask, isDeletedKey: false, }) retTask := &storage.ScaleDownTask{} - if err := m.DB.Table(m.TableName).Find(cond).One(ctx, retTask); err != nil { + if err = m.DB.Table(m.TableName).Find(cond).One(ctx, retTask); err != nil { // 如果找不到且opt.CreateIfNotExist,创建新的 if errors.Is(err, drivers.ErrTableRecordNotFound) && opt.CreateIfNotExist { task.CreatedTime = time.Now() @@ -183,6 +183,7 @@ func (m *ModelTask) ListTasks(opt *storage.ListOptions) ([]*storage.ScaleDownTas })) // 只有不设置分页,且limit为0时,才查询全量,否则依然按照limit和page分页查询 if !opt.DoPagination && opt.Limit == 0 { + // nolint count, err := m.DB.Table(m.TableName).Find(operator.NewBranchCondition(operator.And, cond...)).Count(ctx) if err != nil { return nil, fmt.Errorf("get task count err:%v", err) @@ -257,6 +258,7 @@ func (m *ModelTask) ListTasksByStrategy(strategy string, opt *storage.ListOption })) // 只有不设置分页,且limit为0时,才查询全量,否则依然按照limit和page分页查询 if !opt.DoPagination && opt.Limit == 0 { + // nolint count, err := m.DB.Table(m.TableName).Find(operator.NewBranchCondition(operator.And, cond...)).Count(ctx) if err != nil { return nil, fmt.Errorf("get task count err:%v", err) diff --git a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/task_test.go b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/task_test.go index 19d6b300bc..a8815c667a 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/task_test.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/task_test.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ @@ -32,11 +32,11 @@ func TestModelTask_CreateTask(t *testing.T) { TotalNum: 2, NodeGroupStrategy: "nodegroup1", ScaleDownGroups: []*storage.ScaleDownDetail{}, - DrainDelayDays: 2, + DrainDelay: "2", Deadline: time.Now().Add(48 * time.Hour), CreatedTime: time.Now(), UpdatedTime: time.Now(), - IsDelete: false, + IsDeleted: false, IsExecuted: false, Status: "preparing", } @@ -113,17 +113,18 @@ func TestModelTask_CreateTask(t *testing.T) { } } +// nolint func TestModelTask_DeleteTask(t *testing.T) { task := &storage.ScaleDownTask{ TaskID: "taskID1", TotalNum: 2, NodeGroupStrategy: "nodegroup1", ScaleDownGroups: []*storage.ScaleDownDetail{}, - DrainDelayDays: 2, + DrainDelay: "2", Deadline: time.Now().Add(48 * time.Hour), CreatedTime: time.Now(), UpdatedTime: time.Now(), - IsDelete: false, + IsDeleted: false, IsExecuted: false, Status: "preparing", } @@ -213,17 +214,18 @@ func TestModelTask_DeleteTask(t *testing.T) { } } +// nolint func TestModelTask_GetTask(t *testing.T) { task := &storage.ScaleDownTask{ TaskID: "taskID1", TotalNum: 2, NodeGroupStrategy: "nodegroup1", ScaleDownGroups: []*storage.ScaleDownDetail{}, - DrainDelayDays: 2, + DrainDelay: "2", Deadline: time.Now().Add(48 * time.Hour), CreatedTime: time.Now(), UpdatedTime: time.Now(), - IsDelete: false, + IsDeleted: false, IsExecuted: false, Status: "preparing", } @@ -315,11 +317,11 @@ func TestModelTask_ListTasks(t *testing.T) { TotalNum: 2, NodeGroupStrategy: "nodegroup1", ScaleDownGroups: []*storage.ScaleDownDetail{}, - DrainDelayDays: 2, + DrainDelay: "2", Deadline: time.Now().Add(48 * time.Hour), CreatedTime: time.Now(), UpdatedTime: time.Now(), - IsDelete: false, + IsDeleted: false, IsExecuted: false, Status: "preparing", } @@ -348,6 +350,7 @@ func TestModelTask_ListTasks(t *testing.T) { mockFields.find.On("WithSort", mock.Anything).Return(mockFields.find) mockFields.find.On("WithStart", mock.Anything).Return(mockFields.find) mockFields.find.On("WithLimit", mock.Anything).Return(mockFields.find) + // nolint mockFields.find.On("All", context.Background(), mock.Anything).Return(func(ctx context.Context, result interface{}) error { return reflectInterface(result, []*storage.ScaleDownTask{task}) }) @@ -396,11 +399,11 @@ func TestModelTask_ListTasksByStrategy(t *testing.T) { TotalNum: 2, NodeGroupStrategy: "nodegroup1", ScaleDownGroups: []*storage.ScaleDownDetail{}, - DrainDelayDays: 2, + DrainDelay: "2", Deadline: time.Now().Add(48 * time.Hour), CreatedTime: time.Now(), UpdatedTime: time.Now(), - IsDelete: false, + IsDeleted: false, IsExecuted: false, Status: "preparing", } @@ -431,6 +434,7 @@ func TestModelTask_ListTasksByStrategy(t *testing.T) { mockFields.find.On("WithSort", mock.Anything).Return(mockFields.find) mockFields.find.On("WithStart", mock.Anything).Return(mockFields.find) mockFields.find.On("WithLimit", mock.Anything).Return(mockFields.find) + // nolint mockFields.find.On("All", context.Background(), mock.Anything).Return(func(ctx context.Context, result interface{}) error { return reflectInterface(result, []*storage.ScaleDownTask{task}) }) @@ -474,17 +478,18 @@ func TestModelTask_ListTasksByStrategy(t *testing.T) { } } +// nolint func TestModelTask_UpdateTask(t *testing.T) { task := &storage.ScaleDownTask{ TaskID: "taskID1", TotalNum: 2, NodeGroupStrategy: "nodegroup1", ScaleDownGroups: []*storage.ScaleDownDetail{}, - DrainDelayDays: 2, + DrainDelay: "2", Deadline: time.Now().Add(48 * time.Hour), CreatedTime: time.Now(), UpdatedTime: time.Now(), - IsDelete: false, + IsDeleted: false, IsExecuted: false, Status: "preparing", } diff --git a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/utils.go b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/utils.go index b39d15cd7f..1a354b5137 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/utils.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/utils.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ diff --git a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/utils_test.go b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/utils_test.go index 33ec013105..ebfbef0cfd 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/utils_test.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/storage/mongo/utils_test.go @@ -1,12 +1,12 @@ /* * Tencent is pleased to support the open source community by making Blueking Container Service available. - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * Licensed under the MIT License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions and + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and * limitations under the License. */ diff --git a/bcs-services/bcs-nodegroup-manager/pkg/storage/types.go b/bcs-services/bcs-nodegroup-manager/pkg/storage/types.go index ebc07e6356..2b7bf4a70f 100644 --- a/bcs-services/bcs-nodegroup-manager/pkg/storage/types.go +++ b/bcs-services/bcs-nodegroup-manager/pkg/storage/types.go @@ -4,7 +4,7 @@ * Licensed under the MIT License (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * http://opensource.org/licenses/MIT - * Unless required by applicable law or agreed to in writing, software distributed under, + * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions and * limitations under the License. @@ -51,7 +51,9 @@ const ( ) const ( - BufferStrategyType = "buffer" + // BufferStrategyType buffer type + BufferStrategyType = "buffer" + // HierarchicalStrategyType hierarchicalBuffer HierarchicalStrategyType = "hierarchicalBuffer" ) @@ -316,10 +318,7 @@ type ScaleDownTask struct { // IsTerminated check task status func (t *ScaleDownTask) IsTerminated() bool { - if t.Status != TaskRequestingState { - return true - } - return false + return t.Status != TaskRequestingState } // IsExecuting check task status