refactor: remove usless options (#5671)

refactor: remove useless options
This commit is contained in:
hongming
2023-05-10 14:01:46 +08:00
committed by GitHub
parent e140fb387c
commit fafe98b4f0
13 changed files with 208 additions and 106 deletions

View File

@@ -107,7 +107,6 @@ import (
"kubesphere.io/kubesphere/pkg/simple/client/k8s"
"kubesphere.io/kubesphere/pkg/simple/client/logging"
"kubesphere.io/kubesphere/pkg/simple/client/monitoring"
"kubesphere.io/kubesphere/pkg/simple/client/s3"
"kubesphere.io/kubesphere/pkg/simple/client/sonarqube"
"kubesphere.io/kubesphere/pkg/utils/clusterclient"
"kubesphere.io/kubesphere/pkg/utils/iputil"
@@ -146,8 +145,6 @@ type APIServer struct {
DevopsClient devops.Interface
S3Client s3.Interface
SonarClient sonarqube.SonarInterface
EventsClient events.Client

View File

@@ -39,13 +39,13 @@ type Interface interface {
// 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 deletes the given key, no error returned if the key doesn't exist
Del(keys ...string) error
// Exists checks the existence of a give key
Exists(keys ...string) (bool, error)
// Expires updates object's expiration time, return err if key doesn't exist
// Expire updates object's expiration time, return err if key doesn't exist
Expire(key string, duration time.Duration) error
}
@@ -60,6 +60,10 @@ func New(option *Options, stopCh <-chan struct{}) (Interface, error) {
return nil, err
}
if option.Type == TypeInMemoryCache {
klog.Warning("In-memory cache will be used, this may cause data inconsistencies when running with multiple replicas.")
}
cache, err := cacheFactories[option.Type].Create(option.Options, stopCh)
if err != nil {
klog.Errorf("failed to create cache, error: %v", err)

View File

@@ -32,9 +32,7 @@ import (
var ErrNoSuchKey = errors.New("no such key")
const (
typeInMemoryCache = "InMemoryCache"
DefaultCacheType = typeInMemoryCache
TypeInMemoryCache = "InMemoryCache"
defaultCleanupPeriod = 2 * time.Hour
)
@@ -176,12 +174,11 @@ type inMemoryCacheFactory struct {
}
func (sf *inMemoryCacheFactory) Type() string {
return typeInMemoryCache
return TypeInMemoryCache
}
func (sf *inMemoryCacheFactory) Create(options options.DynamicOptions, stopCh <-chan struct{}) (Interface, error) {
var sOptions InMemoryCacheOptions
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
DecodeHook: mapstructure.StringToTimeDurationHookFunc(),
WeaklyTypedInput: true,

View File

@@ -31,7 +31,7 @@ type Options struct {
// because redis is not required for some components
func NewCacheOptions() *Options {
return &Options{
Type: "",
Type: TypeInMemoryCache,
Options: map[string]interface{}{},
}
}

View File

@@ -22,6 +22,8 @@ import (
"math"
"time"
fakes3 "kubesphere.io/kubesphere/pkg/simple/client/s3/fake"
"code.cloudfoundry.org/bytefmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
@@ -44,6 +46,8 @@ const (
MinConcurrency = 5
// MaxConcurrency is the maximum concurrency to limit the goroutines.
MaxConcurrency = 128
fakeS3Host = "FAKE"
)
// calculateConcurrency calculates the concurrency for better performance,
@@ -120,6 +124,10 @@ func (s *Client) Delete(key string) error {
}
func NewS3Client(options *Options) (Interface, error) {
if options.Endpoint == fakeS3Host {
return fakes3.NewFakeS3(), nil
}
cred := credentials.NewStaticCredentials(options.AccessKeyID, options.SecretAccessKey, options.SessionToken)
config := aws.Config{