Skip to content

Commit

Permalink
Merge branch 'openshift:master' into runc_cpu_isolation
Browse files Browse the repository at this point in the history
  • Loading branch information
SargunNarula authored Jul 17, 2024
2 parents 33fd5ac + 79ec2e7 commit 1fa3baa
Show file tree
Hide file tree
Showing 58 changed files with 2,275 additions and 1,288 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ pao-functests-mixedcpus:
pao-functests-hypershift:
@echo "Cluster Version"
hack/show-cluster-version.sh
hack/run-test.sh -t "./test/e2e/performanceprofile/functests/0_config" -p "-vv -r --fail-fast --flake-attempts=2 --junit-report=report.xml" -m "Running Functional Tests over Hypershift"
hack/run-test.sh -t "./test/e2e/performanceprofile/functests/0_config ./test/e2e/performanceprofile/functests/1_performance" -p "-vv --label-filter="!openshift" -r --fail-fast --flake-attempts=2 --timeout=2h --junit-report=report.xml" -m "Running Functional Tests over Hypershift"

.PHONY: cluster-clean-pao
cluster-clean-pao:
Expand Down
4 changes: 1 addition & 3 deletions cmd/cluster-node-tuning-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ var (
func init() {
ctrl.SetLogger(zap.New())

if !config.InHyperShift() {
utilruntime.Must(mcov1.AddToScheme(scheme))
}
utilruntime.Must(mcov1.AddToScheme(scheme))
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(tunedv1.AddToScheme(scheme))
utilruntime.Must(apiconfigv1.Install(scheme))
Expand Down
4 changes: 2 additions & 2 deletions hack/dockerfile_install_support.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if [[ "${ID}" == "centos" ]]; then
dnf --setopt=tsflags=nodocs -y install /root/rpms/*.rpm
rm -rf /etc/tuned/recommend.d
echo auto > /etc/tuned/profile_mode
sed -Ei 's|^#?\s*enable_unix_socket\s*=.*$|enable_unix_socket = 1|;s|^#?\s*rollback\s*=.*$|rollback = not_on_exit|;s|^#?\s*profile_dirs\s*=.*$|profile_dirs = /usr/lib/tuned,/var/lib/ocp-tuned/profiles|' /etc/tuned/tuned-main.conf;
sed -Ei 's|^#?\s*enable_unix_socket\s*=.*$|enable_unix_socket = 1|;s|^#?\s*rollback\s*=.*$|rollback = not_on_exit|;s|^#?\s*profile_dirs\s*=.*$|profile_dirs = /usr/lib/tuned/profiles,/usr/lib/tuned,/var/lib/ocp-tuned/profiles|' /etc/tuned/tuned-main.conf;

# Clean up build tools to remove image footprint
dnf remove --setopt=protected_packages= -y ${BUILD_INSTALL_PKGS}
Expand All @@ -44,7 +44,7 @@ else
dnf install --setopt=tsflags=nodocs -y ${INSTALL_PKGS}
rm -rf /etc/tuned/recommend.d
echo auto > /etc/tuned/profile_mode
sed -Ei 's|^#?\s*enable_unix_socket\s*=.*$|enable_unix_socket = 1|;s|^#?\s*rollback\s*=.*$|rollback = not_on_exit|;s|^#?\s*profile_dirs\s*=.*$|profile_dirs = /usr/lib/tuned,/var/lib/ocp-tuned/profiles|' /etc/tuned/tuned-main.conf;
sed -Ei 's|^#?\s*enable_unix_socket\s*=.*$|enable_unix_socket = 1|;s|^#?\s*rollback\s*=.*$|rollback = not_on_exit|;s|^#?\s*profile_dirs\s*=.*$|profile_dirs = /usr/lib/tuned/profiles,/usr/lib/tuned,/var/lib/ocp-tuned/profiles|' /etc/tuned/tuned-main.conf;

fi

Expand Down
4 changes: 2 additions & 2 deletions hack/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ main() {
which ginkgo
if [ $? -ne 0 ]; then
echo "Downloading ginkgo tool"
go install -mod=mod github.com/onsi/ginkgo/v2/[email protected]
GINKGO_VERSION=$(go list -m -f '{{.Version}}' github.com/onsi/ginkgo/v2)
go install -mod=mod github.com/onsi/ginkgo/v2/ginkgo@"${GINKGO_VERSION}"
ginkgo version
fi

Expand All @@ -92,7 +93,6 @@ main() {
if [ "$ONLY_CLI_PRINT" = true ]; then
print "Skipping execution as requested by user ... "
else
trap '{ echo "Running cleanup test suite"; ginkgo test/e2e/performanceprofile/functests/Z_deconfig --flake-attempts=2 --junit-report=report.xml; }' EXIT SIGINT SIGTERM SIGSTOP
print "Executing test suites ... "
GOFLAGS=-mod=vendor ginkgo ${GINKGO_FLAGS}
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewHandler(cli client.Client, scheme *runtime.Scheme) components.Handler {
func (h *handler) Apply(ctx context.Context, obj client.Object, recorder record.EventRecorder, opts *components.Options) error {
profile, ok := obj.(*performancev2.PerformanceProfile)
if !ok {
return fmt.Errorf("wrong type conversion; want=PerformanceProfile got=%T", obj)
return fmt.Errorf("wrong type conversion; want=*PerformanceProfile got=%T", obj)
}

if profileutil.IsPaused(profile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,15 @@ import (

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/config"
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/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/hypershift"
hypershiftconsts "github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/hypershift/consts"
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/resources"
)

const (
hypershiftPerformanceProfileNameLabel = "hypershift.openshift.io/performanceProfileName"
hypershiftNodePoolLabel = "hypershift.openshift.io/nodePool"
tunedConfigMapLabel = "hypershift.openshift.io/tuned-config"
tunedConfigMapConfigKey = "tuning"
mcoConfigMapConfigKey = "config"
ntoGeneratedMachineConfigLabel = "hypershift.openshift.io/nto-generated-machine-config"
)

var _ components.Handler = &handler{}

type handler struct {
Expand Down Expand Up @@ -73,46 +64,30 @@ func (h *handler) Delete(ctx context.Context, profileName string) error {
}

func (h *handler) Exists(ctx context.Context, profileName string) bool {
operatorNamespace := config.OperatorNamespace()
tunedName := components.GetComponentName(profileName, components.ProfileNamePerformance)
if _, err := resources.GetTuned(ctx, h.controlPlaneClient, tunedName, operatorNamespace); !k8serrors.IsNotFound(err) {
klog.Infof("Tuned %q is still exists in the namespace %q", tunedName, operatorNamespace)
return true
}

name := components.GetComponentName(profileName, components.ComponentNamePrefix)
if _, err := resources.GetKubeletConfig(ctx, h.controlPlaneClient, name); !k8serrors.IsNotFound(err) {
klog.Infof("Kubelet Config %q exists in the namespace %q", name, operatorNamespace)
return true
}

if _, err := resources.GetRuntimeClass(ctx, h.dataPlaneClient, name); !k8serrors.IsNotFound(err) {
klog.Infof("Runtime class %q exists in the hosted cluster", name)
return true
}

if _, err := resources.GetMachineConfig(ctx, h.controlPlaneClient, machineconfig.GetMachineConfigName(profileName)); !k8serrors.IsNotFound(err) {
klog.Infof("Machine Config %q exists in the namespace %q", name, operatorNamespace)
return true
}
return false
}

func (h *handler) Apply(ctx context.Context, obj client.Object, recorder record.EventRecorder, options *components.Options) error {
instance, ok := obj.(*corev1.ConfigMap)
if !ok {
return fmt.Errorf("wrong type conversion; want=ConfigMap got=%T", obj)
return fmt.Errorf("wrong type conversion; want=*ConfigMap got=%T", obj)
}

s, ok := instance.Data[hypershift.TuningKey]
s, ok := instance.Data[hypershiftconsts.TuningKey]
if !ok {
return fmt.Errorf("key named %q not found in ConfigMap %q", hypershift.TuningKey, client.ObjectKeyFromObject(obj).String())
return fmt.Errorf("key named %q not found in ConfigMap %q", hypershiftconsts.TuningKey, client.ObjectKeyFromObject(obj).String())
}

profile := &performancev2.PerformanceProfile{}
if err := hypershift.DecodeManifest([]byte(s), h.scheme, profile); err != nil {
if _, err := hypershift.DecodeManifest([]byte(s), h.scheme, profile); err != nil {
return err
}
klog.V(4).InfoS("PerformanceProfile decoded successfully from ConfigMap data", "PerformanceProfileName", profile.Name, "ConfigMapName", instance.GetName())

if profileutil.IsPaused(profile) {
klog.Infof("ignoring reconcile loop for pause performance profile %s", profile.Name)
Expand Down Expand Up @@ -166,7 +141,7 @@ func (h *handler) Apply(ctx context.Context, obj client.Object, recorder record.
}

if mcMutated != nil {
cm, err := h.encapsulateObjInConfigMap(instance, mfs.MachineConfig, profile.Name, mcoConfigMapConfigKey, ntoGeneratedMachineConfigLabel)
cm, err := EncapsulateObjInConfigMap(h.scheme, instance, mfs.MachineConfig, profile.Name, hypershiftconsts.ConfigKey, hypershiftconsts.NTOGeneratedMachineConfigLabel)
if err != nil {
return err
}
Expand All @@ -177,7 +152,7 @@ func (h *handler) Apply(ctx context.Context, obj client.Object, recorder record.
}

if kcMutated != nil {
cm, err := h.encapsulateObjInConfigMap(instance, mfs.KubeletConfig, profile.Name, mcoConfigMapConfigKey, ntoGeneratedMachineConfigLabel)
cm, err := EncapsulateObjInConfigMap(h.scheme, instance, mfs.KubeletConfig, profile.Name, hypershiftconsts.ConfigKey, hypershiftconsts.NTOGeneratedMachineConfigLabel)
if err != nil {
return err
}
Expand All @@ -188,7 +163,7 @@ func (h *handler) Apply(ctx context.Context, obj client.Object, recorder record.
}

if performanceTunedMutated != nil {
cm, err := h.encapsulateObjInConfigMap(instance, mfs.Tuned, profile.Name, tunedConfigMapConfigKey, tunedConfigMapLabel)
cm, err := EncapsulateObjInConfigMap(h.scheme, instance, mfs.Tuned, profile.Name, hypershiftconsts.TuningKey, hypershiftconsts.ControllerGeneratedTunedConfigMapLabel)
if err != nil {
return err
}
Expand All @@ -199,7 +174,7 @@ func (h *handler) Apply(ctx context.Context, obj client.Object, recorder record.
}

if runtimeClassMutated != nil {
err = resources.CreateOrUpdateRuntimeClass(ctx, h.dataPlaneClient, mfs.RuntimeClass)
err = resources.CreateOrUpdateRuntimeClass(ctx, h.dataPlaneClient, runtimeClassMutated)
if err != nil {
return err
}
Expand All @@ -211,23 +186,62 @@ func (h *handler) Apply(ctx context.Context, obj client.Object, recorder record.
}

func (h *handler) getContainerRuntimeName(ctx context.Context, profile *performancev2.PerformanceProfile) (mcov1.ContainerRuntimeDefaultRuntime, error) {
//TODO we need to figure out how containerruntimeconfig works on hypershift
return mcov1.ContainerRuntimeDefaultRuntimeRunc, nil
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 (h *handler) encapsulateObjInConfigMap(instance *corev1.ConfigMap, object client.Object, profileName, dataKey, objectLabel string) (*corev1.ConfigMap, error) {
encodedObj, err := hypershift.EncodeManifest(object, h.scheme)
func EncapsulateObjInConfigMap(scheme *runtime.Scheme, instance *corev1.ConfigMap, object client.Object, profileName, dataKey, objectLabel string) (*corev1.ConfigMap, error) {
encodedObj, err := hypershift.EncodeManifest(object, scheme)
if err != nil {
return nil, err
}
nodePoolNamespacedName, ok := instance.Annotations[hypershiftNodePoolLabel]
nodePoolNamespacedName, ok := instance.Annotations[hypershiftconsts.NodePoolNameLabel]
if !ok {
return nil, fmt.Errorf("annotation %q not found in ConfigMap %q annotations", hypershiftNodePoolLabel, client.ObjectKeyFromObject(instance).String())
return nil, fmt.Errorf("annotation %q not found in ConfigMap %q annotations", hypershiftconsts.NodePoolNameLabel, client.ObjectKeyFromObject(instance).String())
}

name := fmt.Sprintf("%s-%s", strings.ToLower(object.GetObjectKind().GroupVersionKind().Kind), instance.Name)
cm := configMapMeta(name, profileName, instance.GetNamespace(), nodePoolNamespacedName)
err = controllerutil.SetControllerReference(instance, cm, h.scheme)
err = controllerutil.SetControllerReference(instance, cm, scheme)
if err != nil {
return nil, err
}
Expand All @@ -240,21 +254,21 @@ func (h *handler) encapsulateObjInConfigMap(instance *corev1.ConfigMap, object c

func createOrUpdateTunedConfigMap(ctx context.Context, cli client.Client, cm *corev1.ConfigMap) error {
updateFunc := func(orig, dst *corev1.ConfigMap) {
dst.Data[tunedConfigMapConfigKey] = orig.Data[tunedConfigMapConfigKey]
dst.Data[hypershiftconsts.TuningKey] = orig.Data[hypershiftconsts.TuningKey]
}
return createOrUpdateConfigMap(ctx, cli, cm, updateFunc)
}

func createOrUpdateMachineConfigConfigMap(ctx context.Context, cli client.Client, cm *corev1.ConfigMap) error {
machineconfigConfigMapUpdateFunc := func(orig, dst *corev1.ConfigMap) {
dst.Data[mcoConfigMapConfigKey] = orig.Data[mcoConfigMapConfigKey]
dst.Data[hypershiftconsts.ConfigKey] = orig.Data[hypershiftconsts.ConfigKey]
}
return createOrUpdateConfigMap(ctx, cli, cm, machineconfigConfigMapUpdateFunc)
}

func createOrUpdateKubeletConfigConfigMap(ctx context.Context, cli client.Client, cm *corev1.ConfigMap) error {
kubeletConfigConfigMapUpdateFunc := func(orig, dst *corev1.ConfigMap) {
dst.Data[mcoConfigMapConfigKey] = orig.Data[mcoConfigMapConfigKey]
dst.Data[hypershiftconsts.ConfigKey] = orig.Data[hypershiftconsts.ConfigKey]
}
return createOrUpdateConfigMap(ctx, cli, cm, kubeletConfigConfigMapUpdateFunc)
}
Expand All @@ -267,11 +281,11 @@ func configMapMeta(name, profileName, namespace, npNamespacedName string) *corev
Namespace: namespace,
Name: name,
Labels: map[string]string{
hypershiftPerformanceProfileNameLabel: profileName,
hypershiftNodePoolLabel: parseNamespacedName(npNamespacedName),
hypershiftconsts.PerformanceProfileNameLabel: profileName,
hypershiftconsts.NodePoolNameLabel: parseNamespacedName(npNamespacedName),
},
Annotations: map[string]string{
hypershiftNodePoolLabel: npNamespacedName,
hypershiftconsts.NodePoolNameLabel: npNamespacedName,
},
},
}
Expand Down Expand Up @@ -307,3 +321,12 @@ 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
@@ -0,0 +1,30 @@
package consts

const (
// NodePoolNameLabel uses to label ConfigMap objects which are associated with the NodePool
NodePoolNameLabel = "hypershift.openshift.io/nodePool"

// PerformanceProfileNameLabel uses to label a ConfigMaps that hold objects which were
// created by the performanceProfile controller and which are associated with the performance-profile
// name mentioned in the label
PerformanceProfileNameLabel = "hypershift.openshift.io/performanceProfileName"

// ControllerGeneratedTunedConfigMapLabel uses to label a ConfigMap that holds encoded tuned object
ControllerGeneratedTunedConfigMapLabel = "hypershift.openshift.io/tuned-config"

// ControllerGeneratedPerformanceProfileConfigMapLabel uses
//to label a ConfigMap that holds encoded performance-profile object
ControllerGeneratedPerformanceProfileConfigMapLabel = "hypershift.openshift.io/performanceprofile-config"

// NTOGeneratedMachineConfigLabel attached to kubelet and machine config configmaps generated by NTO.
// The Hypershift operator watches these and acts upon their creation/update/deletion.
NTOGeneratedMachineConfigLabel = "hypershift.openshift.io/nto-generated-machine-config"

// TuningKey is the key under ConfigMap.Data on which encoded
// tuned and performance-profile objects are stored.
TuningKey = "tuning"

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

0 comments on commit 1fa3baa

Please sign in to comment.