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

fix(computeresource/tasklevel): Fixed a bug where abnormal calculatio… #8399

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Ccheers
Copy link

@Ccheers Ccheers commented Nov 22, 2024

Fixed a bug where abnormal calculations caused requested resources to exceed limits when Resource type was Memory or EphemeralStorage

Changes

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Has Docs if any changes are user facing, including updates to minimum requirements e.g. Kubernetes version bumps
  • Has Tests included if any functionality added or changed
  • pre-commit Passed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including functionality, content, code)
  • Has a kind label. You can add one by adding a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings). See some examples of good release notes.
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

NONE

…ns caused requested resources to exceed limits when Resource type was Memory or EphemeralStorage
@tekton-robot tekton-robot added the release-note-none Denotes a PR that doesnt merit a release note. label Nov 22, 2024
Copy link

linux-foundation-easycla bot commented Nov 22, 2024

CLA Signed


The committers listed above are authorized under a signed CLA.

@tekton-robot
Copy link
Collaborator

Hi @Ccheers. Thanks for your PR.

I'm waiting for a tektoncd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@tekton-robot tekton-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 22, 2024
@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign dibyom after the PR has been reviewed.
You can assign the PR to them by writing /assign @dibyom in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Ccheers
Copy link
Author

Ccheers commented Nov 22, 2024

/kind bug

@tekton-robot tekton-robot added the kind/bug Categorizes issue or PR as related to a bug. label Nov 22, 2024
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/internal/computeresources/tasklevel/tasklevel.go 94.1% 95.0% 0.9

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ok-to-test
@Ccheers can you detail a bit more what is the issue ? (use-case, or examples)

@tekton-robot tekton-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 5, 2024
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/internal/computeresources/tasklevel/tasklevel.go 94.1% 95.0% 0.9

@Ccheers
Copy link
Author

Ccheers commented Dec 10, 2024

/ok-to-test @Ccheers can you detail a bit more what is the issue ? (use-case, or examples)您能详细说明问题所在吗?(用例或例子)

In previous versions, when calling computeAverageRequests, if there was a Memory resource in corev1.ResourceList, it would cause an abnormal calculation of the Memory resource.
eg:

func Test_computeAverageRequests(t *testing.T) {
	type args struct {
		requests corev1.ResourceList
		steps    int
	}

	tests := []struct {
		name string
		args args
		want map[corev1.ResourceName]string
	}{
		{
			name: "get 1 Mi",
			args: args{
				requests: corev1.ResourceList{
					corev1.ResourceCPU:    resource.MustParse("300m"),
					corev1.ResourceMemory: resource.MustParse("32Mi"),
				},
				steps: 3,
			},
			want: map[corev1.ResourceName]string{
				corev1.ResourceCPU: func() string {
					parse := resource.MustParse("100m")
					return parse.String()
				}(),
				corev1.ResourceMemory: func() string {
					parse := resource.MustParse("11184810")
					return parse.String()
				}(),
			},
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got := computeAverageRequests(tt.args.requests, tt.args.steps)
			mm := make(map[corev1.ResourceName]string, len(got))
			for k, v := range got {
				mm[k] = v.String()
			}
			if !reflect.DeepEqual(mm, tt.want) {
				t.Errorf("computeAverageRequests() = %v, want %v", mm, tt.want)
			}
		})
	}
}

// memory need 11184810
// but got 11184810666m

@Ccheers Ccheers requested a review from vdemeester December 17, 2024 00:00
@Ccheers
Copy link
Author

Ccheers commented Dec 24, 2024

@vdemeester

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesnt merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants