devlopment branch (#1736)

This commit is contained in:
zryfish
2020-01-02 20:52:00 +08:00
committed by GitHub
parent ff0ffe8650
commit eceadec69c
440 changed files with 61524 additions and 3699 deletions

View File

@@ -1,16 +1,16 @@
package alerting
type AlertingOptions struct {
type Options struct {
Endpoint string `json:"endpoint" yaml:"endpoint"`
}
func NewAlertingOptions() *AlertingOptions {
return &AlertingOptions{
func NewAlertingOptions() *Options {
return &Options{
Endpoint: "",
}
}
func (s *AlertingOptions) ApplyTo(options *AlertingOptions) {
func (s *Options) ApplyTo(options *Options) {
if options == nil {
options = s
return

60
pkg/simple/client/cache/cache.go vendored Normal file
View File

@@ -0,0 +1,60 @@
package cache
import "time"
type Interface interface {
// Keys retrieves all keys match the given pattern
Keys(pattern string) ([]string, error)
// Get retrieves the value of the given key, return error if key doesn't exist
Get(key string) (string, error)
// Set sets the value and living duration of the given key, zero duration means never expire
Set(key string, value string, duration time.Duration) error
// Del deletes the given key, no error returned if the key doesn't exists
Del(key string) error
// Exists checks the existence of a give key
Exists(key string) (bool, error)
// Expires updates object's expiration time, return err if key doesn't exist
Expire(key string, duration time.Duration) error
}
type simpleObject struct {
value string
expire time.Time
}
type SimpleCache struct {
store map[string]simpleObject
}
func NewSimpleCache() Interface {
return &SimpleCache{store: make(map[string]simpleObject)}
}
func (s *SimpleCache) Keys(pattern string) ([]string, error) {
panic("implement me")
}
func (s *SimpleCache) Set(key string, value string, duration time.Duration) error {
panic("implement me")
}
func (s *SimpleCache) Del(key string) error {
panic("implement me")
}
func (s *SimpleCache) Get(key string) (string, error) {
return "", nil
}
func (s *SimpleCache) Exists(key string) (bool, error) {
panic("implement me")
}
func (s *SimpleCache) Expire(key string, duration time.Duration) error {
panic("implement me")
}

View File

@@ -1,4 +1,4 @@
package redis
package cache
import (
"github.com/go-redis/redis"
@@ -6,20 +6,20 @@ import (
"kubesphere.io/kubesphere/pkg/utils/reflectutils"
)
type RedisOptions struct {
type Options struct {
RedisURL string
}
// NewRedisOptions returns options points to nowhere,
// because redis is not required for some components
func NewRedisOptions() *RedisOptions {
return &RedisOptions{
func NewRedisOptions() *Options {
return &Options{
RedisURL: "",
}
}
// Validate check options
func (r *RedisOptions) Validate() []error {
func (r *Options) Validate() []error {
errors := make([]error, 0)
_, err := redis.ParseURL(r.RedisURL)
@@ -32,7 +32,7 @@ func (r *RedisOptions) Validate() []error {
}
// ApplyTo apply to another options if it's a enabled option(non empty host)
func (r *RedisOptions) ApplyTo(options *RedisOptions) {
func (r *Options) ApplyTo(options *Options) {
if r.RedisURL != "" {
reflectutils.Override(options, r)
}
@@ -40,7 +40,7 @@ func (r *RedisOptions) ApplyTo(options *RedisOptions) {
// 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.RedisURL, "redis-url", "", "Redis connection URL. If left blank, means redis is unnecessary, "+
func (r *Options) AddFlags(fs *pflag.FlagSet, s *Options) {
fs.StringVar(&r.RedisURL, "redis-url", s.RedisURL, "Redis connection URL. If left blank, means redis is unnecessary, "+
"redis will be disabled. e.g. redis://:password@host:port/db")
}

View File

@@ -15,28 +15,20 @@
limitations under the License.
*/
package redis
package cache
import (
"github.com/go-redis/redis"
"k8s.io/klog"
"time"
)
type RedisClient struct {
type Client struct {
client *redis.Client
}
func NewRedisClientOrDie(options *RedisOptions, stopCh <-chan struct{}) *RedisClient {
client, err := NewRedisClient(options, stopCh)
if err != nil {
panic(err)
}
return client
}
func NewRedisClient(option *RedisOptions, stopCh <-chan struct{}) (*RedisClient, error) {
var r RedisClient
func NewRedisClient(option *Options, stopCh <-chan struct{}) (Interface, error) {
var r Client
options, err := redis.ParseURL(option.RedisURL)
@@ -45,6 +37,10 @@ func NewRedisClient(option *RedisOptions, stopCh <-chan struct{}) (*RedisClient,
return nil, err
}
if stopCh == nil {
klog.Warningf("no stop signal passed, may cause redis connections leaked")
}
r.client = redis.NewClient(options)
if err := r.client.Ping().Err(); err != nil {
@@ -53,6 +49,7 @@ func NewRedisClient(option *RedisOptions, stopCh <-chan struct{}) (*RedisClient,
return nil, err
}
// close redis in case of connection leak
if stopCh != nil {
go func() {
<-stopCh
@@ -65,6 +62,26 @@ func NewRedisClient(option *RedisOptions, stopCh <-chan struct{}) (*RedisClient,
return &r, nil
}
func (r *RedisClient) Redis() *redis.Client {
return r.client
func (r *Client) Get(key string) (string, error) {
return "", nil
}
func (r *Client) Keys(pattern string) ([]string, error) {
panic("implement me")
}
func (r *Client) Set(key string, value string, duration time.Duration) error {
panic("implement me")
}
func (r *Client) Del(key string) error {
panic("implement me")
}
func (r *Client) Exists(key string) (bool, error) {
panic("implement me")
}
func (r *Client) Expire(key string, duration time.Duration) error {
panic("implement me")
}

View File

@@ -0,0 +1,5 @@
package db
//
type Interface interface {
}

View File

@@ -21,15 +21,15 @@ import (
)
const (
JenkinsAllUserRoleName = "kubesphere-user"
jenkinsAllUserRoleName = "kubesphere-user"
)
type DevopsClient struct {
type Client struct {
jenkinsClient *gojenkins.Jenkins
}
func NewDevopsClient(options *DevopsOptions) (*DevopsClient, error) {
var d DevopsClient
func NewDevopsClient(options *Options) (*Client, error) {
var d Client
jenkins := gojenkins.CreateJenkins(nil, options.Host, options.MaxConnections, options.Username, options.Password)
jenkins, err := jenkins.Init()
@@ -49,34 +49,13 @@ func NewDevopsClient(options *DevopsOptions) (*DevopsClient, error) {
return &d, nil
}
func NewDevopsClientOrDie(options *DevopsOptions) *DevopsClient {
jenkins := gojenkins.CreateJenkins(nil, options.Host, options.MaxConnections, options.Username, options.Password)
jenkins, err := jenkins.Init()
if err != nil {
klog.Errorf("failed to connecto to jenkins role, %+v", err)
panic(err)
}
d := &DevopsClient{
jenkinsClient: jenkins,
}
err = d.initializeJenkins()
if err != nil {
klog.Error(err)
panic(err)
}
return d
}
func (c *DevopsClient) Jenkins() *gojenkins.Jenkins {
func (c *Client) Jenkins() *gojenkins.Jenkins {
return c.jenkinsClient
}
var mutex = sync.Mutex{}
func (c *DevopsClient) initializeJenkins() error {
func (c *Client) initializeJenkins() error {
mutex.Lock()
defer mutex.Unlock()
@@ -84,7 +63,7 @@ func (c *DevopsClient) initializeJenkins() error {
return fmt.Errorf("jenkins intialization failed")
}
globalRole, err := c.jenkinsClient.GetGlobalRole(JenkinsAllUserRoleName)
globalRole, err := c.jenkinsClient.GetGlobalRole(jenkinsAllUserRoleName)
if err != nil {
klog.Error(err)
return err
@@ -92,14 +71,14 @@ func (c *DevopsClient) initializeJenkins() error {
// Jenkins uninitialized, create global role
if globalRole == nil {
_, err := c.jenkinsClient.AddGlobalRole(JenkinsAllUserRoleName, gojenkins.GlobalPermissionIds{GlobalRead: true}, true)
_, err := c.jenkinsClient.AddGlobalRole(jenkinsAllUserRoleName, gojenkins.GlobalPermissionIds{GlobalRead: true}, true)
if err != nil {
klog.Error(err)
return err
}
}
_, err = c.jenkinsClient.AddProjectRole(JenkinsAllUserRoleName, "\\n\\s*\\r", gojenkins.ProjectPermissionIds{SCMTag: true}, true)
_, err = c.jenkinsClient.AddProjectRole(jenkinsAllUserRoleName, "\\n\\s*\\r", gojenkins.ProjectPermissionIds{SCMTag: true}, true)
if err != nil {
klog.Error(err)
return err

View File

@@ -0,0 +1,18 @@
package devops
type Job struct {
}
type Interface interface {
GetJob(projectId, pipelineName string) (*Job, error)
DeleteJob(projectId, pipelineId string) (bool, error)
CreateJobInFolder()
GetGlobalRole(roleName string)
AddGlobalRole(roleName string, permission string)
GetProjectRole(roleName string)
}

View File

@@ -6,7 +6,7 @@ import (
"kubesphere.io/kubesphere/pkg/utils/reflectutils"
)
type DevopsOptions struct {
type Options struct {
Host string `json:",omitempty" yaml:"host" description:"Jenkins service host address"`
Username string `json:",omitempty" yaml:"username" description:"Jenkins admin username"`
Password string `json:",omitempty" yaml:"password" description:"Jenkins admin password"`
@@ -14,8 +14,8 @@ type DevopsOptions struct {
}
// NewDevopsOptions returns a `zero` instance
func NewDevopsOptions() *DevopsOptions {
return &DevopsOptions{
func NewDevopsOptions() *Options {
return &Options{
Host: "",
Username: "",
Password: "",
@@ -24,15 +24,15 @@ func NewDevopsOptions() *DevopsOptions {
}
// ApplyTo apply configuration to another options
func (s *DevopsOptions) ApplyTo(options *DevopsOptions) {
func (s *Options) ApplyTo(options *Options) {
if s.Host != "" {
reflectutils.Override(options, s)
}
}
// Validate check if there is misconfiguration in options
func (s *DevopsOptions) Validate() []error {
errors := []error{}
func (s *Options) Validate() []error {
var errors []error
// devops is not needed, ignore rest options
if s.Host == "" {
@@ -50,18 +50,18 @@ func (s *DevopsOptions) Validate() []error {
return errors
}
func (s *DevopsOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&s.Host, "jenkins-host", s.Host, ""+
func (s *Options) AddFlags(fs *pflag.FlagSet, c *Options) {
fs.StringVar(&s.Host, "jenkins-host", c.Host, ""+
"Jenkins service host address. If left blank, means Jenkins "+
"is unnecessary.")
fs.StringVar(&s.Username, "jenkins-username", s.Username, ""+
fs.StringVar(&s.Username, "jenkins-username", c.Username, ""+
"Username for access to Jenkins service. Leave it blank if there isn't any.")
fs.StringVar(&s.Password, "jenkins-password", s.Password, ""+
fs.StringVar(&s.Password, "jenkins-password", c.Password, ""+
"Password for access to Jenkins service, used pair with username.")
fs.IntVar(&s.MaxConnections, "jenkins-max-connections", s.MaxConnections, ""+
fs.IntVar(&s.MaxConnections, "jenkins-max-connections", c.MaxConnections, ""+
"Maximum allowed connections to Jenkins. ")
}

View File

@@ -59,7 +59,7 @@ type ElasticSearchClient struct {
client Client
}
func NewLoggingClient(options *ElasticSearchOptions) (*ElasticSearchClient, error) {
func NewLoggingClient(options *Options) (*ElasticSearchClient, error) {
var version, index string
esClient := &ElasticSearchClient{}

View File

@@ -5,42 +5,42 @@ import (
"kubesphere.io/kubesphere/pkg/utils/reflectutils"
)
type ElasticSearchOptions struct {
type Options struct {
Host string `json:"host" yaml:"host"`
IndexPrefix string `json:"indexPrefix,omitempty" yaml:"indexPrefix"`
Version string `json:"version" yaml:"version"`
}
func NewElasticSearchOptions() *ElasticSearchOptions {
return &ElasticSearchOptions{
func NewElasticSearchOptions() *Options {
return &Options{
Host: "",
IndexPrefix: "fluentbit",
Version: "",
}
}
func (s *ElasticSearchOptions) ApplyTo(options *ElasticSearchOptions) {
func (s *Options) ApplyTo(options *Options) {
if s.Host != "" {
reflectutils.Override(options, s)
}
}
func (s *ElasticSearchOptions) Validate() []error {
func (s *Options) Validate() []error {
errs := []error{}
return errs
}
func (s *ElasticSearchOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&s.Host, "elasticsearch-host", s.Host, ""+
func (s *Options) AddFlags(fs *pflag.FlagSet, c *Options) {
fs.StringVar(&s.Host, "elasticsearch-host", c.Host, ""+
"ElasticSearch logging service host. KubeSphere is using elastic as log store, "+
"if this filed left blank, KubeSphere will use kubernetes builtin log API instead, and"+
" the following elastic search options will be ignored.")
fs.StringVar(&s.IndexPrefix, "index-prefix", s.IndexPrefix, ""+
fs.StringVar(&s.IndexPrefix, "index-prefix", c.IndexPrefix, ""+
"Index name prefix. KubeSphere will retrieve logs against indices matching the prefix.")
fs.StringVar(&s.Version, "elasticsearch-version", s.Version, ""+
fs.StringVar(&s.Version, "elasticsearch-version", c.Version, ""+
"ElasticSearch major version, e.g. 5/6/7, if left blank, will detect automatically."+
"Currently, minimum supported version is 5.x")
}

View File

@@ -1,8 +1,8 @@
package client
import (
"fmt"
goredis "github.com/go-redis/redis"
"errors"
"kubesphere.io/kubesphere/pkg/simple/client/cache"
"kubesphere.io/kubesphere/pkg/simple/client/devops"
esclient "kubesphere.io/kubesphere/pkg/simple/client/elasticsearch"
"kubesphere.io/kubesphere/pkg/simple/client/k8s"
@@ -11,43 +11,36 @@ import (
"kubesphere.io/kubesphere/pkg/simple/client/mysql"
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
"kubesphere.io/kubesphere/pkg/simple/client/prometheus"
"kubesphere.io/kubesphere/pkg/simple/client/redis"
"kubesphere.io/kubesphere/pkg/simple/client/s2is3"
"kubesphere.io/kubesphere/pkg/simple/client/s3"
"kubesphere.io/kubesphere/pkg/simple/client/sonarqube"
"sync"
)
type ClientSetNotEnabledError struct {
err error
}
func (e ClientSetNotEnabledError) Error() string {
return fmt.Sprintf("client set not enabled: %v", e.err)
}
var ErrClientSetNotEnabled = errors.New("client set not enabled")
type ClientSetOptions struct {
mySQLOptions *mysql.MySQLOptions
redisOptions *redis.RedisOptions
mySQLOptions *mysql.Options
redisOptions *cache.Options
kubernetesOptions *k8s.KubernetesOptions
devopsOptions *devops.DevopsOptions
sonarqubeOptions *sonarqube.SonarQubeOptions
ldapOptions *ldap.LdapOptions
s3Options *s2is3.S3Options
openPitrixOptions *openpitrix.OpenPitrixOptions
prometheusOptions *prometheus.PrometheusOptions
kubesphereOptions *kubesphere.KubeSphereOptions
elasticSearhOptions *esclient.ElasticSearchOptions
devopsOptions *devops.Options
sonarqubeOptions *sonarqube.Options
ldapOptions *ldap.Options
s3Options *s3.Options
openPitrixOptions *openpitrix.Options
prometheusOptions *prometheus.Options
kubesphereOptions *kubesphere.Options
elasticSearhOptions *esclient.Options
}
func NewClientSetOptions() *ClientSetOptions {
return &ClientSetOptions{
mySQLOptions: mysql.NewMySQLOptions(),
redisOptions: redis.NewRedisOptions(),
redisOptions: cache.NewRedisOptions(),
kubernetesOptions: k8s.NewKubernetesOptions(),
ldapOptions: ldap.NewLdapOptions(),
devopsOptions: devops.NewDevopsOptions(),
sonarqubeOptions: sonarqube.NewSonarQubeOptions(),
s3Options: s2is3.NewS3Options(),
s3Options: s3.NewS3Options(),
openPitrixOptions: openpitrix.NewOpenPitrixOptions(),
prometheusOptions: prometheus.NewPrometheusOptions(),
kubesphereOptions: kubesphere.NewKubeSphereOptions(),
@@ -55,12 +48,12 @@ func NewClientSetOptions() *ClientSetOptions {
}
}
func (c *ClientSetOptions) SetMySQLOptions(options *mysql.MySQLOptions) *ClientSetOptions {
func (c *ClientSetOptions) SetMySQLOptions(options *mysql.Options) *ClientSetOptions {
c.mySQLOptions = options
return c
}
func (c *ClientSetOptions) SetRedisOptions(options *redis.RedisOptions) *ClientSetOptions {
func (c *ClientSetOptions) SetRedisOptions(options *cache.Options) *ClientSetOptions {
c.redisOptions = options
return c
}
@@ -70,42 +63,42 @@ func (c *ClientSetOptions) SetKubernetesOptions(options *k8s.KubernetesOptions)
return c
}
func (c *ClientSetOptions) SetDevopsOptions(options *devops.DevopsOptions) *ClientSetOptions {
func (c *ClientSetOptions) SetDevopsOptions(options *devops.Options) *ClientSetOptions {
c.devopsOptions = options
return c
}
func (c *ClientSetOptions) SetLdapOptions(options *ldap.LdapOptions) *ClientSetOptions {
func (c *ClientSetOptions) SetLdapOptions(options *ldap.Options) *ClientSetOptions {
c.ldapOptions = options
return c
}
func (c *ClientSetOptions) SetS3Options(options *s2is3.S3Options) *ClientSetOptions {
func (c *ClientSetOptions) SetS3Options(options *s3.Options) *ClientSetOptions {
c.s3Options = options
return c
}
func (c *ClientSetOptions) SetOpenPitrixOptions(options *openpitrix.OpenPitrixOptions) *ClientSetOptions {
func (c *ClientSetOptions) SetOpenPitrixOptions(options *openpitrix.Options) *ClientSetOptions {
c.openPitrixOptions = options
return c
}
func (c *ClientSetOptions) SetPrometheusOptions(options *prometheus.PrometheusOptions) *ClientSetOptions {
func (c *ClientSetOptions) SetPrometheusOptions(options *prometheus.Options) *ClientSetOptions {
c.prometheusOptions = options
return c
}
func (c *ClientSetOptions) SetSonarQubeOptions(options *sonarqube.SonarQubeOptions) *ClientSetOptions {
func (c *ClientSetOptions) SetSonarQubeOptions(options *sonarqube.Options) *ClientSetOptions {
c.sonarqubeOptions = options
return c
}
func (c *ClientSetOptions) SetKubeSphereOptions(options *kubesphere.KubeSphereOptions) *ClientSetOptions {
func (c *ClientSetOptions) SetKubeSphereOptions(options *kubesphere.Options) *ClientSetOptions {
c.kubesphereOptions = options
return c
}
func (c *ClientSetOptions) SetElasticSearchOptions(options *esclient.ElasticSearchOptions) *ClientSetOptions {
func (c *ClientSetOptions) SetElasticSearchOptions(options *esclient.Options) *ClientSetOptions {
c.elasticSearhOptions = options
return c
}
@@ -117,17 +110,17 @@ type ClientSet struct {
csoptions *ClientSetOptions
stopCh <-chan struct{}
mySQLClient *mysql.MySQLClient
mySQLClient *mysql.Client
k8sClient *k8s.KubernetesClient
ldapClient *ldap.LdapClient
devopsClient *devops.DevopsClient
sonarQubeClient *sonarqube.SonarQubeClient
redisClient *redis.RedisClient
s3Client *s2is3.S3Client
prometheusClient *prometheus.PrometheusClient
openpitrixClient *openpitrix.OpenPitrixClient
kubesphereClient *kubesphere.KubeSphereClient
k8sClient k8s.Client
ldapClient *ldap.Client
devopsClient *devops.Client
sonarQubeClient *sonarqube.Client
redisClient cache.Interface
s3Client s3.Interface
prometheusClient *prometheus.Client
openpitrixClient *openpitrix.Client
kubesphereClient *kubesphere.Client
elasticSearchClient *esclient.ElasticSearchClient
}
@@ -159,7 +152,7 @@ func (cs *ClientSet) MySQL() (*mysql.Database, error) {
var err error
if cs.csoptions.mySQLOptions == nil || cs.csoptions.mySQLOptions.Host == "" {
return nil, ClientSetNotEnabledError{}
return nil, ErrClientSetNotEnabled
}
if cs.mySQLClient != nil {
@@ -178,34 +171,34 @@ func (cs *ClientSet) MySQL() (*mysql.Database, error) {
}
}
func (cs *ClientSet) Redis() (*goredis.Client, error) {
func (cs *ClientSet) Cache() (cache.Interface, error) {
var err error
if cs.csoptions.redisOptions == nil || cs.csoptions.redisOptions.RedisURL == "" {
return nil, ClientSetNotEnabledError{}
return nil, ErrClientSetNotEnabled
}
if cs.redisClient != nil {
return cs.redisClient.Redis(), nil
return cs.redisClient, nil
} else {
mutex.Lock()
defer mutex.Unlock()
if cs.redisClient == nil {
cs.redisClient, err = redis.NewRedisClient(cs.csoptions.redisOptions, cs.stopCh)
cs.redisClient, err = cache.NewRedisClient(cs.csoptions.redisOptions, cs.stopCh)
if err != nil {
return nil, err
}
}
return cs.redisClient.Redis(), nil
return cs.redisClient, nil
}
}
func (cs *ClientSet) Devops() (*devops.DevopsClient, error) {
func (cs *ClientSet) Devops() (*devops.Client, error) {
var err error
if cs.csoptions.devopsOptions == nil || cs.csoptions.devopsOptions.Host == "" {
return nil, ClientSetNotEnabledError{}
return nil, ErrClientSetNotEnabled
}
if cs.devopsClient != nil {
@@ -224,11 +217,11 @@ func (cs *ClientSet) Devops() (*devops.DevopsClient, error) {
}
}
func (cs *ClientSet) SonarQube() (*sonarqube.SonarQubeClient, error) {
func (cs *ClientSet) SonarQube() (*sonarqube.Client, error) {
var err error
if cs.csoptions.sonarqubeOptions == nil || cs.csoptions.sonarqubeOptions.Host == "" {
return nil, ClientSetNotEnabledError{}
return nil, ErrClientSetNotEnabled
}
if cs.sonarQubeClient != nil {
@@ -247,11 +240,11 @@ func (cs *ClientSet) SonarQube() (*sonarqube.SonarQubeClient, error) {
}
}
func (cs *ClientSet) Ldap() (*ldap.LdapClient, error) {
func (cs *ClientSet) Ldap() (*ldap.Client, error) {
var err error
if cs.csoptions.ldapOptions == nil || cs.csoptions.ldapOptions.Host == "" {
return nil, ClientSetNotEnabledError{}
return nil, ErrClientSetNotEnabled
}
if cs.ldapClient != nil {
@@ -272,15 +265,15 @@ func (cs *ClientSet) Ldap() (*ldap.LdapClient, error) {
// since kubernetes client is required, we will
// create it on setup
func (cs *ClientSet) K8s() *k8s.KubernetesClient {
func (cs *ClientSet) K8s() k8s.Client {
return cs.k8sClient
}
func (cs *ClientSet) S3() (*s2is3.S3Client, error) {
func (cs *ClientSet) S3() (s3.Interface, error) {
var err error
if cs.csoptions.s3Options == nil || cs.csoptions.s3Options.Endpoint == "" {
return nil, ClientSetNotEnabledError{}
return nil, ErrClientSetNotEnabled
}
if cs.s3Client != nil {
@@ -290,7 +283,7 @@ func (cs *ClientSet) S3() (*s2is3.S3Client, error) {
defer mutex.Unlock()
if cs.s3Client == nil {
cs.s3Client, err = s2is3.NewS3Client(cs.csoptions.s3Options)
cs.s3Client, err = s3.NewS3Client(cs.csoptions.s3Options)
if err != nil {
return nil, err
}
@@ -299,7 +292,7 @@ func (cs *ClientSet) S3() (*s2is3.S3Client, error) {
}
}
func (cs *ClientSet) OpenPitrix() (*openpitrix.OpenPitrixClient, error) {
func (cs *ClientSet) OpenPitrix() (*openpitrix.Client, error) {
var err error
if cs.csoptions.openPitrixOptions == nil ||
@@ -310,7 +303,7 @@ func (cs *ClientSet) OpenPitrix() (*openpitrix.OpenPitrixClient, error) {
cs.csoptions.openPitrixOptions.AttachmentManagerEndpoint == "" ||
cs.csoptions.openPitrixOptions.RepoIndexerEndpoint == "" ||
cs.csoptions.openPitrixOptions.CategoryManagerEndpoint == "" {
return nil, ClientSetNotEnabledError{}
return nil, ErrClientSetNotEnabled
}
if cs.openpitrixClient != nil {
@@ -325,11 +318,11 @@ func (cs *ClientSet) OpenPitrix() (*openpitrix.OpenPitrixClient, error) {
}
}
func (cs *ClientSet) Prometheus() (*prometheus.PrometheusClient, error) {
func (cs *ClientSet) Prometheus() (*prometheus.Client, error) {
var err error
if cs.csoptions.prometheusOptions == nil || cs.csoptions.prometheusOptions.Endpoint == "" {
return nil, ClientSetNotEnabledError{}
return nil, ErrClientSetNotEnabled
}
if cs.prometheusClient != nil {
@@ -348,7 +341,7 @@ func (cs *ClientSet) Prometheus() (*prometheus.PrometheusClient, error) {
}
}
func (cs *ClientSet) KubeSphere() *kubesphere.KubeSphereClient {
func (cs *ClientSet) KubeSphere() *kubesphere.Client {
return cs.kubesphereClient
}
@@ -356,7 +349,7 @@ func (cs *ClientSet) ElasticSearch() (*esclient.ElasticSearchClient, error) {
var err error
if cs.csoptions.elasticSearhOptions == nil || cs.csoptions.elasticSearhOptions.Host == "" {
return nil, ClientSetNotEnabledError{}
return nil, ErrClientSetNotEnabled
}
if cs.elasticSearchClient != nil {

View File

@@ -1,288 +0,0 @@
/*
Copyright 2018 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
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 fluentbitclient
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/clientcmd"
"time"
)
const (
CRDPlural string = "fluentbits"
CRDGroup string = "logging.kubesphere.io"
CRDVersion string = "v1alpha1"
FullCRDName string = CRDPlural + "." + CRDGroup
)
// FluentBitList auto generated by the sdk
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type FluentBitList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []FluentBit `json:"items"`
}
// FluentBit auto generated by the sdk
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type FluentBit struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`
Spec FluentBitSpec `json:"spec"`
Status FluentBitStatus `json:"status,omitempty"`
}
// FluentBitSpec holds the spec for the operator
type FluentBitSpec struct {
Service []Plugin `json:"service"`
Input []Plugin `json:"input"`
Filter []Plugin `json:"filter"`
Output []Plugin `json:"output"`
Settings []Plugin `json:"settings"`
}
// FluentBitStatus holds the status info for the operator
type FluentBitStatus struct {
// Fill me
}
// Plugin struct for fluent-bit plugins
type Plugin struct {
Type string `json:"type" description:"output plugin type, eg. fluentbit-output-es"`
Name string `json:"name" description:"output plugin name, eg. fluentbit-output-es"`
Parameters []Parameter `json:"parameters" description:"output plugin configuration parameters"`
}
// Fluent-bit output plugins
type OutputPlugin struct {
Plugin
Id string `json:"id,omitempty" description:"output uuid"`
Enable bool `json:"enable" description:"active status, one of true, false"`
Updatetime time.Time `json:"updatetime,omitempty" description:"last updatetime"`
}
// Parameter generic parameter type to handle values from different sources
type Parameter struct {
Name string `json:"name" description:"configuration parameter key, eg. Name. refer to Fluent bit's Output Plugins Section for more configuration parameters."`
ValueFrom *ValueFrom `json:"valueFrom,omitempty"`
Value string `json:"value" description:"configuration parameter value, eg. es. refer to Fluent bit's Output Plugins Section for more configuration parameters."`
}
// ValueFrom generic type to determine value origin
type ValueFrom struct {
SecretKeyRef KubernetesSecret `json:"secretKeyRef"`
}
// KubernetesSecret is a ValueFrom type
type KubernetesSecret struct {
Name string `json:"name"`
Key string `json:"key"`
Namespace string `json:"namespace"`
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *FluentBit) DeepCopyInto(out *FluentBit) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
out.Spec = in.Spec
out.Status = in.Status
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FluentBit.
func (in *FluentBit) DeepCopy() *FluentBit {
if in == nil {
return nil
}
out := new(FluentBit)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *FluentBit) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *FluentBitList) DeepCopyInto(out *FluentBitList) {
*out = *in
out.TypeMeta = in.TypeMeta
out.ListMeta = in.ListMeta
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]FluentBit, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FluentBitList.
func (in *FluentBitList) DeepCopy() *FluentBitList {
if in == nil {
return nil
}
out := new(FluentBitList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *FluentBitList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *FluentBitSpec) DeepCopyInto(out *FluentBitSpec) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FluentBitSpec.
func (in *FluentBitSpec) DeepCopy() *FluentBitSpec {
if in == nil {
return nil
}
out := new(FluentBitSpec)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *FluentBitStatus) DeepCopyInto(out *FluentBitStatus) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FluentBitStatus.
func (in *FluentBitStatus) DeepCopy() *FluentBitStatus {
if in == nil {
return nil
}
out := new(FluentBitStatus)
in.DeepCopyInto(out)
return out
}
// Create a Rest client with the new CRD Schema
var SchemeGroupVersion = schema.GroupVersion{Group: CRDGroup, Version: CRDVersion}
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&FluentBit{},
&FluentBitList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}
func NewFluentbitCRDClient(cfg *rest.Config) (*rest.RESTClient, *runtime.Scheme, error) {
scheme := runtime.NewScheme()
SchemeBuilder := runtime.NewSchemeBuilder(addKnownTypes)
if err := SchemeBuilder.AddToScheme(scheme); err != nil {
return nil, nil, err
}
config := *cfg
config.GroupVersion = &SchemeGroupVersion
config.APIPath = "/apis"
config.ContentType = runtime.ContentTypeJSON
config.NegotiatedSerializer = serializer.NewCodecFactory(runtime.NewScheme()).WithoutConversion()
client, err := rest.RESTClientFor(&config)
if err != nil {
return nil, nil, err
}
return client, scheme, nil
}
// This file implement all the (CRUD) client methods we need to access our CRD object
func CrdClient(cl *rest.RESTClient, scheme *runtime.Scheme, namespace string) *crdclient {
return &crdclient{cl: cl, ns: namespace, plural: CRDPlural,
codec: runtime.NewParameterCodec(scheme)}
}
type crdclient struct {
cl *rest.RESTClient
ns string
plural string
codec runtime.ParameterCodec
}
func (f *crdclient) Create(obj *FluentBit) (*FluentBit, error) {
var result FluentBit
err := f.cl.Post().
Namespace(f.ns).Resource(f.plural).
Body(obj).Do().Into(&result)
return &result, err
}
func (f *crdclient) Update(name string, obj *FluentBit) (*FluentBit, error) {
var result FluentBit
err := f.cl.Put().
Namespace(f.ns).Resource(f.plural).
Name(name).Body(obj).Do().Into(&result)
return &result, err
}
func (f *crdclient) Delete(name string, options *metav1.DeleteOptions) error {
return f.cl.Delete().
Namespace(f.ns).Resource(f.plural).
Name(name).Body(options).Do().
Error()
}
func (f *crdclient) Get(name string) (*FluentBit, error) {
var result FluentBit
err := f.cl.Get().
Namespace(f.ns).Resource(f.plural).
Name(name).Do().Into(&result)
return &result, err
}
func (f *crdclient) List(opts metav1.ListOptions) (*FluentBitList, error) {
var result FluentBitList
err := f.cl.Get().
Namespace(f.ns).Resource(f.plural).
VersionedParams(&opts, f.codec).
Do().Into(&result)
return &result, err
}
// Create a new List watch for our TPR
func (f *crdclient) NewListWatch() *cache.ListWatch {
return cache.NewListWatchFromClient(f.cl, f.plural, f.ns, fields.Everything())
}
// return rest config, if path not specified assume in cluster config
func GetClientConfig(kubeconfig string) (*rest.Config, error) {
if kubeconfig != "" {
return clientcmd.BuildConfigFromFlags("", kubeconfig)
}
return rest.InClusterConfig()
}

View File

@@ -11,7 +11,17 @@ import (
"strings"
)
type KubernetesClient struct {
type Client interface {
Kubernetes() kubernetes.Interface
KubeSphere() kubesphere.Interface
S2i() s2i.Interface
Application() applicationclientset.Interface
Discovery() discovery.DiscoveryInterface
Master() string
Config() *rest.Config
}
type kubernetesClient struct {
// kubernetes client interface
k8s *kubernetes.Clientset
@@ -31,7 +41,7 @@ type KubernetesClient struct {
}
// NewKubernetesClientOrDie creates KubernetesClient and panic if there is an error
func NewKubernetesClientOrDie(options *KubernetesOptions) *KubernetesClient {
func NewKubernetesClientOrDie(options *KubernetesOptions) Client {
config, err := clientcmd.BuildConfigFromFlags("", options.KubeConfig)
if err != nil {
panic(err)
@@ -40,7 +50,7 @@ func NewKubernetesClientOrDie(options *KubernetesOptions) *KubernetesClient {
config.QPS = options.QPS
config.Burst = options.Burst
k := &KubernetesClient{
k := &kubernetesClient{
k8s: kubernetes.NewForConfigOrDie(config),
discoveryClient: discovery.NewDiscoveryClientForConfigOrDie(config),
ks: kubesphere.NewForConfigOrDie(config),
@@ -63,7 +73,7 @@ func NewKubernetesClientOrDie(options *KubernetesOptions) *KubernetesClient {
}
// NewKubernetesClient creates a KubernetesClient
func NewKubernetesClient(options *KubernetesOptions) (*KubernetesClient, error) {
func NewKubernetesClient(options *KubernetesOptions) (Client, error) {
config, err := clientcmd.BuildConfigFromFlags("", options.KubeConfig)
if err != nil {
return nil, err
@@ -72,7 +82,7 @@ func NewKubernetesClient(options *KubernetesOptions) (*KubernetesClient, error)
config.QPS = options.QPS
config.Burst = options.Burst
var k KubernetesClient
var k kubernetesClient
k.k8s, err = kubernetes.NewForConfig(config)
if err != nil {
return nil, err
@@ -99,31 +109,31 @@ func NewKubernetesClient(options *KubernetesOptions) (*KubernetesClient, error)
return &k, nil
}
func (k *KubernetesClient) Kubernetes() kubernetes.Interface {
func (k *kubernetesClient) Kubernetes() kubernetes.Interface {
return k.k8s
}
func (k *KubernetesClient) Discovery() discovery.DiscoveryInterface {
func (k *kubernetesClient) Discovery() discovery.DiscoveryInterface {
return k.discoveryClient
}
func (k *KubernetesClient) KubeSphere() kubesphere.Interface {
func (k *kubernetesClient) KubeSphere() kubesphere.Interface {
return k.ks
}
func (k *KubernetesClient) S2i() s2i.Interface {
func (k *kubernetesClient) S2i() s2i.Interface {
return k.s2i
}
func (k *KubernetesClient) Application() applicationclientset.Interface {
func (k *kubernetesClient) Application() applicationclientset.Interface {
return k.application
}
// master address used to generate kubeconfig for downloading
func (k *KubernetesClient) Master() string {
func (k *kubernetesClient) Master() string {
return k.master
}
func (k *KubernetesClient) Config() *rest.Config {
func (k *kubernetesClient) Config() *rest.Config {
return k.config
}

View File

@@ -49,11 +49,11 @@ func (k *KubernetesOptions) ApplyTo(options *KubernetesOptions) {
reflectutils.Override(options, k)
}
func (k *KubernetesOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&k.KubeConfig, "kubeconfig", k.KubeConfig, ""+
func (k *KubernetesOptions) AddFlags(fs *pflag.FlagSet, c *KubernetesOptions) {
fs.StringVar(&k.KubeConfig, "kubeconfig", c.KubeConfig, ""+
"Path for kubernetes kubeconfig file, if left blank, will use "+
"in cluster way.")
fs.StringVar(&k.Master, "master", k.Master, ""+
fs.StringVar(&k.Master, "master", c.Master, ""+
"Used to generate kubeconfig for downloading, if not specified, will use host in kubeconfig.")
}

View File

@@ -40,15 +40,15 @@ type Interface interface {
DeleteWorkspaceDevOpsProjects(workspace, devops string) error
}
type KubeSphereClient struct {
type Client struct {
client *http.Client
apiServer string
accountServer string
}
func NewKubeSphereClient(options *KubeSphereOptions) *KubeSphereClient {
return &KubeSphereClient{
func NewKubeSphereClient(options *Options) *Client {
return &Client{
client: &http.Client{},
apiServer: options.APIServer,
accountServer: options.AccountServer,
@@ -64,7 +64,7 @@ func (e Error) Error() string {
return fmt.Sprintf("status: %d,message: %s", e.status, e.message)
}
func (c *KubeSphereClient) CreateGroup(group *models.Group) (*models.Group, error) {
func (c *Client) CreateGroup(group *models.Group) (*models.Group, error) {
data, err := json.Marshal(group)
if err != nil {
return nil, err
@@ -106,7 +106,7 @@ func (c *KubeSphereClient) CreateGroup(group *models.Group) (*models.Group, erro
return group, nil
}
func (c *KubeSphereClient) UpdateGroup(group *models.Group) (*models.Group, error) {
func (c *Client) UpdateGroup(group *models.Group) (*models.Group, error) {
data, err := json.Marshal(group)
if err != nil {
@@ -149,7 +149,7 @@ func (c *KubeSphereClient) UpdateGroup(group *models.Group) (*models.Group, erro
return group, nil
}
func (c *KubeSphereClient) DeleteGroup(name string) error {
func (c *Client) DeleteGroup(name string) error {
req, err := http.NewRequest(http.MethodDelete, fmt.Sprintf("%s/kapis/iam.kubesphere.io/v1alpha2/groups/%s", c.accountServer, name), nil)
if err != nil {
@@ -178,7 +178,7 @@ func (c *KubeSphereClient) DeleteGroup(name string) error {
return nil
}
func (c *KubeSphereClient) DescribeGroup(name string) (*models.Group, error) {
func (c *Client) DescribeGroup(name string) (*models.Group, error) {
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/kapis/iam.kubesphere.io/v1alpha2/groups/%s", c.accountServer, name), nil)
if err != nil {
@@ -214,7 +214,7 @@ func (c *KubeSphereClient) DescribeGroup(name string) (*models.Group, error) {
return &group, nil
}
func (c *KubeSphereClient) ListUsers() (*models.PageableResponse, error) {
func (c *Client) ListUsers() (*models.PageableResponse, error) {
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/kapis/iam.kubesphere.io/v1alpha2/users", c.accountServer), nil)
if err != nil {
@@ -250,7 +250,7 @@ func (c *KubeSphereClient) ListUsers() (*models.PageableResponse, error) {
return &result, nil
}
func (c *KubeSphereClient) ListWorkspaceDevOpsProjects(workspace string) (*v1alpha2.PageableDevOpsProject, error) {
func (c *Client) ListWorkspaceDevOpsProjects(workspace string) (*v1alpha2.PageableDevOpsProject, error) {
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/kapis/tenant.kubesphere.io/v1alpha2/workspaces/%s/devops", c.apiServer, workspace), nil)
if err != nil {
@@ -290,7 +290,7 @@ func (c *KubeSphereClient) ListWorkspaceDevOpsProjects(workspace string) (*v1alp
}
func (c *KubeSphereClient) DeleteWorkspaceDevOpsProjects(workspace, devops string) error {
func (c *Client) DeleteWorkspaceDevOpsProjects(workspace, devops string) error {
req, err := http.NewRequest(http.MethodDelete, fmt.Sprintf("%s/kapis/tenant.kubesphere.io/v1alpha2/workspaces/%s/devops/%s", c.apiServer, workspace, devops), nil)
if err != nil {

View File

@@ -2,20 +2,20 @@ package kubesphere
import "github.com/spf13/pflag"
type KubeSphereOptions struct {
type Options struct {
APIServer string `json:"apiServer" yaml:"apiServer"`
AccountServer string `json:"accountServer" yaml:"accountServer"`
}
// NewKubeSphereOptions create a default options
func NewKubeSphereOptions() *KubeSphereOptions {
return &KubeSphereOptions{
func NewKubeSphereOptions() *Options {
return &Options{
APIServer: "http://ks-apiserver.kubesphere-system.svc",
AccountServer: "http://ks-account.kubesphere-system.svc",
}
}
func (s *KubeSphereOptions) ApplyTo(options *KubeSphereOptions) {
func (s *Options) ApplyTo(options *Options) {
if s.AccountServer != "" {
options.AccountServer = s.AccountServer
}
@@ -25,13 +25,13 @@ func (s *KubeSphereOptions) ApplyTo(options *KubeSphereOptions) {
}
}
func (s *KubeSphereOptions) Validate() []error {
func (s *Options) Validate() []error {
errs := []error{}
return errs
}
func (s *KubeSphereOptions) AddFlags(fs *pflag.FlagSet) {
func (s *Options) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&s.APIServer, "kubesphere-apiserver-host", s.APIServer, ""+
"KubeSphere apiserver host address.")

View File

@@ -23,13 +23,13 @@ import (
"k8s.io/klog"
)
type LdapClient struct {
type Client struct {
pool Pool
options *LdapOptions
options *Options
}
// panic if cannot connect to ldap service
func NewLdapClient(options *LdapOptions, stopCh <-chan struct{}) (*LdapClient, error) {
func NewLdapClient(options *Options, stopCh <-chan struct{}) (*Client, error) {
pool, err := NewChannelPool(8, 64, "kubesphere", func(s string) (ldap.Client, error) {
conn, err := ldap.Dial("tcp", options.Host)
if err != nil {
@@ -44,7 +44,7 @@ func NewLdapClient(options *LdapOptions, stopCh <-chan struct{}) (*LdapClient, e
return nil, err
}
client := &LdapClient{
client := &Client{
pool: pool,
options: options,
}
@@ -59,7 +59,7 @@ func NewLdapClient(options *LdapOptions, stopCh <-chan struct{}) (*LdapClient, e
return client, nil
}
func (l *LdapClient) NewConn() (ldap.Client, error) {
func (l *Client) NewConn() (ldap.Client, error) {
if l.pool == nil {
err := fmt.Errorf("ldap connection pool is not initialized")
klog.Errorln(err)
@@ -81,10 +81,10 @@ func (l *LdapClient) NewConn() (ldap.Client, error) {
return conn, nil
}
func (l *LdapClient) GroupSearchBase() string {
func (l *Client) GroupSearchBase() string {
return l.options.GroupSearchBase
}
func (l *LdapClient) UserSearchBase() string {
func (l *Client) UserSearchBase() string {
return l.options.UserSearchBase
}

View File

@@ -5,7 +5,7 @@ import (
"kubesphere.io/kubesphere/pkg/utils/reflectutils"
)
type LdapOptions struct {
type Options struct {
Host string `json:"host,omitempty" yaml:"host"`
ManagerDN string `json:"managerDN,omitempty" yaml:"managerDN"`
ManagerPassword string `json:"managerPassword,omitempty" yaml:"managerPassword"`
@@ -15,8 +15,8 @@ type LdapOptions struct {
// NewLdapOptions return a default option
// which host field point to nowhere.
func NewLdapOptions() *LdapOptions {
return &LdapOptions{
func NewLdapOptions() *Options {
return &Options{
Host: "",
ManagerDN: "cn=admin,dc=example,dc=org",
UserSearchBase: "ou=Users,dc=example,dc=org",
@@ -24,32 +24,32 @@ func NewLdapOptions() *LdapOptions {
}
}
func (l *LdapOptions) Validate() []error {
func (l *Options) Validate() []error {
errors := []error{}
return errors
}
func (l *LdapOptions) ApplyTo(options *LdapOptions) {
func (l *Options) ApplyTo(options *Options) {
if l.Host != "" {
reflectutils.Override(options, l)
}
}
func (l *LdapOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&l.Host, "ldap-host", l.Host, ""+
func (l *Options) AddFlags(fs *pflag.FlagSet, s *Options) {
fs.StringVar(&l.Host, "ldap-host", s.Host, ""+
"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, ""+
fs.StringVar(&l.ManagerDN, "ldap-manager-dn", s.ManagerDN, ""+
"Ldap manager account domain name.")
fs.StringVar(&l.ManagerPassword, "ldap-manager-password", l.ManagerPassword, ""+
fs.StringVar(&l.ManagerPassword, "ldap-manager-password", s.ManagerPassword, ""+
"Ldap manager account password.")
fs.StringVar(&l.UserSearchBase, "ldap-user-search-base", l.UserSearchBase, ""+
fs.StringVar(&l.UserSearchBase, "ldap-user-search-base", s.UserSearchBase, ""+
"Ldap user search base.")
fs.StringVar(&l.GroupSearchBase, "ldap-group-search-base", l.GroupSearchBase, ""+
fs.StringVar(&l.GroupSearchBase, "ldap-group-search-base", s.GroupSearchBase, ""+
"Ldap group search base.")
}

View File

@@ -0,0 +1,4 @@
package logging
type Interface interface {
}

View File

@@ -0,0 +1,4 @@
package logging
type Query struct {
}

View File

@@ -0,0 +1,4 @@
package monitoring
type Interface interface {
}

View File

@@ -19,12 +19,12 @@ import (
"k8s.io/klog"
)
type MySQLClient struct {
type Client struct {
database *Database
}
func NewMySQLClient(options *MySQLOptions, stopCh <-chan struct{}) (*MySQLClient, error) {
var m MySQLClient
func NewMySQLClient(options *Options, stopCh <-chan struct{}) (*Client, error) {
var m Client
conn, err := dbr.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/devops?parseTime=1&multiStatements=1&charset=utf8mb4&collation=utf8mb4_unicode_ci", options.Username, options.Password, options.Host), nil)
if err != nil {
@@ -50,8 +50,8 @@ func NewMySQLClient(options *MySQLOptions, stopCh <-chan struct{}) (*MySQLClient
return &m, nil
}
func NewMySQLClientOrDie(options *MySQLOptions, stopCh <-chan struct{}) *MySQLClient {
var m MySQLClient
func NewMySQLClientOrDie(options *Options, stopCh <-chan struct{}) *Client {
var m Client
conn, err := dbr.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/devops?parseTime=1&multiStatements=1&charset=utf8mb4&collation=utf8mb4_unicode_ci", options.Username, options.Password, options.Host), nil)
if err != nil {
@@ -77,6 +77,6 @@ func NewMySQLClientOrDie(options *MySQLOptions, stopCh <-chan struct{}) *MySQLCl
return &m
}
func (m *MySQLClient) Database() *Database {
func (m *Client) Database() *Database {
return m.database
}

View File

@@ -6,7 +6,7 @@ import (
"time"
)
type MySQLOptions struct {
type Options struct {
Host string `json:"host,omitempty" yaml:"host" description:"MySQL service host address"`
Username string `json:"username,omitempty" yaml:"username"`
Password string `json:"-" yaml:"password"`
@@ -16,8 +16,8 @@ type MySQLOptions struct {
}
// NewMySQLOptions create a `zero` value instance
func NewMySQLOptions() *MySQLOptions {
return &MySQLOptions{
func NewMySQLOptions() *Options {
return &Options{
Host: "",
Username: "",
Password: "",
@@ -27,33 +27,33 @@ func NewMySQLOptions() *MySQLOptions {
}
}
func (m *MySQLOptions) Validate() []error {
errors := []error{}
func (m *Options) Validate() []error {
var errors []error
return errors
}
func (m *MySQLOptions) ApplyTo(options *MySQLOptions) {
func (m *Options) ApplyTo(options *Options) {
reflectutils.Override(options, m)
}
func (m *MySQLOptions) AddFlags(fs *pflag.FlagSet) {
func (m *Options) AddFlags(fs *pflag.FlagSet, c *Options) {
fs.StringVar(&m.Host, "mysql-host", m.Host, ""+
fs.StringVar(&m.Host, "mysql-host", c.Host, ""+
"MySQL service host address. If left blank, the following related mysql options will be ignored.")
fs.StringVar(&m.Username, "mysql-username", m.Username, ""+
fs.StringVar(&m.Username, "mysql-username", c.Username, ""+
"Username for access to mysql service.")
fs.StringVar(&m.Password, "mysql-password", m.Password, ""+
fs.StringVar(&m.Password, "mysql-password", c.Password, ""+
"Password for access to mysql, should be used pair with password.")
fs.IntVar(&m.MaxIdleConnections, "mysql-max-idle-connections", m.MaxOpenConnections, ""+
fs.IntVar(&m.MaxIdleConnections, "mysql-max-idle-connections", c.MaxOpenConnections, ""+
"Maximum idle connections allowed to connect to mysql.")
fs.IntVar(&m.MaxOpenConnections, "mysql-max-open-connections", m.MaxOpenConnections, ""+
fs.IntVar(&m.MaxOpenConnections, "mysql-max-open-connections", c.MaxOpenConnections, ""+
"Maximum open connections allowed to connect to mysql.")
fs.DurationVar(&m.MaxConnectionLifeTime, "mysql-max-connection-life-time", m.MaxConnectionLifeTime, ""+
fs.DurationVar(&m.MaxConnectionLifeTime, "mysql-max-connection-life-time", c.MaxConnectionLifeTime, ""+
"Maximum connection life time allowed to connecto to mysql.")
}

View File

@@ -1,16 +1,16 @@
package notification
type NotificationOptions struct {
type Options struct {
Endpoint string
}
func NewNotificationOptions() *NotificationOptions {
return &NotificationOptions{
func NewNotificationOptions() *Options {
return &Options{
Endpoint: "",
}
}
func (s *NotificationOptions) ApplyTo(options *NotificationOptions) {
func (s *Options) ApplyTo(options *Options) {
if options == nil {
options = s
return

View File

@@ -39,7 +39,17 @@ const (
SystemUserPath = ":system"
)
type OpenPitrixClient struct {
type Interface interface {
pb.RuntimeManagerClient
pb.ClusterManagerClient
pb.AppManagerClient
pb.RepoManagerClient
pb.CategoryManagerClient
pb.AttachmentManagerClient
pb.RepoIndexerClient
}
type Client struct {
runtime pb.RuntimeManagerClient
cluster pb.ClusterManagerClient
app pb.AppManagerClient
@@ -123,7 +133,7 @@ func newAppManagerClient(endpoint string) (pb.AppManagerClient, error) {
return pb.NewAppManagerClient(conn), nil
}
func NewOpenPitrixClient(options *OpenPitrixOptions) (*OpenPitrixClient, error) {
func NewOpenPitrixClient(options *Options) (*Client, error) {
runtimeMangerClient, err := newRuntimeManagerClient(options.RuntimeManagerEndpoint)
@@ -174,7 +184,7 @@ func NewOpenPitrixClient(options *OpenPitrixOptions) (*OpenPitrixClient, error)
return nil, err
}
client := OpenPitrixClient{
client := Client{
runtime: runtimeMangerClient,
cluster: clusterManagerClient,
repo: repoManagerClient,
@@ -186,28 +196,28 @@ func NewOpenPitrixClient(options *OpenPitrixOptions) (*OpenPitrixClient, error)
return &client, nil
}
func (c *OpenPitrixClient) Runtime() pb.RuntimeManagerClient {
func (c *Client) Runtime() pb.RuntimeManagerClient {
return c.runtime
}
func (c *OpenPitrixClient) App() pb.AppManagerClient {
func (c *Client) App() pb.AppManagerClient {
return c.app
}
func (c *OpenPitrixClient) Cluster() pb.ClusterManagerClient {
func (c *Client) Cluster() pb.ClusterManagerClient {
return c.cluster
}
func (c *OpenPitrixClient) Category() pb.CategoryManagerClient {
func (c *Client) Category() pb.CategoryManagerClient {
return c.category
}
func (c *OpenPitrixClient) Repo() pb.RepoManagerClient {
func (c *Client) Repo() pb.RepoManagerClient {
return c.repo
}
func (c *OpenPitrixClient) RepoIndexer() pb.RepoIndexerClient {
func (c *Client) RepoIndexer() pb.RepoIndexerClient {
return c.repoIndexer
}
func (c *OpenPitrixClient) Attachment() pb.AttachmentManagerClient {
func (c *Client) Attachment() pb.AttachmentManagerClient {
return c.attachment
}

View File

@@ -6,7 +6,7 @@ import (
"kubesphere.io/kubesphere/pkg/utils/reflectutils"
)
type OpenPitrixOptions struct {
type Options struct {
RuntimeManagerEndpoint string `json:"runtimeManagerEndpoint,omitempty" yaml:"runtimeManagerEndpoint,omitempty"`
ClusterManagerEndpoint string `json:"clusterManagerEndpoint,omitempty" yaml:"clusterManagerEndpoint,omitempty"`
RepoManagerEndpoint string `json:"repoManagerEndpoint,omitempty" yaml:"repoManagerEndpoint,omitempty"`
@@ -16,11 +16,11 @@ type OpenPitrixOptions struct {
RepoIndexerEndpoint string `json:"repoIndexerEndpoint,omitempty" yaml:"repoIndexerEndpoint,omitempty"`
}
func NewOpenPitrixOptions() *OpenPitrixOptions {
return &OpenPitrixOptions{}
func NewOpenPitrixOptions() *Options {
return &Options{}
}
func (s *OpenPitrixOptions) ApplyTo(options *OpenPitrixOptions) {
func (s *Options) ApplyTo(options *Options) {
if options == nil {
options = s
return
@@ -30,7 +30,7 @@ func (s *OpenPitrixOptions) ApplyTo(options *OpenPitrixOptions) {
}
}
func (s *OpenPitrixOptions) IsEmpty() bool {
func (s *Options) IsEmpty() bool {
return s.RuntimeManagerEndpoint == "" &&
s.ClusterManagerEndpoint == "" &&
s.RepoManagerEndpoint == "" &&
@@ -40,7 +40,7 @@ func (s *OpenPitrixOptions) IsEmpty() bool {
s.RepoIndexerEndpoint == ""
}
func (s *OpenPitrixOptions) Validate() []error {
func (s *Options) Validate() []error {
var errs []error
if s.RuntimeManagerEndpoint != "" {
@@ -89,25 +89,25 @@ func (s *OpenPitrixOptions) Validate() []error {
return errs
}
func (s *OpenPitrixOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&s.RuntimeManagerEndpoint, "openpitrix-runtime-manager-endpoint", s.RuntimeManagerEndpoint, ""+
func (s *Options) AddFlags(fs *pflag.FlagSet, c *Options) {
fs.StringVar(&s.RuntimeManagerEndpoint, "openpitrix-runtime-manager-endpoint", c.RuntimeManagerEndpoint, ""+
"OpenPitrix runtime manager endpoint")
fs.StringVar(&s.AppManagerEndpoint, "openpitrix-app-manager-endpoint", s.AppManagerEndpoint, ""+
fs.StringVar(&s.AppManagerEndpoint, "openpitrix-app-manager-endpoint", c.AppManagerEndpoint, ""+
"OpenPitrix app manager endpoint")
fs.StringVar(&s.ClusterManagerEndpoint, "openpitrix-cluster-manager-endpoint", s.ClusterManagerEndpoint, ""+
fs.StringVar(&s.ClusterManagerEndpoint, "openpitrix-cluster-manager-endpoint", c.ClusterManagerEndpoint, ""+
"OpenPitrix cluster manager endpoint")
fs.StringVar(&s.CategoryManagerEndpoint, "openpitrix-category-manager-endpoint", s.CategoryManagerEndpoint, ""+
fs.StringVar(&s.CategoryManagerEndpoint, "openpitrix-category-manager-endpoint", c.CategoryManagerEndpoint, ""+
"OpenPitrix category manager endpoint")
fs.StringVar(&s.RepoManagerEndpoint, "openpitrix-repo-manager-endpoint", s.RepoManagerEndpoint, ""+
fs.StringVar(&s.RepoManagerEndpoint, "openpitrix-repo-manager-endpoint", c.RepoManagerEndpoint, ""+
"OpenPitrix repo manager endpoint")
fs.StringVar(&s.RepoIndexerEndpoint, "openpitrix-repo-indexer-endpoint", s.RepoIndexerEndpoint, ""+
fs.StringVar(&s.RepoIndexerEndpoint, "openpitrix-repo-indexer-endpoint", c.RepoIndexerEndpoint, ""+
"OpenPitrix repo indexer endpoint")
fs.StringVar(&s.AttachmentManagerEndpoint, "openpitrix-attachment-manager-endpoint", s.AttachmentManagerEndpoint, ""+
fs.StringVar(&s.AttachmentManagerEndpoint, "openpitrix-attachment-manager-endpoint", c.AttachmentManagerEndpoint, ""+
"OpenPitrix attachment manager endpoint")
}

View File

@@ -4,25 +4,24 @@ import (
"github.com/spf13/pflag"
)
type PrometheusOptions struct {
type Options struct {
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint"`
SecondaryEndpoint string `json:"secondaryEndpoint,omitempty" yaml:"secondaryEndpoint"`
}
func NewPrometheusOptions() *PrometheusOptions {
return &PrometheusOptions{
func NewPrometheusOptions() *Options {
return &Options{
Endpoint: "",
SecondaryEndpoint: "",
}
}
func (s *PrometheusOptions) Validate() []error {
errs := []error{}
func (s *Options) Validate() []error {
var errs []error
return errs
}
func (s *PrometheusOptions) ApplyTo(options *PrometheusOptions) {
func (s *Options) ApplyTo(options *Options) {
if s.Endpoint != "" {
options.Endpoint = s.Endpoint
}
@@ -32,11 +31,11 @@ func (s *PrometheusOptions) ApplyTo(options *PrometheusOptions) {
}
}
func (s *PrometheusOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&s.Endpoint, "prometheus-endpoint", s.Endpoint, ""+
func (s *Options) AddFlags(fs *pflag.FlagSet, c *Options) {
fs.StringVar(&s.Endpoint, "prometheus-endpoint", c.Endpoint, ""+
"Prometheus service endpoint which stores KubeSphere monitoring data, if left "+
"blank, will use builtin metrics-server as data source.")
fs.StringVar(&s.SecondaryEndpoint, "prometheus-secondary-endpoint", s.SecondaryEndpoint, ""+
fs.StringVar(&s.SecondaryEndpoint, "prometheus-secondary-endpoint", c.SecondaryEndpoint, ""+
"Prometheus secondary service endpoint, if left empty and endpoint is set, will use endpoint instead.")
}

View File

@@ -27,14 +27,17 @@ import (
"time"
)
type PrometheusClient struct {
type Interface interface {
}
type Client struct {
client *http.Client
endpoint string
secondaryEndpoint string
}
func NewPrometheusClient(options *PrometheusOptions) (*PrometheusClient, error) {
return &PrometheusClient{
func NewPrometheusClient(options *Options) (*Client, error) {
return &Client{
client: &http.Client{
Timeout: 10 * time.Second,
},
@@ -43,17 +46,17 @@ func NewPrometheusClient(options *PrometheusOptions) (*PrometheusClient, error)
}, nil
}
func (c *PrometheusClient) QueryToK8SPrometheus(queryType string, params string) (apiResponse v1alpha2.APIResponse) {
func (c *Client) QueryToK8SPrometheus(queryType string, params string) (apiResponse v1alpha2.APIResponse) {
return c.query(c.endpoint, queryType, params)
}
func (c *PrometheusClient) QueryToK8SSystemPrometheus(queryType string, params string) (apiResponse v1alpha2.APIResponse) {
func (c *Client) QueryToK8SSystemPrometheus(queryType string, params string) (apiResponse v1alpha2.APIResponse) {
return c.query(c.secondaryEndpoint, queryType, params)
}
var jsonIter = jsoniter.ConfigCompatibleWithStandardLibrary
func (c *PrometheusClient) query(endpoint string, queryType string, params string) (apiResponse v1alpha2.APIResponse) {
func (c *Client) query(endpoint string, queryType string, params string) (apiResponse v1alpha2.APIResponse) {
url := fmt.Sprintf("%s/api/v1/%s?%s", endpoint, queryType, params)
response, err := c.client.Get(url)

View File

@@ -0,0 +1,17 @@
package s3
import (
"io"
"time"
)
type Interface interface {
// Upload uploads a object to storage and returns object location if succeeded
Upload(key string, body io.Reader) (string, error)
// Get retrieves and object's downloadable location if succeeded
Get(key string, fileName string, expire time.Duration) (string, error)
// Delete deletes an object by its key
Delete(key string) error
}

View File

@@ -1,12 +1,12 @@
package s2is3
package s3
import (
"github.com/spf13/pflag"
"kubesphere.io/kubesphere/pkg/utils/reflectutils"
)
// S3Options contains configuration to access a s3 service
type S3Options struct {
// Options contains configuration to access a s3 service
type Options struct {
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint"`
Region string `json:"region,omitempty" yaml:"region"`
DisableSSL bool `json:"disableSSL" yaml:"disableSSL"`
@@ -17,9 +17,9 @@ type S3Options struct {
Bucket string `json:"bucket,omitempty" yaml:"bucket"`
}
// NewS3Options creates a default disabled S3Options(empty endpoint)
func NewS3Options() *S3Options {
return &S3Options{
// NewS3Options creates a default disabled Options(empty endpoint)
func NewS3Options() *Options {
return &Options{
Endpoint: "",
Region: "us-east-1",
DisableSSL: true,
@@ -32,14 +32,14 @@ func NewS3Options() *S3Options {
}
// Validate check options values
func (s *S3Options) Validate() []error {
errors := []error{}
func (s *Options) Validate() []error {
var errors []error
return errors
}
// ApplyTo overrides options if it's valid, which endpoint is not empty
func (s *S3Options) ApplyTo(options *S3Options) {
func (s *Options) ApplyTo(options *Options) {
if s.Endpoint != "" {
reflectutils.Override(options, s)
}
@@ -47,23 +47,23 @@ func (s *S3Options) ApplyTo(options *S3Options) {
// 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, ""+
func (s *Options) AddFlags(fs *pflag.FlagSet, c *Options) {
fs.StringVar(&s.Endpoint, "s3-endpoint", c.Endpoint, ""+
"Endpoint to access to s3 object storage service, if left blank, the following options "+
"will be ignored.")
fs.StringVar(&s.Region, "s3-region", s.Region, ""+
fs.StringVar(&s.Region, "s3-region", c.Region, ""+
"Region of s3 that will access to, like us-east-1.")
fs.StringVar(&s.AccessKeyID, "s3-access-key-id", s.AccessKeyID, "access key of s2i s3")
fs.StringVar(&s.AccessKeyID, "s3-access-key-id", c.AccessKeyID, "access key of s2i s3")
fs.StringVar(&s.SecretAccessKey, "s3-secret-access-key", s.SecretAccessKey, "secret access key of s2i s3")
fs.StringVar(&s.SecretAccessKey, "s3-secret-access-key", c.SecretAccessKey, "secret access key of s2i s3")
fs.StringVar(&s.SessionToken, "s3-session-token", s.SessionToken, "session token of s2i s3")
fs.StringVar(&s.SessionToken, "s3-session-token", c.SessionToken, "session token of s2i s3")
fs.StringVar(&s.Bucket, "s3-bucket", s.Bucket, "bucket name of s2i s3")
fs.StringVar(&s.Bucket, "s3-bucket", c.Bucket, "bucket name of s2i s3")
fs.BoolVar(&s.DisableSSL, "s3-disable-SSL", s.DisableSSL, "disable ssl")
fs.BoolVar(&s.DisableSSL, "s3-disable-SSL", c.DisableSSL, "disable ssl")
fs.BoolVar(&s.ForcePathStyle, "s3-force-path-style", s.ForcePathStyle, "force path style")
fs.BoolVar(&s.ForcePathStyle, "s3-force-path-style", c.ForcePathStyle, "force path style")
}

View File

@@ -1,20 +1,34 @@
package s2is3
package s3
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"io"
"k8s.io/klog"
"time"
)
type S3Client struct {
type Client struct {
s3Client *s3.S3
s3Session *session.Session
bucket string
}
func NewS3Client(options *S3Options) (*S3Client, error) {
func (s *Client) Upload(key string, body io.Reader) (string, error) {
panic("implement me")
}
func (s *Client) Get(key string, fileName string, expire time.Duration) (string, error) {
panic("implement me")
}
func (s *Client) Delete(key string) error {
panic("implement me")
}
func NewS3Client(options *Options) (Interface, error) {
cred := credentials.NewStaticCredentials(options.AccessKeyID, options.SecretAccessKey, options.SessionToken)
config := aws.Config{
@@ -31,7 +45,7 @@ func NewS3Client(options *S3Options) (*S3Client, error) {
return nil, err
}
var c S3Client
var c Client
c.s3Client = s3.New(s)
c.s3Session = s
@@ -40,8 +54,8 @@ func NewS3Client(options *S3Options) (*S3Client, error) {
return &c, nil
}
// NewS3ClientOrDie creates S3Client and panics if there is an error
func NewS3ClientOrDie(options *S3Options) *S3Client {
// NewS3ClientOrDie creates Client and panics if there is an error
func NewS3ClientOrDie(options *Options) Interface {
cred := credentials.NewStaticCredentials(options.AccessKeyID, options.SecretAccessKey, options.SessionToken)
config := aws.Config{
@@ -59,21 +73,21 @@ func NewS3ClientOrDie(options *S3Options) *S3Client {
client := s3.New(s)
return &S3Client{
return &Client{
s3Client: client,
s3Session: s,
bucket: options.Bucket,
}
}
func (s *S3Client) Client() *s3.S3 {
func (s *Client) Client() *s3.S3 {
return s.s3Client
}
func (s *S3Client) Session() *session.Session {
func (s *Client) Session() *session.Session {
return s.s3Session
}
func (s *S3Client) Bucket() *string {
func (s *Client) Bucket() *string {
return aws.String(s.bucket)
}

View File

@@ -2,7 +2,7 @@ package servicemesh
import "github.com/spf13/pflag"
type ServiceMeshOptions struct {
type Options struct {
// istio pilot discovery service url
IstioPilotHost string `json:"istioPilotHost,omitempty" yaml:"istioPilotHost"`
@@ -15,21 +15,21 @@ type ServiceMeshOptions struct {
}
// NewServiceMeshOptions returns a `zero` instance
func NewServiceMeshOptions() *ServiceMeshOptions {
return &ServiceMeshOptions{
func NewServiceMeshOptions() *Options {
return &Options{
IstioPilotHost: "",
JaegerQueryHost: "",
ServicemeshPrometheusHost: "",
}
}
func (s *ServiceMeshOptions) Validate() []error {
func (s *Options) Validate() []error {
errors := []error{}
return errors
}
func (s *ServiceMeshOptions) ApplyTo(options *ServiceMeshOptions) {
func (s *Options) ApplyTo(options *Options) {
if s.ServicemeshPrometheusHost != "" {
options.ServicemeshPrometheusHost = s.ServicemeshPrometheusHost
}
@@ -43,13 +43,13 @@ func (s *ServiceMeshOptions) ApplyTo(options *ServiceMeshOptions) {
}
}
func (s *ServiceMeshOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&s.IstioPilotHost, "istio-pilot-host", s.IstioPilotHost, ""+
func (s *Options) AddFlags(fs *pflag.FlagSet, c *Options) {
fs.StringVar(&s.IstioPilotHost, "istio-pilot-host", c.IstioPilotHost, ""+
"istio pilot discovery service url")
fs.StringVar(&s.JaegerQueryHost, "jaeger-query-host", s.JaegerQueryHost, ""+
fs.StringVar(&s.JaegerQueryHost, "jaeger-query-host", c.JaegerQueryHost, ""+
"jaeger query service url")
fs.StringVar(&s.ServicemeshPrometheusHost, "servicemesh-prometheus-host", s.ServicemeshPrometheusHost, ""+
fs.StringVar(&s.ServicemeshPrometheusHost, "servicemesh-prometheus-host", c.ServicemeshPrometheusHost, ""+
"prometheus service for servicemesh")
}

View File

@@ -0,0 +1,8 @@
package sonarqube
type Interface interface {
//
GetIssues()
//
}

View File

@@ -4,39 +4,35 @@ import (
"github.com/spf13/pflag"
)
type SonarQubeOptions struct {
type Options struct {
Host string `json:",omitempty" yaml:"host" description:"SonarQube service host address"`
Token string `json:",omitempty" yaml:"token" description:"SonarQube service token"`
}
func NewSonarQubeOptions() *SonarQubeOptions {
return &SonarQubeOptions{
func NewSonarQubeOptions() *Options {
return &Options{
Host: "",
Token: "",
}
}
func NewDefaultSonarQubeOptions() *SonarQubeOptions {
return NewSonarQubeOptions()
}
func (s *SonarQubeOptions) Validate() []error {
errors := []error{}
func (s *Options) Validate() []error {
var errors []error
return errors
}
func (s *SonarQubeOptions) ApplyTo(options *SonarQubeOptions) {
func (s *Options) ApplyTo(options *Options) {
if s.Host != "" {
options.Host = s.Host
options.Token = s.Token
}
}
func (s *SonarQubeOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&s.Host, "sonarqube-host", s.Host, ""+
func (s *Options) AddFlags(fs *pflag.FlagSet, c *Options) {
fs.StringVar(&s.Host, "sonarqube-host", c.Host, ""+
"Sonarqube service address, if left empty, following sonarqube options will be ignored.")
fs.StringVar(&s.Token, "sonarqube-token", s.Token, ""+
fs.StringVar(&s.Token, "sonarqube-token", c.Token, ""+
"Sonarqube service access token.")
}

View File

@@ -7,11 +7,11 @@ import (
"strings"
)
type SonarQubeClient struct {
type Client struct {
client *sonargo.Client
}
func NewSonarQubeClient(options *SonarQubeOptions) (*SonarQubeClient, error) {
func NewSonarQubeClient(options *Options) (*Client, error) {
var endpoint string
if strings.HasSuffix(options.Host, "/") {
@@ -26,10 +26,10 @@ func NewSonarQubeClient(options *SonarQubeOptions) (*SonarQubeClient, error) {
return nil, err
}
return &SonarQubeClient{client: sonar}, err
return &Client{client: sonar}, err
}
func NewSonarQubeClientOrDie(options *SonarQubeOptions) *SonarQubeClient {
func NewSonarQubeClientOrDie(options *Options) *Client {
var endpoint string
if strings.HasSuffix(options.Host, "/") {
@@ -44,11 +44,11 @@ func NewSonarQubeClientOrDie(options *SonarQubeOptions) *SonarQubeClient {
panic(err)
}
return &SonarQubeClient{client: sonar}
return &Client{client: sonar}
}
// return sonarqube client
// Also we can wrap some methods to avoid direct use sonar client
func (s *SonarQubeClient) SonarQube() *sonargo.Client {
func (s *Client) SonarQube() *sonargo.Client {
return s.client
}