From 9b4f8bd4ad376e30a4df61449bc8a0f2f16cb358 Mon Sep 17 00:00:00 2001 From: Frost <2060307490@qq.com> Date: Wed, 30 Oct 2024 21:08:30 +0800 Subject: [PATCH] [OSPP]Support Kubernetes ConfigMap for Apollo java, golang client #79 (#318) --- README.md | 2 +- client.go | 2 +- client_test.go | 2 +- component/remote/async.go | 22 +++- configmap/handler.go | 72 +++++++++++++ configmap/handler_test.go | 177 +++++++++++++++++++++++++++++++ configmap/manager.go | 162 ++++++++++++++++++++++++++++ configmap/manager_test.go | 209 +++++++++++++++++++++++++++++++++++++ env/config/config.go | 15 +++ env/file/file_handler.go | 4 +- env/file/json/json.go | 6 +- env/file/json/json_test.go | 19 ++-- env/file/json/raw_test.go | 16 +-- extension/file.go | 47 +++++++-- extension/file_test.go | 110 ++++++++++++++++++- go.mod | 44 +++++++- go.sum | 102 ++++++++++++++++-- start.go | 34 +++++- start_test.go | 63 +++++++++-- storage/repository.go | 20 +++- 20 files changed, 1065 insertions(+), 63 deletions(-) create mode 100644 configmap/handler.go create mode 100644 configmap/handler_test.go create mode 100644 configmap/manager.go create mode 100644 configmap/manager_test.go diff --git a/README.md b/README.md index ff1c96a9..80fb19e6 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Agollo - Go Client for Apollo * 实时同步配置 * 灰度配置 * 延迟加载(运行时)namespace -* 客户端,配置文件容灾 +* 客户端,多种配置文件容灾(本地文件,k8s中configmap) * 自定义日志,缓存组件 * 支持配置访问秘钥 diff --git a/client.go b/client.go index 5f2d6e5a..8651ac59 100644 --- a/client.go +++ b/client.go @@ -49,7 +49,7 @@ const separator = "," func init() { extension.SetCacheFactory(&memory.DefaultCacheFactory{}) extension.SetLoadBalance(&roundrobin.RoundRobin{}) - extension.SetFileHandler(&jsonFile.FileHandler{}) + extension.AddFileHandler(&jsonFile.FileHandler{}, extension.DefaultWeight) extension.SetHTTPAuth(&sign.AuthSignature{}) // file parser diff --git a/client_test.go b/client_test.go index 8a2d7d00..424d4440 100644 --- a/client_test.go +++ b/client_test.go @@ -247,7 +247,7 @@ func createApolloConfigWithJSON(b []byte) (o interface{}, err error) { } func checkBackupFile(client *internalClient, t *testing.T) { - newConfig, e := extension.GetFileHandler().LoadConfigFile(client.appConfig.GetBackupConfigPath(), client.appConfig.AppID, testDefaultNamespace) + newConfig, e := extension.GetFileHandlers().Front().Value.(extension.HandlerWithPriority).Handler.LoadConfigFile(client.appConfig.GetBackupConfigPath(), client.appConfig.AppID, testDefaultNamespace, client.appConfig.Cluster) Assert(t, newConfig, NotNilVal()) Assert(t, e, NilVal()) Assert(t, newConfig.Configurations, NotNilVal()) diff --git a/component/remote/async.go b/component/remote/async.go index 1b3bffc8..b4d3f2dc 100644 --- a/component/remote/async.go +++ b/component/remote/async.go @@ -147,7 +147,8 @@ func toApolloConfig(resBody []byte) ([]*config.Notification, error) { func loadBackupConfig(namespace string, appConfig config.AppConfig) []*config.ApolloConfig { apolloConfigs := make([]*config.ApolloConfig, 0) config.SplitNamespaces(namespace, func(namespace string) { - c, err := extension.GetFileHandler().LoadConfigFile(appConfig.BackupConfigPath, appConfig.AppID, namespace) + c, err := loadBackupConfiguration(appConfig, namespace, appConfig.Cluster) + if err != nil { log.Errorf("LoadConfigFile error, error: %v", err) return @@ -160,6 +161,25 @@ func loadBackupConfig(namespace string, appConfig config.AppConfig) []*config.Ap return apolloConfigs } +// 从按优先级排好序的所有备份文件来源中尝试加载配置 +func loadBackupConfiguration(appConfig config.AppConfig, namespace string, cluster string) (*config.ApolloConfig, error) { + log.Debugf("Loading backup config") + + handlers := extension.GetFileHandlers() + for e := handlers.Front(); e != nil; e = e.Next() { + h := e.Value.(extension.HandlerWithPriority).Handler + c, err := h.LoadConfigFile(appConfig.BackupConfigPath, appConfig.AppID, namespace, cluster) + if err == nil && c != nil { + log.Infof("The backup file was successfully loaded. config: %s", c) + return c, nil + } + // 改进日志便于排查 + log.Warnf("Failed to load config with handler %T: %v", h, err) + } + + return nil, fmt.Errorf("failed to load backup configuration for namespace %s", namespace) +} + func createApolloConfigWithJSON(b []byte, callback http.CallBack) (o interface{}, err error) { apolloConfig := &config.ApolloConfig{} err = json.Unmarshal(b, apolloConfig) diff --git a/configmap/handler.go b/configmap/handler.go new file mode 100644 index 00000000..8f58f9dc --- /dev/null +++ b/configmap/handler.go @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 configmap + +import ( + "github.com/apolloconfig/agollo/v4/component/log" + "github.com/apolloconfig/agollo/v4/env/config" +) + +var ApolloConfigCache = "apollo-configcache-" + +type ConfigMapHandler struct { + k8sManager *K8sManager +} + +// NewConfigMapHandler 是 ConfigMapHandler 的构造函数 +func NewConfigMapHandler(k8sManager *K8sManager) *ConfigMapHandler { + return &ConfigMapHandler{ + k8sManager: k8sManager, + } +} + +// WriteConfigFile write apollo config to configmap +func (c *ConfigMapHandler) WriteConfigFile(config *config.ApolloConfig, configPath string) error { + configMapName := ApolloConfigCache + config.AppID + key := config.Cluster + "-" + config.NamespaceName + err := c.k8sManager.SetConfigMapWithRetry(configMapName, key, config) + if err != nil { + log.Errorf("Failed to write ConfigMap %s : %v", configMapName, err) + return err + } + return nil +} + +func (c *ConfigMapHandler) GetConfigFile(configDir string, appID string, namespace string) string { + return "" +} + +// LoadConfigFile load ApolloConfig from configmap +func (c *ConfigMapHandler) LoadConfigFile(configPath string, appID string, namespace string, cluster string) (*config.ApolloConfig, error) { + var apolloConfig = &config.ApolloConfig{} + var err error + + if cluster == "" { + cluster = "default" + log.Infof("cluster is empty, use default cluster") + } + configMapName := ApolloConfigCache + appID + key := cluster + "-" + namespace + // 这里把json转回ApolloConfig, ReleaseKey字段会丢失 + apolloConfig.Configurations, err = c.k8sManager.GetConfigMap(configMapName, key) + + apolloConfig.AppID = appID + apolloConfig.Cluster = cluster + apolloConfig.NamespaceName = namespace + return apolloConfig, err +} diff --git a/configmap/handler_test.go b/configmap/handler_test.go new file mode 100644 index 00000000..24c7826d --- /dev/null +++ b/configmap/handler_test.go @@ -0,0 +1,177 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 configmap + +import ( + "context" + "encoding/json" + "fmt" + "github.com/apolloconfig/agollo/v4/env/config" + "github.com/stretchr/testify/assert" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/kubernetes/fake" + "testing" +) + +const ( + appId = "testAppId" + k8sNamespace = "testConfigMapNamespace" + cluster = "testCluster" + namespace = "testNamespace" +) + +var testData = map[string]interface{}{ + "stringKey": "stringValue", + "intKey": 123, + "boolKey": true, + "sliceKey": []interface{}{1, 2, 3}, + "mapKey": map[string]interface{}{ + "nestedStringKey": "nestedStringValue", + "nestedIntKey": 456, + }, +} + +var appConfig = config.AppConfig{ + AppID: appId, + NamespaceName: namespace, + Cluster: cluster, +} + +func TestStore_LoadConfigMap(t *testing.T) { + // 初始化fake clientset + clientset := fake.NewSimpleClientset() + jsonData, err := json.Marshal(testData) + if err != nil { + fmt.Println("Error marshalling map to JSON:", err) + return + } + + // 创建一个ConfigMap对象 + configMap := &corev1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{ + Name: "apollo-configcache-" + appId, + Namespace: k8sNamespace, + }, + Data: map[string]string{ + cluster + "-" + namespace: string(jsonData), + }, + } + + // 使用fake clientset创建ConfigMap + _, err = clientset.CoreV1().ConfigMaps(k8sNamespace).Create(context.TODO(), configMap, metav1.CreateOptions{}) + assert.NoError(t, err) + + // 初始化handler,注入fake clientset + handler := NewConfigMapHandler(&K8sManager{ + clientSet: clientset, + k8sNamespace: k8sNamespace, + }) + + // 执行 + loadedConfig, err := handler.LoadConfigFile("", appConfig.AppID, namespace, cluster) + assert.NoError(t, err) + + // 测试LoadConfigMap方法 + loadedJson, _ := json.Marshal(loadedConfig.Configurations) + assert.NotNil(t, loadedConfig) + assert.Equal(t, jsonData, loadedJson) +} + +func TestStore_WriteConfigMap(t *testing.T) { + // 初始化fake clientset + clientset := fake.NewSimpleClientset() + + var err error + var key = cluster + "-" + namespace + jsonData, err := json.Marshal(testData) + if err != nil { + fmt.Println("Error marshalling map to JSON:", err) + return + } + + // 初始化handler,注入fake clientset + handler := NewConfigMapHandler(&K8sManager{ + clientSet: clientset, + k8sNamespace: k8sNamespace, + }) + + // 反序列化到ApolloConfig + apolloConfig := &config.ApolloConfig{} + apolloConfig.Configurations = testData + apolloConfig.AppID = appId + apolloConfig.Cluster = cluster + apolloConfig.NamespaceName = namespace + + // 测试WriteConfigMap方法 + err = handler.WriteConfigFile(apolloConfig, "") + assert.NoError(t, err) + + // 验证ConfigMap是否被正确创建或更新 + configMap, err := clientset.CoreV1().ConfigMaps(k8sNamespace).Get(context.TODO(), "apollo-configcache-"+appId, metav1.GetOptions{}) + loadedJson, _ := configMap.Data[key] + + var configurations map[string]interface{} + err = json.Unmarshal([]byte(loadedJson), &configurations) + + assert.NoError(t, err) + assert.NotNil(t, configMap) + assert.Equal(t, jsonData, []byte(loadedJson)) +} + +func TestStore_LoadConfigMap_EmptyConfigMap(t *testing.T) { + // 初始化fake clientset + clientset := fake.NewSimpleClientset() + + // 初始化handler,注入fake clientset + handler := NewConfigMapHandler(&K8sManager{ + clientSet: clientset, + k8sNamespace: k8sNamespace, + }) + + // 执行 + loadedConfig, err := handler.LoadConfigFile("", appId, namespace, cluster) + assert.Nil(t, loadedConfig.Configurations) + assert.Error(t, err) +} + +func TestStore_LoadConfigMap_InvalidJSON(t *testing.T) { + // 初始化fake clientset + clientset := fake.NewSimpleClientset() + + // 初始化handler,注入fake clientset + handler := NewConfigMapHandler(&K8sManager{ + clientSet: clientset, + k8sNamespace: k8sNamespace, + }) + // 创建一个ConfigMap对象 + configMap := &corev1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{ + Name: "apollo-configcache-" + appId, + Namespace: k8sNamespace, + }, + Data: map[string]string{ + cluster + "-" + namespace: "invalid json", + }, + } + _, err := clientset.CoreV1().ConfigMaps(k8sNamespace).Create(context.TODO(), configMap, metav1.CreateOptions{}) + assert.NoError(t, err) + loadedConfig, err := handler.LoadConfigFile("", appId, namespace, cluster) + assert.Nil(t, loadedConfig.Configurations) + assert.Error(t, err) +} diff --git a/configmap/manager.go b/configmap/manager.go new file mode 100644 index 00000000..f9984904 --- /dev/null +++ b/configmap/manager.go @@ -0,0 +1,162 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 configmap + +import ( + "context" + "encoding/json" + "fmt" + "github.com/apolloconfig/agollo/v4/component/log" + "github.com/apolloconfig/agollo/v4/env/config" + coreV1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" + metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/client-go/kubernetes" + "k8s.io/client-go/rest" + "k8s.io/client-go/util/retry" + "sync" + "time" +) + +type K8sManager struct { + clientSet kubernetes.Interface + k8sNamespace string +} + +var ( + instance *K8sManager + once sync.Once +) + +func GetK8sManager(k8sNamespace string) (*K8sManager, error) { + var err error + + once.Do(func() { + var config *rest.Config + config, err = rest.InClusterConfig() + if err != nil { + log.Errorf("Error creating in-cluster config: %v", err) + return + } + var clientSet kubernetes.Interface + clientSet, err = kubernetes.NewForConfig(config) + if err != nil { + log.Errorf("Error creating Kubernetes client set: %v", err) + return + } + instance = &K8sManager{ + clientSet: clientSet, + k8sNamespace: k8sNamespace, + } + }) + + if err != nil { + return nil, fmt.Errorf("failed to initialize K8sManager: %v", err) + } + return instance, nil +} + +// SetConfigMapWithRetry 使用k8s版本号机制解决并发问题 +func (m *K8sManager) SetConfigMapWithRetry(configMapName string, key string, config *config.ApolloConfig) error { + var retryParam = wait.Backoff{ + Steps: 5, + Duration: 50 * time.Millisecond, + Factor: 2, + Jitter: 0.2, + } + + err := retry.RetryOnConflict(retryParam, func() error { + return m.SetConfigMap(configMapName, key, config) + }) + + return err +} + +// SetConfigMap 将map[string]interface{}转换为JSON字符串,并创建或更新ConfigMap +func (m *K8sManager) SetConfigMap(configMapName string, key string, config *config.ApolloConfig) error { + k8sNamespace := m.k8sNamespace + + jsonData, err := json.Marshal(config.Configurations) + jsonString := string(jsonData) + if err != nil { + return fmt.Errorf("error marshaling data to JSON: %v", err) + } + log.Infof("Preparing Configmap content,JSON: %s", jsonString) + + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + // 尝试获取 ConfigMap,如果不存在则创建 + cm, err := m.clientSet.CoreV1().ConfigMaps(k8sNamespace).Get(ctx, configMapName, metaV1.GetOptions{}) + if errors.IsNotFound(err) { + cm = &coreV1.ConfigMap{ + ObjectMeta: metaV1.ObjectMeta{ + Name: configMapName, + Namespace: k8sNamespace, + }, + Data: map[string]string{ + key: jsonString, + }, + } + + _, err = m.clientSet.CoreV1().ConfigMaps(k8sNamespace).Create(ctx, cm, metaV1.CreateOptions{}) + if err != nil { + return fmt.Errorf("error creating ConfigMap: %v", err) + } + log.Infof("ConfigMap %s created in namespace %s", configMapName, k8sNamespace) + } else if err != nil { + return fmt.Errorf("error getting ConfigMap: %v", err) + } else { + // ConfigMap 存在,更新数据 + cm.Data[key] = jsonString + _, err = m.clientSet.CoreV1().ConfigMaps(k8sNamespace).Update(ctx, cm, metaV1.UpdateOptions{}) + if err != nil { + return fmt.Errorf("error updating ConfigMap: %v", err) + } + log.Infof("ConfigMap %s updated in namespace %s", configMapName, k8sNamespace) + } + return err +} + +// GetConfigMap 从ConfigMap中获取JSON字符串,并反序列化为map[string]interface{} +func (m *K8sManager) GetConfigMap(configMapName string, key string) (map[string]interface{}, error) { + k8sNamespace := m.k8sNamespace + + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + configMap, err := m.clientSet.CoreV1().ConfigMaps(k8sNamespace).Get(ctx, configMapName, metaV1.GetOptions{}) + if err != nil { + return nil, fmt.Errorf("error getting ConfigMap: %v", err) + } + + // 从ConfigMap中读取JSON数据 + jsonData, ok := configMap.Data[key] + if !ok { + return nil, fmt.Errorf("key: %v not found in ConfigMap", key) + } + + var configurations map[string]interface{} + err = json.Unmarshal([]byte(jsonData), &configurations) + if err != nil { + return nil, fmt.Errorf("error unmarshaling JSON to map[string]interface{}: %v", err) + } + + return configurations, nil +} diff --git a/configmap/manager_test.go b/configmap/manager_test.go new file mode 100644 index 00000000..fb037bc5 --- /dev/null +++ b/configmap/manager_test.go @@ -0,0 +1,209 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 configmap + +import ( + "context" + "github.com/agiledragon/gomonkey/v2" + "github.com/apolloconfig/agollo/v4/env/config" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + coreV1 "k8s.io/api/core/v1" + metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/kubernetes" + "k8s.io/client-go/kubernetes/fake" + "k8s.io/client-go/rest" + "sync" + "testing" + "time" +) + +func TestK8sManager_SetConfigMap(t *testing.T) { + // 创建fake clientSet + clientSet := fake.NewSimpleClientset() + + // 测试数据 + configMapName := "apollo-configcache-test-configmap" + k8sNamespace := "default" + key := "configKey" + apolloConfig := &config.ApolloConfig{ + Configurations: map[string]interface{}{"key": "value"}, + } + + // 创建K8sManager实例 + manager := K8sManager{ + clientSet: clientSet, + k8sNamespace: k8sNamespace, + } + + // 调用SetConfigMap方法 + err := manager.SetConfigMapWithRetry(configMapName, key, apolloConfig) + assert.NoError(t, err) + + // 验证ConfigMap是否被创建 + configMap, err := clientSet.CoreV1().ConfigMaps(k8sNamespace).Get(context.Background(), configMapName, metaV1.GetOptions{}) + assert.NoError(t, err) + assert.NotNil(t, configMap) + assert.Equal(t, string(configMap.Data[key]), + `{"key":"value"}`) +} + +func TestK8sManager_GetConfigMap(t *testing.T) { + // 创建fake clientSet,并预先创建一个ConfigMap + clientSet := fake.NewSimpleClientset(&coreV1.ConfigMap{ + ObjectMeta: metaV1.ObjectMeta{ + Name: "apollo-configcache-test-configmap", + Namespace: "default", + }, + Data: map[string]string{ + "configKey": `{"key":"value"}`, + }, + }) + + // 创建K8sManager实例 + manager := K8sManager{ + clientSet: clientSet, + k8sNamespace: "default", + } + + // 测试数据 + configMapName := "apollo-configcache-test-configmap" + key := "configKey" + + // 调用GetConfigMap方法 + configurations, err := manager.GetConfigMap(configMapName, key) + assert.NoError(t, err) + assert.NotNil(t, configurations) + assert.Equal(t, configurations["key"], "value") +} + +func TestSetConfigMapWithRetryConcurrent(t *testing.T) { + // 创建一个假的Kubernetes客户端 + clientSet := fake.NewSimpleClientset() + + // 创建K8sManager实例 + manager := &K8sManager{ + clientSet: clientSet, + k8sNamespace: "default", + } + + // 定义测试数据 + configMapName := "apollo-configcache-test-configmap" + k8sNamespace := "default" + key := "test-key" + configData1 := &config.ApolloConfig{ + Configurations: map[string]interface{}{ + "key1": "value1", + }, + } + configData2 := &config.ApolloConfig{ + Configurations: map[string]interface{}{ + "key2": "value2", + }, + } + + // 首先创建一个ConfigMap + _, err := clientSet.CoreV1().ConfigMaps(k8sNamespace).Create(context.Background(), &coreV1.ConfigMap{ + ObjectMeta: metaV1.ObjectMeta{ + Name: configMapName, + Namespace: k8sNamespace, + }, + Data: map[string]string{}, + }, metaV1.CreateOptions{}) + require.NoError(t, err) + + // 使用WaitGroup等待两个并发操作完成 + var wg sync.WaitGroup + wg.Add(2) + + // 并发执行SetConfigMapWithRetry + go func() { + defer wg.Done() + err := manager.SetConfigMapWithRetry(configMapName, key, configData1) + require.NoError(t, err) + }() + + go func() { + defer wg.Done() + // 为了模拟并发冲突,这里故意延迟一段时间后再执行 + time.Sleep(1 * time.Millisecond) + err := manager.SetConfigMapWithRetry(configMapName, key, configData2) + require.NoError(t, err) + }() + + // 等待两个并发操作完成 + wg.Wait() + + // 验证ConfigMap是否更新成功 + cm, err := clientSet.CoreV1().ConfigMaps(k8sNamespace).Get(context.Background(), configMapName, metaV1.GetOptions{}) + require.NoError(t, err) + require.NotNil(t, cm) + + // 这里只能验证其中一个更新操作成功的结果,因为两个操作是并发的,最终结果取决于哪个操作最后执行 + // 例如,这里假设configData2的更新是最后执行的 + require.Contains(t, cm.Data[key], `"key2":"value2"`) +} + +func TestGetK8sManager_Singleton(t *testing.T) { + // 重置全局变量 + instance = nil + once = sync.Once{} + + // 模拟成功的 InClusterConfig 和 NewForConfig + patches := gomonkey.NewPatches() + defer patches.Reset() + + patches.ApplyFunc(rest.InClusterConfig, func() (*rest.Config, error) { + return &rest.Config{}, nil + }) + patches.ApplyFunc(kubernetes.NewForConfig, func(config *rest.Config) (*kubernetes.Clientset, error) { + return &kubernetes.Clientset{}, nil + }) + + manager1, err1 := GetK8sManager("default") + manager2, err2 := GetK8sManager("default") + + assert.Nil(t, err1) + assert.Nil(t, err2) + assert.NotNil(t, manager1) + assert.NotNil(t, manager2) + assert.Equal(t, manager1, manager2, "GetK8sManager should return the same instance") +} + +func TestGetK8sManager_InitSuccess(t *testing.T) { + // 重置全局变量 + instance = nil + once = sync.Once{} + + // 模拟成功的 InClusterConfig 和 NewForConfig + patches := gomonkey.NewPatches() + defer patches.Reset() + + patches.ApplyFunc(rest.InClusterConfig, func() (*rest.Config, error) { + return &rest.Config{}, nil + }) + patches.ApplyFunc(kubernetes.NewForConfig, func(config *rest.Config) (*kubernetes.Clientset, error) { + return &kubernetes.Clientset{}, nil + }) + + manager, err := GetK8sManager("default") + + assert.Nil(t, err) + assert.NotNil(t, manager) + assert.Equal(t, "default", manager.k8sNamespace) +} diff --git a/env/config/config.go b/env/config/config.go index ebfde508..8d1d15f2 100644 --- a/env/config/config.go +++ b/env/config/config.go @@ -45,6 +45,7 @@ type AppConfig struct { Cluster string `json:"cluster"` NamespaceName string `json:"namespaceName"` IP string `json:"ip"` + K8sNamespace string `json:"k8sNamespace"` IsBackupConfig bool `default:"true" json:"isBackupConfig"` BackupConfigPath string `json:"backupConfigPath"` Secret string `json:"secret"` @@ -76,6 +77,20 @@ func (a *AppConfig) GetBackupConfigPath() string { return a.BackupConfigPath } +// GetIsBackupConfigToConfigMap whether backup config to configmap after fetch config from apollo +// false : no (The value of k8sNamespace is not set) +// true : yes +func (a *AppConfig) GetIsBackupConfigToConfigMap() bool { + return a.K8sNamespace != "" +} + +func (a *AppConfig) GetK8sNamespace() string { + if a.K8sNamespace == "" { + a.K8sNamespace = "default" + } + return a.K8sNamespace +} + // GetHost GetHost func (a *AppConfig) GetHost() string { u, err := url.Parse(a.IP) diff --git a/env/file/file_handler.go b/env/file/file_handler.go index 336ca59d..dacb6299 100644 --- a/env/file/file_handler.go +++ b/env/file/file_handler.go @@ -21,9 +21,9 @@ import ( "github.com/apolloconfig/agollo/v4/env/config" ) -//FileHandler 备份文件读写 +// FileHandler 备份文件读写 type FileHandler interface { WriteConfigFile(config *config.ApolloConfig, configPath string) error GetConfigFile(configDir string, appID string, namespace string) string - LoadConfigFile(configDir string, appID string, namespace string) (*config.ApolloConfig, error) + LoadConfigFile(configDir string, appID string, namespace string, cluster string) (*config.ApolloConfig, error) } diff --git a/env/file/json/json.go b/env/file/json/json.go index ae5ccce4..4ebf002f 100644 --- a/env/file/json/json.go +++ b/env/file/json/json.go @@ -29,7 +29,7 @@ import ( jsonConfig "github.com/apolloconfig/agollo/v4/env/config/json" ) -//Suffix 默认文件保存类型 +// Suffix 默认文件保存类型 const Suffix = ".json" var ( @@ -95,8 +95,8 @@ func (fileHandler *FileHandler) GetConfigFile(configDir string, appID string, na return configFileMap[namespace] } -//LoadConfigFile load config from file -func (fileHandler *FileHandler) LoadConfigFile(configDir string, appID string, namespace string) (*config.ApolloConfig, error) { +// LoadConfigFile load config from file +func (fileHandler *FileHandler) LoadConfigFile(configDir string, appID string, namespace string, cluster string) (*config.ApolloConfig, error) { configFilePath := fileHandler.GetConfigFile(configDir, appID, namespace) log.Infof("load config file from: %s", configFilePath) c, e := jsonFileConfig.Load(configFilePath, func(b []byte) (interface{}, error) { diff --git a/env/file/json/json_test.go b/env/file/json/json_test.go index e8abf9ed..b1747861 100644 --- a/env/file/json/json_test.go +++ b/env/file/json/json_test.go @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package json import ( @@ -45,7 +44,7 @@ func TestCreateDir(t *testing.T) { } func TestJSONFileHandler_WriteConfigDirFile(t *testing.T) { - extension.SetFileHandler(&FileHandler{}) + extension.AddFileHandler(&FileHandler{}, 0) configPath := "json-conf" jsonStr := `{ "appId": "100004458", @@ -61,17 +60,17 @@ func TestJSONFileHandler_WriteConfigDirFile(t *testing.T) { config, err := createApolloConfigWithJSON([]byte(jsonStr)) os.RemoveAll(configPath) - os.Remove(extension.GetFileHandler().GetConfigFile(configPath, config.AppID, config.NamespaceName)) + os.Remove(extension.GetFileHandlers().Front().Value.(extension.HandlerWithPriority).Handler.GetConfigFile(configPath, config.AppID, config.NamespaceName)) Assert(t, err, NilVal()) - e := extension.GetFileHandler().WriteConfigFile(config, configPath) + e := extension.GetFileHandlers().Front().Value.(extension.HandlerWithPriority).Handler.WriteConfigFile(config, configPath) Assert(t, e, NilVal()) os.RemoveAll(configPath) - os.Remove(extension.GetFileHandler().GetConfigFile(configPath, config.AppID, config.NamespaceName)) + os.Remove(extension.GetFileHandlers().Front().Value.(extension.HandlerWithPriority).Handler.GetConfigFile(configPath, config.AppID, config.NamespaceName)) } func TestJSONFileHandler_WriteConfigFile(t *testing.T) { - extension.SetFileHandler(&FileHandler{}) + extension.AddFileHandler(&FileHandler{}, 0) configPath := "" jsonStr := `{ "appId": "100004458", @@ -86,15 +85,15 @@ func TestJSONFileHandler_WriteConfigFile(t *testing.T) { }` config, err := createApolloConfigWithJSON([]byte(jsonStr)) - os.Remove(extension.GetFileHandler().GetConfigFile(configPath, config.AppID, config.NamespaceName)) + os.Remove(extension.GetFileHandlers().Front().Value.(extension.HandlerWithPriority).Handler.GetConfigFile(configPath, config.AppID, config.NamespaceName)) Assert(t, err, NilVal()) - e := extension.GetFileHandler().WriteConfigFile(config, configPath) + e := extension.GetFileHandlers().Front().Value.(extension.HandlerWithPriority).Handler.WriteConfigFile(config, configPath) Assert(t, e, NilVal()) } func TestJSONFileHandler_LoadConfigFile(t *testing.T) { - extension.SetFileHandler(&FileHandler{}) + extension.AddFileHandler(&FileHandler{}, 0) jsonStr := `{ "appId": "100004458", "cluster": "default", @@ -110,7 +109,7 @@ func TestJSONFileHandler_LoadConfigFile(t *testing.T) { config, err := createApolloConfigWithJSON([]byte(jsonStr)) Assert(t, err, NilVal()) - newConfig, e := extension.GetFileHandler().LoadConfigFile("", config.AppID, config.NamespaceName) + newConfig, e := extension.GetFileHandlers().Front().Value.(extension.HandlerWithPriority).Handler.LoadConfigFile("", config.AppID, config.NamespaceName, config.Cluster) t.Log(newConfig) Assert(t, e, NilVal()) diff --git a/env/file/json/raw_test.go b/env/file/json/raw_test.go index b160f63c..82e16609 100644 --- a/env/file/json/raw_test.go +++ b/env/file/json/raw_test.go @@ -26,7 +26,7 @@ import ( ) func TestRawHandler_WriteConfigDirFile(t *testing.T) { - extension.SetFileHandler(&rawFileHandler{}) + extension.AddFileHandler(&rawFileHandler{}, 0) configPath := "raw-conf" jsonStr := `{ "appId": "100004458", @@ -44,13 +44,13 @@ func TestRawHandler_WriteConfigDirFile(t *testing.T) { os.RemoveAll(configPath) Assert(t, err, NilVal()) - e := extension.GetFileHandler().WriteConfigFile(config, configPath) + e := extension.GetFileHandlers().Front().Value.(extension.HandlerWithPriority).Handler.WriteConfigFile(config, configPath) Assert(t, e, NilVal()) os.RemoveAll(configPath) } func TestRawHandler_WriteConfigFile(t *testing.T) { - extension.SetFileHandler(&rawFileHandler{}) + extension.AddFileHandler(&rawFileHandler{}, 0) configPath := "" jsonStr := `{ "appId": "100004458", @@ -65,15 +65,15 @@ func TestRawHandler_WriteConfigFile(t *testing.T) { }` config, err := createApolloConfigWithJSON([]byte(jsonStr)) - os.Remove(extension.GetFileHandler().GetConfigFile(configPath, config.AppID, config.NamespaceName)) + os.Remove(extension.GetFileHandlers().Front().Value.(extension.HandlerWithPriority).Handler.GetConfigFile(configPath, config.AppID, config.NamespaceName)) Assert(t, err, NilVal()) - e := extension.GetFileHandler().WriteConfigFile(config, configPath) + e := extension.GetFileHandlers().Front().Value.(extension.HandlerWithPriority).Handler.WriteConfigFile(config, configPath) Assert(t, e, NilVal()) } func TestRawHandler_WriteConfigFileWithContent(t *testing.T) { - extension.SetFileHandler(&rawFileHandler{}) + extension.AddFileHandler(&rawFileHandler{}, 0) configPath := "" jsonStr := `{ "appId": "100004458", @@ -87,10 +87,10 @@ func TestRawHandler_WriteConfigFileWithContent(t *testing.T) { config, err := createApolloConfigWithJSON([]byte(jsonStr)) Assert(t, err, NilVal()) - os.Remove(extension.GetFileHandler().GetConfigFile(configPath, config.AppID, config.NamespaceName)) + os.Remove(extension.GetFileHandlers().Front().Value.(extension.HandlerWithPriority).Handler.GetConfigFile(configPath, config.AppID, config.NamespaceName)) Assert(t, err, NilVal()) - e := extension.GetFileHandler().WriteConfigFile(config, configPath) + e := extension.GetFileHandlers().Front().Value.(extension.HandlerWithPriority).Handler.WriteConfigFile(config, configPath) Assert(t, e, NilVal()) } diff --git a/extension/file.go b/extension/file.go index 00277e96..fe2d2bda 100644 --- a/extension/file.go +++ b/extension/file.go @@ -17,16 +17,47 @@ package extension -import "github.com/apolloconfig/agollo/v4/env/file" +import ( + "container/list" + "github.com/apolloconfig/agollo/v4/env/file" +) -var fileHandler file.FileHandler +type HandlerWithPriority struct { + Handler file.FileHandler + priority int +} + +var handlers = list.New() + +const DefaultWeight = 0 + +// AddFileHandler 添加一个 FileHandler 实现,并设定其优先级 +func AddFileHandler(handler file.FileHandler, priority int) { + newHandler := HandlerWithPriority{handler, priority} + + // 在链表中找到合适的位置插入 + for e := handlers.Front(); e != nil; e = e.Next() { + if e.Value.(HandlerWithPriority).priority < priority { + handlers.InsertBefore(newHandler, e) + return + } + } + // 如果没有找到合适的位置,追加到链表末尾 + handlers.PushBack(newHandler) +} -//SetFileHandler 设置备份文件处理 -func SetFileHandler(inFile file.FileHandler) { - fileHandler = inFile +// SetFileHandler 清空当前的 handlers 列表,并设置一个新的 FileHandler +func SetFileHandler(handler file.FileHandler) { + handlers = list.New() + // 添加新的 handler + newHandler := HandlerWithPriority{ + Handler: handler, + priority: DefaultWeight, + } + handlers.PushBack(newHandler) } -//GetFileHandler 获取备份文件处理 -func GetFileHandler() file.FileHandler { - return fileHandler +// GetFileHandlers 返回按优先级排好序的所有的 FileHandler(priority 值越大,优先级越高) +func GetFileHandlers() *list.List { + return handlers } diff --git a/extension/file_test.go b/extension/file_test.go index 5912cee1..dc51c4ed 100644 --- a/extension/file_test.go +++ b/extension/file_test.go @@ -18,6 +18,9 @@ package extension import ( + "container/list" + "github.com/apolloconfig/agollo/v4/env/file" + "github.com/stretchr/testify/assert" "testing" "github.com/apolloconfig/agollo/v4/env/config" @@ -38,14 +41,113 @@ func (r *TestFileHandler) GetConfigFile(configDir string, appID string, namespac return "" } -func (r *TestFileHandler) LoadConfigFile(configDir string, appID string, namespace string) (*config.ApolloConfig, error) { +func (r *TestFileHandler) LoadConfigFile(configDir string, appID string, namespace string, cluster string) (*config.ApolloConfig, error) { return nil, nil } -func TestSetFileHandler(t *testing.T) { - SetFileHandler(&TestFileHandler{}) +func TestAddFileHandler(t *testing.T) { + AddFileHandler(&TestFileHandler{}, 0) - fileHandler := GetFileHandler() + fileHandler := GetFileHandlers().Front().Value.(HandlerWithPriority).Handler.(*TestFileHandler) Assert(t, fileHandler, NotNilVal()) } + +func TestAddAndGetFileHandlers(t *testing.T) { + // 清理handlers切片,确保测试环境干净 + handlers = list.New() + + handler1 := &TestFileHandler{} + handler2 := &TestFileHandler{} + handler3 := &TestFileHandler{} + + // 添加优先级不同的处理器 + AddFileHandler(handler1, 5) + AddFileHandler(handler2, 10) + AddFileHandler(handler3, 1) + + // 获取并验证处理器的顺序 + sortedHandlers := GetFileHandlers() + assert.Equal(t, 3, sortedHandlers.Len(), "应该有三个处理器") + + expectedOrder := []file.FileHandler{handler2, handler1, handler3} + actualOrder := make([]file.FileHandler, 0, sortedHandlers.Len()) + + for e := sortedHandlers.Front(); e != nil; e = e.Next() { + actualOrder = append(actualOrder, e.Value.(HandlerWithPriority).Handler) + } + + assert.Equal(t, expectedOrder, actualOrder, "处理器顺序应该按照优先级排序") +} + +func TestAddFileHandler_SamePriority(t *testing.T) { + // 清空 handlers 列表 + handlers = list.New() + + handler1 := &TestFileHandler{} + handler2 := &TestFileHandler{} + handler3 := &TestFileHandler{} + + // 添加相同优先级的处理器 + AddFileHandler(handler1, 5) + AddFileHandler(handler2, 5) + AddFileHandler(handler3, 5) + + expectedOrder := []file.FileHandler{handler1, handler2, handler3} + actualOrder := make([]file.FileHandler, 0, 3) + + sortedHandlers := GetFileHandlers() + for e := sortedHandlers.Front(); e != nil; e = e.Next() { + actualOrder = append(actualOrder, e.Value.(HandlerWithPriority).Handler) + } + + assert.Equal(t, expectedOrder, actualOrder, "冲突时,处理器顺序应该按照添加顺序排序") +} + +func TestAddFileHandler_EmptyList(t *testing.T) { + // 清空 handlers 列表 + handlers = list.New() + + handler1 := &TestFileHandler{} + + // 添加处理器到空列表 + AddFileHandler(handler1, 5) + + expectedOrder := []file.FileHandler{handler1} + actualOrder := make([]file.FileHandler, 0, 1) + + sortedHandlers := GetFileHandlers() + for e := sortedHandlers.Front(); e != nil; e = e.Next() { + actualOrder = append(actualOrder, e.Value.(HandlerWithPriority).Handler) + } + + assert.Equal(t, expectedOrder, actualOrder, "Handler should be added to the empty list") +} + +func TestSetFileHandler(t *testing.T) { + // 清空 handlers 列表 + handlers = list.New() + + handler1 := &TestFileHandler{} + handler2 := &TestFileHandler{} + handler3 := &TestFileHandler{} + + // 添加多个处理器 + AddFileHandler(handler1, 5) + AddFileHandler(handler2, 10) + AddFileHandler(handler3, 1) + + // 设置新的处理器 + handler4 := &TestFileHandler{} + SetFileHandler(handler4) + + expectedOrder := []file.FileHandler{handler4} + actualOrder := make([]file.FileHandler, 0, 1) + + sortedHandlers := GetFileHandlers() + for e := sortedHandlers.Front(); e != nil; e = e.Next() { + actualOrder = append(actualOrder, e.Value.(HandlerWithPriority).Handler) + } + + assert.Equal(t, expectedOrder, actualOrder, "The handlers should be reset to the new handler") +} diff --git a/go.mod b/go.mod index 3481901f..cc7df1f9 100644 --- a/go.mod +++ b/go.mod @@ -3,24 +3,64 @@ module github.com/apolloconfig/agollo/v4 require ( github.com/agiledragon/gomonkey/v2 v2.11.0 github.com/spf13/viper v1.8.1 + github.com/stretchr/testify v1.8.4 github.com/tevid/gohamcrest v1.1.1 + k8s.io/api v0.28.1 + k8s.io/apimachinery v0.28.1 + k8s.io/client-go v0.28.1 ) require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/emicklei/go-restful/v3 v3.9.0 // indirect + github.com/evanphx/json-patch v5.6.0+incompatible // indirect github.com/fsnotify/fsnotify v1.4.9 // indirect + github.com/go-logr/logr v1.2.4 // indirect + github.com/go-openapi/jsonpointer v0.19.6 // indirect + github.com/go-openapi/jsonreference v0.20.2 // indirect + github.com/go-openapi/swag v0.22.3 // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang/protobuf v1.5.3 // indirect + github.com/google/gnostic-models v0.6.8 // indirect + github.com/google/go-cmp v0.5.9 // indirect + github.com/google/gofuzz v1.2.0 // indirect + github.com/google/uuid v1.3.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect + github.com/josharian/intern v1.0.0 // indirect + github.com/json-iterator/go v1.1.12 // indirect github.com/magiconair/properties v1.8.5 // indirect + github.com/mailru/easyjson v0.7.7 // indirect github.com/mitchellh/mapstructure v1.4.1 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pelletier/go-toml v1.9.3 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/spf13/afero v1.6.0 // indirect github.com/spf13/cast v1.3.1 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.2.0 // indirect - golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect - golang.org/x/text v0.3.5 // indirect + golang.org/x/net v0.13.0 // indirect + golang.org/x/oauth2 v0.8.0 // indirect + golang.org/x/sys v0.10.0 // indirect + golang.org/x/term v0.10.0 // indirect + golang.org/x/text v0.11.0 // indirect + golang.org/x/time v0.3.0 // indirect + google.golang.org/appengine v1.6.7 // indirect + google.golang.org/protobuf v1.30.0 // indirect + gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/ini.v1 v1.62.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect + k8s.io/klog/v2 v2.100.1 // indirect + k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect + k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect + sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect + sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect + sigs.k8s.io/yaml v1.3.0 // indirect ) go 1.20 diff --git a/go.sum b/go.sum index 01bfad84..d0bd95fa 100644 --- a/go.sum +++ b/go.sum @@ -57,9 +57,12 @@ github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnht github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/emicklei/go-restful/v3 v3.9.0 h1:XwGDlfxEnQZzuopoqxwSEllNcCOM9DhhFyhFIIGKwxE= +github.com/emicklei/go-restful/v3 v3.9.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -67,6 +70,8 @@ github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5y github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U= +github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= @@ -74,7 +79,18 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE= +github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= +github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= +github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k= +github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g= +github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -105,8 +121,12 @@ github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I= +github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -118,7 +138,11 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= +github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= @@ -133,8 +157,11 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= @@ -163,7 +190,11 @@ github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2p github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= @@ -171,13 +202,17 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls= github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= @@ -191,12 +226,22 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag= github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/onsi/ginkgo/v2 v2.9.4 h1:xR7vG4IXt5RWx6FfIjyAtsoMAtnc3C/rFXBBd2AjZwE= +github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ= github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -204,6 +249,7 @@ github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndr github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= @@ -221,13 +267,19 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An github.com/spf13/viper v1.8.1 h1:Kq1fyeebqsBfbjZj4EL7gj2IO0mMaiyjYUWcUsl2O44= github.com/spf13/viper v1.8.1/go.mod h1:o0Pch8wJ9BVSWGQMbra6iw0oQ5oktSIBaujf1rJH9Ns= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tevid/gohamcrest v1.1.1 h1:ou+xSqlIw1xfGTg1uq1nif/htZ2S3EzRqLm2BP+tYU0= @@ -328,6 +380,8 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.13.0 h1:Nvo8UFsZ8X3BhAC9699Z1j7XQ3rsZnUUm7jfBEk1ueY= +golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -340,6 +394,8 @@ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.8.0 h1:6dkIjl3j3LtZ/O3sTgZTMsLKSftL/B8Zgq4huOIIUu8= +golang.org/x/oauth2 v0.8.0/go.mod h1:yr7u4HXZRm1R1kBWqr/xKNqewf0plRYoB7sla+BCIXE= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -391,20 +447,26 @@ golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= +golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c= +golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= +golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= +golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= @@ -456,6 +518,7 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.8.0 h1:vSDcovVPld282ceKgDimkRSC8kpaH1dgyc9UMzlt84Y= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -488,6 +551,7 @@ google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= @@ -562,10 +626,15 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= +gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU= gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= @@ -574,8 +643,9 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= @@ -583,6 +653,24 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +k8s.io/api v0.28.1 h1:i+0O8k2NPBCPYaMB+uCkseEbawEt/eFaiRqUx8aB108= +k8s.io/api v0.28.1/go.mod h1:uBYwID+66wiL28Kn2tBjBYQdEU0Xk0z5qF8bIBqk/Dg= +k8s.io/apimachinery v0.28.1 h1:EJD40og3GizBSV3mkIoXQBsws32okPOy+MkRyzh6nPY= +k8s.io/apimachinery v0.28.1/go.mod h1:X0xh/chESs2hP9koe+SdIAcXWcQ+RM5hy0ZynB+yEvw= +k8s.io/client-go v0.28.1 h1:pRhMzB8HyLfVwpngWKE8hDcXRqifh1ga2Z/PU9SXVK8= +k8s.io/client-go v0.28.1/go.mod h1:pEZA3FqOsVkCc07pFVzK076R+P/eXqsgx5zuuRWukNE= +k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg= +k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= +k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 h1:LyMgNKD2P8Wn1iAwQU5OhxCKlKJy0sHc+PcDwFB24dQ= +k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9/go.mod h1:wZK2AVp1uHCp4VamDVgBP2COHZjqD1T68Rf0CM3YjSM= +k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 h1:qY1Ad8PODbnymg2pRbkyMT/ylpTrCM8P2RJ0yroCyIk= +k8s.io/utils v0.0.0-20230406110748-d93618cff8a2/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= +sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= +sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE= +sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E= +sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= +sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= diff --git a/start.go b/start.go index 67b3de9d..d9769d51 100644 --- a/start.go +++ b/start.go @@ -26,35 +26,59 @@ import ( "github.com/apolloconfig/agollo/v4/protocol/auth" ) -//SetSignature 设置自定义 http 授权控件 +// SetSignature 设置自定义 http 授权控件 func SetSignature(auth auth.HTTPAuth) { if auth != nil { extension.SetHTTPAuth(auth) } } -//SetBackupFileHandler 设置自定义备份文件处理组件 +// SetBackupFileHandler 设置自定义备份文件处理组件, 仅保留一个 func SetBackupFileHandler(file file.FileHandler) { if file != nil { extension.SetFileHandler(file) } } -//SetLoadBalance 设置自定义负载均衡组件 +/** + * AddBackupFileHandler 添加自定义备份文件处理组件 + * + * 此函数允许用户添加多个自定义的备份文件处理器,并指定其优先级。 + * 优先级越高的处理器,将会优先被读取。 + * + * 默认的文件缓存实现具有较好的可靠性,推荐优先使用。 + * 文件缓存实现的默认优先级为0。用户可以根据自己的需求设置不同的优先级来决定读取顺序。 + * 推荐将 ConfigMap 实现的优先级设置低于文件缓存。 + * + * 参数: + * - file: 自定义的文件处理器。 + * - priority: 文件处理器的优先级,数值越大优先级越高。若优先级相同,根据添加顺序决定读取顺序 + * + * 示例: + * extension.AddBackupFileHandler(anotherFileHandler, 1) + * extension.AddConfigMapHandler(configMapHandler, -1) + */ +func AddBackupFileHandler(file file.FileHandler, priority int) { + if file != nil { + extension.AddFileHandler(file, priority) + } +} + +// SetLoadBalance 设置自定义负载均衡组件 func SetLoadBalance(loadBalance cluster.LoadBalance) { if loadBalance != nil { extension.SetLoadBalance(loadBalance) } } -//SetLogger 设置自定义logger组件 +// SetLogger 设置自定义logger组件 func SetLogger(loggerInterface log.LoggerInterface) { if loggerInterface != nil { log.InitLogger(loggerInterface) } } -//SetCache 设置自定义cache组件 +// SetCache 设置自定义cache组件 func SetCache(cacheFactory agcache.CacheFactory) { if cacheFactory != nil { extension.SetCacheFactory(cacheFactory) diff --git a/start_test.go b/start_test.go index b83a765e..10450823 100644 --- a/start_test.go +++ b/start_test.go @@ -19,6 +19,8 @@ package agollo import ( "encoding/json" + "github.com/apolloconfig/agollo/v4/env/file" + "github.com/stretchr/testify/assert" "net/http" "os" "testing" @@ -73,7 +75,7 @@ func TestStart(t *testing.T) { value := client.GetValue("key1") Assert(t, "value1", Equal(value)) - handler := extension.GetFileHandler() + handler := extension.GetFileHandlers() Assert(t, handler, NotNilVal()) } @@ -212,17 +214,64 @@ func (fileHandler *testFileHandler) GetConfigFile(configDir string, appID string } // LoadConfigFile load config from file -func (fileHandler *testFileHandler) LoadConfigFile(configDir string, appID string, namespace string) (*config.ApolloConfig, error) { +func (fileHandler *testFileHandler) LoadConfigFile(configDir string, appID string, namespace string, cluster string) (*config.ApolloConfig, error) { return nil, nil } -func TestSetBackupFileHandler(t *testing.T) { - fileHandler := extension.GetFileHandler() +func TestAddBackupFileHandler(t *testing.T) { + fileHandler := extension.GetFileHandlers() Assert(t, fileHandler, NotNilVal()) t2 := &testFileHandler{} - SetBackupFileHandler(t2) - Assert(t, t2, Equal(extension.GetFileHandler())) + AddBackupFileHandler(t2, 10) + + firstHandler := extension.GetFileHandlers().Front().Value.(extension.HandlerWithPriority).Handler + assert.Equal(t, t2, firstHandler, "The handlers should be equal") + //Assert(t, t2, Equal(extension.GetFileHandlers().Front().Value.(extension.HandlerWithPriority).Handler)) +} + +func TestSetBackupFileHandler(t *testing.T) { + handler1 := &testFileHandler{} + handler2 := &testFileHandler{} + + // 设置第一个处理器 + SetBackupFileHandler(handler1) + + expectedOrder1 := []file.FileHandler{handler1} + actualOrder1 := make([]file.FileHandler, 0, 1) + + sortedHandlers1 := extension.GetFileHandlers() + for e := sortedHandlers1.Front(); e != nil; e = e.Next() { + actualOrder1 = append(actualOrder1, e.Value.(extension.HandlerWithPriority).Handler) + } + + assert.Equal(t, expectedOrder1, actualOrder1, "The handlers should be set to handler1") + + // 设置第二个处理器 + SetBackupFileHandler(handler2) + + expectedOrder2 := []file.FileHandler{handler2} + actualOrder2 := make([]file.FileHandler, 0, 1) + + sortedHandlers2 := extension.GetFileHandlers() + for e := sortedHandlers2.Front(); e != nil; e = e.Next() { + actualOrder2 = append(actualOrder2, e.Value.(extension.HandlerWithPriority).Handler) + } + + assert.Equal(t, expectedOrder2, actualOrder2, "The handlers should be set to handler2") + + // 设置 nil 处理器,不应改变现有处理器 + SetBackupFileHandler(nil) + + expectedOrder3 := []file.FileHandler{handler2} + actualOrder3 := make([]file.FileHandler, 0, 1) + + sortedHandlers3 := extension.GetFileHandlers() + for e := sortedHandlers3.Front(); e != nil; e = e.Next() { + actualOrder3 = append(actualOrder3, e.Value.(extension.HandlerWithPriority).Handler) + } + + assert.Equal(t, expectedOrder3, actualOrder3, "The handlers should remain as handler2") } type TestAuth struct{} @@ -269,6 +318,6 @@ func TestStartWithConfigMustReadFromRemote(t *testing.T) { value := client.GetValue("key1") Assert(t, "value1", Equal(value)) - handler := extension.GetFileHandler() + handler := extension.GetFileHandlers() Assert(t, handler, NotNilVal()) } diff --git a/storage/repository.go b/storage/repository.go index 887b718f..5b6e46ef 100644 --- a/storage/repository.go +++ b/storage/repository.go @@ -20,6 +20,7 @@ package storage import ( "container/list" "fmt" + "github.com/apolloconfig/agollo/v4/env/file" "reflect" "strconv" "strings" @@ -453,7 +454,7 @@ func (c *Config) GetBoolValue(key string, defaultValue bool) bool { } // UpdateApolloConfig 根据config server返回的内容更新内存 -// 并判断是否需要写备份文件 +// 并判断是否需要写备份文件和configmap func (c *Cache) UpdateApolloConfig(apolloConfig *config.ApolloConfig, appConfigFunc func() config.AppConfig) { if apolloConfig == nil { log.Error("apolloConfig is null, can't update!") @@ -481,10 +482,23 @@ func (c *Cache) UpdateApolloConfig(apolloConfig *config.ApolloConfig, appConfigF } if appConfig.GetIsBackupConfig() { - // write config file async + // 写备份文件和configmap apolloConfig.AppID = appConfig.AppID - go extension.GetFileHandler().WriteConfigFile(apolloConfig, appConfig.GetBackupConfigPath()) + apolloConfig.Cluster = appConfig.Cluster + apolloConfig.NamespaceName = appConfig.NamespaceName + + handlers := extension.GetFileHandlers() + for e := handlers.Front(); e != nil; e = e.Next() { + h := e.Value.(extension.HandlerWithPriority).Handler + go func(h file.FileHandler) { + err := h.WriteConfigFile(apolloConfig, appConfig.GetBackupConfigPath()) + if err != nil { + log.Error(err) + } + }(h) + } } + } // UpdateApolloConfigCache 根据conf[ig server返回的内容更新内存