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

Contexts complient with kube-builder #204

Merged
merged 1 commit into from
Nov 18, 2020

Conversation

kuritka
Copy link
Collaborator

@kuritka kuritka commented Nov 18, 2020

In order to migration operator-sdk 1.0 we should use contexts to be kube-builder compliant. To achieve this, I reuse default Background context from reconciliation loop. see: https://book.kubebuilder.io/cronjob-tutorial/controller-implementation.html#implementing-a-controller;

func (r *CronJobReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
    ctx := context.Background()
    log := r.Log.WithValues("cronjob", req.NamespacedName)

I changed

  • depresolver doesn't hold context internally
  • update tests
  • use default context instead of context.TODO() within reconciliation queue

@kuritka kuritka force-pushed the k8gb-context-compliant-with-kubebuilder branch from 8bbc4e7 to 2c42b40 Compare November 18, 2020 11:45
@kuritka kuritka force-pushed the k8gb-context-compliant-with-kubebuilder branch from 2c42b40 to 2820c0c Compare November 18, 2020 11:52
Copy link
Member

@ytsarev ytsarev left a comment

Choose a reason for hiding this comment

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

// act
err := resolver.ResolveGslbSpec(gslb)
err := resolver.ResolveGslbSpec(context.TODO(), gslb)
Copy link
Member

@ytsarev ytsarev Nov 18, 2020

Choose a reason for hiding this comment

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

Why do we still use TODO() there?

Copy link
Collaborator Author

@kuritka kuritka Nov 18, 2020

Choose a reason for hiding this comment

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

@ytsarev good question: The point is that you are creating i.e. WithCancel context from existing context.

If you use Background context, you explicitly say: Hey, I'm using context from the top of the tree, usually main package and this context will instantiate another context(s) WithCancel, WithDeadline...

If you use context.TODO() you explicitly say: function just requires some context argument so I will pass TODO which is doing nothing, just to compile. For instance, our tests..

Copy link
Member

Choose a reason for hiding this comment

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

@kuritka cool, makes total sense

@kuritka kuritka merged commit eb30002 into master Nov 18, 2020
@kuritka kuritka deleted the k8gb-context-compliant-with-kubebuilder branch November 19, 2020 09:06
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.

2 participants