Skip to content

Commit

Permalink
feat ✨(ci): added linting
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Hang <[email protected]>
  • Loading branch information
Banh-Canh authored and aamoyel committed Sep 27, 2024
1 parent 7f34ed2 commit cc218a7
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 36 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/linting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Go Lint and Format Check
on:
pull_request:
jobs:
lint_and_format:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22.6'
- name: Install Tools
run: |
go install mvdan.cc/gofumpt@latest
go install github.com/segmentio/golines@latest
- name: Run gofumpt
run: |
gofumpt -d . | tee gofumpt_output.txt
if [ -s gofumpt_output.txt ]; then
echo "gofumpt found issues:"
cat gofumpt_output.txt
exit 1
fi
- name: Run golines
run: |
golines --max-len=160 . --dry-run | tee golines_output.txt
if [ -s golines_output.txt ]; then
echo "golines found lines exceeding 140 characters:"
cat golines_output.txt
exit 1
fi
1 change: 0 additions & 1 deletion .github/workflows/nix-build.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: 'Build'
on:
pull_request:
branches: [main]
push:
jobs:
tests:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/unit-test.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Unit tests
# Trigger the workflow on pull requests and direct pushes to any branch
on:
push:
pull_request:
jobs:
test:
Expand Down
10 changes: 2 additions & 8 deletions internal/controllers/ipcidr_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,7 @@ func IPCidrProgressing(o *ipamv1alpha1.IPCidr) {
})
}

func (r *IPCidrReconciler) patchIPCidrStatus(
ctx context.Context,
ipCidr *ipamv1alpha1.IPCidr,
) error {
func (r *IPCidrReconciler) patchIPCidrStatus(ctx context.Context, ipCidr *ipamv1alpha1.IPCidr) error {
key := client.ObjectKeyFromObject(ipCidr)
latest := &ipamv1alpha1.IPCidr{}
if err := r.Client.Get(ctx, key, latest); err != nil {
Expand Down Expand Up @@ -337,10 +334,7 @@ func (r *IPCidrReconciler) isCidrOverlapping(ctx context.Context, cr *ipamv1alph
}

// ipCidrReconcileRequests returns a list of reconcile.Request based on the ipcidr resource.
func ipCidrReconcileRequests(
ctx context.Context,
mgr manager.Manager,
) ([]reconcile.Request, error) {
func ipCidrReconcileRequests(ctx context.Context, mgr manager.Manager) ([]reconcile.Request, error) {
IPCidrList := &ipamv1alpha1.IPCidrList{}
err := mgr.GetClient().List(ctx, IPCidrList)
if err != nil {
Expand Down
32 changes: 6 additions & 26 deletions internal/controllers/ipclaim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,7 @@ func IPClaimProgressing(o *ipamv1alpha1.IPClaim) {
})
}

func (r *IPClaimReconciler) patchIPClaimStatus(
ctx context.Context,
ipClaim *ipamv1alpha1.IPClaim,
) error {
func (r *IPClaimReconciler) patchIPClaimStatus(ctx context.Context, ipClaim *ipamv1alpha1.IPClaim) error {
key := client.ObjectKeyFromObject(ipClaim)
latest := &ipamv1alpha1.IPClaim{}
if err := r.Client.Get(ctx, key, latest); err != nil {
Expand Down Expand Up @@ -279,11 +276,7 @@ func (r *IPClaimReconciler) reconcileIPClaim(ctx context.Context, cr *ipamv1alph
return nil
}

func (r *IPClaimReconciler) getIpAddr(
ctx context.Context,
cr *ipamv1alpha1.IPClaim,
parentCidr string,
) error {
func (r *IPClaimReconciler) getIpAddr(ctx context.Context, cr *ipamv1alpha1.IPClaim, parentCidr string) error {
claim, err := r.Ipamer.AcquireSpecificIP(ctx, parentCidr, cr.Spec.SpecificIPAddress)
if claim == nil {
err = fmt.Errorf("%w", err)
Expand All @@ -307,10 +300,7 @@ func (r *IPClaimReconciler) getIpAddr(
return nil
}

func (r *IPClaimReconciler) getChildCidr(
ctx context.Context,
cr *ipamv1alpha1.IPClaim,
) (err error) {
func (r *IPClaimReconciler) getChildCidr(ctx context.Context, cr *ipamv1alpha1.IPClaim) (err error) {
var (
claim *goipam.Prefix
cidrCr *ipamv1alpha1.IPCidr
Expand Down Expand Up @@ -436,10 +426,7 @@ func setIPClaimErrorStatus(cr *ipamv1alpha1.IPClaim, err error) {
}

// ipClaimReconcileRequests returns a list of reconcile.Request based on the ipclaim resource.
func ipClaimReconcileRequests(
ctx context.Context,
mgr manager.Manager,
) ([]reconcile.Request, error) {
func ipClaimReconcileRequests(ctx context.Context, mgr manager.Manager) ([]reconcile.Request, error) {
IPClaimList := &ipamv1alpha1.IPClaimList{}
err := mgr.GetClient().List(ctx, IPClaimList)
if err != nil {
Expand All @@ -457,10 +444,7 @@ func ipClaimReconcileRequests(
return requests, nil
}

func (r *IPClaimReconciler) getParentCidr(
ctx context.Context,
cr *ipamv1alpha1.IPClaim,
) (*ipamv1alpha1.IPCidr, error) {
func (r *IPClaimReconciler) getParentCidr(ctx context.Context, cr *ipamv1alpha1.IPClaim) (*ipamv1alpha1.IPCidr, error) {
cidrCR := &ipamv1alpha1.IPCidr{}
cidrNamepacedName := types.NamespacedName{
Name: cr.Spec.IPCidrRef.Name,
Expand Down Expand Up @@ -525,11 +509,7 @@ func (r *IPClaimReconciler) initRegisteredClaims(ctx context.Context) error {
}

// checkParentCidr return an error when the parent cidr is not registered in the ipam.
func (r *IPClaimReconciler) checkParentCidr(
ctx context.Context,
claimCr *ipamv1alpha1.IPClaim,
parentCidr string,
) error {
func (r *IPClaimReconciler) checkParentCidr(ctx context.Context, claimCr *ipamv1alpha1.IPClaim, parentCidr string) error {
_, err := r.Ipamer.PrefixFrom(ctx, parentCidr)
if err != nil {
err = fmt.Errorf("unable to find parent cidr in the ipam, err: %w", err)
Expand Down

0 comments on commit cc218a7

Please sign in to comment.