-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathoptions.go
More file actions
155 lines (135 loc) · 5.49 KB
/
options.go
File metadata and controls
155 lines (135 loc) · 5.49 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* 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
* limitations under the License.
*/
// Package options xxx
package options
import (
"errors"
"io/ioutil"
glog "github.com/Tencent/bk-bcs/bcs-common/common/blog"
"github.com/Tencent/bk-bcs/bcs-common/common/conf"
jsoniter "github.com/json-iterator/go"
)
// DefaultConfig default config
type DefaultConfig struct {
Environment string `json:"environment"`
// ClusterID is only used when CluterIDSource was set to "config"
ClusterID string `json:"clusterID"`
HostIP string `json:"hostIP"`
}
// validate validates DefaultConfig and set proper default values
func (c *DefaultConfig) validate() error { // nolint
if c.ClusterID == "" {
return errors.New("must set ClusterID when ClusterIDSource was set to 'config'")
}
return nil
}
// TLS tls config
type TLS struct {
CAFile string `json:"ca-file"`
CertFile string `json:"cert-file"`
KeyFile string `json:"key-file"`
Password string `json:"password"`
}
// BCSConfig configuration for bcs service discovery
type BCSConfig struct {
// bcs zookeeper host list, split by comma
ZkHosts string `json:"zk"`
TLS TLS `json:"tls"`
// NetServiceZKHosts is zookeepers hosts for netservice discovery, split by comma
NetServiceZKHosts string `json:"netservice-zookeepers"`
// CustomStorageEndpoints, split by comma
CustomStorageEndpoints string `json:"custom-storage-endpoints"`
// CustomNetServiceEndpoints is custom target netservice endpoints, split by comma
CustomNetServiceEndpoints string `json:"custom-netservice-endpoints"`
// whether the k8s cluster and bcs-k8s-watch is in external network
IsExternal bool `json:"is-external"`
// authorization token
CustomStorageEndpointToken string `json:"custom-storage-endpoints-token"`
// WriterQueueLen show writer module chan queue length for data distribute, default 10240
WriterQueueLen int64 `json:"writerQueueLen"`
// PodQueueNum run many queue to distribute Pod event in due to increase storage qps
PodQueueNum int `json:"podQueueNum"`
}
// K8sConfig for installation out of cluster
type K8sConfig struct {
Kubeconfig string `json:"kubeconfig"`
Master string `json:"master"`
TLS TLS `json:"tls"`
}
// WatchResource 指定监听的资源
type WatchResource struct {
// 监听指定的namespace,暂时支持一个
Namespace string `json:"namespace"`
DisableCRD bool `json:"disable_crd"`
DisableNetservice bool `json:"disable_netservice"`
LabelSelectors map[string]string `json:"label_selectors"` // map[resourceType]LabelSelector
}
// WatchConfig k8s-watch config
type WatchConfig struct {
Default DefaultConfig `json:"default"`
BCS BCSConfig `json:"bcs"`
K8s K8sConfig `json:"k8s"`
FilterConfigPath string `json:"filterConfigPath"`
WatchResource WatchResource `json:"watch_resource"`
conf.FileConfig
conf.ProcessConfig
conf.LogConfig
conf.ServiceConfig
conf.MetricConfig
conf.ServerOnlyCertConfig
DebugMode bool `json:"debug_mode"`
}
// NewWatchOptions init watch config
func NewWatchOptions() *WatchConfig {
return &WatchConfig{}
}
// IsWatchManagedFields watch fields
var IsWatchManagedFields bool
// FilterConfig the file config
type FilterConfig struct {
APIResourceSpecification []APIResourceFilter `json:"apiResourceSpecification"`
APIResourceException []APIResourceFilter `json:"apiResourceException"`
K8sGroupVersionWhiteList []string `json:"k8sResourceWhiteList"`
CrdGroupVersionWhiteList []string `json:"crdResourceWhiteList"`
CrdVersionSupport string `json:"crdVersionSupport"`
NamespaceFilters []string `json:"resourceNamespaceFilters"`
NameFilters []string `json:"resourceNameFilters"`
APIResourceLists []ApiResourceList `json:"apiResourceLists"`
IsWatchManagedFields bool `json:"isFilterManagedFields"`
DataMaskConfigList []MaskerConfig `json:"resourceMaskers"`
}
// APIResourceFilter api resource exception
type APIResourceFilter struct {
GroupVersion string `json:"groupVersion"`
ResourceKinds []string `json:"resourceKinds"`
}
// ParseFilter parse filter config from file
func (wc *WatchConfig) ParseFilter() *FilterConfig {
filter := &FilterConfig{}
bytes, err := ioutil.ReadFile(wc.FilterConfigPath)
if err != nil {
glog.Warnf("open filter config file (%s) failed: %s, will not use resource filter", wc.FilterConfigPath, err.Error())
return nil
}
if err := jsoniter.Unmarshal(bytes, filter); err != nil {
glog.Warnf("unmarshal config file (%s) failed: %s, will not use resource filter", wc.FilterConfigPath, err.Error())
return nil
}
IsWatchManagedFields = filter.IsWatchManagedFields
return filter
}
// MaskerConfig config for data mask
type MaskerConfig struct {
Kind string `json:"kind"`
Namespace string `json:"namespace"`
Path []string `json:"path"`
}