Skip to content
Draft
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
27 changes: 18 additions & 9 deletions pkg/operator/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down
26 changes: 6 additions & 20 deletions pkg/operator/mc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
34 changes: 34 additions & 0 deletions pkg/operator/mc_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}
7 changes: 3 additions & 4 deletions pkg/tuned/cmd/render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}

Expand Down