-
-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[OSPP]Support Kubernetes ConfigMap for Apollo java, golang client #79 #318
Merged
Merged
Changes from 15 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
9c177c8
feat:Support Kubernetes ConfigMap cache for Agollo
dyx1234 e198427
fix:add missed config parameter
dyx1234 c2edb74
fix
dyx1234 d233b89
fix
dyx1234 3a2e852
fix
dyx1234 5703446
fix
dyx1234 0a633c5
fix
dyx1234 c2d16e9
fix
dyx1234 13b46b5
fix
dyx1234 ec52796
fix:go version
dyx1234 22911a6
Merge branch 'develop' into master
dyx1234 c779a66
fix: ut
dyx1234 d8892ed
Merge remote-tracking branch 'origin/master'
dyx1234 5df2d22
fix: rename k8sNamespace
dyx1234 1bf6fdd
fix: 版本号机制处理并发
dyx1234 7a6f7c9
fix: 不主动初始化
dyx1234 46c9f7d
fix: 不主动初始化
dyx1234 0ccdf88
feat: 将file接口统一,并提供优先级策略
dyx1234 1bbb9e4
feat: 将file接口统一,并提供优先级策略
dyx1234 862ffe4
bugfix
dyx1234 1d16552
bugfix
dyx1234 f6e7a38
fix
dyx1234 ccfda6b
fix
dyx1234 b6aeff6
fix
dyx1234 9914308
fix once
dyx1234 421d18d
final fix
dyx1234 7c213e3
fix: change default value to 0
dyx1234 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
||
if err != nil { | ||
log.Errorf("LoadConfigFile error, error: %v", err) | ||
return | ||
|
@@ -160,6 +161,21 @@ func loadBackupConfig(namespace string, appConfig config.AppConfig) []*config.Ap | |
return apolloConfigs | ||
} | ||
|
||
func loadBackupConfiguration(appConfig config.AppConfig, namespace string) (*config.ApolloConfig, error) { | ||
if appConfig.GetIsBackupConfig() { | ||
c, err := extension.GetFileHandler().LoadConfigFile(appConfig.BackupConfigPath, appConfig.AppID, namespace) | ||
if err == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 如果 err 为空,但是读取的配置文件对象(c) 为空,需要继续尝试下一个 handler 吗? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 是要的,疏忽了。已优化这个循环的逻辑 |
||
return c, nil | ||
} | ||
} | ||
|
||
if appConfig.GetIsBackupConfigToConfigMap() { | ||
return extension.GetConfigMapHandler().LoadConfigMap(appConfig, appConfig.K8sNamespace) | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
||
func createApolloConfigWithJSON(b []byte, callback http.CallBack) (o interface{}, err error) { | ||
apolloConfig := &config.ApolloConfig{} | ||
err = json.Unmarshal(b, apolloConfig) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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 extension | ||
|
||
import "github.com/apolloconfig/agollo/v4/store" | ||
|
||
var configMapHandler store.ConfigMapHandler | ||
|
||
// SetConfigMapHandler Set the ConfigMap cache handler | ||
func SetConfigMapHandler(inConfigMapHandler store.ConfigMapHandler) { | ||
configMapHandler = inConfigMapHandler | ||
} | ||
|
||
// GetConfigMapHandler Get the ConfigMap cache handler | ||
func GetConfigMapHandler() store.ConfigMapHandler { | ||
return configMapHandler | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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 extension | ||
|
||
import ( | ||
"github.com/apolloconfig/agollo/v4/env/config" | ||
. "github.com/tevid/gohamcrest" | ||
"testing" | ||
) | ||
|
||
type TestConfigMapHandler struct { | ||
} | ||
|
||
func (t *TestConfigMapHandler) LoadConfigMap(appConfig config.AppConfig, k8sNamespace string) (*config.ApolloConfig, error) { | ||
return nil, nil | ||
} | ||
|
||
func (t *TestConfigMapHandler) WriteConfigMap(config *config.ApolloConfig, k8sNamespace string) error { | ||
return nil | ||
} | ||
|
||
// TestSetConfigMapHandler 测试 SetConfigMapHandler 函数 | ||
func TestSetConfigMapHandler(t *testing.T) { | ||
SetConfigMapHandler(&TestConfigMapHandler{}) | ||
|
||
resultConfigMapHandler := GetConfigMapHandler() | ||
|
||
Assert(t, resultConfigMapHandler, NotNilVal()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么会会修改 client?我理解整体的框架应该是没有变化。
只是提供一个新的插件,通过文档告诉用户有这个插件可以选择。
我理解只需要按下方实现方式实现即可:
https://github.sheincorp.cn/zouyx/agollo_demo/tree/master/custom/file
如果是现在这种改法,可能会在用户升级的时候出现不兼容状态。
出现这种状态,可能会导致用户出现测试成本增加,或者生产故障。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我最初是在client文件的init里,作为插件初始化的。
但是那个位置无法获取用户的配置信息(*config.AppConfig)来判断是否初始化这个插件。如果盲目初始化插件会调用GetK8sManager方法,连接不到k8s的话会直接报错。所以挪到StartWithConfig这个方法里来了。
这样会有什么问题吗,如果用户没设置IsBackupConfigToConfigMap,就不进行这个插件的初始化