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

Emit an event if overwriting PodTemplate affinity #2859

Conversation

adshmh
Copy link
Contributor

@adshmh adshmh commented Jun 24, 2020

Changes

The taskrun controller now emits a warning event if the affinity
specified by pod template will be overwritten with affinity assistant.
Closes #2678

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes tests (if functionality changed/added)
  • Includes docs (if user facing)
  • Commit messages follow commit message best practices
  • Release notes block has been filled in or deleted (only if no user facing changes)

See the contribution guide for more details.

Double check this list of stuff that's easy to miss:

Reviewer Notes

If API changes are included, additive changes must be approved by at least two OWNERS and backwards incompatible changes must be approved by more than 50% of the OWNERS, and they must first be added in a backwards compatible way.

Release Notes

The taskrun controller emits a warning event if pod template affinity will be overwritten with affinity assistant.

@tekton-robot tekton-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 24, 2020
@tekton-robot
Copy link
Collaborator

Hi @adshmh. 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
Copy link
Collaborator

This PR cannot be merged: expecting exactly one kind/ label

Available kind/ labels are:

kind/bug: Categorizes issue or PR as related to a bug.
kind/flake: Categorizes issue or PR as related to a flakey test
kind/cleanup: Categorizes issue or PR as related to cleaning up code, process, or technical debt.
kind/design: Categorizes issue or PR as related to design.
kind/documentation: Categorizes issue or PR as related to documentation.
kind/feature: Categorizes issue or PR as related to a new feature.
kind/misc: Categorizes issue or PR as a miscellaneuous one.

@adshmh
Copy link
Contributor Author

adshmh commented Jun 24, 2020

/cc @jlpettersson

@tekton-robot
Copy link
Collaborator

This PR cannot be merged: expecting exactly one kind/ label

Available kind/ labels are:

kind/bug: Categorizes issue or PR as related to a bug.
kind/flake: Categorizes issue or PR as related to a flakey test
kind/cleanup: Categorizes issue or PR as related to cleaning up code, process, or technical debt.
kind/design: Categorizes issue or PR as related to design.
kind/documentation: Categorizes issue or PR as related to documentation.
kind/feature: Categorizes issue or PR as related to a new feature.
kind/misc: Categorizes issue or PR as a miscellaneuous one.

@jlpettersson
Copy link
Member

/ok-to-test

@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 Jun 24, 2020
@tekton-robot
Copy link
Collaborator

This PR cannot be merged: expecting exactly one kind/ label

Available kind/ labels are:

kind/bug: Categorizes issue or PR as related to a bug.
kind/flake: Categorizes issue or PR as related to a flakey test
kind/cleanup: Categorizes issue or PR as related to cleaning up code, process, or technical debt.
kind/design: Categorizes issue or PR as related to design.
kind/documentation: Categorizes issue or PR as related to documentation.
kind/feature: Categorizes issue or PR as related to a new feature.
kind/misc: Categorizes issue or PR as a miscellaneuous one.

1 similar comment
@tekton-robot
Copy link
Collaborator

This PR cannot be merged: expecting exactly one kind/ label

Available kind/ labels are:

kind/bug: Categorizes issue or PR as related to a bug.
kind/flake: Categorizes issue or PR as related to a flakey test
kind/cleanup: Categorizes issue or PR as related to cleaning up code, process, or technical debt.
kind/design: Categorizes issue or PR as related to design.
kind/documentation: Categorizes issue or PR as related to documentation.
kind/feature: Categorizes issue or PR as related to a new feature.
kind/misc: Categorizes issue or PR as a miscellaneuous one.

@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/pod/pod.go 84.5% 85.1% 0.5
pkg/reconciler/taskrun/taskrun.go 77.6% 77.4% -0.1

@adshmh
Copy link
Contributor Author

adshmh commented Jun 24, 2020

/retest

1 similar comment
@adshmh
Copy link
Contributor Author

adshmh commented Jun 25, 2020

/retest

Copy link
Member

@jlpettersson jlpettersson left a comment

Choose a reason for hiding this comment

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

Thank you for this!

Just a few minor things - that potentially can be changed, but no blockers.

/lgtm

pkg/pod/pod.go Outdated

// WillOverwritePodSetAffinity returns a bool indicating whether the
// affinity for pods will be overwritten with affinity assistant.
func WillOverwritePodSetAffinity(taskRun *v1beta1.TaskRun) bool {
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to declare this in a package so that it can be private?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review. I think this is related to the comment below, i.e. if the WillOverwritePodSetAffinity is moved to the reconciler package, then it can be made private.


// WarningOverwritingPodAffinity indicates that the affinity specified by
// the pod template will be overwritten with affinity assistant
WarningOverwritingPodAffinity = "PodAffinityOverwrite"
Copy link
Member

Choose a reason for hiding this comment

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

Also this, is it possible to declare this in a context so that it can be private? I think it is only used in a single place - so I feel it should be possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review. Fixed.

@@ -360,11 +360,15 @@ func (c *Reconciler) reconcile(ctx context.Context, tr *v1beta1.TaskRun,
tr.Spec.Workspaces = taskRunWorkspaces
}

willOverwriteAffinity := podconvert.WillOverwritePodSetAffinity(tr)
pod, err = c.createPod(ctx, tr, rtr)
Copy link
Member

Choose a reason for hiding this comment

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

is it possible to move in the willOverwritePodSetAffinity to inside c.createPod() - not sure it is possible, but it would be closer to the place where the affinity is set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review. Yes, it can be moved inside createPod, but then we need to pass the recorder to createPod as well, and it will need to start emitting events. I implemented it this way to avoid changing createPod signature, and to keep all the event emitting in the reconciler package.

If moving this to the pod package is preferred, please let me know and I'll update the PR.

Copy link

Choose a reason for hiding this comment

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

It looks like you wouldn't have to change the signature of createPod, you can look up the recorder from the context:

// in c.createPod
recorder := controller.GetEventRecorder(ctx)
if recorder != nil && willOverwritePodAffinity(tr) {
    recorder.Eventf(...)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the reviews. Moved willOverwritePodSetAffinity to createPod, no changes were made to the signature of createPod.

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 25, 2020
@tekton-robot
Copy link
Collaborator

This PR cannot be merged: expecting exactly one kind/ label

Available kind/ labels are:

kind/bug: Categorizes issue or PR as related to a bug.
kind/flake: Categorizes issue or PR as related to a flakey test
kind/cleanup: Categorizes issue or PR as related to cleaning up code, process, or technical debt.
kind/design: Categorizes issue or PR as related to design.
kind/documentation: Categorizes issue or PR as related to documentation.
kind/feature: Categorizes issue or PR as related to a new feature.
kind/misc: Categorizes issue or PR as a miscellaneuous one.

@adshmh adshmh force-pushed the 2678-emit-event-when-set-affinity-property-is-overwritten branch from 8a765be to 7ee173b Compare June 25, 2020 20:28
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Jun 25, 2020
@tekton-robot
Copy link
Collaborator

This PR cannot be merged: expecting exactly one kind/ label

Available kind/ labels are:

kind/question: Issues or PRs that are questions around the project or a particular feature
kind/bug: Categorizes issue or PR as related to a bug.
kind/flake: Categorizes issue or PR as related to a flakey test
kind/cleanup: Categorizes issue or PR as related to cleaning up code, process, or technical debt.
kind/design: Categorizes issue or PR as related to design.
kind/documentation: Categorizes issue or PR as related to documentation.
kind/feature: Categorizes issue or PR as related to a new feature.
kind/misc: Categorizes issue or PR as a miscellaneuous one.

1 similar comment
@tekton-robot
Copy link
Collaborator

This PR cannot be merged: expecting exactly one kind/ label

Available kind/ labels are:

kind/question: Issues or PRs that are questions around the project or a particular feature
kind/bug: Categorizes issue or PR as related to a bug.
kind/flake: Categorizes issue or PR as related to a flakey test
kind/cleanup: Categorizes issue or PR as related to cleaning up code, process, or technical debt.
kind/design: Categorizes issue or PR as related to design.
kind/documentation: Categorizes issue or PR as related to documentation.
kind/feature: Categorizes issue or PR as related to a new feature.
kind/misc: Categorizes issue or PR as a miscellaneuous one.

@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/pod/pod.go 84.5% 85.1% 0.5
pkg/reconciler/taskrun/taskrun.go 77.6% 77.4% -0.1

@jlpettersson
Copy link
Member

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 29, 2020
@tekton-robot
Copy link
Collaborator

This PR cannot be merged: expecting exactly one kind/ label

Available kind/ labels are:

kind/question: Issues or PRs that are questions around the project or a particular feature
kind/bug: Categorizes issue or PR as related to a bug.
kind/flake: Categorizes issue or PR as related to a flakey test
kind/cleanup: Categorizes issue or PR as related to cleaning up code, process, or technical debt.
kind/design: Categorizes issue or PR as related to design.
kind/documentation: Categorizes issue or PR as related to documentation.
kind/feature: Categorizes issue or PR as related to a new feature.
kind/misc: Categorizes issue or PR as a miscellaneuous one.

@jlpettersson
Copy link
Member

/kind feature

@tekton-robot tekton-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Jun 29, 2020
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.

pkg/pod/pod.go Outdated
if taskRun.Spec.PodTemplate != nil {
podTemplate = *taskRun.Spec.PodTemplate
}
return taskRun.Annotations[workspace.AnnotationAffinityAssistantName] != "" && podTemplate.Affinity != nil
Copy link

Choose a reason for hiding this comment

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

Is it possible that taskRun.Annotations is ever a nil map? I think this might panic if so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review. I did not introduce a nil check here as it is only reading the map so there won't be a panic if the map is nil. Please let me know if I am missing something here regarding the nil check.

@@ -360,11 +360,15 @@ func (c *Reconciler) reconcile(ctx context.Context, tr *v1beta1.TaskRun,
tr.Spec.Workspaces = taskRunWorkspaces
}

willOverwriteAffinity := podconvert.WillOverwritePodSetAffinity(tr)
pod, err = c.createPod(ctx, tr, rtr)
Copy link

Choose a reason for hiding this comment

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

It looks like you wouldn't have to change the signature of createPod, you can look up the recorder from the context:

// in c.createPod
recorder := controller.GetEventRecorder(ctx)
if recorder != nil && willOverwritePodAffinity(tr) {
    recorder.Eventf(...)
}

@tekton-robot tekton-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 9, 2020
@adshmh adshmh force-pushed the 2678-emit-event-when-set-affinity-property-is-overwritten branch from 7ee173b to bc7e8b2 Compare September 29, 2020 18:35
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Sep 29, 2020
The taskrun controller now emits a warning event if the affinity
specified by pod template will be overwritten with affinity assistant.
Closes tektoncd#2678
@adshmh adshmh force-pushed the 2678-emit-event-when-set-affinity-property-is-overwritten branch from bc7e8b2 to 380c8c4 Compare September 29, 2020 18:47
@tekton-robot tekton-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 29, 2020
@adshmh
Copy link
Contributor Author

adshmh commented Sep 29, 2020

/retest

@ghost
Copy link

ghost commented Oct 2, 2020

/approve

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jlpettersson, sbwsg

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

The pull request process is described 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

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 2, 2020
@ghost
Copy link

ghost commented Oct 2, 2020

@tektoncd/core-maintainers does anyone have bandwidth to review and lgtm if all looks ok?

pod, err = c.KubeClientSet.CoreV1().Pods(tr.Namespace).Create(pod)
if err == nil && willOverwritePodSetAffinity(tr) {
if recorder := controller.GetEventRecorder(ctx); recorder != nil {
recorder.Eventf(tr, corev1.EventTypeWarning, "PodAffinityOverwrite", "Pod template affinity is overwritten by affinity assistant for pod %q", pod.Name)
Copy link
Member

@pritidesai pritidesai Oct 2, 2020

Choose a reason for hiding this comment

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

I would have introduced const here for PodAffinityOverwrite but going through the reviews from @jlpettersson on the same 🙃 , looks good for now, can be converted to const if needed in future

@pritidesai
Copy link
Member

/lgtm

thanks @adshmh @jlpettersson @sbwsg 🙏

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 2, 2020
@tekton-robot tekton-robot merged commit d98d204 into tektoncd:master Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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.

Emit an Event when a set affinity property is overwritten
5 participants