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

chore: initialization touchups #2676

Closed
wants to merge 1 commit into from
Closed

chore: initialization touchups #2676

wants to merge 1 commit into from

Conversation

ellistarn
Copy link
Contributor

@ellistarn ellistarn commented Oct 17, 2022

Fixes #

Description

  • Subclasses context.Context w/ operator.Context that contains process-wide accessible objects.
  • Collapses operator specific options/injection into operator package

How was this change tested?

Does this change impact docs?

  • Yes, PR includes docs updates
  • Yes, issue opened: #
  • No

Release Note


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ellistarn ellistarn requested a review from a team as a code owner October 17, 2022 17:45
@netlify
Copy link

netlify bot commented Oct 17, 2022

Deploy Preview for karpenter-docs-prod canceled.

Name Link
🔨 Latest commit 63618a9
🔍 Latest deploy log https://app.netlify.com/sites/karpenter-docs-prod/deploys/634dda9256e8630007729ac8

// Options exposes shared components that are initialized by the startup.Initialize() call
type Options struct {
Ctx context.Context
// Context is the root context for the operator and exposes shared components used by the entire process
Copy link
Contributor

Choose a reason for hiding this comment

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

We should rename this file to Context if we are renaming the concept

KubeClient: ctx.KubeClient,
StartAsync: ctx.StartAsync,
})
utilruntime.Must(ctx.Manager.AddHealthzCheck("cloud-provider", cloudProvider.LivenessProbe))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove the HealthCheck interface now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used all over, unfortunately.

controllers.GetControllers(options, cloudProvider)...,
).Start(options.Ctx); err != nil {
ctx := operator.NewContextOrDie()
cloudProvider := awscloudprovider.NewCloudProvider(ctx, cloudprovider.Options{
Copy link
Contributor

Choose a reason for hiding this comment

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

I have some small concerns about exposing the manager through the context in this way. If someone does a typed conversion to the operator.Context object within the cloudprovider, they could then have access to the manager which seems like something we want to avoid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. Will play with this.

BaseContext: newRunnableContext(config, opts, logging.FromContext(ctx)),
MetricsBindAddress: fmt.Sprintf(":%d", options.MetricsPort),
HealthProbeBindAddress: fmt.Sprintf(":%d", options.HealthProbePort),
BaseContext: func() context.Context { return ctx },
Copy link
Contributor

Choose a reason for hiding this comment

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

Base context was introduced to avoid top-level context cancellation from stopping runnable cleanup as shown here. We shouldn't be passing the top-level context in a closure here since this gets back to the issue that controller-runtime was trying to avoid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed and added a comment

startinformers()
return ctx
}

func WithNamespacedName(ctx context.Context, namespacedname types.NamespacedName) context.Context {
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 these two methods stay in injection?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They're relied upon in the AWS API which creates a circular dependency. I need to make some other changes to remove this.

jonathan-innis
jonathan-innis previously approved these changes Oct 17, 2022
Copy link
Contributor

@jonathan-innis jonathan-innis left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

jonathan-innis
jonathan-innis previously approved these changes Oct 17, 2022
Copy link
Contributor

@jonathan-innis jonathan-innis left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

jonathan-innis
jonathan-innis previously approved these changes Oct 17, 2022
Copy link
Contributor

@jonathan-innis jonathan-innis left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

Copy link
Contributor

@jonathan-innis jonathan-innis left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

}

// Context is the root context for the operator and exposes shared components used by the entire process
type Context struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

After some thought, I want to discuss this decision a bit more. Primarily because I am concerned with the ramifications of passing fields that would normally be passed through to controller constructors as part of the context.Context struct.

In general, the Context object is used for request-specific context and cancellation and not for instantiation/performing dependency injection.

I'm curious for what your thought is in where else this Context might be passed; otherwise, I'm leaning more towards continuing calling this Options

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we need to sort out the neutrality of these bits too, since options currently co-mingles AWS specific and vendor agnostic parameters. Let's spend some time pair programming this.

@ellistarn ellistarn closed this Oct 18, 2022
@ellistarn ellistarn deleted the init2 branch October 20, 2022 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants