Skip to content

Commit

Permalink
fix: make no error
Browse files Browse the repository at this point in the history
  • Loading branch information
xdlbdy committed Apr 20, 2022
1 parent 164fe91 commit d84ac3a
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 118 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ VSPROTO_ROOT=$(VANUS_ROOT)/../vsproto

export VANUS_LOG_LEVEL=debug

DOCKER_REGISTRY ?= linkall.cloud
DOCKER_REPO ?= ${DOCKER_REGISTRY}/vanus
DOCKER_REGISTRY ?= public.ecr.aws
DOCKER_REPO ?= ${DOCKER_REGISTRY}/t8a4l2d7
IMAGE_TAG ?= latest
#os linux or darwin
GOOS ?= linux
Expand Down
2 changes: 1 addition & 1 deletion build/images/controller/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ARG TARGETOS
ARG TARGETARCH
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build-controller

FROM centos:8.4.2105
FROM alpine:3.15.4
RUN mkdir -p /server
COPY --from=builder /workspace/vanus/bin/controller /server/bin/controller
WORKDIR /server
Expand Down
2 changes: 1 addition & 1 deletion build/images/gateway/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ARG TARGETOS
ARG TARGETARCH
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build-gateway

FROM centos:8.4.2105
FROM alpine:3.15.4
RUN mkdir -p /server
COPY --from=builder /workspace/vanus/bin/gateway /server/bin/gateway
WORKDIR /server
Expand Down
2 changes: 1 addition & 1 deletion build/images/store/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ARG TARGETOS
ARG TARGETARCH
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build-store

FROM centos:8.4.2105
FROM alpine:3.15.4
RUN mkdir -p /server
COPY --from=builder /workspace/vanus/bin/store /server/bin/store
WORKDIR /server
Expand Down
2 changes: 1 addition & 1 deletion build/images/trigger/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ARG TARGETOS
ARG TARGETARCH
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build-trigger

FROM centos:8.4.2105
FROM alpine:3.15.4
RUN mkdir -p /server
COPY --from=builder /workspace/vanus/bin/trigger /server/bin/trigger
WORKDIR /server
Expand Down
54 changes: 2 additions & 52 deletions cmd/store/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ import (
"flag"
"fmt"
"github.com/linkall-labs/vanus/internal/store"
"gopkg.in/yaml.v3"
"io"
"net"
"os"
"time"

// third-party libraries.
"google.golang.org/grpc"

Expand All @@ -37,53 +33,18 @@ import (
"github.com/linkall-labs/vanus/internal/primitive"
"github.com/linkall-labs/vanus/internal/raft/transport"
"github.com/linkall-labs/vanus/internal/store/segment"
"github.com/linkall-labs/vanus/internal/util"
"github.com/linkall-labs/vanus/observability/log"
)

<<<<<<< HEAD
func main() {
f := flag.String("config", "./config/gateway.yaml", "gateway config file path")
flag.Parse()
cfg, err := segment.Init(*f)
cfg, err := store.InitConfig(*f)
if err != nil {
log.Error(nil, "init config error", map[string]interface{}{log.KeyError: err})
os.Exit(-1)
}
listen, err := net.Listen("tcp", fmt.Sprintf(":%d", cfg.Port))
=======
var (
configPath = flag.String("config-file", "./config/store.yaml", "the configuration file of controller")
)

func main() {
flag.Parse()

f, err := os.Open(*configPath)
if err != nil {
log.Error(nil, "open configuration file failed", map[string]interface{}{
log.KeyError: err,
})
os.Exit(-1)
}
data, err := io.ReadAll(f)
if err != nil {
log.Error(nil, "read configuration file failed", map[string]interface{}{
log.KeyError: err,
})
os.Exit(-1)
}

cfg := store.Config{}
if err = yaml.Unmarshal(data, &cfg); err != nil {
log.Error(nil, "unmarshall configuration file failed", map[string]interface{}{
log.KeyError: err,
})
os.Exit(-1)
}

listen, err := net.Listen("tcp", fmt.Sprintf("%s:%d", cfg.IP, cfg.Port))
>>>>>>> 14516ae (feat: add store.Config)
if err != nil {
log.Error(context.Background(), "failed to listen", map[string]interface{}{
"error": err,
Expand All @@ -104,13 +65,7 @@ func main() {
host := transport.NewHost(reslover)
raftSrv := transport.NewRaftServer(context.TODO(), host)
raftpb.RegisterRaftServerServer(grpcServer, raftSrv)

<<<<<<< HEAD
srv := segment.NewSegmentServer(fmt.Sprintf("%s:%d", util.LocalIp, cfg.Port), cfg.ControllerAddr,
uint64(1), stopCallback)
=======
srv := segment.NewSegmentServer(cfg, stopCallback)
>>>>>>> 14516ae (feat: add store.Config)
srv := segment.NewSegmentServer(*cfg, stopCallback)
if err != nil {
stopCallback()
log.Error(context.Background(), "start SegmentServer failed", map[string]interface{}{
Expand All @@ -133,13 +88,8 @@ func main() {

go func() {
log.Info(ctx, "the SegmentServer ready to work", map[string]interface{}{
<<<<<<< HEAD
"time": util.FormatTime(time.Now()),
=======
"listen_ip": cfg.IP,
"listen_port": cfg.Port,
"time": util.FormatTime(time.Now()),
>>>>>>> 14516ae (feat: add store.Config)
})
if err = grpcServer.Serve(listen); err != nil {
log.Error(ctx, "grpc server occurred an error", map[string]interface{}{
Expand Down
2 changes: 1 addition & 1 deletion cmd/trigger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func main() {
ctx := signal.SetupSignalContext()
f := flag.String("config", "./config/trigger.yaml", "trigger worker config file path")
flag.Parse()
c, err := trigger.Init(*f)
c, err := trigger.InitConfig(*f)
if err != nil {
log.Error(nil, "init config error", map[string]interface{}{log.KeyError: err})
os.Exit(-1)
Expand Down
2 changes: 1 addition & 1 deletion config/trigger.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
port: 2149
controller_addr: "127.0.0.1:2048"
controller: ["127.0.0.1:2048"]
53 changes: 46 additions & 7 deletions deploy/yaml/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,35 @@ metadata:
name: config-controller
namespace: vanus
data:
port: 2049
controller.yaml: |-
name: "test-1"
ip: "127.0.0.1"
port: 2049
etcd:
- "127.0.0.1:2379"
data_dir: "/data/vanus"
topology:
service_a: "127.0.0.1:2049"
metadata:
key_prefix: "/wenfeng"
embed_etcd:
name: "etcd-1"
data_dir: "etcd/node1"
client_addr: "127.0.0.1:2379"
peer_addr: "127.0.0.1:2380"
clusters:
- "etcd-1=http://127.0.0.1:2380"
trigger:
storage:
keyPrefix: "/xdl"
serverList: [ "127.0.0.1:2379" ]
---
apiVersion: v1
kind: Service
metadata:
name: vanus-controller
namespace: vanus
labels:
app: vanus-controller
spec:
Expand All @@ -36,36 +58,53 @@ spec:
name: vanus-controller
---
apiVersion: apps/v1
kind: Deployment
kind: StatefulSet
metadata:
name: vanus-controller
namespace: vanus
labels:
app.kubernetes.io/name: vanus-controller
app: vanus-controller
spec:
selector:
matchLabels:
app: vanus-controller
replicas: 3
serviceName: vanus-controller
volumeClaimTemplates:
- metadata:
name: data
labels:
app: vanus-controller
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
template:
metadata:
labels:
app: vanus-controller
app.kubernetes.io/name: vanus-controller
spec:
containers:
- name: controller
image: linkall.cloud/vanus/controller:latest
image: public.ecr.aws/t8a4l2d7/controller:latest
resources:
requests:
cpu: 100m
memory: 100Mi
ports:
- name: grpc
containerPort: 2049
- name: etcd-client
containerPort: 2379
- name: etcd-peer
containerPort: 2380
volumeMounts:
- name: config-controller
mountPath: /server/config/controller.yaml
subPath: controller.yaml
mountPath: /server/config
- name: data
mountPath: /data
volumes:
- name: config-controller
configMap:
Expand Down
8 changes: 4 additions & 4 deletions deploy/yaml/gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ metadata:
name: config-gateway
namespace: vanus
data:
port: 8080
controller_addr: "127.0.0.1:2049"
gateway.yaml: |-
port: 8080
controller_addr: "127.0.0.1:2049"
---
apiVersion: apps/v1
Expand Down Expand Up @@ -66,8 +67,7 @@ spec:
containerPort: 8080
volumeMounts:
- name: config-gateway
mountPath: /server/config/gateway.yaml
subPath: gateway.yaml
mountPath: /server/config
volumes:
- name: config-gateway
configMap:
Expand Down
8 changes: 4 additions & 4 deletions deploy/yaml/store.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ metadata:
name: config-store
namespace: vanus
data:
port: 11811
controller_addr: "127.0.0.1:2049"
store.yaml: |-
port: 11811
controller_addr: "127.0.0.1:2049"
---
apiVersion: apps/v1
Expand Down Expand Up @@ -65,8 +66,7 @@ spec:
containerPort: 11811
volumeMounts:
- name: config-store
mountPath: /server/config/store.yaml
subPath: store.yaml
mountPath: /server/config
volumes:
- name: config-store
configMap:
Expand Down
14 changes: 9 additions & 5 deletions deploy/yaml/trigger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ metadata:
name: config-trigger
namespace: vanus
data:
port: 2149
controller_addr: "127.0.0.1:2049"
trigger.yaml: |-
port: 2149
controller:
- "vanus-controller-0.vanus-controller.vanus.svc.cluster.local:2049"
- "vanus-controller-1.vanus-controller.vanus.svc.cluster.local:2049"
- "vanus-controller-2.vanus-controller.vanus.svc.cluster.local:2049"
---
apiVersion: apps/v1
Expand All @@ -40,7 +44,8 @@ spec:
spec:
containers:
- name: trigger
image: linkall.com/vanus/trigger:latest
image: public.ecr.aws/t8a4l2d7/trigger:latest
imagePullPolicy: Always
resources:
requests:
cpu: 100m
Expand All @@ -50,8 +55,7 @@ spec:
containerPort: 2149
volumeMounts:
- name: config-trigger
mountPath: /server/config/trigger.yaml
subPath: trigger.yaml
mountPath: /server/config
volumes:
- name: config-trigger
configMap:
Expand Down
14 changes: 13 additions & 1 deletion internal/store/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

package store

import "github.com/linkall-labs/vanus/internal/primitive/vanus"
import (
"github.com/linkall-labs/vanus/internal/primitive"
"github.com/linkall-labs/vanus/internal/primitive/vanus"
)

type Config struct {
ControllerAddresses []string `json:"controllers"`
Expand All @@ -28,3 +31,12 @@ type VolumeInfo struct {
Dir string `json:"dir"`
Capacity uint64 `json:"capacity"`
}

func InitConfig(filename string) (*Config, error) {
c := new(Config)
err := primitive.LoadConfig(filename, c)
if err != nil {
return nil, err
}
return c, nil
}
33 changes: 0 additions & 33 deletions internal/store/segment/config.go

This file was deleted.

Loading

0 comments on commit d84ac3a

Please sign in to comment.