Skip to content

Commit

Permalink
Merge pull request #197 from peerless1024/refactor/fix_lint_error
Browse files Browse the repository at this point in the history
Refactor/fix lint error
  • Loading branch information
ChaoyongLiang authored Dec 19, 2024
2 parents c11fec7 + 64ea301 commit 11de8c2
Show file tree
Hide file tree
Showing 22 changed files with 360 additions and 336 deletions.
21 changes: 19 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ ORG = polarismesh
REPO = polaris-controller
SIDECAR_INIT_REPO = polaris-sidecar-init
ENVOY_SIDECAR_INIT_REPO = polaris-envoy-bootstrap-generator
IMAGE_TAG = v1.7.1
IMAGE_TAG = v1.7.2
PLATFORMS = linux/amd64,linux/arm64

.PHONY: all
all: build-amd64 build-arm64 build-multi-arch-image \
all: fmt build-amd64 build-arm64 build-multi-arch-image \
build-sidecar-init build-envoy-sidecar-init push-image

.PHONY: build-amd64
Expand Down Expand Up @@ -49,3 +49,20 @@ clean:
rm -rf bin
rm -rf polaris-controller-release*

.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...

.PHONY: generate-multi-arch-image
generate-multi-arch-image: fmt build-amd64 build-arm64
@echo "------------------"
@echo "--> Generate multi-arch docker image to registry for polaris-controller"
@echo "------------------"
@docker buildx build -f ./docker/Dockerfile --tag $(ORG)/$(REPO):$(IMAGE_TAG) --platform $(PLATFORMS) ./

.PHONY: push-multi-arch-image
push-multi-arch-image: generate-multi-arch-image
@echo "------------------"
@echo "--> Push multi-arch docker image to registry for polaris-controller"
@echo "------------------"
@docker image push $(ORG)/$(REPO):$(IMAGE_TAG) --platform $(PLATFORMS)
4 changes: 2 additions & 2 deletions cmd/polaris-controller/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package app

import (
"io/ioutil"
"os"

"gopkg.in/yaml.v2"

Expand Down Expand Up @@ -65,7 +65,7 @@ type controllerConfig struct {
}

func readConfFromFile() (*controllerConfig, error) {
buf, err := ioutil.ReadFile(MeshFile)
buf, err := os.ReadFile(MeshFile)
if err != nil {
log.Errorf("read file error, %v", err)
return nil, err
Expand Down
4 changes: 3 additions & 1 deletion cmd/polaris-controller/app/options/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ func RunServer(
defer close(stoppedCh)
<-stopCh
ctx, cancel := context.WithTimeout(context.Background(), shutDownTimeout)
server.Shutdown(ctx)
if err := server.Shutdown(ctx); err != nil {
log.Warnf("server Shutdown error:%+v", err)
}
cancel()
}()

Expand Down
6 changes: 3 additions & 3 deletions cmd/polaris-controller/app/polaris-controller-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package app
import (
"context"
"fmt"
"io/ioutil"
"io"
"math/rand"
"net"
"net/http"
Expand Down Expand Up @@ -239,8 +239,8 @@ func assignFlags(rootCmd *cobra.Command) {

func closeGrpcLog() {
var (
infoW = ioutil.Discard
warningW = ioutil.Discard
infoW = io.Discard
warningW = io.Discard
errorW = os.Stderr
)
grpclog.SetLoggerV2(grpclog.NewLoggerV2(infoW, warningW, errorW))
Expand Down
2 changes: 1 addition & 1 deletion cmd/polaris-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

func main() {
rand.Seed(time.Now().UnixNano())
rand.New(rand.NewSource(time.Now().UnixNano()))

command := app.NewPolarisControllerManagerCommand()
logs.InitLogs()
Expand Down
2 changes: 1 addition & 1 deletion common/log/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func Configure(optionsMap map[string]*Options) error {

// capture gRPC logging
if options.LogGrpc {
grpclog.SetLogger(zapgrpc.NewLogger(captureLogger.WithOptions(zap.AddCallerSkip(2))))
grpclog.SetLoggerV2(zapgrpc.NewLogger(captureLogger.WithOptions(zap.AddCallerSkip(2))))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cache/config_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ func (csm *CachedConfigFileMap) Delete(key string) {
func (csm *CachedConfigFileMap) Load(key string) (value *v1.ConfigMap, ok bool) {
v, ok := csm.sm.Load(key)
if v != nil {
value, ok2 := v.(*v1.ConfigMap)
result, ok2 := v.(*v1.ConfigMap)
if !ok2 {
ok = false
}
return value, ok
return result, ok
}
return value, ok
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cache/service_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ func (csm *CachedServiceMap) Delete(key string) {
func (csm *CachedServiceMap) Load(key string) (value *v1.Service, ok bool) {
v, ok := csm.sm.Load(key)
if v != nil {
value, ok2 := v.(*v1.Service)
result, ok2 := v.(*v1.Service)
if !ok2 {
ok = false
}
return value, ok
return result, ok
}
return value, ok
}
Expand Down
8 changes: 3 additions & 5 deletions pkg/controller/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ func (p *PolarisController) compareInstanceUpdate(service *v1.Service, spec *add
// ttl 默认是5s
ttl, err := strconv.Atoi(ttlStr)
if err != nil {
ttl = 5
log.SyncNamingScope().Errorf("annotation 'polarismesh.cn/ttl' value: %s, converted to type int error %v",
ttlStr, err)
} else {
if ttl > 0 && ttl <= 60 {
healthCheck.Type = util.IntPtr(0)
Expand Down Expand Up @@ -317,10 +318,7 @@ func (p *PolarisController) compareInstanceUpdate(service *v1.Service, spec *add
}

if newMetadataStr == "" {
if isPolarisInstanceHasCustomMeta(oldMetadata) {
return true
}
return false
return isPolarisInstanceHasCustomMeta(oldMetadata)
}
newMetaMap := make(map[string]string)
err := json.Unmarshal([]byte(newMetadataStr), &newMetaMap)
Expand Down
4 changes: 0 additions & 4 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,6 @@ func (p *PolarisController) process(t *Task) error {
return err
}

func (p *PolarisController) handleErr(err error, task *Task) {

}

// CounterPolarisService
func (p *PolarisController) CounterPolarisService() {
serviceList, err := p.serviceLister.List(labels.Everything())
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (p *PolarisController) processSyncInstance(service *v1.Service) (err error)
fmt.Sprintf("%s Current polaris instance is %v", serviceMsg, currentIPs),
fmt.Sprintf("%s addIns %v deleteIns %v updateIns %v", serviceMsg, addIns, deleteIns, updateIns),
}
log.SyncNamingScope().Infof(strings.Join(msg, "\n"))
log.SyncNamingScope().Info(strings.Join(msg, "\n"))

var addInsErr, deleteInsErr, updateInsErr error

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ func (p *PolarisController) onNamespaceUpdate(old, cur interface{}) {
// 3. 无 sync -> 有 sync,将 ns 下 service、configmap 加入队列,标志为 polaris 要处理的,即添加
// 4. 有 sync -> 无 sync,将 ns 下 service、configmap 加入队列,标志为 polaris 不需要处理的,即删除

operation := OperationEmpty
if !isOldSync && !isCurSync {
// 情况 1
return
}
var operation Operation
if isCurSync {
// 情况 2、3
operation = OperationAdd
Expand Down
Loading

0 comments on commit 11de8c2

Please sign in to comment.