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

Introduce sharedmain.WebhookMain* #1084

Merged
merged 1 commit into from
Feb 21, 2020

Conversation

pmorie
Copy link
Member

@pmorie pmorie commented Feb 12, 2020

WebhookMain* now implements the old main flow - while Main* no longer serves webhooks. This allows us to retain the existing behavior for webhooks - which require additional investigation / decision making on how to deal with HA concerns.

Related to #1007

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Feb 12, 2020
@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 12, 2020
Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve
/hold

HOLDing as I think we need to stage this into the downstream repos to prevent breaking them (since the webhook MUST move to the new signature, and auto-import will fail).

@knative-prow-robot knative-prow-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. 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 Feb 13, 2020
if err != nil {
log.Fatalf("Error building kubeconfig: %v", err)
}
cfg := ParseAndGetConfigOrDie()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, since you don't use the cfg, you could consider just:
MainWithConfig(ctx, component, ParseAndGetConfigOrDie(), ctors...)
but not a big deal either way.

}

profilingHandler := profiling.NewHandler(logger, false)

// Watch the logging config map and dynamically update logging levels.
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe move this and observability die above setting up the controllers so it's grouped by where the pieces necessary to construct it are set up? My reasoning being that if all the dies are as early as possible, just makes it easier to reason about the code?
Again, not a big deal :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ack, I tried to preserve the existing flow as much as possible for lower review overhead, but reading it now it's a bit apart. I'll rejigger

log.Fatalf("Error reading/parsing logging configuration: %v", err)
}
logger, atomicLevel := logging.NewLoggerFromConfig(loggingConfig, component)
ctx = logging.WithLogger(ctx, logger)
Copy link
Contributor

Choose a reason for hiding this comment

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

You might want to document this in the function comments. I think the intent is that this will also modify the incoming context and attach a logger to it. I think it would be good to document that because it's not (to me) immediately clear that's what's happening. Alternatively, if the intent is for the caller to then create / decorate their context with the logger is to return above with:
return logging.NewLoggerFromConfig(loggingConfig, component).

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the code as it stands is even wrong. WithLogger will create a new context that you have no access to in this case.

I agree, we should probably just do the WithLogger call right after calling SetupLoggerOrDie at the calling side.

Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops, good catch. I will fix

if _, err := kubeclient.Get(ctx).CoreV1().ConfigMaps(system.Namespace()).Get(logging.ConfigMapName(),
metav1.GetOptions{}); err == nil {
cmw.Watch(logging.ConfigMapName(), logging.UpdateLevelFromConfigMap(logger, atomicLevel, component))
} else if !apierrors.IsNotFound(err) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if it is not found? Seems like it should also fail? Or put another way, is there a reason not to die on any error?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a copy of the code as it lives in the Main function today. This has been changed not to cause the component to die a while ago.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then I think at the very least we should clearly document what's going on. There are cases where this will NOT establish a watch nor die? Seems like if there's any reason (temporary can't reach), this will fail? Or maybe I'm just misunderstanding something :)

Copy link
Contributor

Choose a reason for hiding this comment

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

See #872 for the broader reasoning of that behavior. I agree we should add into the comment that this will not watch the logging config if it doesn't exist (but die on any other error)

cmw.Watch(metrics.ConfigMapName(),
metrics.UpdateExporterFromConfigMap(component, logger),
profilingHandler.UpdateFromConfigMap)
} else if !apierrors.IsNotFound(err) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto here, what happens if it fails for another reason?

Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Feb 13, 2020
@vaikas
Copy link
Contributor

vaikas commented Feb 14, 2020

/lgtm
Thanks!!

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Feb 14, 2020
@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Feb 17, 2020
@pmorie pmorie force-pushed the separate-webhooks branch 2 times, most recently from 62e0c6f to 7e9c53a Compare February 19, 2020 22:55
Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mattmoor, pmorie

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

@mattmoor
Copy link
Member

/unhold

@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 21, 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. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants