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

Refactor into distinct packages to prep for adding firewall support to Nodes #186

Merged
merged 1 commit into from
Mar 11, 2024

Conversation

AshleyDumaine
Copy link
Contributor

@AshleyDumaine AshleyDumaine commented Mar 8, 2024

General:

  • Have you removed all sensitive information, including but not limited to access keys and passwords?
  • Have you checked to ensure there aren't other open or closed Pull Requests for the same bug/feature/question?

Pull Request Guidelines:

  1. Does your submission pass tests?
  2. Have you added tests?
  3. Are you addressing a single feature in this PR?
  4. Are your commits atomic, addressing one change per commit?
  5. Are you following the conventions of the language?
  6. Have you saved your large formatting changes for a different PR, so we can focus on your work?
  7. Have you explained your rationale for why this feature is needed?
  8. Have you linked your PR to an open issue

This PR moves out the Firewall logic into its own firewall package so it can be used for managing Firewalls for both LoadBalancer Services (NodeBalancers) and Nodes.
I also split out the annotations and client since I was getting an import cycle with just the existing linode and new firewall packages.

The change to add support for Firewalls based on Node annotations will be tackled in a separate PR.

@AshleyDumaine AshleyDumaine force-pushed the fw-nodes branch 2 times, most recently from edc6484 to d897018 Compare March 8, 2024 20:59
@AshleyDumaine AshleyDumaine marked this pull request as ready for review March 8, 2024 21:05
@@ -39,7 +39,7 @@ type Client interface {
// linodego.Client implements Client
var _ Client = (*linodego.Client)(nil)

func newLinodeClient(token, ua, apiURL string) (*linodego.Client, error) {
func NewLinodeClient(token, ua, apiURL string) (*linodego.Client, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this function is now exported, I would recommend adding some godoc.

This is a bit of a nit, but client.NewLinodeClient kind of stutters. Maybe calling the function New would flow a bit more nicely.

Lastly, please expand the ua argument to userAgent, so that even without godoc, the argument's purpose is clear.

@@ -1,6 +1,6 @@
package linode
package client
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a heads up: moving this file into a new package would constitute a major version bump of this module. However, this module's last-tagged version is still < v1, so it should be fine. Just be aware that this may break downstream users of this module.

Comment on lines 308 to 312
var newFirewallID int
var err error

fwID := service.GetAnnotations()[annotations.AnnLinodeCloudFirewallID]
newFirewallID, err = strconv.Atoi(fwID)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: There is no need to declare newFirewallID and err this high up.

Suggested change
var newFirewallID int
var err error
fwID := service.GetAnnotations()[annotations.AnnLinodeCloudFirewallID]
newFirewallID, err = strconv.Atoi(fwID)
fwID := service.GetAnnotations()[annotations.AnnLinodeCloudFirewallID]
newFirewallID, err := strconv.Atoi(fwID)

Comment on lines 354 to 355
err = l.Client.DeleteFirewallDevice(ctx, existingFirewallID, deviceID)
if 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:

Suggested change
err = l.Client.DeleteFirewallDevice(ctx, existingFirewallID, deviceID)
if err != nil {
if err := l.Client.DeleteFirewallDevice(ctx, existingFirewallID, deviceID); err != nil {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated and in a few other spots in this file too

Copy link
Contributor

@nesv nesv left a comment

Choose a reason for hiding this comment

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

LGTM

@AshleyDumaine AshleyDumaine merged commit 0295e50 into main Mar 11, 2024
4 checks passed
@AshleyDumaine AshleyDumaine deleted the fw-nodes branch March 11, 2024 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants