refactor code structure (#1738)
This commit is contained in:
39
pkg/simple/client/cache/cache.go
vendored
39
pkg/simple/client/cache/cache.go
vendored
@@ -20,41 +20,4 @@ type Interface interface {
|
||||
|
||||
// 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")
|
||||
}
|
||||
}
|
||||
40
pkg/simple/client/cache/simple_cache.go
vendored
Normal file
40
pkg/simple/client/cache/simple_cache.go
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
package cache
|
||||
|
||||
import "time"
|
||||
|
||||
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")
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package devops
|
||||
|
||||
type Job struct {
|
||||
|
||||
}
|
||||
|
||||
type Interface interface {
|
||||
|
||||
39
pkg/simple/client/monitoring/interface.go
Normal file
39
pkg/simple/client/monitoring/interface.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package monitoring
|
||||
|
||||
|
||||
type ClusterQuery struct {
|
||||
|
||||
}
|
||||
|
||||
type ClusterMetrics struct {
|
||||
|
||||
}
|
||||
|
||||
type WorkspaceQuery struct {
|
||||
|
||||
}
|
||||
|
||||
type WorkspaceMetrics struct {
|
||||
|
||||
}
|
||||
|
||||
type NamespaceQuery struct {
|
||||
|
||||
}
|
||||
|
||||
type NamespaceMetrics struct {
|
||||
|
||||
}
|
||||
|
||||
// Interface defines all the abstract behaviors of monitoring
|
||||
type Interface interface {
|
||||
|
||||
// Get
|
||||
GetClusterMetrics(query ClusterQuery) ClusterMetrics
|
||||
|
||||
//
|
||||
GetWorkspaceMetrics(query WorkspaceQuery) WorkspaceMetrics
|
||||
|
||||
//
|
||||
GetNamespaceMetrics(query NamespaceQuery) NamespaceMetrics
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package monitoring
|
||||
|
||||
type Interface interface {
|
||||
}
|
||||
31
pkg/simple/client/monitoring/prometheus.go
Normal file
31
pkg/simple/client/monitoring/prometheus.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// prometheus implements monitoring interface backed by Prometheus
|
||||
type prometheus struct {
|
||||
options *Options
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
func NewPrometheus(options *Options) Interface {
|
||||
return &prometheus{
|
||||
options:options,
|
||||
client: &http.Client{ Timeout: 10 * time.Second },
|
||||
}
|
||||
}
|
||||
|
||||
func (p prometheus) GetClusterMetrics(query ClusterQuery) ClusterMetrics {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (p prometheus) GetWorkspaceMetrics(query WorkspaceQuery) WorkspaceMetrics {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (p prometheus) GetNamespaceMetrics(query NamespaceQuery) NamespaceMetrics {
|
||||
panic("implement me")
|
||||
}
|
||||
41
pkg/simple/client/monitoring/prometheus_options.go
Normal file
41
pkg/simple/client/monitoring/prometheus_options.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint"`
|
||||
SecondaryEndpoint string `json:"secondaryEndpoint,omitempty" yaml:"secondaryEndpoint"`
|
||||
}
|
||||
|
||||
func NewPrometheusOptions() *Options {
|
||||
return &Options{
|
||||
Endpoint: "",
|
||||
SecondaryEndpoint: "",
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Options) Validate() []error {
|
||||
var errs []error
|
||||
return errs
|
||||
}
|
||||
|
||||
func (s *Options) ApplyTo(options *Options) {
|
||||
if s.Endpoint != "" {
|
||||
options.Endpoint = s.Endpoint
|
||||
}
|
||||
|
||||
if s.SecondaryEndpoint != "" {
|
||||
options.SecondaryEndpoint = s.SecondaryEndpoint
|
||||
}
|
||||
}
|
||||
|
||||
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", c.SecondaryEndpoint, ""+
|
||||
"Prometheus secondary service endpoint, if left empty and endpoint is set, will use endpoint instead.")
|
||||
}
|
||||
1
pkg/simple/client/monitoring/prometheus_test.go
Normal file
1
pkg/simple/client/monitoring/prometheus_test.go
Normal file
@@ -0,0 +1 @@
|
||||
package monitoring
|
||||
@@ -27,8 +27,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Interface interface {
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
client *http.Client
|
||||
|
||||
@@ -54,32 +54,6 @@ func NewS3Client(options *Options) (Interface, error) {
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
// 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{
|
||||
Region: aws.String(options.Region),
|
||||
Endpoint: aws.String(options.Endpoint),
|
||||
DisableSSL: aws.Bool(options.DisableSSL),
|
||||
S3ForcePathStyle: aws.Bool(options.ForcePathStyle),
|
||||
Credentials: cred,
|
||||
}
|
||||
|
||||
s, err := session.NewSession(&config)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := s3.New(s)
|
||||
|
||||
return &Client{
|
||||
s3Client: client,
|
||||
s3Session: s,
|
||||
bucket: options.Bucket,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Client) Client() *s3.S3 {
|
||||
|
||||
return s.s3Client
|
||||
|
||||
Reference in New Issue
Block a user