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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/daemon: idiomatic Go cleanup #369

Merged
merged 1 commit into from
Feb 4, 2019

Conversation

runcom
Copy link
Member

@runcom runcom commented Feb 1, 2019

Went through a bunch of cleanup to be more idiomatic when writing Go
code (no else if previous return, default values, return on err, bool comparison etc etc)
(mainly went to read and learn the code)
There should be no functional change at all.

(so sorry for this PR 馃懠 )

Signed-off-by: Antonio Murdaca runcom@linux.com

@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 1, 2019
@runcom runcom force-pushed the cleanup-idiomatic branch 2 times, most recently from 65ce691 to f5390aa Compare February 1, 2019 23:23
@kikisdeliveryservice
Copy link
Contributor

@runcom this is the best thank you! checking it out!

@runcom runcom force-pushed the cleanup-idiomatic branch 4 times, most recently from 26d0227 to e6f8364 Compare February 3, 2019 22:08
@runcom
Copy link
Member Author

runcom commented Feb 4, 2019

/test e2e-aws

@@ -12,7 +12,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
kscheme "k8s.io/client-go/kubernetes/scheme"

"github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
v1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Golint doing stupid stuff

if err := dn.writeUnits(newConfig.Spec.Config.Systemd.Units); err != nil {
return err
}

if err := dn.deleteStaleData(oldConfig, newConfig); 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.

nit: if in future you add another step after deleteStaleData, you'll have to bring back this if... The current setup keeps it clearer imo.

Copy link
Member Author

Choose a reason for hiding this comment

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

Boils down to preference for me, if you prefer it that way I'll change it back

@@ -4,7 +4,7 @@ import (
"fmt"

"github.com/golang/glog"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this? Maybe corev1?

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 is golint doing this, overlooked

Went through a bunch of cleanup to be more idiomatic when writing Go
code (no else if previous return, default values, return on err, bool
comparisons etc etc)
(mainly went to read and learn the code)
There should be no functional change at all.

Signed-off-by: Antonio Murdaca <runcom@linux.com>
@cgwalters
Copy link
Member

/approve

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 4, 2019
Copy link
Member

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

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

LGTM but leaving open for others to review.

Copy link
Member

@ashcrow ashcrow left a comment

Choose a reason for hiding this comment

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

LGTM

@ashcrow
Copy link
Member

ashcrow commented Feb 4, 2019

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Feb 4, 2019
@jlebon
Copy link
Member

jlebon commented Feb 4, 2019

Very nice!
/lgtm

Copy link
Contributor

@yuqi-zhang yuqi-zhang left a comment

Choose a reason for hiding this comment

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

/approve
One minor nit, otherwise thanks for the cleanup!

degraded_err := nw.SetUpdateDegraded(err, client, node)
if degraded_err != nil {
glog.Errorf("Error while setting degraded: %v", degraded_err)
degradedErr := nw.SetUpdateDegraded(err, client, node)
Copy link
Contributor

Choose a reason for hiding this comment

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

To keep it consistent we should probably just make it if degradedErr := nw.SetUpdateDegraded(err, client, node); degradedErr != nil here right?

@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ashcrow, cgwalters, jlebon, runcom, yuqi-zhang

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

@openshift-merge-robot openshift-merge-robot merged commit e621b7c into openshift:master Feb 4, 2019
@runcom runcom deleted the cleanup-idiomatic branch February 4, 2019 19:25
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. 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.

None yet

9 participants