Skip to content

Util dir refactor #649

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 8 commits into from
Oct 25, 2018
Merged

Util dir refactor #649

merged 8 commits into from
Oct 25, 2018

Conversation

estroz
Copy link
Member

@estroz estroz commented Oct 19, 2018

Description of the change:

  • Create a top-level internal dir, with a util sub dir that will contain utility packages with specific designations, ex. internal/util/fileutil will only contain functions, types, etc. that operate on files.
  • Break up and remove commands/operator-sdk/cmd/cmdutil/util.go
  • Break up and move pkg/util/file_util.go to internal/util/fileutil
  • Move pkg/tlsutil to pkg/tls and pkg/util/k8sutil to pkg/k8sutil

Motivation for the change: General utility packages and files containing disparate data are best avoided, especially those exported such that users can access internal data. As per @shawn-hurley's concerns, the way the SDK handle's utility functions needs reassessment. This is an attempt at doing so, and is open to modification/being thrown out.

@openshift-ci-robot openshift-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 19, 2018
@estroz estroz force-pushed the util-refactor branch 4 times, most recently from 5b3b4dd to e44cb2e Compare October 22, 2018 17:41
@openshift-ci-robot openshift-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 22, 2018
@estroz estroz force-pushed the util-refactor branch 2 times, most recently from 96addfd to 37d640d Compare October 22, 2018 23:20
@shawn-hurley
Copy link
Member

I would like to propose util/tlsutil -> k8s/tls or tls I know we think of them as utility functions but wouldn't it be nice to expose them as a full functional tls package for k8s?

I like the move to internal for our internal utilities with specific packages for each!

I have not gone through the PR in detail but I would like to 👍 the approach and make sure that enough people agree then do a more thorough review.

@hasbro17
Copy link
Contributor

Yeah pkg/tlsutil is supposed to be a util that we want users to use(after we add some documentation for it), so it should probably be more exposed under its own package as pkg/tls.

pkg/util is more for our own internal utils.

@estroz
Copy link
Member Author

estroz commented Oct 23, 2018

@hasbro17 if pkg/util is for our internal utils then I'll move k8sutil into internal/util. @shawn-hurley I'll move pkg/util/tlsutil -> pkg/tls.

@estroz estroz changed the title [WIP] Util dir refactor Util dir refactor Oct 23, 2018
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 23, 2018
@estroz
Copy link
Member Author

estroz commented Oct 23, 2018

Note: this is failing because dep tries to find the new internal/util/k8sutil directory in master but cannot. This issue is a symptom of dep not supporting PR refspecs. Once golang/dep#1658 is merged, the SDK e2e test code can inject PR refspecs into Gopkg.toml and solve issues such as this.

…onstants instead of hard-coded strings for dirs and filenames
@estroz estroz force-pushed the util-refactor branch 2 times, most recently from 15b5715 to 622339f Compare October 24, 2018 20:54
@estroz estroz force-pushed the util-refactor branch 4 times, most recently from 3c354e5 to d2f13df Compare October 24, 2018 22:14
@@ -42,7 +44,7 @@ import (
"{{ .Repo }}/pkg/apis"
"{{ .Repo }}/pkg/controller"

k8sutil "github.com/operator-framework/operator-sdk/pkg/util/k8sutil"
k8sutil "github.com/operator-framework/operator-sdk/pkg/k8s"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can keep this as pkg/k8sutil. That's more descriptive than pkg/k8s imo.

Copy link
Contributor

Choose a reason for hiding this comment

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

Especially give that we're aliasing it as k8sutil.

// https://github.com/golang/dep/pull/1658
solveFailRe := regexp.MustCompile(`(?m)^[ \t]*Solving failure:.+github\.com/operator-framework/operator-sdk.+:$`)
if solveFailRe.Match(cmdOut) {
prSlug, ok := os.LookupEnv("TRAVIS_PULL_REQUEST_SLUG")
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's necessary to duplicate this code. Since this has to be run at some point anyway, I think we should just run the gopkg fix immediately after the new command in all cases instead of later in the code. In that case, the regex check only contains a t.Fatal and we don't have duplicate code.

@openshift-ci-robot openshift-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 25, 2018
Copy link
Contributor

@hasbro17 hasbro17 left a comment

Choose a reason for hiding this comment

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

LGTM

@estroz estroz force-pushed the util-refactor branch 2 times, most recently from fa77761 to 3edece9 Compare October 25, 2018 21:46
@estroz estroz mentioned this pull request Oct 25, 2018
…e exported

commands/operator-sdk/cmd/*: use internal/util packages and get rid of command/.../cmdutil

pkg/util/*: move all pkg utilities into pkg/util
@estroz estroz force-pushed the util-refactor branch 2 times, most recently from 06807f2 to 6e1be93 Compare October 25, 2018 23:22
@estroz estroz merged commit 5a9f7d1 into operator-framework:master Oct 25, 2018
@estroz estroz deleted the util-refactor branch October 25, 2018 23:46
@estroz estroz restored the util-refactor branch October 26, 2018 18:55
@estroz estroz deleted the util-refactor branch October 26, 2018 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs discussion size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants