From aff4595b183da238d1ca98a10479a8aaaca64ab0 Mon Sep 17 00:00:00 2001 From: junfengP Date: Mon, 13 Nov 2023 10:20:58 +0800 Subject: [PATCH] feat: isolate nacos-sdk-go into pkg/nacos/client/impl (#9) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 限制nacos sdk引用在pkg/nacos/client/impl包下 --- cmd/main.go | 6 +- .../dynamicconfiguration_controller_test.go | 7 +- pkg/nacos/auth/auth_manager.go | 95 ---------- pkg/nacos/auth/auth_provider.go | 24 ++- pkg/nacos/client/config_client.go | 46 +++++ pkg/nacos/client/impl/default_client.go | 171 ++++++++++++++++++ pkg/nacos/config/config_client.go | 108 ----------- pkg/nacos/nacos_controller.go | 31 ++-- 8 files changed, 257 insertions(+), 231 deletions(-) delete mode 100644 pkg/nacos/auth/auth_manager.go create mode 100644 pkg/nacos/client/config_client.go create mode 100644 pkg/nacos/client/impl/default_client.go delete mode 100644 pkg/nacos/config/config_client.go diff --git a/cmd/main.go b/cmd/main.go index 3533077..0615508 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -19,6 +19,8 @@ package main import ( "flag" "github.com/nacos-group/nacos-controller/pkg/nacos" + "github.com/nacos-group/nacos-controller/pkg/nacos/auth" + "github.com/nacos-group/nacos-controller/pkg/nacos/client/impl" "os" // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.) @@ -92,7 +94,9 @@ func main() { os.Exit(1) } - if err = controller.NewDynamicConfigurationReconciler(mgr.GetClient(), mgr.GetScheme(), nacos.SyncConfigOptions{}).SetupWithManager(mgr); err != nil { + if err = controller.NewDynamicConfigurationReconciler(mgr.GetClient(), mgr.GetScheme(), nacos.SyncConfigOptions{ + ConfigClient: impl.NewDefaultNacosConfigClient(auth.NewDefaultNacosAuthProvider(mgr.GetClient())), + }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "DynamicConfiguration") os.Exit(1) } diff --git a/pkg/controller/dynamicconfiguration_controller_test.go b/pkg/controller/dynamicconfiguration_controller_test.go index 2300d22..55489ab 100644 --- a/pkg/controller/dynamicconfiguration_controller_test.go +++ b/pkg/controller/dynamicconfiguration_controller_test.go @@ -4,6 +4,7 @@ import ( "fmt" v12 "github.com/nacos-group/nacos-controller/api/v1" "github.com/nacos-group/nacos-controller/pkg/nacos/auth" + "github.com/nacos-group/nacos-controller/pkg/nacos/client/impl" "github.com/nacos-group/nacos-sdk-go/v2/vo" . "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" @@ -391,7 +392,7 @@ func checkDynamicConfigurationStatus(dc *v12.DynamicConfiguration) { } func getContentByDataId(dc *v12.DynamicConfiguration) (string, bool) { - configClient, err := auth.GetNacosAuthManger().GetNacosConfigClient(&auth.DefaultNaocsAuthProvider{Client: k8sClient}, dc) + configClient, err := impl.GetNacosClientBuilder().Build(&auth.DefaultNacosAuthProvider{Client: k8sClient}, dc) gomega.Expect(err).NotTo(gomega.HaveOccurred()) content, err := configClient.GetConfig(vo.ConfigParam{ Group: dc.Spec.NacosServer.Group, @@ -402,7 +403,7 @@ func getContentByDataId(dc *v12.DynamicConfiguration) (string, bool) { } func createOrUpdateContentInNaocs(dc *v12.DynamicConfiguration, dataId, content string) { - configClient, err := auth.GetNacosAuthManger().GetNacosConfigClient(&auth.DefaultNaocsAuthProvider{Client: k8sClient}, dc) + configClient, err := impl.GetNacosClientBuilder().Build(&auth.DefaultNacosAuthProvider{Client: k8sClient}, dc) gomega.Expect(err).NotTo(gomega.HaveOccurred()) serverContent, err := configClient.GetConfig(vo.ConfigParam{ Group: dc.Spec.NacosServer.Group, @@ -420,7 +421,7 @@ func createOrUpdateContentInNaocs(dc *v12.DynamicConfiguration, dataId, content } func deleteDataIdInNaocs(dc *v12.DynamicConfiguration, dataId string) { - configClient, err := auth.GetNacosAuthManger().GetNacosConfigClient(&auth.DefaultNaocsAuthProvider{Client: k8sClient}, dc) + configClient, err := impl.GetNacosClientBuilder().Build(&auth.DefaultNacosAuthProvider{Client: k8sClient}, dc) gomega.Expect(err).NotTo(gomega.HaveOccurred()) _, err = configClient.DeleteConfig(vo.ConfigParam{ Group: dc.Spec.NacosServer.Group, diff --git a/pkg/nacos/auth/auth_manager.go b/pkg/nacos/auth/auth_manager.go deleted file mode 100644 index 6a5ca91..0000000 --- a/pkg/nacos/auth/auth_manager.go +++ /dev/null @@ -1,95 +0,0 @@ -package auth - -import ( - "fmt" - nacosiov1 "github.com/nacos-group/nacos-controller/api/v1" - "github.com/nacos-group/nacos-sdk-go/v2/clients" - "github.com/nacos-group/nacos-sdk-go/v2/clients/config_client" - "github.com/nacos-group/nacos-sdk-go/v2/common/constant" - "github.com/nacos-group/nacos-sdk-go/v2/vo" - "strconv" - "strings" - "sync" -) - -type NacosAuthManager struct { - cache sync.Map -} - -type ConfigClientParam struct { - Endpoint string - ServerAddr string - Namespace string - AuthInfo ConfigClientAuthInfo -} - -type ConfigClientAuthInfo struct { - AccessKey string - SecretKey string -} - -var manager = NacosAuthManager{ - cache: sync.Map{}, -} - -func GetNacosAuthManger() *NacosAuthManager { - return &manager -} - -func (m *NacosAuthManager) GetNacosConfigClient(authProvider NacosAuthProvider, dc *nacosiov1.DynamicConfiguration) (config_client.IConfigClient, error) { - if dc == nil { - return nil, fmt.Errorf("empty DynamicConfiguration") - } - nacosServer := dc.Spec.NacosServer - // 简化判空逻辑,cacheKey仅内部使用 - cacheKey := fmt.Sprintf("%s-%s-%s", nacosServer.Endpoint, nacosServer.ServerAddr, nacosServer.Namespace) - cachedClient, ok := m.cache.Load(cacheKey) - if ok && cachedClient != nil { - return cachedClient.(config_client.IConfigClient), nil - } - clientParams, err := authProvider.GetNacosClientParams(dc) - if err != nil { - return nil, err - } - var sc []constant.ServerConfig - clientOpts := []constant.ClientOption{ - constant.WithAccessKey(clientParams.AuthInfo.AccessKey), - constant.WithSecretKey(clientParams.AuthInfo.SecretKey), - constant.WithTimeoutMs(5000), - constant.WithNotLoadCacheAtStart(true), - constant.WithLogDir("/tmp/nacos/log"), - constant.WithCacheDir("/tmp/nacos/cache"), - constant.WithLogLevel("debug"), - constant.WithNamespaceId(clientParams.Namespace), - } - if len(clientParams.Endpoint) > 0 { - clientOpts = append(clientOpts, constant.WithEndpoint(clientParams.Endpoint)) - } else if len(clientParams.ServerAddr) > 0 { - port := 8848 - ip := clientParams.ServerAddr - if strings.Contains(ip, ":") { - split := strings.Split(ip, ":") - ip = split[0] - if v, err := strconv.Atoi(split[1]); err != nil { - return nil, fmt.Errorf("invalid ServerAddr: %s", clientParams.ServerAddr) - } else { - port = v - } - - } - sc = []constant.ServerConfig{ - *constant.NewServerConfig(ip, uint64(port)), - } - } - cc := *constant.NewClientConfig(clientOpts...) - configClient, err := clients.NewConfigClient( - vo.NacosClientParam{ - ClientConfig: &cc, - ServerConfigs: sc, - }) - if err != nil { - return nil, err - } - m.cache.Store(cacheKey, configClient) - return configClient, nil -} diff --git a/pkg/nacos/auth/auth_provider.go b/pkg/nacos/auth/auth_provider.go index 21b3411..9426d11 100644 --- a/pkg/nacos/auth/auth_provider.go +++ b/pkg/nacos/auth/auth_provider.go @@ -19,15 +19,31 @@ var ( secretGVK = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Secret"} ) +type ConfigClientParam struct { + Endpoint string + ServerAddr string + Namespace string + AuthInfo ConfigClientAuthInfo +} + +type ConfigClientAuthInfo struct { + AccessKey string + SecretKey string +} + type NacosAuthProvider interface { GetNacosClientParams(*nacosiov1.DynamicConfiguration) (*ConfigClientParam, error) } -type DefaultNaocsAuthProvider struct { +type DefaultNacosAuthProvider struct { client.Client } -func (p *DefaultNaocsAuthProvider) GetNacosClientParams(dc *nacosiov1.DynamicConfiguration) (*ConfigClientParam, error) { +func NewDefaultNacosAuthProvider(c client.Client) NacosAuthProvider { + return &DefaultNacosAuthProvider{Client: c} +} + +func (p *DefaultNacosAuthProvider) GetNacosClientParams(dc *nacosiov1.DynamicConfiguration) (*ConfigClientParam, error) { if dc == nil { return nil, fmt.Errorf("empty DynamicConfiguration") } @@ -56,7 +72,7 @@ func (p *DefaultNaocsAuthProvider) GetNacosClientParams(dc *nacosiov1.DynamicCon return nil, fmt.Errorf("either endpoint or serverAddr should be set") } -func (p *DefaultNaocsAuthProvider) getNacosAuthInfo(obj *v1.ObjectReference) (*ConfigClientAuthInfo, error) { +func (p *DefaultNacosAuthProvider) getNacosAuthInfo(obj *v1.ObjectReference) (*ConfigClientAuthInfo, error) { switch obj.GroupVersionKind().String() { case secretGVK.String(): return p.getNaocsAuthFromSecret(obj) @@ -65,7 +81,7 @@ func (p *DefaultNaocsAuthProvider) getNacosAuthInfo(obj *v1.ObjectReference) (*C } } -func (p *DefaultNaocsAuthProvider) getNaocsAuthFromSecret(obj *v1.ObjectReference) (*ConfigClientAuthInfo, error) { +func (p *DefaultNacosAuthProvider) getNaocsAuthFromSecret(obj *v1.ObjectReference) (*ConfigClientAuthInfo, error) { s := v1.Secret{} err := p.Get(context.TODO(), types.NamespacedName{Namespace: obj.Namespace, Name: obj.Name}, &s) if err != nil { diff --git a/pkg/nacos/client/config_client.go b/pkg/nacos/client/config_client.go new file mode 100644 index 0000000..30e8b83 --- /dev/null +++ b/pkg/nacos/client/config_client.go @@ -0,0 +1,46 @@ +package client + +import ( + nacosv1 "github.com/nacos-group/nacos-controller/api/v1" + "sync" +) + +var _defaultClient NacosConfigClient +var _lock = sync.Mutex{} + +func RegisterNacosClientIfAbsent(c NacosConfigClient) { + _lock.Lock() + defer _lock.Unlock() + if _defaultClient == nil { + _defaultClient = c + } +} + +func RegisterNacosClient(c NacosConfigClient) { + _lock.Lock() + defer _lock.Unlock() + _defaultClient = c +} + +func GetDefaultNacosClient() NacosConfigClient { + if _defaultClient == nil { + panic("No default NacosConfigClient registered") + } + return _defaultClient +} + +type NacosConfigClient interface { + GetConfig(param NacosConfigParam) (string, error) + PublishConfig(param NacosConfigParam) (bool, error) + DeleteConfig(param NacosConfigParam) (bool, error) + ListenConfig(param NacosConfigParam) error + CancelListenConfig(param NacosConfigParam) error +} + +type NacosConfigParam struct { + DynamicConfiguration *nacosv1.DynamicConfiguration + DataId string + Group string + Content string + OnChange func(namespace, group, dataId, data string) +} diff --git a/pkg/nacos/client/impl/default_client.go b/pkg/nacos/client/impl/default_client.go new file mode 100644 index 0000000..44abe8c --- /dev/null +++ b/pkg/nacos/client/impl/default_client.go @@ -0,0 +1,171 @@ +package impl + +import ( + "errors" + "fmt" + nacosiov1 "github.com/nacos-group/nacos-controller/api/v1" + "github.com/nacos-group/nacos-controller/pkg/nacos/auth" + "github.com/nacos-group/nacos-controller/pkg/nacos/client" + "github.com/nacos-group/nacos-sdk-go/v2/clients" + "github.com/nacos-group/nacos-sdk-go/v2/clients/config_client" + "github.com/nacos-group/nacos-sdk-go/v2/common/constant" + "github.com/nacos-group/nacos-sdk-go/v2/vo" + "strconv" + "strings" + "sync" +) + +type ClientBuilder struct { + cache sync.Map +} + +var builder = ClientBuilder{ + cache: sync.Map{}, +} + +func GetNacosClientBuilder() *ClientBuilder { + return &builder +} + +func (m *ClientBuilder) Build(authProvider auth.NacosAuthProvider, dc *nacosiov1.DynamicConfiguration) (config_client.IConfigClient, error) { + if dc == nil { + return nil, fmt.Errorf("empty DynamicConfiguration") + } + nacosServer := dc.Spec.NacosServer + // 简化判空逻辑,cacheKey仅内部使用 + cacheKey := fmt.Sprintf("%s-%s-%s", nacosServer.Endpoint, nacosServer.ServerAddr, nacosServer.Namespace) + cachedClient, ok := m.cache.Load(cacheKey) + if ok && cachedClient != nil { + return cachedClient.(config_client.IConfigClient), nil + } + clientParams, err := authProvider.GetNacosClientParams(dc) + if err != nil { + return nil, err + } + var sc []constant.ServerConfig + clientOpts := []constant.ClientOption{ + constant.WithAccessKey(clientParams.AuthInfo.AccessKey), + constant.WithSecretKey(clientParams.AuthInfo.SecretKey), + constant.WithTimeoutMs(5000), + constant.WithNotLoadCacheAtStart(true), + constant.WithLogDir("/tmp/nacos/log"), + constant.WithCacheDir("/tmp/nacos/cache"), + constant.WithLogLevel("debug"), + constant.WithNamespaceId(clientParams.Namespace), + } + if len(clientParams.Endpoint) > 0 { + clientOpts = append(clientOpts, constant.WithEndpoint(clientParams.Endpoint)) + } else if len(clientParams.ServerAddr) > 0 { + port := 8848 + ip := clientParams.ServerAddr + if strings.Contains(ip, ":") { + split := strings.Split(ip, ":") + ip = split[0] + if v, err := strconv.Atoi(split[1]); err != nil { + return nil, fmt.Errorf("invalid ServerAddr: %s", clientParams.ServerAddr) + } else { + port = v + } + + } + sc = []constant.ServerConfig{ + *constant.NewServerConfig(ip, uint64(port)), + } + } + cc := *constant.NewClientConfig(clientOpts...) + configClient, err := clients.NewConfigClient( + vo.NacosClientParam{ + ClientConfig: &cc, + ServerConfigs: sc, + }) + if err != nil { + return nil, err + } + m.cache.Store(cacheKey, configClient) + return configClient, nil +} + +// DefaultNacosConfigClient 基于Nacos SDK GO 实现配置操作 +type DefaultNacosConfigClient struct { + authProvider auth.NacosAuthProvider + clientBuilder *ClientBuilder +} + +func (c *DefaultNacosConfigClient) CancelListenConfig(param client.NacosConfigParam) error { + if param.DynamicConfiguration == nil { + return errors.New("empty DynamicConfiguration") + } + proxyClient, err := c.clientBuilder.Build(c.authProvider, param.DynamicConfiguration) + if err != nil { + return err + } + return proxyClient.CancelListenConfig(vo.ConfigParam{ + Group: param.Group, + DataId: param.DataId, + }) +} + +func (c *DefaultNacosConfigClient) GetConfig(param client.NacosConfigParam) (string, error) { + if param.DynamicConfiguration == nil { + return "", errors.New("empty DynamicConfiguration") + } + proxyClient, err := c.clientBuilder.Build(c.authProvider, param.DynamicConfiguration) + if err != nil { + return "", err + } + return proxyClient.GetConfig(vo.ConfigParam{ + Group: param.Group, + DataId: param.DataId, + }) +} + +func (c *DefaultNacosConfigClient) PublishConfig(param client.NacosConfigParam) (bool, error) { + if param.DynamicConfiguration == nil { + return false, errors.New("empty DynamicConfiguration") + } + proxyClient, err := c.clientBuilder.Build(c.authProvider, param.DynamicConfiguration) + if err != nil { + return false, err + } + return proxyClient.PublishConfig(vo.ConfigParam{ + Group: param.Group, + DataId: param.DataId, + Content: param.Content, + }) +} + +func (c *DefaultNacosConfigClient) DeleteConfig(param client.NacosConfigParam) (bool, error) { + if param.DynamicConfiguration == nil { + return false, errors.New("empty DynamicConfiguration") + } + proxyClient, err := c.clientBuilder.Build(c.authProvider, param.DynamicConfiguration) + if err != nil { + return false, err + } + return proxyClient.DeleteConfig(vo.ConfigParam{ + Group: param.Group, + DataId: param.DataId, + }) +} + +func (c *DefaultNacosConfigClient) ListenConfig(param client.NacosConfigParam) error { + if param.DynamicConfiguration == nil { + return errors.New("empty DynamicConfiguration") + } + proxyClient, err := c.clientBuilder.Build(c.authProvider, param.DynamicConfiguration) + if err != nil { + return err + } + return proxyClient.ListenConfig(vo.ConfigParam{ + Group: param.Group, + DataId: param.DataId, + OnChange: param.OnChange, + }) +} + +func NewDefaultNacosConfigClient(p auth.NacosAuthProvider) client.NacosConfigClient { + return &DefaultNacosConfigClient{ + authProvider: p, + clientBuilder: GetNacosClientBuilder(), + } +} diff --git a/pkg/nacos/config/config_client.go b/pkg/nacos/config/config_client.go deleted file mode 100644 index 2008d4e..0000000 --- a/pkg/nacos/config/config_client.go +++ /dev/null @@ -1,108 +0,0 @@ -package config - -import ( - "errors" - nacosv1 "github.com/nacos-group/nacos-controller/api/v1" - "github.com/nacos-group/nacos-controller/pkg/nacos/auth" - "github.com/nacos-group/nacos-sdk-go/v2/vo" -) - -type NacosConfigClient interface { - GetConfig(param NacosConfigParam) (string, error) - PublishConfig(param NacosConfigParam) (bool, error) - DeleteConfig(param NacosConfigParam) (bool, error) - ListenConfig(param NacosConfigParam) error - CancelListenConfig(param NacosConfigParam) error -} - -type DefaultNacosConfigClient struct { - authProvider auth.NacosAuthProvider - authManager *auth.NacosAuthManager -} - -func (c *DefaultNacosConfigClient) CancelListenConfig(param NacosConfigParam) error { - if param.DynamicConfiguration == nil { - return errors.New("empty DynamicConfiguration") - } - proxyClient, err := c.authManager.GetNacosConfigClient(c.authProvider, param.DynamicConfiguration) - if err != nil { - return err - } - return proxyClient.CancelListenConfig(vo.ConfigParam{ - Group: param.Group, - DataId: param.DataId, - }) -} - -func (c *DefaultNacosConfigClient) GetConfig(param NacosConfigParam) (string, error) { - if param.DynamicConfiguration == nil { - return "", errors.New("empty DynamicConfiguration") - } - proxyClient, err := c.authManager.GetNacosConfigClient(c.authProvider, param.DynamicConfiguration) - if err != nil { - return "", err - } - return proxyClient.GetConfig(vo.ConfigParam{ - Group: param.Group, - DataId: param.DataId, - }) -} - -func (c *DefaultNacosConfigClient) PublishConfig(param NacosConfigParam) (bool, error) { - if param.DynamicConfiguration == nil { - return false, errors.New("empty DynamicConfiguration") - } - proxyClient, err := c.authManager.GetNacosConfigClient(c.authProvider, param.DynamicConfiguration) - if err != nil { - return false, err - } - return proxyClient.PublishConfig(vo.ConfigParam{ - Group: param.Group, - DataId: param.DataId, - Content: param.Content, - }) -} - -func (c *DefaultNacosConfigClient) DeleteConfig(param NacosConfigParam) (bool, error) { - if param.DynamicConfiguration == nil { - return false, errors.New("empty DynamicConfiguration") - } - proxyClient, err := c.authManager.GetNacosConfigClient(c.authProvider, param.DynamicConfiguration) - if err != nil { - return false, err - } - return proxyClient.DeleteConfig(vo.ConfigParam{ - Group: param.Group, - DataId: param.DataId, - }) -} - -func (c *DefaultNacosConfigClient) ListenConfig(param NacosConfigParam) error { - if param.DynamicConfiguration == nil { - return errors.New("empty DynamicConfiguration") - } - proxyClient, err := c.authManager.GetNacosConfigClient(c.authProvider, param.DynamicConfiguration) - if err != nil { - return err - } - return proxyClient.ListenConfig(vo.ConfigParam{ - Group: param.Group, - DataId: param.DataId, - OnChange: param.OnChange, - }) -} - -func NewDefaultNacosConfigClient(p auth.NacosAuthProvider, m *auth.NacosAuthManager) NacosConfigClient { - return &DefaultNacosConfigClient{ - authProvider: p, - authManager: m, - } -} - -type NacosConfigParam struct { - DynamicConfiguration *nacosv1.DynamicConfiguration - DataId string - Group string - Content string - OnChange func(namespace, group, dataId, data string) -} diff --git a/pkg/nacos/nacos_controller.go b/pkg/nacos/nacos_controller.go index ed7f7d3..c5dd8cc 100644 --- a/pkg/nacos/nacos_controller.go +++ b/pkg/nacos/nacos_controller.go @@ -4,8 +4,7 @@ import ( "context" "fmt" nacosiov1 "github.com/nacos-group/nacos-controller/api/v1" - "github.com/nacos-group/nacos-controller/pkg/nacos/auth" - "github.com/nacos-group/nacos-controller/pkg/nacos/config" + nacosclient "github.com/nacos-group/nacos-controller/pkg/nacos/client" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -18,28 +17,20 @@ type SyncConfigurationController struct { client.Client mappings *DataId2DCMappings locks *LockManager - configClient config.NacosConfigClient + configClient nacosclient.NacosConfigClient server2ClusterCallbackFn func(namespace, group, dataId, content string) } type SyncConfigOptions struct { - AuthManger *auth.NacosAuthManager - AuthProvider auth.NacosAuthProvider - ConfigClient config.NacosConfigClient + ConfigClient nacosclient.NacosConfigClient Callback Server2ClusterCallback Mappings *DataId2DCMappings Locks *LockManager } func NewSyncConfigurationController(c client.Client, opt SyncConfigOptions) *SyncConfigurationController { - if opt.AuthProvider == nil { - opt.AuthProvider = &auth.DefaultNaocsAuthProvider{Client: c} - } - if opt.AuthManger == nil { - opt.AuthManger = auth.GetNacosAuthManger() - } if opt.ConfigClient == nil { - opt.ConfigClient = config.NewDefaultNacosConfigClient(opt.AuthProvider, opt.AuthManger) + opt.ConfigClient = nacosclient.GetDefaultNacosClient() } if opt.Mappings == nil { opt.Mappings = NewDataId2DCMappings() @@ -107,7 +98,7 @@ func (scc *SyncConfigurationController) finalizeCluster2Server(ctx context.Conte group := dc.Spec.NacosServer.Group var errDataIdList []string for _, dataId := range dc.Spec.DataIds { - _, err := scc.configClient.DeleteConfig(config.NacosConfigParam{ + _, err := scc.configClient.DeleteConfig(nacosclient.NacosConfigParam{ DynamicConfiguration: dc, Group: group, DataId: dataId, @@ -163,7 +154,7 @@ func (scc *SyncConfigurationController) syncCluster2Server(ctx context.Context, if !exist { // If dataId is not exist in cluster, and syncDeletion is true. Then we delete dataId in nacos server. if dc.Spec.Strategy.SyncDeletion { - _, err := scc.configClient.DeleteConfig(config.NacosConfigParam{ + _, err := scc.configClient.DeleteConfig(nacosclient.NacosConfigParam{ DynamicConfiguration: dc, Group: group, DataId: dataId, @@ -181,7 +172,7 @@ func (scc *SyncConfigurationController) syncCluster2Server(ctx context.Context, } // If syncPolicy is IfAbsent, then we check the dataId in nacos server first if dc.Spec.Strategy.SyncPolicy == nacosiov1.IfAbsent { - conf, err := scc.configClient.GetConfig(config.NacosConfigParam{ + conf, err := scc.configClient.GetConfig(nacosclient.NacosConfigParam{ DynamicConfiguration: dc, Group: group, DataId: dataId, @@ -202,7 +193,7 @@ func (scc *SyncConfigurationController) syncCluster2Server(ctx context.Context, continue } } - _, err = scc.configClient.PublishConfig(config.NacosConfigParam{ + _, err = scc.configClient.PublishConfig(nacosclient.NacosConfigParam{ DynamicConfiguration: dc, DataId: dataId, Group: group, @@ -268,7 +259,7 @@ func (scc *SyncConfigurationController) syncServer2Cluster(ctx context.Context, syncIfAbsent := dc.Spec.Strategy.SyncPolicy == nacosiov1.IfAbsent for _, dataId := range dc.Spec.DataIds { logWithId := l.WithValues("dataId", dataId) - content, err := scc.configClient.GetConfig(config.NacosConfigParam{ + content, err := scc.configClient.GetConfig(nacosclient.NacosConfigParam{ DynamicConfiguration: dc, Group: group, DataId: dataId, @@ -311,7 +302,7 @@ func (scc *SyncConfigurationController) syncServer2Cluster(ctx context.Context, continue } if !scc.mappings.HasMapping(namespace, group, dataId, nn) { - err = scc.configClient.ListenConfig(config.NacosConfigParam{ + err = scc.configClient.ListenConfig(nacosclient.NacosConfigParam{ DynamicConfiguration: dc, Group: group, DataId: dataId, @@ -343,7 +334,7 @@ func (scc *SyncConfigurationController) syncServer2Cluster(ctx context.Context, dcNNList := scc.mappings.GetDCList(namespace, group, dataId) if len(dcNNList) == 0 { l.Info("no DynamicConfiguration listen to this dataId, stop listening from nacos server", "dataId", dataId) - if err := scc.configClient.CancelListenConfig(config.NacosConfigParam{ + if err := scc.configClient.CancelListenConfig(nacosclient.NacosConfigParam{ DynamicConfiguration: dc, Group: group, DataId: dataId,