add more option comments
This commit is contained in:
@@ -20,7 +20,34 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// install api for config
|
||||
// Package config saves configuration for running KubeSphere components
|
||||
//
|
||||
// Config can be configured from command line flags and configuration file.
|
||||
// Command line flags hold higher priority than configuration file. But if
|
||||
// component Endpoint/Host/APIServer was left empty, all of that component
|
||||
// command line flags will be ignored, use configuration file instead.
|
||||
// For example, we have configuration file
|
||||
//
|
||||
// mysql:
|
||||
// host: mysql.kubesphere-system.svc
|
||||
// username: root
|
||||
// password: password
|
||||
//
|
||||
// At the same time, have command line flags like following:
|
||||
//
|
||||
// --mysql-host mysql.openpitrix-system.svc --mysql-username king --mysql-password 1234
|
||||
//
|
||||
// We will use `king:1234@mysql.openpitrix-system.svc` from command line flags rather
|
||||
// than `root:password@mysql.kubesphere-system.svc` from configuration file,
|
||||
// cause command line has higher priority. But if command line flags like following:
|
||||
//
|
||||
// --mysql-username root --mysql-password password
|
||||
//
|
||||
// we will `root:password@mysql.kubesphere-system.svc` as input, case
|
||||
// mysql-host is missing in command line flags, all other mysql command line flags
|
||||
// will be ignored.
|
||||
|
||||
// InstallAPI installs api for config
|
||||
func InstallAPI(c *restful.Container) {
|
||||
ws := runtime.NewWebService(schema.GroupVersion{
|
||||
Group: "",
|
||||
@@ -39,7 +66,7 @@ func InstallAPI(c *restful.Container) {
|
||||
c.Add(ws)
|
||||
}
|
||||
|
||||
// load configuration after setup
|
||||
// Load loads configuration after setup
|
||||
func Load() error {
|
||||
sharedConfig = newConfig()
|
||||
|
||||
@@ -69,7 +96,10 @@ func Load() error {
|
||||
}
|
||||
|
||||
const (
|
||||
// DefaultConfigurationName is the default name of configuration
|
||||
DefaultConfigurationName = "kubesphere"
|
||||
|
||||
// DefaultConfigurationPath the default location of the configuration file
|
||||
DefaultConfigurationPath = "/etc/kubesphere"
|
||||
)
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package devops
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/pflag"
|
||||
"kubesphere.io/kubesphere/pkg/utils/reflectutils"
|
||||
)
|
||||
|
||||
type DevopsOptions struct {
|
||||
@@ -22,29 +23,14 @@ func NewDevopsOptions() *DevopsOptions {
|
||||
}
|
||||
}
|
||||
|
||||
// ApplyTo apply configuration to another options
|
||||
func (s *DevopsOptions) ApplyTo(options *DevopsOptions) {
|
||||
if options == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if s.Host != "" {
|
||||
options.Host = s.Host
|
||||
}
|
||||
|
||||
if s.Username != "" {
|
||||
options.Username = s.Username
|
||||
}
|
||||
|
||||
if s.Password != "" {
|
||||
options.Password = s.Password
|
||||
}
|
||||
|
||||
if s.MaxConnections > 0 {
|
||||
options.MaxConnections = s.MaxConnections
|
||||
if s.Host != "" && options != nil {
|
||||
reflectutils.Override(options, s)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Validate check if there is misconfiguration in options
|
||||
func (s *DevopsOptions) Validate() []error {
|
||||
errors := []error{}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ type KubernetesClient struct {
|
||||
config *rest.Config
|
||||
}
|
||||
|
||||
// NewKubernetesClient
|
||||
// NewKubernetesClientOrDie creates KubernetesClient and panic if there is an error
|
||||
func NewKubernetesClientOrDie(options *KubernetesOptions) *KubernetesClient {
|
||||
config, err := clientcmd.BuildConfigFromFlags("", options.KubeConfig)
|
||||
if err != nil {
|
||||
@@ -47,6 +47,7 @@ func NewKubernetesClientOrDie(options *KubernetesOptions) *KubernetesClient {
|
||||
return k
|
||||
}
|
||||
|
||||
// NewKubernetesClient creates a KubernetesClient
|
||||
func NewKubernetesClient(options *KubernetesOptions) (*KubernetesClient, error) {
|
||||
config, err := clientcmd.BuildConfigFromFlags("", options.KubeConfig)
|
||||
if err != nil {
|
||||
|
||||
@@ -31,12 +31,14 @@ func (l *LdapOptions) Validate() []error {
|
||||
}
|
||||
|
||||
func (l *LdapOptions) ApplyTo(options *LdapOptions) {
|
||||
reflectutils.Override(options, l)
|
||||
if l.Host != "" {
|
||||
reflectutils.Override(options, l)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *LdapOptions) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&l.Host, "ldap-host", l.Host, ""+
|
||||
"Ldap service host, if left blank, all of the following options will "+
|
||||
"Ldap service host, if left blank, all of the following ldap options will "+
|
||||
"be ignored and ldap will be disabled.")
|
||||
|
||||
fs.StringVar(&l.ManagerDN, "ldap-manager-dn", l.ManagerDN, ""+
|
||||
|
||||
@@ -17,7 +17,14 @@ type MySQLOptions struct {
|
||||
|
||||
// NewMySQLOptions create a `zero` value instance
|
||||
func NewMySQLOptions() *MySQLOptions {
|
||||
return &MySQLOptions{}
|
||||
return &MySQLOptions{
|
||||
Host: "",
|
||||
Username: "",
|
||||
Password: "",
|
||||
MaxIdleConnections: 100,
|
||||
MaxOpenConnections: 100,
|
||||
MaxConnectionLifeTime: time.Duration(10) * time.Second,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MySQLOptions) Validate() []error {
|
||||
@@ -33,11 +40,20 @@ func (m *MySQLOptions) ApplyTo(options *MySQLOptions) {
|
||||
func (m *MySQLOptions) AddFlags(fs *pflag.FlagSet) {
|
||||
|
||||
fs.StringVar(&m.Host, "mysql-host", m.Host, ""+
|
||||
"MySQL service host address. If left blank, following options will be ignored.")
|
||||
"MySQL service host address. If left blank, the following related mysql options will be ignored.")
|
||||
|
||||
fs.StringVar(&m.Username, "mysql-username", m.Username, ""+
|
||||
"Username for access to mysql service.")
|
||||
|
||||
fs.StringVar(&m.Password, "mysql-password", m.Password, ""+
|
||||
"Password for access to mysql, should be used pair with password.")
|
||||
|
||||
fs.IntVar(&m.MaxIdleConnections, "mysql-max-idle-connections", m.MaxOpenConnections, ""+
|
||||
"Maximum idle connections allowed to connect to mysql.")
|
||||
|
||||
fs.IntVar(&m.MaxOpenConnections, "mysql-max-open-connections", m.MaxOpenConnections, ""+
|
||||
"Maximum open connections allowed to connect to mysql.")
|
||||
|
||||
fs.DurationVar(&m.MaxConnectionLifeTime, "mysql-max-connection-life-time", m.MaxConnectionLifeTime, ""+
|
||||
"Maximum connection life time allowed to connecto to mysql.")
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ func NewOpenPitrixOptions() *OpenPitrixOptions {
|
||||
}
|
||||
|
||||
func (s *OpenPitrixOptions) ApplyTo(options *OpenPitrixOptions) {
|
||||
reflectutils.Override(options, s)
|
||||
if s.APIServer != "" {
|
||||
reflectutils.Override(options, s)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *OpenPitrixOptions) Validate() []error {
|
||||
|
||||
@@ -2,7 +2,6 @@ package prometheus
|
||||
|
||||
import (
|
||||
"github.com/spf13/pflag"
|
||||
"kubesphere.io/kubesphere/pkg/utils/reflectutils"
|
||||
)
|
||||
|
||||
type PrometheusOptions struct {
|
||||
@@ -24,7 +23,13 @@ func (s *PrometheusOptions) Validate() []error {
|
||||
}
|
||||
|
||||
func (s *PrometheusOptions) ApplyTo(options *PrometheusOptions) {
|
||||
reflectutils.Override(options, s)
|
||||
if s.Endpoint != "" {
|
||||
options.Endpoint = s.Endpoint
|
||||
}
|
||||
|
||||
if s.SecondaryEndpoint != "" {
|
||||
options.SecondaryEndpoint = s.SecondaryEndpoint
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PrometheusOptions) AddFlags(fs *pflag.FlagSet) {
|
||||
|
||||
@@ -25,6 +25,7 @@ func NewRedisOptions() *RedisOptions {
|
||||
}
|
||||
}
|
||||
|
||||
// Validate check options
|
||||
func (r *RedisOptions) Validate() []error {
|
||||
errors := make([]error, 0)
|
||||
|
||||
@@ -34,13 +35,22 @@ func (r *RedisOptions) Validate() []error {
|
||||
}
|
||||
}
|
||||
|
||||
if r.DB < 0 {
|
||||
errors = append(errors, fmt.Errorf("--redis-db is less than 0"))
|
||||
}
|
||||
|
||||
return errors
|
||||
}
|
||||
|
||||
// ApplyTo apply to another options if it's a enabled option(non empty host)
|
||||
func (r *RedisOptions) ApplyTo(options *RedisOptions) {
|
||||
reflectutils.Override(options, r)
|
||||
if r.Host != "" {
|
||||
reflectutils.Override(options, r)
|
||||
}
|
||||
}
|
||||
|
||||
// AddFlags add option flags to command line flags,
|
||||
// if redis-host left empty, the following options will be ignored.
|
||||
func (r *RedisOptions) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&r.Host, "redis-host", r.Host, ""+
|
||||
"Redis service host address. If left blank, means redis is unnecessary, "+
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"kubesphere.io/kubesphere/pkg/utils/reflectutils"
|
||||
)
|
||||
|
||||
// S3Options contains configuration to access a s3 service
|
||||
type S3Options struct {
|
||||
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
|
||||
Region string `json:"region,omitempty" yaml:"region,omitempty"`
|
||||
@@ -16,6 +17,7 @@ type S3Options struct {
|
||||
Bucket string `json:"bucket,omitempty" yaml:"bucket,omitempty"`
|
||||
}
|
||||
|
||||
// NewS3Options creates a default disabled S3Options(empty endpoint)
|
||||
func NewS3Options() *S3Options {
|
||||
return &S3Options{
|
||||
Endpoint: "",
|
||||
@@ -29,33 +31,39 @@ func NewS3Options() *S3Options {
|
||||
}
|
||||
}
|
||||
|
||||
// Validate check options values
|
||||
func (s *S3Options) Validate() []error {
|
||||
errors := []error{}
|
||||
|
||||
return errors
|
||||
}
|
||||
|
||||
// ApplyTo overrides options if it's valid, which endpoint is not empty
|
||||
func (s *S3Options) ApplyTo(options *S3Options) {
|
||||
reflectutils.Override(options, s)
|
||||
if s.Endpoint != "" {
|
||||
reflectutils.Override(options, s)
|
||||
}
|
||||
}
|
||||
|
||||
// AddFlags add options flags to command line flags,
|
||||
// if s3-endpoint if left empty, following options will be ignored
|
||||
func (s *S3Options) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&s.Endpoint, "s3-endpoint", s.Endpoint, ""+
|
||||
"Endpoint to access to s3 object storage service, if left blank, the following options "+
|
||||
"will be ignored.")
|
||||
|
||||
fs.StringVar(&s.Region, "s3-region", "us-east-1", ""+
|
||||
fs.StringVar(&s.Region, "s3-region", s.Region, ""+
|
||||
"Region of s3 that will access to, like us-east-1.")
|
||||
|
||||
fs.StringVar(&s.AccessKeyID, "s3-access-key-id", "AKIAIOSFODNN7EXAMPLE", "access key of s2i s3")
|
||||
fs.StringVar(&s.AccessKeyID, "s3-access-key-id", s.AccessKeyID, "access key of s2i s3")
|
||||
|
||||
fs.StringVar(&s.SecretAccessKey, "s3-secret-access-key", "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", "secret access key of s2i s3")
|
||||
fs.StringVar(&s.SecretAccessKey, "s3-secret-access-key", s.SecretAccessKey, "secret access key of s2i s3")
|
||||
|
||||
fs.StringVar(&s.SessionToken, "s3-session-token", s.SessionToken, "session token of s2i s3")
|
||||
|
||||
fs.StringVar(&s.Bucket, "s3-bucket", "s2i-binaries", "bucket name of s2i s3")
|
||||
fs.StringVar(&s.Bucket, "s3-bucket", s.Bucket, "bucket name of s2i s3")
|
||||
|
||||
fs.BoolVar(&s.DisableSSL, "s3-disable-SSL", true, "disable ssl")
|
||||
fs.BoolVar(&s.DisableSSL, "s3-disable-SSL", s.DisableSSL, "disable ssl")
|
||||
|
||||
fs.BoolVar(&s.ForcePathStyle, "s3-force-path-style", true, "force path style")
|
||||
fs.BoolVar(&s.ForcePathStyle, "s3-force-path-style", s.ForcePathStyle, "force path style")
|
||||
}
|
||||
|
||||
@@ -33,16 +33,13 @@ func (s *SonarQubeOptions) ApplyTo(options *SonarQubeOptions) {
|
||||
|
||||
if s.Host != "" {
|
||||
options.Host = s.Host
|
||||
}
|
||||
|
||||
if s.Token != "" {
|
||||
options.Token = s.Token
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SonarQubeOptions) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&s.Host, "sonarqube-host", s.Host, ""+
|
||||
"Sonarqube service address if enabled.")
|
||||
"Sonarqube service address, if left empty, following sonarqube options will be ignored.")
|
||||
|
||||
fs.StringVar(&s.Token, "sonarqube-token", s.Token, ""+
|
||||
"Sonarqube service access token.")
|
||||
|
||||
Reference in New Issue
Block a user