Skip to content

Commit

Permalink
fix: init service config
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito committed Jan 25, 2024
1 parent bd44fc9 commit 1dee177
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 16 deletions.
5 changes: 3 additions & 2 deletions pkg/manager/component/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import (
"context"
"encoding/json"
"fmt"
"path"
"reflect"

"github.com/pkg/errors"
apps "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1beta1"
Expand All @@ -29,8 +32,6 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/klog"
"path"
"reflect"

"yunion.io/x/onecloud-operator/pkg/apis/constants"
"yunion.io/x/onecloud-operator/pkg/apis/onecloud/v1alpha1"
Expand Down
8 changes: 8 additions & 0 deletions pkg/service-init/component/apigateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ func (a apiGateway) GetConfig(oc *v1alpha1.OnecloudCluster, cfg *v1alpha1.Oneclo

return opt, nil
}

func (a apiGateway) GetServiceInitConfig(oc *v1alpha1.OnecloudCluster) map[string]interface{} {
return map[string]interface{}{
"ws_port": constants.APIWebsocketPort,
"cors_hosts": oc.Spec.APIGateway.CorsHosts,
}
}

func (a apiGateway) GetDefaultCloudUser(cfg *v1alpha1.OnecloudClusterConfig) *v1alpha1.CloudUser {
return &cfg.APIGateway.CloudUser
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/service-init/component/base_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func (bs baseService) GetOptions() interface{} {
return bs.options
}

func (c baseService) GetServiceInitConfig(oc *v1alpha1.OnecloudCluster) map[string]interface{} {
return map[string]interface{}{}
}

func (c baseService) GetConfig(oc *v1alpha1.OnecloudCluster, cfg *v1alpha1.OnecloudClusterConfig) (interface{}, error) {
return nil, nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/service-init/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Component interface {
BuildClusterConfigCloudUser(clsCfg *v1alpha1.OnecloudClusterConfig, user v1alpha1.CloudUser) error

GetConfig(oc *v1alpha1.OnecloudCluster, cfg *v1alpha1.OnecloudClusterConfig) (interface{}, error)
GetServiceInitConfig(oc *v1alpha1.OnecloudCluster) map[string]interface{}
GetOptions() interface{}
GetDefaultDBConfig(cfg *v1alpha1.OnecloudClusterConfig) *v1alpha1.DBConfig
GetDefaultClickhouseConfig(cfg *v1alpha1.OnecloudClusterConfig) *v1alpha1.DBConfig
Expand Down
20 changes: 11 additions & 9 deletions pkg/service-init/component/glance.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,23 @@ func (g glance) GetConfig(oc *v1alpha1.OnecloudCluster, cfg *v1alpha1.OnecloudCl
option.SetClickhouseOptions(&opt.DBOptions, oc.Spec.Clickhouse, config.ClickhouseConf)
option.SetOptionsServiceTLS(&opt.BaseOptions, false)
option.SetServiceCommonOptions(&opt.CommonOptions, oc, config.ServiceDBCommonOptions.ServiceCommonOptions)

opt.FilesystemStoreDatadir = constants.GlanceFileStoreDir
//opt.TorrentStoreDir = constants.GlanceTorrentStoreDir
opt.EnableTorrentService = false
// TODO: fix this
opt.AutoSyncTable = true
opt.Port = config.Port
return opt, nil
}

func (g glance) GetServiceInitConfig(oc *v1alpha1.OnecloudCluster) map[string]interface{} {
ret := map[string]interface{}{
"filesystem_store_datadir": constants.GlanceFileStoreDir,
"enable_torrent_service": false,
"enable_remote_executor": true,
}
if oc.Spec.ProductVersion == v1alpha1.ProductVersionCMP {
opt.EnableRemoteExecutor = false
opt.TargetImageFormats = []string{"qcow2", "vmdk"}
} else {
opt.EnableRemoteExecutor = true
ret["enable_remote_executor"] = false
ret["target_image_formats"] = []string{"qcow2", "vmdk"}
}
return opt, nil
return ret
}

func (g glance) GetPhaseControl(man controller.ComponentManager) controller.PhaseControl {
Expand Down
12 changes: 9 additions & 3 deletions pkg/service-init/component/keystone.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,20 @@ func (k keystone) GetConfig(oc *v1alpha1.OnecloudCluster, cfg *v1alpha1.Onecloud
option.SetOptionsServiceTLS(&opt.BaseOptions, oc.Spec.Keystone.DisableTLS)
option.SetServiceBaseOptions(&opt.BaseOptions, oc.GetRegion(), config.ServiceBaseConfig)

opt.BootstrapAdminUserPassword = oc.Spec.Keystone.BootstrapPassword
// always reset admin user password to ensure password is correct
opt.ResetAdminUserPassword = true
opt.AdminPort = constants.KeystoneAdminPort

return opt, nil
}

func (k keystone) GetServiceInitConfig(oc *v1alpha1.OnecloudCluster) map[string]interface{} {
ret := map[string]interface{}{
"bootstrap_admin_user_password": oc.Spec.Keystone.BootstrapPassword,
// always reset admin user password to ensure password is correct
"ResetAdminUserPassword": true,
}
return ret
}

func (k keystone) GetDefaultDBConfig(cfg *v1alpha1.OnecloudClusterConfig) *v1alpha1.DBConfig {
return &cfg.Keystone.DB
}
Expand Down
1 change: 1 addition & 0 deletions pkg/service-init/component/kubeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (r kubeServer) GetConfig(oc *v1alpha1.OnecloudCluster, cfg *v1alpha1.Oneclo

return opt, nil
}

func (r kubeServer) GetPhaseControl(man controller.ComponentManager) controller.PhaseControl {
return man.KubeServer(nil)
}
1 change: 1 addition & 0 deletions pkg/service-init/component/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (r notify) GetDefaultClickhouseConfig(cfg *v1alpha1.OnecloudClusterConfig)
func (r notify) GetDefaultCloudUser(cfg *v1alpha1.OnecloudClusterConfig) *v1alpha1.CloudUser {
return &cfg.Notify.CloudUser
}

func (r notify) GetConfig(oc *v1alpha1.OnecloudCluster, cfg *v1alpha1.OnecloudClusterConfig) (interface{}, error) {
opt := &options.Options
if err := option.SetOptionsDefault(opt, constants.ServiceTypeNotify); err != nil {
Expand Down
10 changes: 8 additions & 2 deletions pkg/service-init/component/webconsole.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package component

import (
"fmt"

"yunion.io/x/onecloud-operator/pkg/apis/constants"
"yunion.io/x/onecloud-operator/pkg/controller"
"yunion.io/x/onecloud-operator/pkg/util/option"
Expand Down Expand Up @@ -44,8 +45,6 @@ func (r webconsole) GetConfig(oc *v1alpha1.OnecloudCluster, cfg *v1alpha1.Oneclo
option.SetOptionsServiceTLS(&opt.BaseOptions, false)
option.SetServiceCommonOptions(&opt.CommonOptions, oc, config.ServiceCommonOptions)

opt.IpmitoolPath = "/usr/sbin/ipmitool"
opt.EnableAutoLogin = true
address := oc.Spec.LoadBalancerEndpoint
opt.Port = constants.WebconsolePort
// opt.ApiServer = fmt.Sprintf("https://%s:%d", address, constants.WebconsolePort)
Expand All @@ -54,6 +53,13 @@ func (r webconsole) GetConfig(oc *v1alpha1.OnecloudCluster, cfg *v1alpha1.Oneclo
return opt, nil
}

func (r webconsole) GetServiceInitConfig(oc *v1alpha1.OnecloudCluster) map[string]interface{} {
return map[string]interface{}{
"ipmitool_path": "/usr/sbin/ipmitool",
"enable_auto_login": true,
}
}

func (w webconsole) GetDefaultDBConfig(cfg *v1alpha1.OnecloudClusterConfig) *v1alpha1.DBConfig {
return &cfg.Webconsole.DB
}
Expand Down
19 changes: 19 additions & 0 deletions pkg/util/onecloud/onecloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package onecloud

import (
"context"
"net/http"
"reflect"
"strings"
Expand All @@ -32,6 +33,7 @@ import (
identityapi "yunion.io/x/onecloud/pkg/apis/identity"
monitorapi "yunion.io/x/onecloud/pkg/apis/monitor"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/auth"
"yunion.io/x/onecloud/pkg/mcclient/modulebase"
ansible_modules "yunion.io/x/onecloud/pkg/mcclient/modules/ansible"
"yunion.io/x/onecloud/pkg/mcclient/modules/compute"
Expand Down Expand Up @@ -910,3 +912,20 @@ func GetConfig(opt interface{}) jsonutils.JSONObject {
}
return options
}

func InitServiceConfig(service, region string, opts map[string]interface{}) error {
s := auth.GetAdminSession(context.Background(), region)
resp, err := identity.ServicesV3.GetSpecific(s, service, "config", nil)
if err != nil {
return errors.Wrapf(err, "get spec")
}
values := jsonutils.NewDict()
for k, v := range opts {
if resp.Contains("config", "default", k) {
continue
}
values.Add(jsonutils.Marshal(v), "config", "default", k)
}
_, err = identity.ServicesV3.PerformAction(s, service, "config", values)
return err
}

0 comments on commit 1dee177

Please # to comment.