1 // Copyright 2020 Chaos Mesh Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package config 15 16 import ( 17 "time" 18 19 "github.com/kelseyhightower/envconfig" 20 21 "github.com/chaos-mesh/chaos-mesh/pkg/webhook/config/watcher" 22 ) 23 24 // TLSConfig defines the configuration for chaos-daemon tls client 25 type TLSConfig struct { 26 // ChaosDaemonClientCert is the path of chaos daemon certificate 27 ChaosDaemonClientCert string `envconfig:"CHAOS_DAEMON_CLIENT_CERT" default:""` 28 // ChaosDaemonClientKey is the path of chaos daemon certificate key 29 ChaosDaemonClientKey string `envconfig:"CHAOS_DAEMON_CLIENT_KEY" default:""` 30 // ChaosMeshCACert is the path of chaos mesh ca cert 31 ChaosMeshCACert string `envconfig:"CHAOS_MESH_CA_CERT" default:""` 32 } 33 34 // ChaosControllerConfig defines the configuration for Chaos Controller 35 type ChaosControllerConfig struct { 36 // ChaosDaemonPort is the port which grpc server listens on 37 ChaosDaemonPort int `envconfig:"CHAOS_DAEMON_SERVICE_PORT" default:"31767"` 38 39 TLSConfig 40 41 // The QPS config for kubernetes client 42 QPS float32 `envconfig:"QPS" default:"30"` 43 // The Burst config for kubernetes client 44 Burst int `envconfig:"BURST" default:"50"` 45 46 // BPFKIPort is the port which BFFKI grpc server listens on 47 BPFKIPort int `envconfig:"BPFKI_PORT" default:"50051"` 48 // MetricsAddr is the address the metric endpoint binds to 49 MetricsAddr string `envconfig:"METRICS_ADDR" default:":10080"` 50 // PprofAddr is the address the pprof endpoint binds to. 51 PprofAddr string `envconfig:"PPROF_ADDR" default:"0"` 52 // EnableLeaderElection enables leader election for controller manager 53 // Enabling this will ensure there is only one active controller manager 54 EnableLeaderElection bool `envconfig:"ENABLE_LEADER_ELECTION" default:"false"` 55 // EnableFilterNamespace will filter namespace with annotation. Only the pods/containers in namespace 56 // annotated with `chaos-mesh.org/inject=enabled` will be injected 57 EnableFilterNamespace bool `envconfig:"ENABLE_FILTER_NAMESPACE" default:"false"` 58 // CertsDir is the directory for storing certs key file and cert file 59 CertsDir string `envconfig:"CERTS_DIR" default:"/etc/webhook/certs"` 60 // RPCTimeout is timeout of RPC between controllers and chaos-operator 61 RPCTimeout time.Duration `envconfig:"RPC_TIMEOUT" default:"1m"` 62 WatcherConfig *watcher.Config 63 // ClusterScoped means control Chaos Object in cluster level(all namespace), 64 ClusterScoped bool `envconfig:"CLUSTER_SCOPED" default:"true"` 65 // TargetNamespace is the target namespace to injecting chaos. 66 // It only works with ClusterScoped is false; 67 TargetNamespace string `envconfig:"TARGET_NAMESPACE" default:""` 68 69 // DNSServiceName is the name of DNS service, which is used for DNS chaos 70 DNSServiceName string `envconfig:"CHAOS_DNS_SERVICE_NAME" default:""` 71 DNSServicePort int `envconfig:"CHAOS_DNS_SERVICE_PORT" default:""` 72 73 // SecurityMode is used for enable authority validation in admission webhook 74 SecurityMode bool `envconfig:"SECURITY_MODE" default:"true" json:"security_mode"` 75 76 // Namespace is the namespace which the controller manager run in 77 Namespace string `envconfig:"NAMESPACE" default:""` 78 79 // AllowHostNetworkTesting removes the restriction on chaos testing pods with `hostNetwork` set to true 80 AllowHostNetworkTesting bool `envconfig:"ALLOW_HOST_NETWORK_TESTING" default:"false"` 81 82 // PodFailurePauseImage is used to set a custom image for pod failure 83 PodFailurePauseImage string `envconfig:"POD_FAILURE_PAUSE_IMAGE" default:"gcr.io/google-containers/pause:latest"` 84 } 85 86 // EnvironChaosController returns the settings from the environment. 87 func EnvironChaosController() (ChaosControllerConfig, error) { 88 cfg := ChaosControllerConfig{} 89 err := envconfig.Process("", &cfg) 90 return cfg, err 91 } 92