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

Remove context field from structs #1290

Merged
merged 11 commits into from Jul 23, 2021

Conversation

slashpai
Copy link
Member

Following the discussion in slack we need to remove context from struct field. Removing the context from struct field and passing it as first argument to functions that require it

  • I added CHANGELOG entry for this change.
  • No user facing changes, so no entry in CHANGELOG was needed.

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 19, 2021
@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 19, 2021
@slashpai
Copy link
Member Author

/retest

@slashpai slashpai changed the title WIP: Remove context field from structs Remove context field from structs Jul 20, 2021
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 20, 2021
@slashpai
Copy link
Member Author

@fpetkovski Could you please review?

@@ -203,7 +203,7 @@ func Main() int {

wg, ctx := errgroup.WithContext(ctx)

wg.Go(func() error { return o.Run(ctx.Done()) })
wg.Go(func() error { return o.Run(ctx, ctx.Done()) })
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rather change the signature of Run() since it could use ctx.Done()

Suggested change
wg.Go(func() error { return o.Run(ctx, ctx.Done()) })
wg.Go(func() error { return o.Run(ctx) })

Copy link
Contributor

Choose a reason for hiding this comment

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

Is operator.Run trying to satisfy an interface that has Run(ctx, stopCh <-struct{})?

@@ -143,7 +142,7 @@ func New(kubeConfigPath string) (*Framework, cleanUpFunc, error) {
// Prometheus client depends on setup above.
f.ThanosQuerierClient, err = NewPrometheusClientFromRoute(
openshiftRouteClient,
f.Ctx,
ctx,
Copy link
Contributor

Choose a reason for hiding this comment

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

(nit) to follow the conventions, ctx should be the first argument.

namespace string
userWorkloadNamespace string
version string
}

func NewStatusReporter(ctx context.Context, client clientv1.ClusterOperatorInterface, name string, namespace, userWorkloadNamespace, version string) *StatusReporter {
func NewStatusReporter(client clientv1.ClusterOperatorInterface, name string, namespace, userWorkloadNamespace, version string) *StatusReporter {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: name string, -> name

func (o *Operator) worker() {
for o.processNextWorkItem() {
func (o *Operator) worker(ctx context.Context) {
for o.processNextWorkItem(ctx) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@simonpasquier I am guessing that if the context gets cancelled, the next work item be processed. Could you please confirm my hunch?

Copy link
Contributor

Choose a reason for hiding this comment

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

good catch! yes I agree that we should verify whether the context has been cancelled before processing the next item.

Copy link
Contributor

Choose a reason for hiding this comment

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

at the same time, Run() currently doesn't wait for any of the goroutines to stop before exiting so it would need to be addressed not only for worker() IMHO. I'm ok with having a follow-up PR to "fix" this.

Copy link
Contributor

@sthaha sthaha left a comment

Choose a reason for hiding this comment

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

The changes looks good to me but I think we need a test that validates the expected behaviour if a context is cancelled
WDYT @slashpai @simonpasquier ?

unavailableMessage string = "Rollout of the monitoring stack failed and is degraded. Please investigate the degraded status error."
asExpectedReason string = "AsExpected"
StorageNotConfiguredMessage = "Prometheus is running without persistent storage which can lead to data loss during upgrades and cluster disruptions. Please refer to the official documentation to see how to configure storage for Prometheus: https://docs.openshift.com/container-platform/4.8/monitoring/configuring-the-monitoring-stack.html"
StorageNotConfiguredReason = "PrometheusDataPersistenceNotConfigured"
Copy link
Member Author

Choose a reason for hiding this comment

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

This was changed when ran go fmt

@simonpasquier
Copy link
Contributor

The changes looks good to me but I think we need a test that validates the expected behaviour if a context is cancelled

I couldn't think of an easy way to test this so I'm fine without it.

@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 22, 2021
@simonpasquier
Copy link
Contributor

@slashpai could you rebase?

@slashpai
Copy link
Member Author

@slashpai could you rebase?

Sure I will get that done when login tomorrow. Are we good with the changes or anymore changes are needed?

@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 23, 2021
@slashpai
Copy link
Member Author

@simonpasquier rebased

@fpetkovski
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 23, 2021
@fpetkovski
Copy link
Contributor

/hold for @simonpasquier's final review

@openshift-ci openshift-ci bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jul 23, 2021
@openshift-ci openshift-ci bot removed lgtm Indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jul 23, 2021
@fpetkovski
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 23, 2021
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jul 23, 2021
@simonpasquier
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 23, 2021
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 23, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fpetkovski, simonpasquier, slashpai

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:
  • OWNERS [fpetkovski,simonpasquier,slashpai]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@slashpai
Copy link
Member Author

/retest

@simonpasquier
Copy link
Contributor

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 23, 2021
@openshift-merge-robot openshift-merge-robot merged commit e302364 into openshift:master Jul 23, 2021
@slashpai slashpai deleted the remove_ctx_struct branch October 13, 2022 17:03
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. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants