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

Enables status subresource in order to fix generation bumping #786

Closed

Conversation

bsnchan
Copy link
Contributor

@bsnchan bsnchan commented Apr 30, 2018

Fixes #642

Proposed Changes

  • all Elafros CRDs now use the status subresource - api server now bumps metadata.generation
  • remove all generation bumping logic from the webhook
  • controllers now reference metadata.generation instead of spec.generation
  • patching is used instead of update when adding route labels to the configuration
    • prevents bumping the generation since nested template specs have a k8s
      Time struct which, during serialization, are not omitted
      when empty

Release Note

* all Elafros CRDs now use the status subresource to enable automatic generation bumping
* action required: Requires k8s 1.10
* action required: kube-apiserver has the feature gate `CustomResourceSubresources=true` set

cc @dprotaso

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@google-prow-robot google-prow-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Apr 30, 2018
Copy link
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good.

@@ -122,14 +116,6 @@ type ConfigurationList struct {
Items []Configuration `json:"items"`
}

func (r *Configuration) GetGeneration() int64 {
return r.Spec.Generation
Copy link
Member

Choose a reason for hiding this comment

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

You could have left these and moved them to point to the ObjectMeta instead.

Copy link
Member

Choose a reason for hiding this comment

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

isReady: false,
},
}
cases := []struct {
Copy link
Member

Choose a reason for hiding this comment

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

@adrcunha @bobcatfish

Can we add a test that 'gofmt' is a no-op on all our go files? Somehow these got checked in with 2 spaces rather than tabs earlier.

Copy link
Member

Choose a reason for hiding this comment

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

yeah :(

Copy link
Contributor

Choose a reason for hiding this comment

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

@evankanderson @jonjohnsonjr @dprotaso It looks like the relevant issue is #582 - prow has a /lint command but there are obstacles to running automatically.

If you don't mind waiting I'm looking into something related which might help with this 😇

Copy link
Contributor

Choose a reason for hiding this comment

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

and then i never did anything about it :(

@@ -265,7 +265,7 @@ func (c *Controller) syncHandler(key string) error {
if config.GetGeneration() == config.Status.ObservedGeneration {
// TODO(vaikas): Check to see if Status.LatestCreatedRevisionName is ready and update Status.LatestReady
glog.Infof("Skipping reconcile since already reconciled %d == %d",
config.Spec.Generation, config.Status.ObservedGeneration)
config.Generation, config.Status.ObservedGeneration)
Copy link
Member

Choose a reason for hiding this comment

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

Why isn't this config.ObjectMeta.Generation, like Annotations, below?

mostly just curious.

Copy link
Member

Choose a reason for hiding this comment

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

metav1.ObjectMeta being inlined - you could used config.Annotations directly actually. Might be worth a separate issue to define a convention.

@@ -361,25 +361,12 @@ func (c *Controller) syncHandler(key string) error {
}

func generateRevisionName(u *v1alpha1.Configuration) (string, error) {
// TODO: consider making sure the length of the
// string will not cause problems down the stack
if u.Spec.Generation == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

I'm assuming that this is now handled by the normal k8s machinery? This was really annoying before.

Copy link
Member

Choose a reason for hiding this comment

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

Yup. Though, like it's mentioned in the PR/commit message, it requires v1.10 and the feature gate.

if config.Labels == nil {
config.Labels = make(map[string]string)
} else if _, ok := config.Labels[ela.RouteLabelKey]; ok {
if _, ok := config.Labels[ela.RouteLabelKey]; ok {
Copy link
Member

Choose a reason for hiding this comment

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

We didn't need the previous check because "A nil map behaves like an empty map when reading, but attempts to write to a nil map will cause a runtime panic; don't do that.", right?

https://blog.golang.org/go-maps-in-action

Copy link
Member

@dprotaso dprotaso Apr 30, 2018

Choose a reason for hiding this comment

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

Yup - see example here: https://play.golang.org/p/Q5GRlc2ceES

You needed the make(map) before this PR since it was going to insert something into the map

routeName,
configName string) error {

pathPart := strings.Replace(ela.RouteLabelKey, "/", "~1", -1)
Copy link
Member

Choose a reason for hiding this comment

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

What's the output here? The "~1" is confusing to me. Might be worth a comment.

Copy link
Member

Choose a reason for hiding this comment

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

Once this is PR merged in jsonpath we'll change this to be

patch := []jsonpatch.JsonPatchOperation{
	{
		Operation: "add",
		Path:      jsonpath.MakePath("metadata/labels", ela.RouteLabelKey),
		Value:     routeName,
	},
]}

Copy link
Member

Choose a reason for hiding this comment

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

+1 to comment, probably linking to the PR.

}(),
Patch: patchBytes,
Allowed: true,
PatchType: &patchType,
Copy link
Member

Choose a reason for hiding this comment

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

For my own curiosity, why doesn't &admissionv1beta1.PatchTypeJSONPatch work, and we need to make a local copy instead?

Copy link
Member

Choose a reason for hiding this comment

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

Go doesn't allow it see: https://stackoverflow.com/questions/35146286/find-address-of-constant-in-go

The inline function was doing the same thing before - this is more obvious in my opinion

Copy link
Member

Choose a reason for hiding this comment

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

+1 I prefer the local over the function.

@evankanderson
Copy link
Member

/approve
/lgtm

You may need to chime in that everything is happy with CLAs (and it looks like our tests are unhappy on this PR for some reason). A sample error from the conformance test:

I0430 19:43:09.661] E0430 19:42:33.692063       1 route.go:618] Failed to patch Configuration configuration-example: jsonpatch add operation does not apply: doc is missing path: /metadata/labels/elafros.dev~1route
I0430 19:43:09.661] E0430 19:42:33.692113       1 route.go:295] error syncing "default/route-example": jsonpatch add operation does not apply: doc is missing path: /metadata/labels/elafros.dev~1route

@google-prow-robot google-prow-robot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Apr 30, 2018
@dprotaso
Copy link
Member

@evankanderson the google bot is having issues when @bsnchan and I co-author commits/PRs. It's getting pretty annoying at this point.

The failing test is probably because the k8s test environment prow? is using kubernetes 1.9.6 vs. 1.10 with the feature-gate

@evankanderson
Copy link
Member

evankanderson commented May 1, 2018 via email

@dprotaso
Copy link
Member

dprotaso commented May 1, 2018

I think it's more about @bsnchan opening PRs which have me as co-author. I type

/approve
/iapprove
/imokwithit

nm - it worked

@dprotaso dprotaso mentioned this pull request May 1, 2018
@google-prow-robot google-prow-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 2, 2018
Copy link
Contributor

@tcnghia tcnghia left a comment

Choose a reason for hiding this comment

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

/lgtm

@google-prow-robot google-prow-robot added the lgtm Indicates that a PR is ready to be merged. label May 2, 2018
@adrcunha
Copy link
Contributor

adrcunha commented May 2, 2018

/retest

@mattmoor
Copy link
Member

mattmoor commented Jun 4, 2018

/hold cancel

I think this is (finally) unblocked. @dprotaso @bsnchan thanks for your patience

@google-prow-robot google-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 4, 2018
@google-prow-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bsnchan, dprotaso, evankanderson

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

dprotaso and others added 4 commits June 6, 2018 10:41
* This requires k8s 1.10 with CustomResourceSubresources feature gate
enabled

* Patching is used instead of update when adding labels
  - prevents bumping the generation since nested specs have a k8s
    Time struct which, during serialization, are not omitted
    when empty

knative/serving#642

Signed-off-by: Brenda Chan <brchan@pivotal.io>
Signed-off-by: Brenda Chan <brchan@pivotal.io>
Signed-off-by: Dave Protasowski <dprotaso@gmail.com>
* This is required to enable CustomResourceSubresources

knative/serving#642
@knative-metrics-robot
Copy link

The following is the coverage report on pkg/. Say /test pull-knative-serving-go-coverage to run the coverage report again

File Old Coverage New Coverage Delta
pkg/apis/serving/v1alpha1/configuration_types.go 96.0% 95.7% -0.3%
pkg/apis/serving/v1alpha1/configuration_types_test.go 96.0% 95.7% -0.3%
pkg/apis/serving/v1alpha1/revision_types.go 82.8% 81.5% -1.3%
pkg/apis/serving/v1alpha1/revision_types_test.go 82.8% 81.5% -1.3%
pkg/apis/serving/v1alpha1/route_types.go 58.3% 63.6% 5.3%
pkg/apis/serving/v1alpha1/service_types.go 95.8% 95.5% -0.4%
pkg/apis/serving/v1alpha1/service_types_test.go 95.8% 95.5% -0.4%
pkg/controller/configuration/configuration.go 76.9% 77.4% 0.5%
pkg/controller/configuration/configuration_test.go 76.9% 77.4% 0.5%
pkg/controller/route/route.go 77.9% 77.7% -0.3%
pkg/controller/route/route_test.go 77.9% 77.7% -0.3%
pkg/controller/revision/revision.go 74.8% 74.8% -0.0%
pkg/webhook/webhook.go 44.6% 38.1% -6.5%
pkg/webhook/webhook_test.go 44.6% 38.1% -6.5%

*TestCoverage feature is being tested, do not rely on any info here yet

@knative-metrics-robot
Copy link

The following is the coverage report on pkg/. Say /test pull-knative-serving-go-coverage to run the coverage report again

File Old Coverage New Coverage Delta
pkg/apis/serving/v1alpha1/revision_types.go 82.8% 81.5% -1.3%
pkg/apis/serving/v1alpha1/revision_types_test.go 82.8% 81.5% -1.3%
pkg/apis/serving/v1alpha1/route_types.go 58.3% 63.6% 5.3%
pkg/apis/serving/v1alpha1/service_types.go 95.8% 95.5% -0.4%
pkg/apis/serving/v1alpha1/service_types_test.go 95.8% 95.5% -0.4%
pkg/apis/serving/v1alpha1/configuration_types.go 96.0% 95.7% -0.3%
pkg/apis/serving/v1alpha1/configuration_types_test.go 96.0% 95.7% -0.3%
pkg/controller/configuration/configuration.go 76.9% 77.4% 0.5%
pkg/controller/configuration/configuration_test.go 76.9% 77.4% 0.5%
pkg/controller/route/route.go 77.9% 77.7% -0.3%
pkg/controller/route/route_test.go 77.9% 77.7% -0.3%
pkg/controller/revision/revision.go 74.8% 74.8% -0.0%
pkg/webhook/webhook.go 44.6% 38.1% -6.5%
pkg/webhook/webhook_test.go 44.6% 38.1% -6.5%

*TestCoverage feature is being tested, do not rely on any info here yet

@bsnchan
Copy link
Contributor Author

bsnchan commented Jun 6, 2018

@mattmoor this should be good to go!

@dprotaso already approved the CLA business in this comment.

@dprotaso
Copy link
Member

@mattmoor @vaikas-google can we mark this one blocked on k8s 1.11 when the subresource feature gate moves to beta.

@evankanderson
Copy link
Member

To record for posterity the conversation as I know it:

The subresource support in k8s 1.10 is an Alpha feature locked behind a feature flag. Many k8s providers do not provide any access to alpha features, and requiring an alpha feature is likely to make it difficult to run the serving components on shared or production clusters. (GKE does provide access to alpha features, but limits alpha cluster lifespan to 30 days. AWS and Azure don't generally provide access to alpha features at all.)

We're going to hold this PR for 1.11 (maybe plus a week or two?) when CRD subresources should be a beta feature. Once we commit this to the repo and cut a release containing it, our customers will need to upgrade to k8s 1.11 in order to continue using the serving stack.

@mattmoor
Copy link
Member

/hold

As @evankanderson said.

@google-prow-robot google-prow-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 11, 2018
@evankanderson
Copy link
Member

As such, if there are parts where we can factor out the actual subresource call and flag-protect it (e.g. replace the subresource call with a PATCH on the parent for now), we could land this sooner.

We'd probably have to keep the Generation in the object specs for now, but many of the helpers could go in now, and we could phase in the two write paths in a follow-on PR if this one gets too unwieldy.

@bsnchan
Copy link
Contributor Author

bsnchan commented Jun 28, 2018

/label k8s-1.11

@bsnchan
Copy link
Contributor Author

bsnchan commented Jul 4, 2018

/label k8s 1.11

@bsnchan
Copy link
Contributor Author

bsnchan commented Jul 4, 2018

/label "k8s 1.11"

@bbrowning
Copy link
Contributor

Should we revisit this since Kubernetes 1.11 has been out for 3 months and Kubernetes 1.12 has since been released? Or would we like to hold off requiring Kubernetes 1.11 for the next release of Serving?

@bsnchan bsnchan closed this Nov 14, 2018
@dprotaso
Copy link
Member

@bbrowning yup it's on me

@dprotaso
Copy link
Member

GKE now has 1.11 - so our the Prow CI/CD can test the changes

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. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.