Skip to content

Commit

Permalink
koord-manager: fix noderesource update when compared values are zero (#…
Browse files Browse the repository at this point in the history
…1550)

Signed-off-by: saintube <[email protected]>
  • Loading branch information
saintube committed Aug 16, 2023
1 parent 96e7ea6 commit 4d28dbc
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
5 changes: 1 addition & 4 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ archives:
{{ .Version }}_
{{ .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else }}{{ .Arch }}{{ end }}
{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_
{{ . }}{{ end }}
{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}
{{- else }}{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ end }}
checksum:
name_template: 'checksums.txt'
snapshot:
Expand Down
10 changes: 9 additions & 1 deletion pkg/slo-controller/noderesource/noderesource_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const (

var (
NodeResourcePlugins []string
AllPlugins []string
)

type NodeResourceReconciler struct {
Expand Down Expand Up @@ -137,7 +138,14 @@ func InitFlags(fs *flag.FlagSet) {
"'-noderesource-plugins=*' enables all plugins. "+
"'-noderesource-plugins=BatchResource' means only the 'BatchResource' plugin is enabled. "+
"'-noderesource-plugins=*,-BatchResource' means all plugins except the 'BatchResource' plugin are enabled.\n"+
"All plugins: %s", strings.Join(NodeResourcePlugins, ", ")))
"All plugins: %s", strings.Join(AllPlugins, ", ")))
}

func addPluginOption(plugin framework.Plugin, enabled bool) {
AllPlugins = append(AllPlugins, plugin.Name())
if enabled {
NodeResourcePlugins = append(NodeResourcePlugins, plugin.Name())
}
}

func isPluginEnabled(pluginName string) bool {
Expand Down
5 changes: 3 additions & 2 deletions pkg/slo-controller/noderesource/plugins_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (

func init() {
// set default plugins
NodeResourcePlugins = append(NodeResourcePlugins, midresource.PluginName)
NodeResourcePlugins = append(NodeResourcePlugins, batchresource.PluginName)
addPluginOption(&midresource.Plugin{}, true)
addPluginOption(&batchresource.Plugin{}, true)
}

func addPlugins(filter framework.FilterFn) {
Expand All @@ -40,6 +40,7 @@ func addPlugins(filter framework.FilterFn) {
}

var (
// SetupPlugins implement the setup for node resource plugin.
setupPlugins = []framework.SetupPlugin{}
// NodePreparePlugin implements node resource preparing for the calculated results.
nodePreparePlugins = []framework.NodePreparePlugin{
Expand Down
3 changes: 2 additions & 1 deletion pkg/util/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ func IsResourceDiff(old, new corev1.ResourceList, resourceName corev1.ResourceNa
return false
}

return newQuant >= oldQuant*(1+diffThreshold) || newQuant <= oldQuant*(1-diffThreshold)
// not equal for both are zero
return newQuant > oldQuant*(1+diffThreshold) || newQuant < oldQuant*(1-diffThreshold)
}

func QuantityPtr(q resource.Quantity) *resource.Quantity {
Expand Down
19 changes: 16 additions & 3 deletions pkg/util/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,25 @@ func TestIsResourceDiff(t *testing.T) {
},
want: true,
},
{
name: "both resources are zero",
args: args{
old: corev1.ResourceList{
corev1.ResourceCPU: *resource.NewQuantity(0, resource.DecimalSI),
},
new: corev1.ResourceList{
corev1.ResourceCPU: *resource.NewQuantity(0, resource.DecimalSI),
},
resourceName: corev1.ResourceCPU,
diffThreshold: 2,
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsResourceDiff(tt.args.old, tt.args.new, tt.args.resourceName, tt.args.diffThreshold); got != tt.want {
t.Errorf("IsResourceDiff() = %v, want %v", got, tt.want)
}
got := IsResourceDiff(tt.args.old, tt.args.new, tt.args.resourceName, tt.args.diffThreshold)
assert.Equal(t, tt.want, got)
})
}
}
Expand Down

0 comments on commit 4d28dbc

Please sign in to comment.