Skip to content

Commit

Permalink
- sync config api_server to common service
Browse files Browse the repository at this point in the history
  • Loading branch information
wanyaoqi committed Apr 23, 2020
1 parent b30a29f commit 2ce9c33
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/controller/onecloud_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,23 @@ func (c keystoneComponent) SystemInit() error {
if err := doCreateCommonService(s); err != nil {
return errors.Wrap(err, "create common service")
}
if err := doSyncCommonConfigure(s, c.getCommonConfig()); err != nil {
return errors.Wrap(err, "sync common configure")
}
return nil
})
}

func (c keystoneComponent) getCommonConfig() map[string]string {
getApiGatewayUrl := fmt.Sprintf("https://%s:%d",
NewClusterComponentName(c.GetCluster().GetName(), v1alpha1.APIGatewayComponentType),
constants.APIGatewayPort,
)
return map[string]string{
"api_server": getApiGatewayUrl,
}
}

func shouldDoPolicyRoleInit(s *mcclient.ClientSession) (bool, error) {
ret, err := modules.Policies.List(s, nil)
if err != nil {
Expand Down Expand Up @@ -532,6 +545,11 @@ func doCreateCommonService(s *mcclient.ClientSession) error {
return err
}

func doSyncCommonConfigure(s *mcclient.ClientSession, defaultConf map[string]string) error {
_, err := onecloud.SyncServiceConfig(s, defaultConf, constants.ServiceNameCommon)
return err
}

func doRegisterOfflineCloudMeta(s *mcclient.ClientSession, regionId string) error {
return onecloud.RegisterServicePublicInternalEndpoint(s, regionId,
constants.ServiceNameOfflineCloudmeta,
Expand Down
24 changes: 24 additions & 0 deletions pkg/util/onecloud/onecloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,27 @@ func EnsureDevtoolTemplate(
return CreateDevtoolTemplate(s, name, hosts, mods, files, interval)
})
}

func SyncServiceConfig(
s *mcclient.ClientSession, syncConf map[string]string, serviceName string,
) (jsonutils.JSONObject, error) {
iconf, err := modules.ServicesV3.GetSpecific(s, serviceName, "config", nil)
if err != nil {
return nil, err
}
conf := iconf.(*jsonutils.JSONDict)
if !conf.Contains("config") {
conf.Add(jsonutils.NewDict(), "config")
}
if !conf.Contains("config", "default") {
conf.Add(jsonutils.NewDict(), "config", "default")
}
for k, v := range syncConf {
if _, ok := conf.GetString("config", "default", k); ok == nil {
continue
} else {
conf.Add(jsonutils.NewString(v), "config", "default", k)
}
}
return modules.ServicesV3.PerformAction(s, serviceName, "config", conf)
}

0 comments on commit 2ce9c33

Please sign in to comment.