Skip to content
Merged
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
2 changes: 2 additions & 0 deletions cmd/cluster-node-tuning-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import (
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/cmd/render"
"github.com/openshift/cluster-node-tuning-operator/pkg/signals"
"github.com/openshift/cluster-node-tuning-operator/pkg/tuned"
tunedrender "github.com/openshift/cluster-node-tuning-operator/pkg/tuned/cmd/render"
"github.com/openshift/cluster-node-tuning-operator/pkg/util"
"github.com/openshift/cluster-node-tuning-operator/version"
)
Expand Down Expand Up @@ -107,6 +108,7 @@ func prepareCommands() {

if !config.InHyperShift() {
rootCmd.AddCommand(render.NewRenderCommand())
rootCmd.AddCommand(tunedrender.NewRenderBootCmdMCCommand())
}
}

Expand Down
22 changes: 11 additions & 11 deletions pkg/operator/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ func (c *Controller) syncMachineConfig(pools []*mcfgv1.MachineConfigPool, labels
kernelArguments []string
)

name := getMachineConfigNameForPools(pools)
name := GetMachineConfigNameForPools(pools)
nodes, err := c.pc.getNodesForPool(pools[0])
if err != nil {
return err
Expand Down Expand Up @@ -812,18 +812,18 @@ func (c *Controller) syncMachineConfig(pools []*mcfgv1.MachineConfigPool, labels
klog.V(2).Infof("not creating a MachineConfig with empty kernelArguments")
return nil
}
mc = newMachineConfig(name, annotations, labels, kernelArguments)
mc = NewMachineConfig(name, annotations, labels, kernelArguments)
_, err = c.clients.MC.MachineconfigurationV1().MachineConfigs().Create(context.TODO(), mc, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("failed to create MachineConfig %s: %v", mc.ObjectMeta.Name, err)
}
klog.Infof("created MachineConfig %s with%s", mc.ObjectMeta.Name, machineConfigGenerationLogLine(len(bootcmdline) != 0, bootcmdline))
klog.Infof("created MachineConfig %s with%s", mc.ObjectMeta.Name, MachineConfigGenerationLogLine(len(bootcmdline) != 0, bootcmdline))
return nil
}
return err
}

mcNew := newMachineConfig(name, annotations, labels, kernelArguments)
mcNew := NewMachineConfig(name, annotations, labels, kernelArguments)

kernelArgsEq := util.StringSlicesEqual(mc.Spec.KernelArguments, kernelArguments)
if kernelArgsEq {
Expand All @@ -836,7 +836,7 @@ func (c *Controller) syncMachineConfig(pools []*mcfgv1.MachineConfigPool, labels
mc.Spec.KernelArguments = kernelArguments
mc.Spec.Config = mcNew.Spec.Config

l := machineConfigGenerationLogLine(!kernelArgsEq, bootcmdline)
l := MachineConfigGenerationLogLine(!kernelArgsEq, bootcmdline)
klog.V(2).Infof("syncMachineConfig(): updating MachineConfig %s with%s", mc.ObjectMeta.Name, l)
_, err = c.clients.MC.MachineconfigurationV1().MachineConfigs().Update(context.TODO(), mc, metav1.UpdateOptions{})
if err != nil {
Expand Down Expand Up @@ -900,7 +900,7 @@ func (c *Controller) syncMachineConfigHyperShift(nodePoolName string, profile *t
klog.V(2).Infof("not creating a MachineConfig with empty kernelArguments")
return nil
}
mc := newMachineConfig(mcName, annotations, nil, kernelArguments)
mc := NewMachineConfig(mcName, annotations, nil, kernelArguments)

// put the MC into a ConfigMap and create that instead
mcConfigMap, err = newConfigMapForMachineConfig(configMapName, nodePoolName, mc)
Expand All @@ -912,7 +912,7 @@ func (c *Controller) syncMachineConfigHyperShift(nodePoolName string, profile *t
if err != nil {
return fmt.Errorf("failed to create ConfigMap %s for MachineConfig %s: %v", configMapName, mc.ObjectMeta.Name, err)
}
klog.Infof("created ConfigMap %s for MachineConfig %s with%s", configMapName, mc.ObjectMeta.Name, machineConfigGenerationLogLine(len(bootcmdline) != 0, bootcmdline))
klog.Infof("created ConfigMap %s for MachineConfig %s with%s", configMapName, mc.ObjectMeta.Name, MachineConfigGenerationLogLine(len(bootcmdline) != 0, bootcmdline))
return nil
}
return err
Expand All @@ -926,7 +926,7 @@ func (c *Controller) syncMachineConfigHyperShift(nodePoolName string, profile *t
return nil
}

mcNew := newMachineConfig(mcName, annotations, nil, kernelArguments)
mcNew := NewMachineConfig(mcName, annotations, nil, kernelArguments)

// Compare kargs between existing and new mcfg
kernelArgsEq := util.StringSlicesEqual(mc.Spec.KernelArguments, kernelArguments)
Expand All @@ -951,7 +951,7 @@ func (c *Controller) syncMachineConfigHyperShift(nodePoolName string, profile *t
mc.Spec.KernelArguments = kernelArguments
mc.Spec.Config = mcNew.Spec.Config

l := machineConfigGenerationLogLine(!kernelArgsEq, bootcmdline)
l := MachineConfigGenerationLogLine(!kernelArgsEq, bootcmdline)
klog.V(2).Infof("syncMachineConfig(): updating MachineConfig %s with%s", mc.ObjectMeta.Name, l)

newData, err := serializeMachineConfig(mc)
Expand Down Expand Up @@ -1078,7 +1078,7 @@ func (c *Controller) getMachineConfigNamesForTuned() (map[string]bool, error) {

mcNames := map[string]bool{}

for _, recommend := range tunedRecommend(tunedList) {
for _, recommend := range TunedRecommend(tunedList) {
if recommend.Profile == nil || recommend.MachineConfigLabels == nil {
continue
}
Expand All @@ -1087,7 +1087,7 @@ func (c *Controller) getMachineConfigNamesForTuned() (map[string]bool, error) {
if err != nil {
return nil, err
}
mcName := getMachineConfigNameForPools(pools)
mcName := GetMachineConfigNameForPools(pools)

mcNames[mcName] = true
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/operator/mc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
MachineConfigPrefix string = "50-nto"
)

func newMachineConfig(name string, annotations map[string]string, labels map[string]string, kernelArguments []string) *mcfgv1.MachineConfig {
func NewMachineConfig(name string, annotations map[string]string, labels map[string]string, kernelArguments []string) *mcfgv1.MachineConfig {
if labels == nil {
labels = map[string]string{}
}
Expand All @@ -43,7 +43,7 @@ func newMachineConfig(name string, annotations map[string]string, labels map[str
}
}

func getMachineConfigNameForPools(pools []*mcfgv1.MachineConfigPool) string {
func GetMachineConfigNameForPools(pools []*mcfgv1.MachineConfigPool) string {
var (
sb strings.Builder
sbPrimary strings.Builder
Expand Down Expand Up @@ -211,7 +211,7 @@ func (pc *ProfileCalculator) getPrimaryPoolForNode(node *corev1.Node) (*mcfgv1.M
return pools[0], nil
}

func machineConfigGenerationLogLine(bCmdline bool, bootcmdline string) string {
func MachineConfigGenerationLogLine(bCmdline bool, bootcmdline string) string {
var (
sb strings.Builder
)
Expand Down
12 changes: 6 additions & 6 deletions pkg/operator/profilecalculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (pc *ProfileCalculator) calculateProfile(nodeName string) (string, map[stri
return "", nil, nil, operand, fmt.Errorf("failed to list Tuned: %v", err)
}

for _, recommend := range tunedRecommend(tunedList) {
for _, recommend := range TunedRecommend(tunedList) {
var (
pools []*mcfgv1.MachineConfigPool
node *corev1.Node
Expand Down Expand Up @@ -257,7 +257,7 @@ func (pc *ProfileCalculator) calculateProfileHyperShift(nodeName string) (string
}
tunedList = append(tunedList, defaultTuned)

for _, recommend := range tunedRecommend(tunedList) {
for _, recommend := range TunedRecommend(tunedList) {
// Start with node/pod label based matching
if recommend.Match != nil && pc.profileMatches(recommend.Match, nodeName) {
klog.V(3).Infof("calculateProfileHyperShift: node / pod label matching used for node: %s, tunedProfileName: %s, nodePoolName: %s, operand: %v", nodeName, *recommend.Profile, "", recommend.Operand)
Expand Down Expand Up @@ -512,7 +512,7 @@ func (pc *ProfileCalculator) tunedUsesPodLabels(match []tunedv1.TunedMatch) bool

// tunedsUseNodeLabels returns true if any of the Tuned CRs uses Node labels.
func (pc *ProfileCalculator) tunedsUseNodeLabels(tunedSlice []*tunedv1.Tuned) bool {
for _, recommend := range tunedRecommend(tunedSlice) {
for _, recommend := range TunedRecommend(tunedSlice) {
if pc.tunedUsesNodeLabels(recommend.Match) {
return true
}
Expand All @@ -522,7 +522,7 @@ func (pc *ProfileCalculator) tunedsUseNodeLabels(tunedSlice []*tunedv1.Tuned) bo

// tunedsUsePodLabels returns true if any of the Tuned CRs uses Pod labels.
func (pc *ProfileCalculator) tunedsUsePodLabels(tunedSlice []*tunedv1.Tuned) bool {
for _, recommend := range tunedRecommend(tunedSlice) {
for _, recommend := range TunedRecommend(tunedSlice) {
if pc.tunedUsesPodLabels(recommend.Match) {
return true
}
Expand All @@ -537,9 +537,9 @@ func (pc *ProfileCalculator) getNodePoolNameForNode(node *corev1.Node) (string,
return nodePoolName, nil
}

// tunedRecommend returns a priority-sorted TunedRecommend slice out of
// TunedRecommend returns a priority-sorted TunedRecommend slice out of
// a slice of Tuned objects for profile-calculation purposes.
func tunedRecommend(tunedSlice []*tunedv1.Tuned) []tunedv1.TunedRecommend {
func TunedRecommend(tunedSlice []*tunedv1.Tuned) []tunedv1.TunedRecommend {
var recommendAll []tunedv1.TunedRecommend

// Tuned profiles should have unique priority across all Tuned CRs and users
Expand Down
5 changes: 3 additions & 2 deletions pkg/performanceprofile/cmd/render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
performancev2 "github.com/openshift/cluster-node-tuning-operator/pkg/apis/performanceprofile/v2"
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/components/machineconfig"
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/components/manifestset"
"github.com/openshift/cluster-node-tuning-operator/pkg/util"

v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -72,7 +73,7 @@ func render(inputDir, outputDir string) error {
klog.Info("Rendering files into: ", outputDir)

// Read asset directory fileInfo
filePaths, err := listFiles(inputDir)
filePaths, err := util.ListFiles(inputDir)
klog.V(4).Infof("listed files: %v", filePaths)
if err != nil {
return err
Expand All @@ -99,7 +100,7 @@ func render(inputDir, outputDir string) error {
}
defer file.Close()

manifests, err := parseManifests(file.Name(), file)
manifests, err := util.ParseManifests(file.Name(), file)
if err != nil {
return fmt.Errorf("error parsing manifests from %s: %w", file.Name(), err)
}
Expand Down
85 changes: 85 additions & 0 deletions pkg/tuned/cmd/render/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package render

import (
"flag"
"fmt"

"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/components"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

"k8s.io/klog"
)

type renderOpts struct {
assetsInDir []string
assetsOutDir string
}

func NewRenderBootCmdMCCommand() *cobra.Command {
renderOpts := renderOpts{}

cmd := &cobra.Command{
Use: "render-bootcmd-mc",
Short: "Render MC with kernel args",
Run: func(cmd *cobra.Command, args []string) {
if err := renderOpts.Validate(); err != nil {
klog.Fatal(err)
}

if err := renderOpts.Run(); err != nil {
klog.Fatal(err)
}
},
}

addKlogFlags(cmd)
renderOpts.AddFlags(cmd.Flags())
return cmd
}

func (r *renderOpts) AddFlags(fs *pflag.FlagSet) {
fs.StringArrayVar(&r.assetsInDir, "asset-input-dir", []string{components.AssetsDir}, "Input path for the assets directory. (Can use it more than one to define multiple directories)")
fs.StringVar(&r.assetsOutDir, "asset-output-dir", r.assetsOutDir, "Output path for the rendered manifests.")
}

func (r *renderOpts) Validate() error {
var err string
if len(r.assetsInDir) == 0 {
err += "asset-input-dir must be specified. "
}
if len(r.assetsOutDir) == 0 {
err += "asset-output-dir must be specified. "
}

if len(err) == 0 {
return nil
}
return fmt.Errorf(err)
}

func (r *renderOpts) Run() error {
return render(r.assetsInDir, r.assetsOutDir)
}

func addKlogFlags(cmd *cobra.Command) {
fs := flag.NewFlagSet("", flag.PanicOnError)
klog.InitFlags(fs)
cmd.Flags().AddGoFlagSet(fs)
}
Loading