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 commands #644

Merged
merged 51 commits into from
Dec 26, 2024
Merged

Refactor commands #644

merged 51 commits into from
Dec 26, 2024

Conversation

mostafa
Copy link
Member

@mostafa mostafa commented Dec 22, 2024

Ticket(s)

Fixes #324
Fixes #370

Description

In this PR, I removed global variables in favor of encapsulation within a struct that is initialized locally. Almost all functions now receive parameters instead of relying on those global variables, which improves maintainability. I refactored the run command and broken it down into procedural methods within the GatewayDApp struct. The functionality remained the same. I added a few tests and improved the existing ones by removing reliance on global variables. I refactored other commands as well. The flags are now processed inside the command's Run function, instead of updating global variables, which caused many issues in tests.

Related PRs

N/A

Development Checklist

  • I have added a descriptive title to this PR.
  • I have squashed related commits together.
  • I have rebased my branch on top of the latest main branch.
  • I have performed a self-review of my own code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added docstring(s) to my code.
  • I have made corresponding changes to the documentation (docs).
  • I have updated docs using make gen-docs command.
  • I have addedupdated tests for my changes.
  • I have signed all the commits.

Legal Checklist

Copy link

github-actions bot commented Dec 22, 2024

Overview

Image reference ghcr.io/gatewayd-io/gatewayd:5d9801f gatewaydio/gatewayd:latest
- digest 123bdbbe1777 383013efa302
- tag 5d9801f latest
- provenance b6df86a
- vulnerabilities critical: 0 high: 0 medium: 1 low: 0 critical: 0 high: 1 medium: 1 low: 0
- platform linux/amd64 linux/amd64
- size 20 MB 18 MB (-2.3 MB)
- packages 144 140 (-4)
Base Image alpine:3
also known as:
3.20
3.20.3
latest
alpine:3.20
also known as:
3
3.20.3
latest
- vulnerabilities critical: 0 high: 0 medium: 1 low: 0 critical: 0 high: 0 medium: 1 low: 0
Packages and Vulnerabilities (6 package changes and 1 vulnerability changes)
  • ➖ 3 packages removed
  • ♾️ 3 packages changed
  • 133 packages unchanged
  • ❗ 1 vulnerabilities added
Changes for packages of type apk (3 changes)
Package Version
ghcr.io/gatewayd-io/gatewayd:5d9801f
Version
gatewaydio/gatewayd:latest
ca-certificates 20240705-r0
openssl 3.3.2-r0
pax-utils 1.3.7-r2
Changes for packages of type golang (3 changes)
Package Version
ghcr.io/gatewayd-io/gatewayd:5d9801f
Version
gatewaydio/gatewayd:latest
♾️ github.com/gatewayd-io/gatewayd (devel) 0.0.0-20241214123014-b6df86a6fe94
♾️ golang.org/x/net 0.33.0 0.32.0
critical: 0 high: 1 medium: 0 low: 0
Added vulnerabilities (1):
  • high : CVE--2024--45338
♾️ stdlib go1.23.4 1.23.4

@mostafa mostafa changed the title Refactor run command Refactor commands Dec 24, 2024
@mostafa mostafa self-assigned this Dec 25, 2024
@mostafa mostafa linked an issue Dec 26, 2024 that may be closed by this pull request
@mostafa mostafa marked this pull request as ready for review December 26, 2024 13:35
@mostafa mostafa merged commit ce578fc into main Dec 26, 2024
5 checks passed
@mostafa mostafa deleted the refactor-run-cmd branch December 26, 2024 13:44
sinadarbouy pushed a commit that referenced this pull request Feb 18, 2025
* Refactor global variables into a global struct
* Update tests
* Use param instead of global variable
* Update tests
* Fix formatting
* Add a hack to fix the tests
* Ignore raft files
* Fix tests
* Remove global variables
* Use a global app variable for test only and assign it only in tests
* Add stopGracefully as a method to the GatewayDInstance struct
* Move signal handler to the top to avoid half-states on exit
* Add a new function for creating an instance of GatewayDInstance using parsed flags
* Remove duplicate internal functions
* Update tests
* Use exported functions instead of internal variables
* Remove global variables
* Update tests
* Fix linter error
* Ignore dupl linter
* Fix tests with the actual log output
* Clean up after test
* Remove global variables
* Skip path slip verification
* Fix tests
* Remove backup
* Another try to fix the test
* Fix missing/unknown behavior
* Add a pull-only test
* Declare variable before assignment
* Fix plugin install behavior
* Fix plugin install with no overwrite
* Revert changes
* Rename variable
* Use filepath to join paths
* Remove unnecessary file
* Ignore plugins file if exists
* Remove duplicate code
* Reset the pull-only flag
* Check if the server is properly closed before erroring out
* Refactor run command into a separate file
* Fix bug in handling early exit
* Move left-over functions
* Add comments
* Fix linter errors
* Fix missing log message and span
* Handle errors when stopping the listener for gRPC server
* Graceful shutdown of gRPC server
* Revert changes to path
* Use local variable
* Replace all context.TODO with context.Background
* Split exit codes into a separate file
* Remove unused constant and renumber others
* Use exported function instead of internal variables
* Ignore linter errors
* Rename variable and comment to match the behavior
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.

Refactor cmd/run.go Remove and don't rely on global variables in commands
1 participant