Skip to content

Order ContainerStatuses the same as spec.Containers#7866

Merged
knative-prow-robot merged 10 commits intoknative:masterfrom
taragu:ordered-containerstatuses
May 8, 2020
Merged

Order ContainerStatuses the same as spec.Containers#7866
knative-prow-robot merged 10 commits intoknative:masterfrom
taragu:ordered-containerstatuses

Conversation

@taragu
Copy link
Contributor

@taragu taragu commented May 6, 2020

/lint

Fixes #7658

Proposed Changes

  • Order ContainerStatuses so it has the same order as spec.Containers

Release Note

Order ContainerStatuses so it has the same order as spec.Containers

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label May 6, 2020
@knative-prow-robot knative-prow-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. area/API API objects and controllers labels May 6, 2020
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@taragu: 0 warnings.

Details

In response to this:

/lint

Fixes #7658

Proposed Changes

  • Order ContainerStatuses so it has the same order as spec.Containers

Release Note

Order ContainerStatuses so it has the same order as spec.Containers

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.

@taragu
Copy link
Contributor Author

taragu commented May 6, 2020

/cc @dprotaso

for _, container := range rev.Spec.Containers {
containerIndexMap := map[string]int{}
for i, container := range rev.Spec.Containers {
containerIndexMap[container.Name] = i
Copy link
Contributor

Choose a reason for hiding this comment

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

one possible approach: since Go allows concurrently writing to an array from multiple goroutines as long as each individual element is only accessed from one, could we directly store to rev.Status.ContainerStatus[i] = .. in this loop (obviously making sure to do i := i and pre-create the array with the right size)?

That way we can lose this map, the channel stuff and the second loop - and any errors could be returned normally via the digestGrp.Wait().

Copy link
Contributor

Choose a reason for hiding this comment

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

yep that as well :)

image: container.Image,
digestError: err,
}
rev.Status.MarkContainerHealthyFalse(v1.ReasonContainerMissing,
Copy link
Contributor

Choose a reason for hiding this comment

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

think this is racey unfortunately cos we can fail in parallel, probably need to do this after the loop

Copy link
Contributor

Choose a reason for hiding this comment

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

That was my suggestion to @savitaashture in the other PR to just use sync.Once, though won't help with return.

Copy link
Contributor

Choose a reason for hiding this comment

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

cant we just do something like

err := digestGrp.Wait(); 
if err != nil {
 	rev.Status.MarkContainerHealthyFalse(v1.ReasonContainerMissing, err)
}
return err

?

Copy link
Contributor

Choose a reason for hiding this comment

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

now that we're filling everything in line, probably no reason why not.

Copy link
Contributor

@markusthoemmes markusthoemmes May 7, 2020

Choose a reason for hiding this comment

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

We can't do this because the Mark function takes a container image too. We'd need a special error type to do that.

Copy link
Contributor

@julz julz May 7, 2020

Choose a reason for hiding this comment

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

Yah, that (special error type) is what I was suggesting in #7866 (comment). Though sync.Once would work too if necc.

v1.RevisionContainerMissingMessage(
container.Image, err.Error()))
return err
failedContainerImage = container.Image
Copy link
Contributor

Choose a reason for hiding this comment

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

this still races I think (there's still only one failedContainerImage potentially written by multiple goroutines), but I think we could just build and return an error containing the v1.RevisionContainerMissingMessage which we can unwrap at the bottom.

@taragu
Copy link
Contributor Author

taragu commented May 6, 2020

/retest

image: container.Image,
digestError: err,
}
return fmt.Errorf(v1.RevisionContainerMissingMessage(container.Image, err.Error()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf(v1.RevisionContainerMissingMessage(container.Image, err.Error()))
return errors.New(v1.RevisionContainerMissingMessage(container.Image, err.Error()))

@taragu taragu force-pushed the ordered-containerstatuses branch from 1f66322 to 19ffa32 Compare May 7, 2020 16:24
})
if err := digestGrp.Wait(); err != nil {
rev.Status.MarkContainerHealthyFalse(v1.ReasonContainerMissing, err.Error())
rev.Status.ContainerStatuses = make([]v1.ContainerStatuses, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The TestContainerErrorMsg e2e test was failing because if we don't clear this out, we will try to create image cache so the config will fail with a different message

for _, container := range rev.Status.ContainerStatuses {

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. why not nil?
  2. you can do this differently by using local variable for the list and only assigning it if err != nil.

@knative-metrics-robot
Copy link

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

File Old Coverage New Coverage Delta
pkg/reconciler/revision/revision.go 98.1% 98.0% -0.2

@julz
Copy link
Contributor

julz commented May 7, 2020

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label May 7, 2020
Copy link
Contributor

@vagababov vagababov left a comment

Choose a reason for hiding this comment

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

/lgtm

@dprotaso
Copy link
Member

dprotaso commented May 7, 2020

/approve

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 7, 2020
@taragu
Copy link
Contributor Author

taragu commented May 8, 2020

/retest

@knative-test-reporter-robot

The following jobs failed:

Test name Triggers Retries
pull-knative-serving-integration-tests 0/3
pull-knative-serving-upgrade-tests pull-knative-serving-upgrade-tests 1/3

Failed non-flaky tests preventing automatic retry of pull-knative-serving-integration-tests:

test/e2e.TestSubrouteLocalSTS
test/e2e.TestSubrouteLocalSTS/fqdn

Copy link
Contributor

@markusthoemmes markusthoemmes left a comment

Choose a reason for hiding this comment

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

Very nice refactoring! Thanks!

/lgtm
/approve

@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dprotaso, markusthoemmes, taragu

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

The pull request process is described here

Details 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

@markusthoemmes
Copy link
Contributor

/retest

1 similar comment
@taragu
Copy link
Contributor Author

taragu commented May 8, 2020

/retest

@knative-prow-robot knative-prow-robot merged commit 72af798 into knative:master May 8, 2020
@taragu taragu deleted the ordered-containerstatuses branch July 29, 2020 11:40
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. area/API API objects and controllers cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. 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.

Modify order of the revision ContainerStatus in sync with Spec

9 participants