Skip to content

Commit

Permalink
Merge pull request #536 from cheney-lin/dev/mem_guard
Browse files Browse the repository at this point in the history
refactor(sysadvisor): support dynamic enable memory guard
  • Loading branch information
nightmeng authored Apr 15, 2024
2 parents c271037 + 1e39f1e commit 40d6b81
Show file tree
Hide file tree
Showing 15 changed files with 353 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"k8s.io/apimachinery/pkg/util/errors"
cliflag "k8s.io/component-base/cli/flag"

"github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options/dynamic/adminqos/advisor"
"github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options/dynamic/adminqos/eviction"
"github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options/dynamic/adminqos/reclaimedresource"
"github.com/kubewharf/katalyst-core/pkg/config/agent/dynamic/adminqos"
Expand All @@ -28,23 +29,27 @@ import (
type AdminQoSOptions struct {
*reclaimedresource.ReclaimedResourceOptions
*eviction.EvictionOptions
*advisor.AdvisorOptions
}

func NewAdminQoSOptions() *AdminQoSOptions {
return &AdminQoSOptions{
ReclaimedResourceOptions: reclaimedresource.NewReclaimedResourceOptions(),
EvictionOptions: eviction.NewEvictionOptions(),
AdvisorOptions: advisor.NewAdvisorOptions(),
}
}

func (o *AdminQoSOptions) AddFlags(fss *cliflag.NamedFlagSets) {
o.ReclaimedResourceOptions.AddFlags(fss)
o.EvictionOptions.AddFlags(fss)
o.AdvisorOptions.AddFlags(fss)
}

func (o *AdminQoSOptions) ApplyTo(c *adminqos.AdminQoSConfiguration) error {
var errList []error
errList = append(errList, o.ReclaimedResourceOptions.ApplyTo(c.ReclaimedResourceConfiguration))
errList = append(errList, o.EvictionOptions.ApplyTo(c.EvictionConfiguration))
errList = append(errList, o.AdvisorOptions.ApplyTo(c.AdvisorConfiguration))
return errors.NewAggregate(errList)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2022 The Katalyst Authors.
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 advisor

import (
"k8s.io/apimachinery/pkg/util/errors"
cliflag "k8s.io/component-base/cli/flag"

"github.com/kubewharf/katalyst-core/pkg/config/agent/dynamic/adminqos/advisor"
)

type AdvisorOptions struct {
*MemoryGuardOptions
}

func NewAdvisorOptions() *AdvisorOptions {
return &AdvisorOptions{
MemoryGuardOptions: NewMemoryGuardOptions(),
}
}

func (o *AdvisorOptions) AddFlags(fss *cliflag.NamedFlagSets) {
o.MemoryGuardOptions.AddFlags(fss)
}

func (o *AdvisorOptions) ApplyTo(c *advisor.AdvisorConfiguration) error {
var errList []error
errList = append(errList, o.MemoryGuardOptions.ApplyTo(c.MemoryGuardConfiguration))
return errors.NewAggregate(errList)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright 2022 The Katalyst Authors.
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 advisor

import (
cliflag "k8s.io/component-base/cli/flag"

"github.com/kubewharf/katalyst-core/pkg/config/agent/dynamic/adminqos/advisor"
)

type MemoryGuardOptions struct {
Enable bool
}

func NewMemoryGuardOptions() *MemoryGuardOptions {
return &MemoryGuardOptions{
Enable: true,
}
}

// AddFlags parses the flags to CPUPressureEvictionOptions
func (o *MemoryGuardOptions) AddFlags(fss *cliflag.NamedFlagSets) {
fs := fss.FlagSet("memory-guard")

fs.BoolVar(&o.Enable, "memory-guard-enable", o.Enable,
"set true to enable memory guard")
}

func (o *MemoryGuardOptions) ApplyTo(c *advisor.MemoryGuardConfiguration) error {
c.Enable = o.Enable
return nil
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/google/cadvisor v0.44.2
github.com/google/uuid v1.3.0
github.com/klauspost/cpuid/v2 v2.2.6
github.com/kubewharf/katalyst-api v0.4.1-0.20240407044918-5d1dfd91ffa4
github.com/kubewharf/katalyst-api v0.4.1-0.20240409131259-e2612e3fc126
github.com/montanaflynn/stats v0.7.1
github.com/opencontainers/runc v1.1.6
github.com/opencontainers/selinux v1.10.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kubewharf/katalyst-api v0.4.1-0.20240407044918-5d1dfd91ffa4 h1:YUrPtBBTMJFTLK9hgZzwimyBvoHOdcLCfarEh3/9zxw=
github.com/kubewharf/katalyst-api v0.4.1-0.20240407044918-5d1dfd91ffa4/go.mod h1:Y2IeIorxQamF2a3oa0+URztl5QCSty6Jj3zD83R8J9k=
github.com/kubewharf/katalyst-api v0.4.1-0.20240409131259-e2612e3fc126 h1:QdxIE9FXS9330/FausiLqpY+SOAOtgH+kX0CjluGN8w=
github.com/kubewharf/katalyst-api v0.4.1-0.20240409131259-e2612e3fc126/go.mod h1:Y2IeIorxQamF2a3oa0+URztl5QCSty6Jj3zD83R8J9k=
github.com/kubewharf/kubelet v1.24.6-kubewharf.8 h1:2e89T/nZTgzaVhyRsZuwEdRk8V8kJXs4PRkgfeG4Ai4=
github.com/kubewharf/kubelet v1.24.6-kubewharf.8/go.mod h1:MxbSZUx3wXztFneeelwWWlX7NAAStJ6expqq7gY2J3c=
github.com/kyoh86/exportloopref v0.1.7/go.mod h1:h1rDl2Kdj97+Kwh4gdz3ujE7XHmH51Q0lUiZ1z4NLj8=
Expand Down
Loading

0 comments on commit 40d6b81

Please sign in to comment.