Skip to content

Commit

Permalink
e2e:performance: decode to valid kubeletconfig object (openshift#1091)
Browse files Browse the repository at this point in the history
We're facing issues with the existing regex pattern,
so let's perform the check properly, by decoding the output
and compare the values.

Signed-off-by: Talor Itzhak <[email protected]>
  • Loading branch information
Tal-or authored Jun 26, 2024
1 parent 6de4dca commit 0a2f7b3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
21 changes: 19 additions & 2 deletions pkg/util/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ import (
"path/filepath"
"strings"

mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/components"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
yamlutil "k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/client-go/kubernetes/scheme"

mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/components"
)

type manifest struct {
Expand Down Expand Up @@ -168,3 +171,17 @@ func AppendMissingDefaultMCPManifests(currentMCPs []*mcfgv1.MachineConfigPool) [

return append(finalMCPList, currentMCPs...)
}

func DeserializeObjectFromData(data []byte, addToSchemeFn ...func(scheme2 *runtime.Scheme) error) (runtime.Object, error) {
for _, fn := range addToSchemeFn {
if err := fn(scheme.Scheme); err != nil {
return nil, err
}
}
decode := scheme.Codecs.UniversalDeserializer().Decode
obj, _, err := decode(data, nil, nil)
if err != nil {
return nil, err
}
return obj, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
"k8s.io/utils/cpuset"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -24,6 +25,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"
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/utils/schedstat"
manifestsutil "github.com/openshift/cluster-node-tuning-operator/pkg/util"
testutils "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/cgroup"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/cgroup/controller"
Expand Down Expand Up @@ -135,8 +137,11 @@ var _ = Describe("[rfe_id:27363][performance] CPU Management", Ordered, func() {
out, err = nodes.ExecCommand(context.TODO(), workerRTNode, cmd)
Expect(err).ToNot(HaveOccurred(), "failed to cat kubelet.conf")
conf := testutils.ToString(out)
// kubelet.conf changed formatting, there is a space after colons atm. Let's deal with both cases with a regex
Expect(conf).To(MatchRegexp(fmt.Sprintf(`"reservedSystemCPUs": ?"%s"`, reservedCPU)))
obj, err := manifestsutil.DeserializeObjectFromData([]byte(conf), kubeletconfigv1beta1.AddToScheme)
Expect(err).ToNot(HaveOccurred())
kc, ok := obj.(*kubeletconfigv1beta1.KubeletConfiguration)
Expect(ok).To(BeTrue(), "wrong type %T", obj)
Expect(kc.ReservedSystemCPUs).To(Equal(reservedCPU))

By("checking CPU affinity mask for kernel scheduler")
cmd = []string{"/bin/bash", "-c", "taskset -pc 1"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog"
kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
"k8s.io/utils/cpuset"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -26,6 +27,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"
profilecomponent "github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/components/profile"
manifestsutil "github.com/openshift/cluster-node-tuning-operator/pkg/util"
testutils "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils"
testclient "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/client"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/discovery"
Expand Down Expand Up @@ -304,9 +306,21 @@ var _ = Describe("[rfe_id:28761][performance] Updating parameters in performance
Entry("[test_id:28025] verify that cpu affinity mask was updated", context.TODO(), chkCmdLineFn, []string{"tuned.non_isolcpus=.*9"}, true, true),
Entry("[test_id:28071] verify that cpu balancer disabled", context.TODO(), chkCmdLineFn, []string{"isolcpus=domain,managed_irq,1-2"}, true, false),
Entry("[test_id:28071] verify that cpu balancer disabled", context.TODO(), chkCmdLineFn, []string{"systemd.cpu_affinity=0,3"}, true, false),
// kubelet.conf changed formatting, there is a space after colons atm. Let's deal with both cases with a regex
Entry("[test_id:28935] verify that reservedSystemCPUs was updated", context.TODO(), chkKubeletConfigFn, []string{`"reservedSystemCPUs": ?"0,3"`}, true, true),
Entry("[test_id:28760] verify that topologyManager was updated", context.TODO(), chkKubeletConfigFn, []string{`"topologyManagerPolicy": ?"best-effort"`}, true, true),
)

DescribeTable("Verify that kubelet parameters were updated", func(ctx context.Context, cmdFn checkFunction, getterFn func(kubeletCfg *kubeletconfigv1beta1.KubeletConfiguration) string, wantedValue string) {
for _, node := range workerRTNodes {
result, err := cmdFn(ctx, &node)
obj, err := manifestsutil.DeserializeObjectFromData([]byte(result), kubeletconfigv1beta1.AddToScheme)
Expect(err).ToNot(HaveOccurred())

kc, ok := obj.(*kubeletconfigv1beta1.KubeletConfiguration)
Expect(ok).To(BeTrue(), "wrong type %T", obj)
Expect(getterFn(kc)).To(Equal(wantedValue))
}
},
Entry("[test_id:28935] verify that reservedSystemCPUs was updated", context.TODO(), chkKubeletConfigFn, func(k *kubeletconfigv1beta1.KubeletConfiguration) string { return k.ReservedSystemCPUs }, "0,3"),
Entry("[test_id:28760] verify that topologyManager was updated", context.TODO(), chkKubeletConfigFn, func(k *kubeletconfigv1beta1.KubeletConfiguration) string { return k.TopologyManagerPolicy }, "best-effort"),
)

It("[test_id:27738] should succeed to disable the RT kernel", func() {
Expand Down

0 comments on commit 0a2f7b3

Please sign in to comment.