diff --git a/pkg/operator/controller.go b/pkg/operator/controller.go index 9a01b95aa6..8aa012229e 100644 --- a/pkg/operator/controller.go +++ b/pkg/operator/controller.go @@ -789,7 +789,8 @@ func (c *Controller) syncMachineConfig(labels map[string]string, profile *tunedv c.mcLabelsAcrossMCP[profile.Name] = false } - name := GetMachineConfigNameForPools(pools) + // Use the TuneD daemon profile name for the MachineConfig name + name := GetMachineConfigNameForProfile(profile.Spec.Config.TunedProfile) klog.V(2).Infof("syncMachineConfig(): %v", name) nodes, err := c.pc.getNodesForPool(pools[0]) @@ -914,7 +915,8 @@ func (c *Controller) syncMachineConfigHyperShift(nodePoolName string, profile *t kernelArguments []string ) - mcName := MachineConfigPrefix + "-" + nodePoolName + // Use the TuneD daemon profile name for the MachineConfig name + mcName := GetMachineConfigNameForProfile(profile.Spec.Config.TunedProfile) configMapName := mcConfigMapName(nodePoolName) nodes, err := c.getNodesForNodePool(nodePoolName) @@ -1122,19 +1124,26 @@ func (c *Controller) getMachineConfigNamesForTuned() (map[string]bool, error) { return nil, fmt.Errorf("failed to list Tuned: %v", err) } + // Consider only current profiles. + profileList, err := c.listers.TunedProfiles.List(labels.Everything()) + if err != nil { + return nil, fmt.Errorf("failed to list Tuned Profiles: %v", err) + } + currentProfileNames := map[string]bool{} + for _, profile := range profileList { + currentProfileNames[profile.Spec.Config.TunedProfile] = true + } + mcNames := map[string]bool{} for _, recommend := range TunedRecommend(tunedList) { - if recommend.Profile == nil || recommend.MachineConfigLabels == nil { + if recommend.Profile == nil || recommend.MachineConfigLabels == nil || + !currentProfileNames[*recommend.Profile] { continue } - pools, err := c.pc.getPoolsForMachineConfigLabels(recommend.MachineConfigLabels) - if err != nil { - return nil, err - } - mcName := GetMachineConfigNameForPools(pools) - + // Use the TuneD profile name directly for the MachineConfig name. + mcName := GetMachineConfigNameForProfile(*recommend.Profile) mcNames[mcName] = true } diff --git a/pkg/operator/mc.go b/pkg/operator/mc.go index b310fe4378..da67293c22 100644 --- a/pkg/operator/mc.go +++ b/pkg/operator/mc.go @@ -68,29 +68,15 @@ func printMachineConfigPoolsNames(pools []*mcfgv1.MachineConfigPool) string { return sb.String() } -// GetMachineConfigNameForPools takes pools a slice of MachineConfigPools and returns -// a MachineConfig name to be used for MachineConfigPool based matching. -func GetMachineConfigNameForPools(pools []*mcfgv1.MachineConfigPool) string { - var ( - sb strings.Builder - poolNames []string - ) - - for _, pool := range pools { - if pool == nil { - continue - } - poolNames = append(poolNames, pool.Name) - } - // See OCPBUGS-24792: the slice of MCP objects can be passed in random order. - sort.Strings(poolNames) +// GetMachineConfigNameForProfile takes a TuneD daemon profile name and returns +// a MachineConfig name to be used for that profile. +func GetMachineConfigNameForProfile(profileName string) string { + var sb strings.Builder sb.WriteString(MachineConfigPrefix) - if len(poolNames) > 0 { + if profileName != "" { sb.WriteString("-") - // Use the first MCP's name out of all alphabetically sorted MCP names. This will either be a custom pool name - // or master/worker in that order. - sb.WriteString(poolNames[0]) + sb.WriteString(profileName) } return sb.String() diff --git a/pkg/operator/mc_test.go b/pkg/operator/mc_test.go new file mode 100644 index 0000000000..43c66da310 --- /dev/null +++ b/pkg/operator/mc_test.go @@ -0,0 +1,34 @@ +package operator + +import ( + "testing" +) + +func TestGetMachineConfigNameForProfile(t *testing.T) { + tests := []struct { + name string + profileName string + expected string + }{ + { + name: "standard profile name generated by PPC", + profileName: "openshift-node-performance-performance", + expected: "50-nto-openshift-node-performance-performance", + }, + { + // This should never happen. + name: "empty profile name", + profileName: "", + expected: "50-nto", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := GetMachineConfigNameForProfile(tt.profileName) + if result != tt.expected { + t.Errorf("GetMachineConfigNameForProfile(%q) = %q, want %q", tt.profileName, result, tt.expected) + } + }) + } +} diff --git a/pkg/tuned/cmd/render/render.go b/pkg/tuned/cmd/render/render.go index e89f813064..5cfe2b420e 100644 --- a/pkg/tuned/cmd/render/render.go +++ b/pkg/tuned/cmd/render/render.go @@ -262,7 +262,7 @@ func render(inputDir []string, outputDir string, mcpName string) error { return err } - mc, err := renderMachineConfig(mcp, bootcmdline, mcConfigs, mcp.Spec.MachineConfigSelector.MatchLabels) + mc, err := renderMachineConfig(recommendedProfile, bootcmdline, mcConfigs, mcp.Spec.MachineConfigSelector.MatchLabels) if err != nil { klog.Errorf("error while rendering machine config %v", err) return fmt.Errorf("error while rendering machine config: %w", err) @@ -314,14 +314,13 @@ func loadDefaultCrTuneD(tuneD *[]*tunedv1.Tuned) error { return nil } -func renderMachineConfig(pool *mcfgv1.MachineConfigPool, bootcmdline string, mConfigs []*mcfgv1.MachineConfig, mcLabels map[string]string) (*mcfgv1.MachineConfig, error) { +func renderMachineConfig(profileName string, bootcmdline string, mConfigs []*mcfgv1.MachineConfig, mcLabels map[string]string) (*mcfgv1.MachineConfig, error) { if len(bootcmdline) == 0 { klog.Info("Empty cmdbootline. Avoid creating MachineConfig") return nil, nil } - pools := []*mcfgv1.MachineConfigPool{pool} - mcName := operator.GetMachineConfigNameForPools(pools) + mcName := operator.GetMachineConfigNameForProfile(profileName) kernelArgs := util.SplitKernelArguments(bootcmdline) annotations := map[string]string{operator.GeneratedByControllerVersionAnnotationKey: version.Version}