Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Automated cherry pick of #1042: fix: remove useless options from configmap #1043

Open
wants to merge 1 commit into
base: release/3.11
Choose a base branch
from
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
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
22 changes: 22 additions & 0 deletions pkg/util/onecloud/onecloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package onecloud

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

"golang.org/x/sync/errgroup"
Expand All @@ -24,9 +25,11 @@ 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/modulebase"
Expand Down Expand Up @@ -888,3 +891,22 @@ 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
}