Skip to content

Commit 11de8c2

Browse files
Merge pull request #197 from peerless1024/refactor/fix_lint_error
Refactor/fix lint error
2 parents c11fec7 + 64ea301 commit 11de8c2

File tree

22 files changed

+360
-336
lines changed

22 files changed

+360
-336
lines changed

Makefile

+19-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ ORG = polarismesh
33
REPO = polaris-controller
44
SIDECAR_INIT_REPO = polaris-sidecar-init
55
ENVOY_SIDECAR_INIT_REPO = polaris-envoy-bootstrap-generator
6-
IMAGE_TAG = v1.7.1
6+
IMAGE_TAG = v1.7.2
77
PLATFORMS = linux/amd64,linux/arm64
88

99
.PHONY: all
10-
all: build-amd64 build-arm64 build-multi-arch-image \
10+
all: fmt build-amd64 build-arm64 build-multi-arch-image \
1111
build-sidecar-init build-envoy-sidecar-init push-image
1212

1313
.PHONY: build-amd64
@@ -49,3 +49,20 @@ clean:
4949
rm -rf bin
5050
rm -rf polaris-controller-release*
5151

52+
.PHONY: fmt
53+
fmt: ## Run go fmt against code.
54+
go fmt ./...
55+
56+
.PHONY: generate-multi-arch-image
57+
generate-multi-arch-image: fmt build-amd64 build-arm64
58+
@echo "------------------"
59+
@echo "--> Generate multi-arch docker image to registry for polaris-controller"
60+
@echo "------------------"
61+
@docker buildx build -f ./docker/Dockerfile --tag $(ORG)/$(REPO):$(IMAGE_TAG) --platform $(PLATFORMS) ./
62+
63+
.PHONY: push-multi-arch-image
64+
push-multi-arch-image: generate-multi-arch-image
65+
@echo "------------------"
66+
@echo "--> Push multi-arch docker image to registry for polaris-controller"
67+
@echo "------------------"
68+
@docker image push $(ORG)/$(REPO):$(IMAGE_TAG) --platform $(PLATFORMS)

cmd/polaris-controller/app/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package app
1717

1818
import (
19-
"io/ioutil"
19+
"os"
2020

2121
"gopkg.in/yaml.v2"
2222

@@ -65,7 +65,7 @@ type controllerConfig struct {
6565
}
6666

6767
func readConfFromFile() (*controllerConfig, error) {
68-
buf, err := ioutil.ReadFile(MeshFile)
68+
buf, err := os.ReadFile(MeshFile)
6969
if err != nil {
7070
log.Errorf("read file error, %v", err)
7171
return nil, err

cmd/polaris-controller/app/options/serve.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ func RunServer(
9595
defer close(stoppedCh)
9696
<-stopCh
9797
ctx, cancel := context.WithTimeout(context.Background(), shutDownTimeout)
98-
server.Shutdown(ctx)
98+
if err := server.Shutdown(ctx); err != nil {
99+
log.Warnf("server Shutdown error:%+v", err)
100+
}
99101
cancel()
100102
}()
101103

cmd/polaris-controller/app/polaris-controller-manager.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package app
1818
import (
1919
"context"
2020
"fmt"
21-
"io/ioutil"
21+
"io"
2222
"math/rand"
2323
"net"
2424
"net/http"
@@ -239,8 +239,8 @@ func assignFlags(rootCmd *cobra.Command) {
239239

240240
func closeGrpcLog() {
241241
var (
242-
infoW = ioutil.Discard
243-
warningW = ioutil.Discard
242+
infoW = io.Discard
243+
warningW = io.Discard
244244
errorW = os.Stderr
245245
)
246246
grpclog.SetLoggerV2(grpclog.NewLoggerV2(infoW, warningW, errorW))

cmd/polaris-controller/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
func main() {
31-
rand.Seed(time.Now().UnixNano())
31+
rand.New(rand.NewSource(time.Now().UnixNano()))
3232

3333
command := app.NewPolarisControllerManagerCommand()
3434
logs.InitLogs()

common/log/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func Configure(optionsMap map[string]*Options) error {
293293

294294
// capture gRPC logging
295295
if options.LogGrpc {
296-
grpclog.SetLogger(zapgrpc.NewLogger(captureLogger.WithOptions(zap.AddCallerSkip(2))))
296+
grpclog.SetLoggerV2(zapgrpc.NewLogger(captureLogger.WithOptions(zap.AddCallerSkip(2))))
297297
}
298298
}
299299
}

pkg/cache/config_cache.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ func (csm *CachedConfigFileMap) Delete(key string) {
4040
func (csm *CachedConfigFileMap) Load(key string) (value *v1.ConfigMap, ok bool) {
4141
v, ok := csm.sm.Load(key)
4242
if v != nil {
43-
value, ok2 := v.(*v1.ConfigMap)
43+
result, ok2 := v.(*v1.ConfigMap)
4444
if !ok2 {
4545
ok = false
4646
}
47-
return value, ok
47+
return result, ok
4848
}
4949
return value, ok
5050
}

pkg/cache/service_cache.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ func (csm *CachedServiceMap) Delete(key string) {
4040
func (csm *CachedServiceMap) Load(key string) (value *v1.Service, ok bool) {
4141
v, ok := csm.sm.Load(key)
4242
if v != nil {
43-
value, ok2 := v.(*v1.Service)
43+
result, ok2 := v.(*v1.Service)
4444
if !ok2 {
4545
ok = false
4646
}
47-
return value, ok
47+
return result, ok
4848
}
4949
return value, ok
5050
}

pkg/controller/apis.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ func (p *PolarisController) compareInstanceUpdate(service *v1.Service, spec *add
275275
// ttl 默认是5s
276276
ttl, err := strconv.Atoi(ttlStr)
277277
if err != nil {
278-
ttl = 5
278+
log.SyncNamingScope().Errorf("annotation 'polarismesh.cn/ttl' value: %s, converted to type int error %v",
279+
ttlStr, err)
279280
} else {
280281
if ttl > 0 && ttl <= 60 {
281282
healthCheck.Type = util.IntPtr(0)
@@ -317,10 +318,7 @@ func (p *PolarisController) compareInstanceUpdate(service *v1.Service, spec *add
317318
}
318319

319320
if newMetadataStr == "" {
320-
if isPolarisInstanceHasCustomMeta(oldMetadata) {
321-
return true
322-
}
323-
return false
321+
return isPolarisInstanceHasCustomMeta(oldMetadata)
324322
}
325323
newMetaMap := make(map[string]string)
326324
err := json.Unmarshal([]byte(newMetadataStr), &newMetaMap)

pkg/controller/controller.go

-4
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,6 @@ func (p *PolarisController) process(t *Task) error {
285285
return err
286286
}
287287

288-
func (p *PolarisController) handleErr(err error, task *Task) {
289-
290-
}
291-
292288
// CounterPolarisService
293289
func (p *PolarisController) CounterPolarisService() {
294290
serviceList, err := p.serviceLister.List(labels.Everything())

pkg/controller/endpoint.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (p *PolarisController) processSyncInstance(service *v1.Service) (err error)
192192
fmt.Sprintf("%s Current polaris instance is %v", serviceMsg, currentIPs),
193193
fmt.Sprintf("%s addIns %v deleteIns %v updateIns %v", serviceMsg, addIns, deleteIns, updateIns),
194194
}
195-
log.SyncNamingScope().Infof(strings.Join(msg, "\n"))
195+
log.SyncNamingScope().Info(strings.Join(msg, "\n"))
196196

197197
var addInsErr, deleteInsErr, updateInsErr error
198198

pkg/controller/namespace.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ func (p *PolarisController) onNamespaceUpdate(old, cur interface{}) {
6868
// 3. 无 sync -> 有 sync,将 ns 下 service、configmap 加入队列,标志为 polaris 要处理的,即添加
6969
// 4. 有 sync -> 无 sync,将 ns 下 service、configmap 加入队列,标志为 polaris 不需要处理的,即删除
7070

71-
operation := OperationEmpty
7271
if !isOldSync && !isCurSync {
7372
// 情况 1
7473
return
7574
}
75+
var operation Operation
7676
if isCurSync {
7777
// 情况 2、3
7878
operation = OperationAdd

0 commit comments

Comments
 (0)