Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-0.15] scheduler: update: use unstructured in RenderConfig #228

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
4 changes: 0 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ require (
k8s.io/apimachinery v0.26.4
k8s.io/client-go v0.26.4
k8s.io/klog/v2 v2.80.1
k8s.io/kube-scheduler v0.26.4
k8s.io/kubelet v0.26.4
k8s.io/kubernetes v1.26.4
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d
sigs.k8s.io/controller-runtime v0.13.1
sigs.k8s.io/scheduler-plugins v0.24.9
sigs.k8s.io/yaml v1.3.0
)

Expand Down Expand Up @@ -78,7 +75,6 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiserver v0.26.4 // indirect
k8s.io/component-base v0.26.4 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
Expand Down
19 changes: 0 additions & 19 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/diktyo-io/appgroup-api v0.0.9-alpha h1:rqRNOl4CRD313a+ugZJ2rJAN2sNe5GGd4PfyaV44Dy4=
github.com/diktyo-io/networktopology-api v0.0.8-alpha h1:8bSVk6JdUgYd719mXfHgkGZ2eXOfTF436mLu/TQ7WHM=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
github.com/emicklei/go-restful/v3 v3.8.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
Expand All @@ -96,7 +94,6 @@ github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH
github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch/v5 v5.6.0 h1:b91NhWfaz02IuVxO9faSllyAtNXHMPkC5J8sJCLunww=
github.com/evanphx/json-patch/v5 v5.6.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4=
github.com/francoispqt/gojay v1.2.13 h1:d2m3sFjloqoIUQU3TsHBgj6qg/BVGlTBeHDUmyJnXKk=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
Expand Down Expand Up @@ -141,7 +138,6 @@ github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfU
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
Expand Down Expand Up @@ -223,7 +219,6 @@ github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJS
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
Expand Down Expand Up @@ -270,7 +265,6 @@ github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8m
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
Expand Down Expand Up @@ -303,8 +297,6 @@ github.com/openshift/client-go v0.0.0-20221019143426-16aed247da5c h1:CV76yFOTXmq
github.com/openshift/client-go v0.0.0-20221019143426-16aed247da5c/go.mod h1:lFMO8mLHXWFzSdYvGNo8ivF9SfF6zInA8ZGw4phRnUE=
github.com/openshift/machine-config-operator v0.0.1-0.20221101091906-fa5e7ae3f0e9 h1:Vev+TWP5/sczE1UitOa8pSgWF91j60U5i1815nSGpi0=
github.com/openshift/machine-config-operator v0.0.1-0.20221101091906-fa5e7ae3f0e9/go.mod h1:YZfaDeVq2GdvgI2dBibpeqMlDPnXTG0aM9Uf3CNal6A=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/paypal/load-watcher v0.2.2 h1:tKCy3Ts8LnihFSLKmyrOODrdt9ulbRXe0MFbxe9U2Bk=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/pin/tftp v2.1.0+incompatible/go.mod h1:xVpZOMCXTy+A5QMjEVN0Glwa1sUvaJhFXbr/aAxuxGY=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -346,7 +338,6 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa/go.mod h1:2RVY1rIf+2J2o/IM9+vPq9RzmHDSseB7FoXiSNIUsoU=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
Expand Down Expand Up @@ -749,14 +740,11 @@ k8s.io/apiextensions-apiserver v0.26.4 h1:9D2RTxYGxrG5uYg6D7QZRcykXvavBvcA59j5kT
k8s.io/apiextensions-apiserver v0.26.4/go.mod h1:cd4uGFGIgzEqUghWpRsr9KE8j2KNTjY8Ji8pnMMazyw=
k8s.io/apimachinery v0.26.4 h1:rZccKdBLg9vP6J09JD+z8Yr99Ce8gk3Lbi9TCx05Jzs=
k8s.io/apimachinery v0.26.4/go.mod h1:ats7nN1LExKHvJ9TmwootT00Yz05MuYqPXEXaVeOy5I=
k8s.io/apiserver v0.26.4 h1:3Oq4mnJv0mzVX7BR/Nod+8KjlELf/3Ljvu9ZWDyLUoA=
k8s.io/apiserver v0.26.4/go.mod h1:yAY3O1vBM4/0OIGAGeWcdfzQvgdwJ188VirLcuSAVnw=
k8s.io/client-go v0.26.4 h1:/7P/IbGBuT73A+G97trf44NTPSNqvuBREpOfdLbHvD4=
k8s.io/client-go v0.26.4/go.mod h1:6qOItWm3EwxJdl/8p5t7FWtWUOwyMdA8N9ekbW4idpI=
k8s.io/code-generator v0.26.4/go.mod h1:ryaiIKwfxEJEaywEzx3dhWOydpVctKYbqLajJf0O8dI=
k8s.io/component-base v0.26.4 h1:Bg2xzyXNKL3eAuiTEu3XE198d6z22ENgFgGQv2GGOUk=
k8s.io/component-base v0.26.4/go.mod h1:lTuWL1Xz/a4e80gmIC3YZG2JCO4xNwtKWHJWeJmsq20=
k8s.io/component-helpers v0.26.4 h1:qbZrh8QmfL+Yn7lWEI/BPrvITGgkBy33djP5Tzsu2hA=
k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/gengo v0.0.0-20220902162205-c0856e24416d/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
Expand All @@ -765,13 +753,8 @@ k8s.io/klog/v2 v2.80.1 h1:atnLQ121W371wYYFawwYx1aEY2eUfs4l3J72wtgAwV4=
k8s.io/klog/v2 v2.80.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 h1:+70TFaan3hfJzs+7VK2o+OGxg8HsuBr/5f6tVAjDu6E=
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280/go.mod h1:+Axhij7bCpeqhklhUTe3xmOn6bWxolyZEeyaFpjGtl4=
k8s.io/kube-scheduler v0.26.4 h1:J+ZCWQV64atAfHEomA5XrmNlbYI5XtN950zIQZioTnI=
k8s.io/kube-scheduler v0.26.4/go.mod h1:Mzh7sJavoa6+74a0vwv4+OpQXZYAwJA1jEWUkCfuixo=
k8s.io/kubelet v0.26.4 h1:SEQPfjN4lu4uL9O8NdeN7Aum3liQ4kOnp/yC3jMRMUo=
k8s.io/kubelet v0.26.4/go.mod h1:ZMPGTCnrQ5UOlC7igXhbW9cgna1LtTRWLaHub4dA2FU=
k8s.io/kubernetes v1.26.4 h1:/c00/JjOltBwhNOBs+hO433Q3fRyeWWtyYF6z2xtmag=
k8s.io/kubernetes v1.26.4/go.mod h1:NxzR7U7mS+OGa3J/qweI86Pek//mlfHqDgt6NNGdz8g=
k8s.io/metrics v0.26.4 h1:ijyerycmjVp9EVPfDqha8eb+s9jw5c+A9MkTvuRBdms=
k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d h1:0Smp/HP1OH4Rvhe+4B8nWGERtlqAGSftbSbbmm45oFs=
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
Expand All @@ -782,8 +765,6 @@ sigs.k8s.io/controller-runtime v0.13.1 h1:tUsRCSJVM1QQOOeViGeX3GMT3dQF1eePPw6sEE
sigs.k8s.io/controller-runtime v0.13.1/go.mod h1:Zbz+el8Yg31jubvAEyglRZGdLAjplZl+PgtYNI6WNTI=
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 h1:iXTIw73aPyC+oRdyqqvVJuloN1p0AC/kzH07hu3NE+k=
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/scheduler-plugins v0.24.9 h1:9oGtwk6uh7mZMCX8+O+PipQzBiRq9d2+E3xq1cn7zbc=
sigs.k8s.io/scheduler-plugins v0.24.9/go.mod h1:0u2b/0SwY2ozDhOD/f1S3e5IbStoDFLUK8yP5dJTaQ8=
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE=
sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
Expand Down
35 changes: 0 additions & 35 deletions pkg/manifests/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ import (
"k8s.io/apimachinery/pkg/runtime"
k8sjson "k8s.io/apimachinery/pkg/runtime/serializer/json"
k8sscheme "k8s.io/client-go/kubernetes/scheme"
schedconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"

"sigs.k8s.io/controller-runtime/pkg/client"
schedscheme "sigs.k8s.io/scheduler-plugins/apis/config/scheme"
"sigs.k8s.io/scheduler-plugins/apis/config/v1beta2"
)

func SerializeObject(obj runtime.Object, out io.Writer) error {
Expand Down Expand Up @@ -77,38 +74,6 @@ func loadObject(path string) (runtime.Object, error) {
return DeserializeObjectFromData(data)
}

func DecodeSchedulerConfigFromData(data []byte) (*schedconfig.KubeSchedulerConfiguration, error) {
decoder := schedscheme.Codecs.UniversalDecoder()
obj, gvk, err := decoder.Decode(data, nil, nil)

if err != nil {
return nil, err
}

schedCfg, ok := obj.(*schedconfig.KubeSchedulerConfiguration)
if !ok {
return nil, fmt.Errorf("decoded unsupported type: %T gvk=%s", obj, gvk)
}
return schedCfg, nil
}

func EncodeSchedulerConfigToData(schedCfg *schedconfig.KubeSchedulerConfiguration) ([]byte, error) {
yamlInfo, ok := runtime.SerializerInfoForMediaType(schedscheme.Codecs.SupportedMediaTypes(), runtime.ContentTypeYAML)
if !ok {
return nil, fmt.Errorf("unable to locate encoder -- %q is not a supported media type", runtime.ContentTypeYAML)
}

encoder := schedscheme.Codecs.EncoderForVersion(yamlInfo.Serializer, v1beta2.SchemeGroupVersion)

var buf bytes.Buffer
err := encoder.Encode(schedCfg, &buf)
if err != nil {
return nil, err
}

return buf.Bytes(), nil
}

func RenderObjects(objs []client.Object, w io.Writer) error {
for _, obj := range objs {
fmt.Fprintf(w, "---\n")
Expand Down
28 changes: 0 additions & 28 deletions pkg/manifests/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@ import (
apiextensionv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"
kubeschedulerconfigv1beta2 "k8s.io/kube-scheduler/config/v1beta2"
"k8s.io/utils/pointer"
apiconfigv1beta2 "sigs.k8s.io/scheduler-plugins/apis/config/v1beta2"

k8sschedpluginsconf "sigs.k8s.io/scheduler-plugins/apis/config"
k8sschedpluginsconfv1beta2 "sigs.k8s.io/scheduler-plugins/apis/config/v1beta2"
k8sschedpluginsconfv1beta3 "sigs.k8s.io/scheduler-plugins/apis/config/v1beta3"

rteassets "github.com/k8stopologyawareschedwg/deployer/pkg/assets/rte"
selinuxassets "github.com/k8stopologyawareschedwg/deployer/pkg/assets/selinux"
Expand Down Expand Up @@ -80,11 +74,6 @@ var src embed.FS

func init() {
apiextensionv1.AddToScheme(scheme.Scheme)
apiconfigv1beta2.AddToScheme(scheme.Scheme)
kubeschedulerconfigv1beta2.AddToScheme(scheme.Scheme)
k8sschedpluginsconf.AddToScheme(scheme.Scheme)
k8sschedpluginsconfv1beta2.AddToScheme(scheme.Scheme)
k8sschedpluginsconfv1beta3.AddToScheme(scheme.Scheme)
machineconfigv1.Install(scheme.Scheme)
securityv1.Install(scheme.Scheme)
}
Expand Down Expand Up @@ -455,23 +444,6 @@ func SecurityContextConstraint(component string) (*securityv1.SecurityContextCon
return scc, nil
}

func KubeSchedulerConfigurationFromData(data []byte) (*kubeschedulerconfigv1beta2.KubeSchedulerConfiguration, error) {
obj, err := DeserializeObjectFromData(data)
if err != nil {
return nil, err
}

sc, ok := obj.(*kubeschedulerconfigv1beta2.KubeSchedulerConfiguration)
if !ok {
return nil, fmt.Errorf("unexpected type, got %T %v", obj, obj.GetObjectKind())
}
return sc, nil
}

func KubeSchedulerConfigurationToData(sc *kubeschedulerconfigv1beta2.KubeSchedulerConfiguration) ([]byte, error) {
return SerializeObjectToData(sc)
}

func validateComponent(component string) error {
if component == ComponentAPI || component == ComponentResourceTopologyExporter || component == ComponentNodeFeatureDiscovery || component == ComponentSchedulerPlugin {
return nil
Expand Down
12 changes: 11 additions & 1 deletion pkg/manifests/sched/sched.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ func (mf Manifests) Render(logger logr.Logger, options RenderOptions) (Manifests
ret.DPScheduler.Spec.Replicas = newInt32(replicas)
ret.DPController.Spec.Replicas = newInt32(replicas)

err := schedupdate.SchedulerConfig(ret.ConfigMap, options.ProfileName, options.CacheResyncPeriod)
params := manifests.ConfigParams{
Cache: &manifests.ConfigCacheParams{
ResyncPeriodSeconds: newInt64(int64(options.CacheResyncPeriod.Seconds())),
},
}

err := schedupdate.SchedulerConfig(ret.ConfigMap, options.ProfileName, &params)
if err != nil {
return ret, err
}
Expand Down Expand Up @@ -211,3 +217,7 @@ func GetManifests(plat platform.Platform, namespace string) (Manifests, error) {
func newInt32(value int32) *int32 {
return &value
}

func newInt64(value int64) *int64 {
return &value
}
137 changes: 137 additions & 0 deletions pkg/manifests/schedparams.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* 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.
*
* Copyright 2023 Red Hat, Inc.
*/

package manifests

import (
"fmt"

"sigs.k8s.io/yaml"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/klog/v2"
)

const (
SchedulerConfigFileName = "scheduler-config.yaml" // TODO duplicate from yaml
SchedulerPluginName = "NodeResourceTopologyMatch"
)

type ConfigCacheParams struct {
ResyncPeriodSeconds *int64
}

type ConfigParams struct {
ProfileName string // can't be empty, so no need for pointer
Cache *ConfigCacheParams
}

func DecodeSchedulerProfilesFromData(data []byte) ([]ConfigParams, error) {
params := []ConfigParams{}

var r unstructured.Unstructured
if err := yaml.Unmarshal(data, &r.Object); err != nil {
klog.ErrorS(err, "cannot unmarshal scheduler config")
return params, nil
}

profiles, ok, err := unstructured.NestedSlice(r.Object, "profiles")
if !ok || err != nil {
klog.ErrorS(err, "failed to process unstructured data", "profiles", ok)
return params, nil
}
for _, prof := range profiles {
profile, ok := prof.(map[string]interface{})
if !ok {
klog.V(1).InfoS("unexpected profile data")
return params, nil
}

profileName, ok, err := unstructured.NestedString(profile, "schedulerName")
if !ok || err != nil {
klog.ErrorS(err, "failed to get profile name", "profileName", ok)
return params, nil
}

pluginConfigs, ok, err := unstructured.NestedSlice(profile, "pluginConfig")
if !ok || err != nil {
klog.ErrorS(err, "failed to process unstructured data", "pluginConfig", ok)
return params, nil
}
for _, plConf := range pluginConfigs {
pluginConf, ok := plConf.(map[string]interface{})
if !ok {
klog.V(1).InfoS("unexpected profile coonfig data")
return params, nil
}

name, ok, err := unstructured.NestedString(pluginConf, "name")
if !ok || err != nil {
klog.ErrorS(err, "failed to process unstructured data", "name", ok)
return params, nil
}
if name != SchedulerPluginName {
continue
}
args, ok, err := unstructured.NestedMap(pluginConf, "args")
if !ok || err != nil {
klog.ErrorS(err, "failed to process unstructured data", "args", ok)
return params, nil
}

profileParams, err := extractParams(profileName, args)
if err != nil {
klog.ErrorS(err, "failed to extract params", "name", name, "profile", profileName)
continue
}

params = append(params, profileParams)
}
}

return params, nil

}

func FindSchedulerProfileByName(profileParams []ConfigParams, schedulerName string) *ConfigParams {
for idx := range profileParams {
params := &profileParams[idx]
if params.ProfileName == schedulerName {
return params
}
}
return nil
}

func extractParams(profileName string, args map[string]interface{}) (ConfigParams, error) {
params := ConfigParams{
ProfileName: profileName,
Cache: &ConfigCacheParams{},
}
// json quirk: we know it's int64, yet it's detected as float64
resyncPeriod, ok, err := unstructured.NestedFloat64(args, "cacheResyncPeriodSeconds")
if !ok {
// nothing to do
return params, nil
}
if err != nil {
return params, fmt.Errorf("cannot process field cacheResyncPeriodSeconds: %w", err)
}

val := int64(resyncPeriod)
params.Cache.ResyncPeriodSeconds = &val
return params, nil
}
Loading