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 github.com/packethost/pkg/env dependency #324

Merged
merged 7 commits into from
Apr 3, 2023

Conversation

jacobweinstock
Copy link
Member

@jacobweinstock jacobweinstock commented Mar 30, 2023

Description

Remove github.com/packethost/pkg/env dependency and remove unused code. While I tried to stay away from as much refactoring as possible, there is some in here that was needed in order to remove the github.com/packethost/pkg/env dependency. Other than this, code was moved around to decrease the cognitive load of understanding this code base and prepare us for a more holistic refactor that will include the deprecation of github.com/packethost/dhcp4-go and github.com/packethost/pkg entirely.

Why is this needed

Fixes: #

How Has This Been Tested?

Will be doing some manual testing with the Helm chart. Will update here with the results, once complete.

How are existing users impacted? What migration steps/scripts do we need?

Checklist:

I have:

  • updated the documentation and/or roadmap (if required)
  • added unit or e2e tests
  • provided instructions on how to upgrade

@jacobweinstock jacobweinstock added the do-not-merge Signal to Mergify to block merging of the PR. label Mar 30, 2023
@jacobweinstock jacobweinstock changed the title Remove packethost/pkg/env dependency Remove github.com/packethost/pkg/env dependency Mar 30, 2023
@codecov
Copy link

codecov bot commented Mar 31, 2023

Codecov Report

Merging #324 (7bef88c) into main (4627e3a) will decrease coverage by 2%.
The diff coverage is 20%.

❗ Current head 7bef88c differs from pull request most recent head e0d3b96. Consider uploading reports for the commit e0d3b96 to get more accurate results

@@         Coverage Diff         @@
##           main   #324   +/-   ##
===================================
- Coverage    19%    18%   -2%     
===================================
  Files        19     17    -2     
  Lines      1140   1073   -67     
===================================
- Hits        222    197   -25     
+ Misses      903    862   -41     
+ Partials     15     14    -1     
Impacted Files Coverage Δ
client/client.go 0% <ø> (ø)
cmd/boots/main.go 0% <0%> (-23%) ⬇️
dhcp/server/server.go 7% <0%> (-4%) ⬇️
ipxe/auto.go 0% <0%> (ø)
job/dhcp.go 45% <0%> (ø)
job/job.go 10% <0%> (+3%) ⬆️
cmd/boots/env.go 18% <18%> (ø)
cmd/boots/cli.go 80% <80%> (ø)

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Reorganize files and functionality to live with
packages that have the same util. This enables isolating
functionality and is a step toward completely removing
global variables used in the conf package.

Signed-off-by: Jacob Weinstock <[email protected]>
Signed-off-by: Jacob Weinstock <[email protected]>
Reorganize code to be able to remove the packethost/pkg/env
dependency. The idea is to follow up with a refactor
to clean up the cmd/boot/ package to handle cli flags
and env vars in a uniform way.

Signed-off-by: Jacob Weinstock <[email protected]>
Signed-off-by: Jacob Weinstock <[email protected]>
Signed-off-by: Jacob Weinstock <[email protected]>
Some required values were not being passed into
the ipxe.Handler struct.

Signed-off-by: Jacob Weinstock <[email protected]>
@jacobweinstock jacobweinstock removed the do-not-merge Signal to Mergify to block merging of the PR. label Mar 31, 2023
Copy link
Member

@chrisdoherty4 chrisdoherty4 left a comment

Choose a reason for hiding this comment

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

I suspect, given the intent to refactor more holistically, the comments aren't really worth addressing.

Comment on lines +83 to +84
err = errors.New("unable to auto-detect public IPv4")
panic(err)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
err = errors.New("unable to auto-detect public IPv4")
panic(err)
panic("unable to auto-detect public IPv4")

Comment on lines +92 to +93
err := errors.New("PUBLIC_SYSLOG_IP must be an IPv4 address")
panic(err)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
err := errors.New("PUBLIC_SYSLOG_IP must be an IPv4 address")
panic(err)
panic("PUBLIC_SYSLOG_IP must be an IPv4 address")

for _, oui := range slice {
_, err := net.ParseMAC(oui + ":00:00:00")
if err != nil {
panic(errors.Errorf("invalid oui in TINK_IGNORED_OUIS oui=%s", oui))
Copy link
Member

Choose a reason for hiding this comment

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

Should this be panicking?

Comment on lines +63 to +64
err := errors.New("PUBLIC_IP must be an IPv4 address")
panic(err)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
err := errors.New("PUBLIC_IP must be an IPv4 address")
panic(err)
panic("PUBLIC_IP must be an IPv4 address")

i, err := strconv.Atoi(v)
if err != nil {
err = errors.Wrap(err, "failed to parse int from env var")
panic(err)
Copy link
Member

Choose a reason for hiding this comment

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

Should this be panicking?

}
} else {
// not an IP, panic
panic("invalid ip cidr in TRUSTED_PROXIES cidr=" + cidr)
Copy link
Member

Choose a reason for hiding this comment

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

Should this be panicking?

ignore := map[string]struct{}{}
for _, ip := range slice {
if net.ParseIP(ip) == nil {
panic(errors.Errorf("invalid ip address in TINK_IGNORED_GIS ip=%s", ip))
Copy link
Member

Choose a reason for hiding this comment

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

Should this be panicking?

@jacobweinstock
Copy link
Member Author

I suspect, given the intent to refactor more holistically, the comments aren't really worth addressing.

Yeah, exactly. I have another PR thats in the works to clean up all of this. Thanks for the review!

@jacobweinstock jacobweinstock added the ready-to-merge Signal to Mergify to merge the PR. label Apr 3, 2023
@mergify mergify bot merged commit 6f22d28 into tinkerbell:main Apr 3, 2023
@jacobweinstock jacobweinstock deleted the remove-dep branch April 3, 2023 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge Signal to Mergify to merge the PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants