Skip to content

Commit 4962902

Browse files
authored
Merge pull request openshift-kni#1537 from Tal-or/rte_config_support_legacy_format
e2e:config: support old RTE config format
2 parents cf6b010 + ba7b70a commit 4962902

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

test/internal/configuration/configuration.go

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ import (
2323
"time"
2424

2525
corev1 "k8s.io/api/core/v1"
26+
"k8s.io/klog/v2"
2627

28+
"sigs.k8s.io/controller-runtime/pkg/client"
2729
"sigs.k8s.io/yaml"
2830

2931
"github.com/k8stopologyawareschedwg/deployer/pkg/deployer/platform"
3032
nrtv1alpha2 "github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha2"
33+
"github.com/k8stopologyawareschedwg/resource-topology-exporter/pkg/podres/middleware/podexclude"
3134

3235
"github.com/openshift-kni/numaresources-operator/pkg/version"
3336
rteconfig "github.com/openshift-kni/numaresources-operator/rte/pkg/config"
@@ -52,6 +55,14 @@ var (
5255
MachineConfigPoolUpdateInterval time.Duration
5356
)
5457

58+
// ConfigLegacy is the legacy config.yaml format which is used by the RTE until v4.18.0.
59+
type ConfigLegacy struct {
60+
ExcludeList map[string][]string `json:"excludeList,omitempty"`
61+
TopologyManagerPolicy string `json:"topologyManagerPolicy,omitempty"`
62+
TopologyManagerScope string `json:"topologyManagerScope,omitempty"`
63+
PodExcludes map[string]string `json:"podExcludes"`
64+
}
65+
5566
func init() {
5667
var err error
5768

@@ -86,8 +97,12 @@ func ValidateAndExtractRTEConfigData(cm *corev1.ConfigMap) (rteconfig.Config, er
8697
return cfg, fmt.Errorf("config.yaml not found in ConfigMap %s/%s", cm.Namespace, cm.Name)
8798
}
8899

89-
if err := yaml.Unmarshal([]byte(raw), &cfg); err != nil {
90-
return cfg, fmt.Errorf("failed to unmarshal config.yaml: %w", err)
100+
if err := yaml.UnmarshalStrict([]byte(raw), &cfg); err != nil {
101+
klog.ErrorS(err, "failed to unmarshal config.yaml; falling back to legacy config", "configMap", client.ObjectKeyFromObject(cm))
102+
cfg, err = rteConfigFromConfigLegacy(raw)
103+
if err != nil {
104+
return cfg, err
105+
}
91106
}
92107

93108
if cfg.Kubelet.TopologyManagerPolicy != "single-numa-node" {
@@ -109,3 +124,27 @@ func CheckTopologyManagerConfigMatching(nrt *nrtv1alpha2.NodeResourceTopology, c
109124
}
110125
return matchingErr
111126
}
127+
128+
func rteConfigFromConfigLegacy(raw string) (rteconfig.Config, error) {
129+
var cfg rteconfig.Config
130+
var cfgLegacy ConfigLegacy
131+
132+
if err := yaml.UnmarshalStrict([]byte(raw), &cfgLegacy); err != nil {
133+
return cfg, fmt.Errorf("failed to unmarshal legacy config.yaml: %w", err)
134+
}
135+
136+
cfg.Kubelet = rteconfig.KubeletParams{
137+
TopologyManagerPolicy: cfgLegacy.TopologyManagerPolicy,
138+
TopologyManagerScope: cfgLegacy.TopologyManagerScope,
139+
}
140+
cfg.ResourceExclude = cfgLegacy.ExcludeList
141+
cfg.PodExclude = make(podexclude.List, 0, len(cfgLegacy.PodExcludes))
142+
for namespace, name := range cfgLegacy.PodExcludes {
143+
cfg.PodExclude = append(cfg.PodExclude, podexclude.Item{
144+
NamespacePattern: namespace,
145+
NamePattern: name,
146+
})
147+
}
148+
149+
return cfg, nil
150+
}

0 commit comments

Comments
 (0)