Skip to content

possible synchronizer refactor solution #182

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

Merged
merged 18 commits into from
May 5, 2020
Merged

Conversation

ianzhang366
Copy link
Contributor

A POC PR for the following issue:
https://github.com/open-cluster-management/backlog/issues/1948

  • Code changes to the following folder, are the one trying to implement the idea, run synchronizer as service, the details of the idea is explained in the above issue,
    pkg/synchronizer/kubernetes
    Also, with the changes, we don't need the housekeeping on synchronizer, since the synchronizer will watch on the sync channel(with buffered size as 4 by default)

  • Code changes to the below folder is a small demonstration of the possible changes for the sub-reconcilers code changes, if we use this PR.
    pkg/subscriber/namespace

Please let me know your thoughts on this refactor. If you guys like it, I will try to apply the new approach to all sub-reconcilers.

FYI, I haven't fixed the test case, but the namespace subscription flow was tested and succeeded with the following examples,

https://github.com/ianzhang366/acm-applifecycle-samples/tree/master/namespace-ops/distribute-resource-via-namespace

ianzhang366 added 16 commits April 29, 2020 12:12
Signed-off-by: ianzhang366 <[email protected]>
Signed-off-by: ianzhang366 <[email protected]>
Signed-off-by: ianzhang366 <[email protected]>
Signed-off-by: ianzhang366 <[email protected]>
Signed-off-by: ianzhang366 <[email protected]>
Signed-off-by: ianzhang366 <[email protected]>
Signed-off-by: ianzhang366 <[email protected]>
Signed-off-by: ianzhang366 <[email protected]>
Signed-off-by: ianzhang366 <[email protected]>
Signed-off-by: ianzhang366 <[email protected]>
Signed-off-by: ianzhang366 <[email protected]>
Signed-off-by: ianzhang366 <[email protected]>
Signed-off-by: ianzhang366 <[email protected]>
Copy link
Contributor

@mikeshng mikeshng left a comment

Choose a reason for hiding this comment

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

A few minor things to double check.

Also I saw a few statements that are like obj := obj are those intentional? Is there a better syntax for that?

errLocal := r.Client.Get(context.TODO(), subcfgkey, subitem.SubscriptionConfigMap)
errRemote := r.hubclient.Get(context.TODO(), subcfgkey, subitem.SubscriptionConfigMap)

if errRemote != nil && errLocal != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just double checking. Is this purposely an AND condition? Is it ok if just one of them has err?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

here the idea is checking if the reference configmap exists on hub or local. So, if both of them says no, then we really have a problem. Otherwise, we are fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As the obj := obj, the obj is a pointer within the for loop, if we don't do this, then the obj pointer might cause us some issue.

The sonar cloud pointed out this one.

golang/go#20733


return nil
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

Double check please. Always return err if it gets this far?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are right. I should've use return nil, which is more friendly. I don't remember why I made this change...

However, using return err is equal to return nil over here. I mean, if the code gets this far, the only way is the err == nil

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok you should change it back to return nil in case err is set in the future and code readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure


pkgMap[dplkey.Name] = true
//this is for the adaption of the new synchronizer API
klog.V(10).Infof("ingnor this kvalid %v, only exist for adopting synchronizer API", kvalid)
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: ingnor should be ignore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm, if we dont have print statement like this, then we have to the kvalid within the function...

However, with the new code changes, we don't actually need to use the kvalid. The idea way is change the function signature to get rid of the kvalid parameter... but I don't want to change the original call chain that much... that's why I did the above print..

Copy link
Contributor

Choose a reason for hiding this comment

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

I was referring to your spelling mistake.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

if err != nil {
err = utils.SetInClusterPackageStatus(&(ghsi.Subscription.Status), dpltosync.GetName(), err, nil)

ghsi.successful = false
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: put this before the utils.SetInClusterPackageStatus

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 don't get it... why there's a difference? Please explain a bit more

Copy link
Contributor

Choose a reason for hiding this comment

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

err = xyz()
if err

Should be together for better code readability.

Also, logic flow wise its better. Setting it to false right away its quick than call the potential longer running function and wait then set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Signed-off-by: ianzhang366 <[email protected]>
@sonarqubecloud
Copy link

sonarqubecloud bot commented May 5, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 13 Code Smells

57.0% 57.0% Coverage
2.6% 2.6% Duplication

@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ianzhang366, mikeshng, rokej, xiangjingli

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

@ianzhang366 ianzhang366 merged commit 66f5813 into master May 5, 2020
@ianzhang366 ianzhang366 deleted the izhang-sync-with-channel branch June 1, 2020 17:29
chenz4027 pushed a commit that referenced this pull request Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants