Skip to content

Commit

Permalink
fix: remove useless options from configmap
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito committed Jan 25, 2024
1 parent 39e6dc0 commit 962bcff
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
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
21 changes: 21 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,21 @@ 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() {
return config
}
for _, k := range options.SortedKeys() {
if !utils.IsInArray(k, identityapi.ServiceBlacklistOptionMap["default"]) {
options.Remove(k)
}
}
return options
}

0 comments on commit 962bcff

Please sign in to comment.