Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/manager/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/klog"

"yunion.io/x/jsonutils"
"yunion.io/x/log"
errorswrap "yunion.io/x/pkg/errors"
"yunion.io/x/pkg/utils"
Expand All @@ -49,6 +48,7 @@ import (
"yunion.io/x/onecloud-operator/pkg/manager"
"yunion.io/x/onecloud-operator/pkg/service-init/component"
"yunion.io/x/onecloud-operator/pkg/util/k8sutil"
"yunion.io/x/onecloud-operator/pkg/util/onecloud"
)

type ComponentManager struct {
Expand Down Expand Up @@ -638,7 +638,7 @@ func (m *ComponentManager) newConfigMap(componentType v1alpha1.ComponentType, zo
}

func (m *ComponentManager) newServiceConfigMap(cType v1alpha1.ComponentType, zone string, oc *v1alpha1.OnecloudCluster, opt interface{}) *corev1.ConfigMap {
configYaml := jsonutils.Marshal(opt).YAMLString()
configYaml := onecloud.GetConfig(opt).YAMLString()
return m.newConfigMap(cType, zone, oc, configYaml)
}

Expand Down
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
3 changes: 2 additions & 1 deletion pkg/service-init/component/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"yunion.io/x/onecloud-operator/pkg/controller"
"yunion.io/x/onecloud-operator/pkg/manager/config"
"yunion.io/x/onecloud-operator/pkg/service-init/cluster"
"yunion.io/x/onecloud-operator/pkg/util/onecloud"
)

type PrepareManager interface {
Expand Down Expand Up @@ -283,7 +284,7 @@ func (m *prepareManager) syncComponentConfig(
case string:
optContent = opt.(string)
default:
optContent = jsonutils.Marshal(opt).YAMLString()
optContent = onecloud.GetConfig(opt).YAMLString()
}
if err := os.WriteFile(
cfgFilePath,
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
41 changes: 41 additions & 0 deletions pkg/util/onecloud/onecloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
package onecloud

import (
"context"
"net/http"
"reflect"
"strings"

"golang.org/x/sync/errgroup"
Expand All @@ -24,11 +26,14 @@ import (
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/util/httputils"
"yunion.io/x/pkg/utils"

ansibleapi "yunion.io/x/onecloud/pkg/apis/ansible"
devtoolapi "yunion.io/x/onecloud/pkg/apis/devtool"
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 @@ -888,3 +893,39 @@ func EnsureAgentAnsiblePlaybookRef(s *mcclient.ClientSession) error {
}
return nil
}

func GetConfig(opt interface{}) jsonutils.JSONObject {
config := jsonutils.Marshal(opt)
options, ok := config.(*jsonutils.JSONDict)
if !ok {
return config
}
rv := reflect.Indirect(reflect.ValueOf(opt))
if !(rv.FieldByName("CommonOptions").IsValid() ||
(rv.FieldByName("DBOptions").IsValid() && rv.FieldByName("BaseOptions").IsValid())) { // keystone
return config
}
for _, k := range options.SortedKeys() {
if !utils.IsInArray(k, identityapi.ServiceBlacklistOptionMap["default"]) {
options.Remove(k)
}
}
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
}