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
9 changes: 1 addition & 8 deletions assets/performanceprofile/configs/99-runtimes.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,11 @@ infra_ctr_cpuset = "{{.ReservedCpus}}"
{{if .SharedCpus}}shared_cpuset = "{{.SharedCpus}}"{{end}}
{{end}}

# We should copy paste the default runtime because this snippet will override the whole runtimes section
[crio.runtime.runtimes.runc]
runtime_path = ""
runtime_type = "oci"
runtime_root = "/run/runc"

# The CRI-O will check the allowed_annotations under the runtime handler and apply high-performance hooks when one of
# high-performance annotations presents under it.
# We should provide the runtime_path because we need to inform that we want to re-use runc binary and we
# do not have high-performance binary under the $PATH that will point to it.
[crio.runtime.runtimes.high-performance]
runtime_path = "{{.RuntimePath}}"
runtime_type = "oci"
runtime_root = "{{.RuntimeRoot}}"
inherit_default_runtime = true
allowed_annotations = ["cpu-load-balancing.crio.io", "cpu-quota.crio.io", "irq-load-balancing.crio.io", "cpu-c-states.crio.io", "cpu-freq-governor.crio.io"{{ if .CrioSharedCPUsAnnotation }}{{ printf ", %q" .CrioSharedCPUsAnnotation}}{{end}}]
1 change: 0 additions & 1 deletion hack/render-sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,5 @@ function rendersync() {
rendersync manual-cluster/performance base/performance default
rendersync bootstrap-cluster/performance pinned-cluster/default bootstrap/no-mcp
rendersync bootstrap-cluster/performance pinned-cluster/default bootstrap-cluster/extra-mcp bootstrap/extra-mcp
rendersync bootstrap-cluster/performance pinned-cluster/default container-runtime-crun bootstrap/extra-ctrcfg
rendersync --owner-ref none -- base/performance manual-cluster/performance no-ref
rendersync --owner-ref none -- base/performance manual-cluster/cpuFrequency default/cpuFrequency
2 changes: 1 addition & 1 deletion manifests/40-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ rules:
verbs: ["create","get","delete","list","update","watch"]
# Needed by the core operator functionality.
- apiGroups: ["machineconfiguration.openshift.io"]
resources: ["machineconfigpools", "containerruntimeconfigs"]
resources: ["machineconfigpools"]
verbs: ["get","list","watch"]
# Needed by the leases mechanism.
- apiGroups: ["coordination.k8s.io"]
Expand Down
7 changes: 3 additions & 4 deletions pkg/operator/hypershift.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ const (
// TODO remove once HyperShift has switched to using new key.
tunedConfigMapConfigKeyDeprecated = "tuned"

operatorGeneratedMachineConfig = "hypershift.openshift.io/nto-generated-machine-config"
mcConfigMapDataKey = "config"
generatedConfigMapPrefix = "nto-mc-"
HypershiftControllerGeneratedContainerRuntimeConfig = "hypershift.openshift.io/containerruntimeconfig-config"
operatorGeneratedMachineConfig = "hypershift.openshift.io/nto-generated-machine-config"
mcConfigMapDataKey = "config"
generatedConfigMapPrefix = "nto-mc-"
)

// syncHostedClusterTuneds synchronizes Tuned objects embedded in ConfigMaps
Expand Down
36 changes: 1 addition & 35 deletions pkg/performanceprofile/cmd/render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ func render(ownerRefMode, inputDir, outputDir string) error {
mcPools []*mcfgv1.MachineConfigPool
mcConfigs []*mcfgv1.MachineConfig
infra *apicfgv1.Infrastructure
ctrcfgs []*mcfgv1.ContainerRuntimeConfig
)
// Iterate through the file paths and read in desired files
for _, path := range filePaths {
Expand Down Expand Up @@ -137,8 +136,6 @@ func render(ownerRefMode, inputDir, outputDir string) error {
if obj.Name == clusterConfigResourceName {
infra = obj
}
case *mcfgv1.ContainerRuntimeConfig:
ctrcfgs = append(ctrcfgs, obj)
default:
klog.Infof("skipping %q [%d] manifest because of unhandled %T", file.Name(), idx+1, obji)
}
Expand Down Expand Up @@ -184,17 +181,11 @@ func render(ownerRefMode, inputDir, outputDir string) error {
continue
}

defaultRuntime, err := getContainerRuntimeName(pp, mcp, ctrcfgs)
if err != nil {
return fmt.Errorf("render: could not determine high-performance runtime class container-runtime for profile %q; %w", pp.Name, err)
}

components, err := manifestset.GetNewComponents(pp,
&performanceprofilecomponents.Options{
ProfileMCP: mcp,
MachineConfig: performanceprofilecomponents.MachineConfigOptions{
PinningMode: partitioningMode,
DefaultRuntime: defaultRuntime},
PinningMode: partitioningMode},
})
if err != nil {
return err
Expand Down Expand Up @@ -388,28 +379,3 @@ func selectMachineConfigPool(pools []*mcfgv1.MachineConfigPool, selectors map[st

return mcp, nil
}

func getContainerRuntimeName(profile *performancev2.PerformanceProfile, mcp *mcfgv1.MachineConfigPool, ctrcfgs []*mcfgv1.ContainerRuntimeConfig) (mcfgv1.ContainerRuntimeDefaultRuntime, error) {
mcpLabels := labels.Set(mcp.Labels)
var matchingCtrConfigs []*mcfgv1.ContainerRuntimeConfig
for _, ctrcfg := range ctrcfgs {
ctrcfgSelector, err := v1.LabelSelectorAsSelector(ctrcfg.Spec.MachineConfigPoolSelector)
if err != nil {
return "", err
}
if ctrcfgSelector.Matches(mcpLabels) {
matchingCtrConfigs = append(matchingCtrConfigs, ctrcfg)
}
}

if len(matchingCtrConfigs) == 0 {
klog.Infof("no ContainerRuntimeConfig found that matches MCP labels %s that associated with performance profile %q; using default container runtime", mcpLabels.String(), profile.Name)
return mcfgv1.ContainerRuntimeDefaultRuntimeRunc, nil
}

if len(matchingCtrConfigs) > 1 {
return "", fmt.Errorf("more than one ContainerRuntimeConfig found that matches MCP labels %s that associated with performance profile %q", mcpLabels.String(), profile.Name)
}

return matchingCtrConfigs[0].Spec.ContainerRuntimeConfig.DefaultRuntime, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ type Options struct {

type MachineConfigOptions struct {
PinningMode *apiconfigv1.CPUPartitioningMode
DefaultRuntime mcov1.ContainerRuntimeDefaultRuntime
MixedCPUsEnabled bool
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,18 @@ import (

corev1 "k8s.io/api/core/v1"
k8serros "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

mcov1 "github.com/openshift/api/machineconfiguration/v1"
performancev2 "github.com/openshift/cluster-node-tuning-operator/pkg/apis/performanceprofile/v2"
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/components"
"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"
profileutil "github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/components/profile"
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/resources"
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/status"
)

var _ components.Handler = &handler{}
Expand Down Expand Up @@ -49,13 +45,6 @@ func (h *handler) Apply(ctx context.Context, obj client.Object, recorder record.
// set missing options
opts.MachineConfig.MixedCPUsEnabled = opts.MixedCPUsFeatureGateEnabled && profileutil.IsMixedCPUsEnabled(profile)

ctrRuntime, err := h.getContainerRuntimeName(ctx, profile, opts.ProfileMCP)
if err != nil {
return fmt.Errorf("could not determine high-performance runtime class container-runtime for profile %q; %w", profile.Name, err)
}
klog.V(2).Infof("using %q as high-performance runtime class container-runtime for profile %q", ctrRuntime, profile.Name)

opts.MachineConfig.DefaultRuntime = ctrRuntime
components, err := manifestset.GetNewComponents(profile, opts)
if err != nil {
return err
Expand Down Expand Up @@ -170,45 +159,3 @@ func (h *handler) Exists(ctx context.Context, profileName string) bool {
}
return false
}

func (h *handler) getContainerRuntimeName(ctx context.Context, profile *performancev2.PerformanceProfile, mcp *mcov1.MachineConfigPool) (mcov1.ContainerRuntimeDefaultRuntime, error) {
ctrcfgList := &mcov1.ContainerRuntimeConfigList{}
if err := h.Client.List(ctx, ctrcfgList); err != nil {
return "", err
}

if len(ctrcfgList.Items) == 0 {
return mcov1.ContainerRuntimeDefaultRuntimeRunc, nil
}

var ctrcfgs []*mcov1.ContainerRuntimeConfig
mcpSetLabels := labels.Set(mcp.Labels)
for i := 0; i < len(ctrcfgList.Items); i++ {
ctrcfg := &ctrcfgList.Items[i]
ctrcfgSelector, err := metav1.LabelSelectorAsSelector(ctrcfg.Spec.MachineConfigPoolSelector)
if err != nil {
return "", err
}
if ctrcfgSelector.Matches(mcpSetLabels) {
ctrcfgs = append(ctrcfgs, ctrcfg)
}
}

if len(ctrcfgs) == 0 {
klog.V(1).Infof("no ContainerRuntimeConfig found that matches MCP labels %s that associated with performance profile %q; using default container runtime", mcpSetLabels.String(), profile.Name)
return mcov1.ContainerRuntimeDefaultRuntimeRunc, nil
}

if len(ctrcfgs) > 1 {
return "", fmt.Errorf("more than one ContainerRuntimeConfig found that matches MCP labels %s that associated with performance profile %q", mcpSetLabels.String(), profile.Name)
}

condition := status.GetLatestContainerRuntimeConfigCondition(ctrcfgs[0].Status.Conditions)
if condition == nil {
return "", fmt.Errorf("ContainerRuntimeConfig: %q no conditions reported (yet)", ctrcfgs[0].Name)
}
if condition.Type != mcov1.ContainerRuntimeConfigSuccess || condition.Status != corev1.ConditionTrue {
return "", fmt.Errorf("ContainerRuntimeConfig: %q failed to be applied: message=%q", ctrcfgs[0].Name, condition.Message)
}
return ctrcfgs[0].Spec.ContainerRuntimeConfig.DefaultRuntime, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ const (
templateOvsSliceDefinitionFile = "ovs.slice"
templateOvsSliceUsageFile = "01-use-ovs-slice.conf"
templateWorkload = "Workload"
templateRuntimePath = "RuntimePath"
templateRuntimeRoot = "RuntimeRoot"
templateCrioSharedCPUsAnnotation = "CrioSharedCPUsAnnotation"
)

Expand Down Expand Up @@ -573,10 +571,7 @@ func addContent(ignitionConfig *igntypes.Config, content []byte, dst string, mod
}

func renderCrioConfigSnippet(profile *performancev2.PerformanceProfile, src string, opts *components.MachineConfigOptions) ([]byte, error) {
templateArgs := map[string]string{
templateRuntimePath: "/bin/runc",
templateRuntimeRoot: "/run/runc",
}
templateArgs := map[string]string{}

if profile.Spec.CPU.Reserved != nil {
templateArgs[templateReservedCpus] = string(*profile.Spec.CPU.Reserved)
Expand All @@ -587,11 +582,6 @@ func renderCrioConfigSnippet(profile *performancev2.PerformanceProfile, src stri
templateArgs[templateCrioSharedCPUsAnnotation] = "cpu-shared.crio.io"
}

if opts.DefaultRuntime == machineconfigv1.ContainerRuntimeDefaultRuntimeCrun {
templateArgs[templateRuntimePath] = "/usr/bin/crun"
templateArgs[templateRuntimeRoot] = "/run/crun"
}

profileTemplate, err := template.ParseFS(assets.Configs, src)
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

mcov1 "github.com/openshift/api/machineconfiguration/v1"
performancev2 "github.com/openshift/cluster-node-tuning-operator/pkg/apis/performanceprofile/v2"
ntoconfig "github.com/openshift/cluster-node-tuning-operator/pkg/config"
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/components"
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/components/manifestset"
profileutil "github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/components/profile"
Expand Down Expand Up @@ -96,13 +94,6 @@ func (h *handler) Apply(ctx context.Context, obj client.Object, recorder record.
// set missing options
options.MachineConfig.MixedCPUsEnabled = options.MixedCPUsFeatureGateEnabled && profileutil.IsMixedCPUsEnabled(profile)

ctrRuntime, err := h.getContainerRuntimeName(ctx, profile)
if err != nil {
return fmt.Errorf("could not determine high-performance runtime class container-runtime for profile %q; %w", profile.Name, err)
}
klog.Infof("using %q as high-performance runtime class container-runtime for profile %q", ctrRuntime, profile.Name)
options.MachineConfig.DefaultRuntime = ctrRuntime

mfs, err := manifestset.GetNewComponents(profile, options)
if err != nil {
return err
Expand Down Expand Up @@ -190,50 +181,6 @@ func (h *handler) Apply(ctx context.Context, obj client.Object, recorder record.
return nil
}

func (h *handler) getContainerRuntimeName(ctx context.Context, profile *performancev2.PerformanceProfile) (mcov1.ContainerRuntimeDefaultRuntime, error) {
cmList := &corev1.ConfigMapList{}
if err := h.controlPlaneClient.List(ctx, cmList, &client.ListOptions{
Namespace: ntoconfig.OperatorNamespace(),
}); err != nil {
return "", err
}
var ctrcfgs []*mcov1.ContainerRuntimeConfig
for _, cm := range cmList.Items {
data, ok := cm.Data[hypershiftconsts.ConfigKey]
// container runtime config should be store in the Config key
if !ok {
continue
}
// ConfigMaps with the PerformanceProfileNameLabel label are generated by
// the controller itself
if _, ok = cm.Labels[hypershiftconsts.PerformanceProfileNameLabel]; ok {
continue
}
ctrcfg, err := validateAndExtractContainerRuntimeConfigFrom(h.scheme, []byte(data))
if err != nil {
return "", fmt.Errorf("failed to get ContainerRuntime name %w", err)
}
if ctrcfg != nil {
ctrcfgs = append(ctrcfgs, ctrcfg)
}
}
if len(ctrcfgs) == 0 {
klog.V(1).Infof("no ContainerRuntimeConfig found that associated with performance profile %q; using default container runtime %q", profile.Name, mcov1.ContainerRuntimeDefaultRuntimeRunc)
return mcov1.ContainerRuntimeDefaultRuntimeRunc, nil
}
if len(ctrcfgs) > 1 {
return "", fmt.Errorf("more than one ContainerRuntimeConfig found that associated with performance profile %q", profile.Name)
}
// Ideally, the controller is supposed to check the ContainerRuntimeConfig status and return the value only if
// ContainerRuntimeConfig applied successfully.
// On hypershift, the controller does not have access to the status, so it would have to relay on hypershift operator
// to apply the ContainerRuntimeConfig configuration correctly.
// In case something goes wrong with the ContainerRuntimeConfig application,
// the hypershift operator won't be applying NTO controller's configuration either
// and will reflect that on the NodePool's status.
return ctrcfgs[0].Spec.ContainerRuntimeConfig.DefaultRuntime, nil
}

func EncapsulateObjInConfigMap(scheme *runtime.Scheme, instance *corev1.ConfigMap, object client.Object, profileName, dataKey string, objectLabels map[string]string) (*corev1.ConfigMap, error) {
encodedObj, err := hypershift.EncodeManifest(object, scheme)
if err != nil {
Expand Down Expand Up @@ -328,12 +275,3 @@ func createOrUpdateConfigMap(ctx context.Context, cli client.Client, cm *corev1.
}
return nil
}

func validateAndExtractContainerRuntimeConfigFrom(scheme *runtime.Scheme, manifest []byte) (*mcov1.ContainerRuntimeConfig, error) {
ctrcfg := &mcov1.ContainerRuntimeConfig{}
ok, err := hypershift.DecodeManifest(manifest, scheme, ctrcfg)
if !ok {
return nil, err
}
return ctrcfg, err
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
TuningKey = "tuning"

// ConfigKey is the key under ConfigMap.Data on which encoded
// machine-config, kubelet-config and container-runtime-config objects are stored.
// machine-config, kubelet-config objects are stored.
ConfigKey = "config"

// PerformanceProfileStatusKey is the key under ConfigMap.Data on which an encoded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ func GetObjectConfigMapDataKey(obj runtime.Object) string {
case *performancev2.PerformanceProfile, *performancev2.PerformanceProfileList, *tunedv1.Tuned, *tunedv1.TunedList:
return hypershiftconsts.TuningKey
case *machineconfigv1.KubeletConfig, *machineconfigv1.KubeletConfigList,
*machineconfigv1.MachineConfig, *machineconfigv1.MachineConfigList,
*machineconfigv1.ContainerRuntimeConfig, *machineconfigv1.ContainerRuntimeConfigList:
*machineconfigv1.MachineConfig, *machineconfigv1.MachineConfigList:
return hypershiftconsts.ConfigKey
default:
return ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,6 @@ func getLatestKubeletConfigCondition(conditions []mcov1.KubeletConfigCondition)
return latestCondition
}

func GetLatestContainerRuntimeConfigCondition(conditions []mcov1.ContainerRuntimeConfigCondition) *mcov1.ContainerRuntimeConfigCondition {
var latestCondition *mcov1.ContainerRuntimeConfigCondition
for i := 0; i < len(conditions); i++ {
if latestCondition == nil || latestCondition.LastTransitionTime.Before(&conditions[i].LastTransitionTime) {
latestCondition = &conditions[i]
}
}
return latestCondition
}

func removeUnMatchedTunedProfiles(nodes []corev1.Node, profiles []tunedv1.Profile) []tunedv1.Profile {
filteredProfiles := make([]tunedv1.Profile, 0)
for _, profile := range profiles {
Expand Down
Loading