Skip to content

Commit

Permalink
Merge pull request #6 from askuy/feature/emptyk8s
Browse files Browse the repository at this point in the history
增加k8s enable开关,默认enable开启
  • Loading branch information
askuy authored Jun 28, 2024
2 parents c2f3c3c + 8cad856 commit a148488
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
10 changes: 10 additions & 0 deletions component.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ type KubernetesEvent struct {

// New ...
func newComponent(name string, config *Config, logger *elog.Component) *Component {
// 如果没有开启,那么返回一个nil的k8s client,这个时候,认为业务方不会使用这个组件。
// 这个目的是为了docker-compose这类业务,虽然使用了同样代码,enable=false,让业务不panic
if !config.Enable {
return &Component{
name: name,
config: config,
logger: logger,
Clientset: nil,
}
}
client, err := kubernetes.NewForConfig(config.toRestConfig())
if err != nil {
logger.Panic("new component err", elog.FieldErr(err))
Expand Down
5 changes: 3 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
type Config struct {
// Addr k8s API Server 地址
Addr string
// Debug 是否开启debug模式
Debug bool
// 是否开启,默认开启
Enable bool
// Token k8s API Server 请求token
Token string
// Token k8s API Server 请求token file
Expand All @@ -33,6 +33,7 @@ type Config struct {
func DefaultConfig() *Config {
return &Config{
Addr: inClusterAddr(),
Enable: true,
Token: inClusterToken(),
Namespaces: []string{inClusterNamespace()},
TLSClientConfigInsecure: true,
Expand Down
1 change: 0 additions & 1 deletion container.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func Load(key string) *Container {
c.logger.Panic("parse config error", elog.FieldErr(err), elog.FieldKey(key))
return c
}
c.logger.Debug("config info", elog.String("name", c.name), elog.Any("config", c.config))
c.logger = c.logger.With(elog.FieldComponentName(key))
c.name = key
return c
Expand Down
6 changes: 0 additions & 6 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ func WithAddr(addr string) Option {
}
}

func WithDebug(debug bool) Option {
return func(c *Container) {
c.config.Debug = debug
}
}

func WithToken(token string) Option {
return func(c *Container) {
c.config.Token = token
Expand Down

0 comments on commit a148488

Please sign in to comment.