This is an automated email from the ASF dual-hosted git repository.

zhongxjian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-kubernetes.git


The following commit(s) were added to refs/heads/master by this push:
     new b6015535 [operator] Supplementing the logic of the client factory
b6015535 is described below

commit b6015535ae7176fe69940adcbfe3f61b36962a39
Author: mfordjody <[email protected]>
AuthorDate: Wed Dec 11 11:28:22 2024 +0800

    [operator] Supplementing the logic of the client factory
---
 pkg/kube/client.go         |  3 ++-
 pkg/kube/client_factory.go | 13 ++++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/pkg/kube/client.go b/pkg/kube/client.go
index ef0955eb..21a532ac 100644
--- a/pkg/kube/client.go
+++ b/pkg/kube/client.go
@@ -32,7 +32,7 @@ type CLIClient interface {
 type ClientOption func(cliClient CLIClient) CLIClient
 
 func NewCLIClient(clientCfg clientcmd.ClientConfig, opts ...ClientOption) 
(CLIClient, error) {
-       return nil, nil
+       return newInternalClient(newClientFactory(clientCfg, true), opts...)
 }
 
 func newInternalClient(factory *clientFactory, opts ...ClientOption) 
(CLIClient, error) {
@@ -46,6 +46,7 @@ func newInternalClient(factory *clientFactory, opts 
...ClientOption) (CLIClient,
        for _, opt := range opts {
                opt(&c)
        }
+
        return nil, err
 }
 
diff --git a/pkg/kube/client_factory.go b/pkg/kube/client_factory.go
index 5d9e544e..a615571c 100644
--- a/pkg/kube/client_factory.go
+++ b/pkg/kube/client_factory.go
@@ -11,6 +11,8 @@ import (
        "k8s.io/client-go/tools/clientcmd"
        "k8s.io/client-go/util/homedir"
        "path/filepath"
+       "regexp"
+       "strings"
        "time"
 )
 
@@ -32,7 +34,8 @@ func newClientFactory(clientConfig clientcmd.ClientConfig, 
diskCache bool) *clie
                if diskCache {
                        cacheDir := filepath.Join(homedir.HomeDir(), ".kube", 
"cache")
                        httpCacheDir := filepath.Join(cacheDir, "http")
-                       return 
diskcached.NewCachedDiscoveryClientForConfig(restConfig, nil, httpCacheDir, 
6*time.Hour)
+                       discoveryCacheDir := 
computeDiscoverCacheDir(filepath.Join(cacheDir, "discovery"), restConfig.Host)
+                       return 
diskcached.NewCachedDiscoveryClientForConfig(restConfig, discoveryCacheDir, 
httpCacheDir, 6*time.Hour)
                }
                d, err := discovery.NewDiscoveryClientForConfig(restConfig)
                if err != nil {
@@ -61,3 +64,11 @@ func (c *clientFactory) ToRestConfig() (*rest.Config, error) 
{
        }
        return SetRestDefaults(restConfig), nil
 }
+
+var overlyCautiousIllegalFileCharacters = regexp.MustCompile(`[^(\w/.)]`)
+
+func computeDiscoverCacheDir(dir, host string) string {
+       schemelesshost := strings.Replace(strings.Replace(host, "https://";, "", 
1), "http://";, "", 1)
+       safehost := 
overlyCautiousIllegalFileCharacters.ReplaceAllString(schemelesshost, "_")
+       return filepath.Join(dir, safehost)
+}

Reply via email to