-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathconfig.go
133 lines (117 loc) · 3.63 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Tencent is pleased to support the open source community by making Polaris available.
//
// Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
//
// Licensed under the BSD 3-Clause License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/BSD-3-Clause
//
// 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 app
import (
"os"
"gopkg.in/yaml.v2"
"github.com/polarismesh/polaris-controller/cmd/polaris-controller/app/options"
"github.com/polarismesh/polaris-controller/common"
"github.com/polarismesh/polaris-controller/common/log"
)
// ProxyMetadata mesh envoy用到的配置
type ProxyMetadata struct {
ServerAddress string `yaml:"serverAddress"`
ClusterName string `yaml:"clusterName"`
OpenDemand string `yaml:"openDemand"`
CAAddress string `yaml:"caAddress"`
}
// DefaultConfig mesh envoy sidecar 用到的配置
type DefaultConfig struct {
ProxyMetadata ProxyMetadata `yaml:"proxyMetadata"`
}
// SidecarInject sidecar 注入相关
type SidecarInject struct {
Mode string `yaml:"mode"`
Ignores []IgnorePod `yaml:"ignorePods"`
}
type IgnorePod struct {
Namespace string `yaml:"namespace"`
PodName string `yaml:"podName"`
}
type Server struct {
// 健康探测时间间隔
HealthCheckDuration string `yaml:"healthCheckDuration"`
// 定时对账时间间隔
ResyncDuration string `yaml:"resyncDuration"`
}
type controllerConfig struct {
// 北极星服务端地址
ServerAddress string `yaml:"serverAddress"`
// 北极星服务端token(北极星开启鉴权时需要配置)
PolarisAccessToken string `yaml:"accessToken"`
// Operator 北极星主账户ID, 用于数据同步
Operator string `yaml:"operator"`
// 容器集群名称或ID
ClusterName string `yaml:"clusterName"`
// k8s服务同步配置
ServiceSync *options.ServiceSync `yaml:"serviceSync"`
// 配置同步配置
ConfigSync *options.ConfigSync `yaml:"configSync"`
// sidecar注入相关配置
SidecarInject SidecarInject `yaml:"sidecarInject"`
// mesh envoy 相关配置
DefaultConfig DefaultConfig `yaml:"defaultConfig"`
// 组件日志配置
Logger map[string]*log.Options `yaml:"logger"`
// 健康检查和对账配置
Server Server `yaml:"server"`
}
func (c *controllerConfig) getPolarisServerAddress() string {
// 新配置格式
if c.ServerAddress != "" {
return c.ServerAddress
}
// 老的配置格式
if c.ServiceSync.ServerAddress != "" {
return c.ServiceSync.ServerAddress
}
return common.PolarisServerAddress
}
func (c *controllerConfig) getPolarisAccessToken() string {
// 新配置格式
if c.PolarisAccessToken != "" {
return c.PolarisAccessToken
}
// 老的配置格式
if c.ServiceSync.PolarisAccessToken != "" {
return c.ServiceSync.PolarisAccessToken
}
return ""
}
func (c *controllerConfig) getPolarisOperator() string {
// 新配置格式
if c.Operator != "" {
return c.Operator
}
// 老的配置格式
if c.ServiceSync.Operator != "" {
return c.ServiceSync.Operator
}
return ""
}
func readConfFromFile() (*controllerConfig, error) {
buf, err := os.ReadFile(BootstrapConfigFile)
if err != nil {
log.Errorf("read file error, %v", err)
return nil, err
}
c := &controllerConfig{}
err = yaml.Unmarshal(buf, c)
if err != nil {
log.Errorf("unmarshal config error, %v", err)
return nil, err
}
return c, nil
}