Skip to content

Commit

Permalink
run gofumpt & goimports (#5162)
Browse files Browse the repository at this point in the history
* run gofumpt & goimports
* add format to lint ci workflow
  • Loading branch information
pdabelf5 authored Feb 26, 2024
1 parent 837b42b commit a8cf318
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 35 deletions.
22 changes: 20 additions & 2 deletions .github/workflows/lint.yml → .github/workflows/lint-format.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint
name: Lint & Formatting

on:
pull_request:
Expand All @@ -10,13 +10,31 @@ defaults:
shell: bash

concurrency:
group: ${{ github.ref_name }}-lint
group: ${{ github.ref_name }}-lint-format
cancel-in-progress: true

permissions:
contents: read

jobs:

format:
name: Format
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Setup Golang Environment
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: go.mod

- name: Run goimports & gofumpt
run: |
make format
git diff --exit-code
lint:
name: Lint
runs-on: ubuntu-22.04
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ lint-python: ## Run linter for python tests
@isort .
@black .

.PHONY: format
format: ## Run goimports & gofmt
@go install golang.org/x/tools/cmd/goimports
@go install mvdan.cc/gofumpt@latest
@goimports -l -w .
@gofumpt -l -w .

.PHONY: staticcheck
staticcheck: ## Run staticcheck linter
@staticcheck -version >/dev/null 2>&1 || go install honnef.co/go/tools/cmd/[email protected];
Expand Down
1 change: 0 additions & 1 deletion internal/certmanager/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ func SyncFnFor(
var certs []*cmapi.Certificate

certs, err = nsi.cmLister.Certificates(vs.GetNamespace()).List(labels.Everything())

if err != nil {
return err
}
Expand Down
24 changes: 0 additions & 24 deletions internal/k8s/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,6 @@ func (lbc *LoadBalancerController) syncEndpointSlices(task task) bool {

ns, _, _ := cache.SplitMetaNamespaceKey(key)
obj, endpointSliceExists, err = lbc.getNamespacedInformer(ns).endpointSliceLister.GetByKey(key)

if err != nil {
lbc.syncQueue.Requeue(task, err)
return false
Expand Down Expand Up @@ -1364,7 +1363,6 @@ func (lbc *LoadBalancerController) syncPolicy(task task) {

ns, _, _ := cache.SplitMetaNamespaceKey(key)
obj, polExists, err = lbc.getNamespacedInformer(ns).policyLister.GetByKey(key)

if err != nil {
lbc.syncQueue.Requeue(task, err)
return
Expand Down Expand Up @@ -1423,7 +1421,6 @@ func (lbc *LoadBalancerController) syncTransportServer(task task) {

ns, _, _ := cache.SplitMetaNamespaceKey(key)
obj, tsExists, err = lbc.getNamespacedInformer(ns).transportServerLister.GetByKey(key)

if err != nil {
lbc.syncQueue.Requeue(task, err)
return
Expand Down Expand Up @@ -1502,7 +1499,6 @@ func (lbc *LoadBalancerController) syncVirtualServer(task task) {

ns, _, _ := cache.SplitMetaNamespaceKey(key)
obj, vsExists, err = lbc.getNamespacedInformer(ns).virtualServerLister.GetByKey(key)

if err != nil {
lbc.syncQueue.Requeue(task, err)
return
Expand Down Expand Up @@ -1611,7 +1607,6 @@ func (lbc *LoadBalancerController) processChanges(changes []ResourceChange) {

ns, _, _ := cache.SplitMetaNamespaceKey(key)
_, vsExists, err = lbc.getNamespacedInformer(ns).virtualServerLister.GetByKey(key)

if err != nil {
glog.Errorf("Error when getting VirtualServer for %v: %v", key, err)
}
Expand All @@ -1634,7 +1629,6 @@ func (lbc *LoadBalancerController) processChanges(changes []ResourceChange) {

ns, _, _ := cache.SplitMetaNamespaceKey(key)
_, ingExists, err = lbc.getNamespacedInformer(ns).ingressLister.GetByKeySafe(key)

if err != nil {
glog.Errorf("Error when getting Ingress for %v: %v", key, err)
}
Expand All @@ -1656,7 +1650,6 @@ func (lbc *LoadBalancerController) processChanges(changes []ResourceChange) {

ns, _, _ := cache.SplitMetaNamespaceKey(key)
_, tsExists, err = lbc.getNamespacedInformer(ns).transportServerLister.GetByKey(key)

if err != nil {
glog.Errorf("Error when getting TransportServer for %v: %v", key, err)
}
Expand Down Expand Up @@ -2276,7 +2269,6 @@ func (lbc *LoadBalancerController) syncVirtualServerRoute(task task) {

ns, _, _ := cache.SplitMetaNamespaceKey(key)
obj, exists, err = lbc.getNamespacedInformer(ns).virtualServerRouteLister.GetByKey(key)

if err != nil {
lbc.syncQueue.Requeue(task, err)
return
Expand Down Expand Up @@ -2308,7 +2300,6 @@ func (lbc *LoadBalancerController) syncIngress(task task) {

ns, _, _ := cache.SplitMetaNamespaceKey(key)
ing, ingExists, err = lbc.getNamespacedInformer(ns).ingressLister.GetByKeySafe(key)

if err != nil {
lbc.syncQueue.Requeue(task, err)
return
Expand Down Expand Up @@ -2362,7 +2353,6 @@ func (lbc *LoadBalancerController) syncService(task task) {

ns, _, _ := cache.SplitMetaNamespaceKey(key)
obj, exists, err = lbc.getNamespacedInformer(ns).svcLister.GetByKey(key)

if err != nil {
lbc.syncQueue.Requeue(task, err)
return
Expand Down Expand Up @@ -2470,7 +2460,6 @@ func (lbc *LoadBalancerController) syncSecret(task task) {
return
}
obj, secrExists, err = lbc.getNamespacedInformer(namespace).secretLister.GetByKey(key)

if err != nil {
lbc.syncQueue.Requeue(task, err)
return
Expand Down Expand Up @@ -3323,7 +3312,6 @@ func (lbc *LoadBalancerController) getPolicies(policies []conf_v1.PolicyReferenc
var err error

policyObj, exists, err = lbc.getNamespacedInformer(polNamespace).policyLister.GetByKey(policyKey)

if err != nil {
errors = append(errors, fmt.Errorf("failed to get policy %s: %w", policyKey, err))
continue
Expand Down Expand Up @@ -3706,7 +3694,6 @@ func (lbc *LoadBalancerController) getEndpointsForServiceWithSubselector(targetP
var pods []*api_v1.Pod
nsi := lbc.getNamespacedInformer(svc.Namespace)
pods, err = nsi.podLister.ListByNamespace(svc.Namespace, labels.Merge(svc.Spec.Selector, subselector).AsSelector())

if err != nil {
return nil, fmt.Errorf("error getting pods in namespace %v that match the selector %v: %w", svc.Namespace, labels.Merge(svc.Spec.Selector, subselector), err)
}
Expand Down Expand Up @@ -3808,7 +3795,6 @@ func (lbc *LoadBalancerController) getHealthChecksForIngressBackend(backend *net
var pods []*api_v1.Pod
nsi := lbc.getNamespacedInformer(svc.Namespace)
pods, err = nsi.podLister.ListByNamespace(svc.Namespace, labels.Set(svc.Spec.Selector).AsSelector())

if err != nil {
glog.V(3).Infof("Error fetching pods for namespace %v: %v", svc.Namespace, err)
return nil
Expand Down Expand Up @@ -3861,7 +3847,6 @@ func (lbc *LoadBalancerController) getExternalEndpointsForIngressBackend(backend
func (lbc *LoadBalancerController) getEndpointsForIngressBackend(backend *networking.IngressBackend, svc *api_v1.Service) (result []podEndpoint, isExternal bool, err error) {
var endpointSlices []discovery_v1.EndpointSlice
endpointSlices, err = lbc.getNamespacedInformer(svc.Namespace).endpointSliceLister.GetServiceEndpointSlices(svc)

if err != nil {
if svc.Spec.Type == api_v1.ServiceTypeExternalName {
if !lbc.isNginxPlus {
Expand Down Expand Up @@ -3934,7 +3919,6 @@ func (lbc *LoadBalancerController) getPodOwnerTypeAndNameFromAddress(ns, name st
var err error

obj, exists, err = lbc.getNamespacedInformer(ns).podLister.GetByKey(fmt.Sprintf("%s/%s", ns, name))

if err != nil {
glog.Warningf("could not get pod by key %s/%s: %v", ns, name, err)
return "", ""
Expand Down Expand Up @@ -3983,7 +3967,6 @@ func (lbc *LoadBalancerController) getTargetPort(svcPort api_v1.ServicePort, svc
var pods []*api_v1.Pod
var err error
pods, err = lbc.getNamespacedInformer(svc.Namespace).podLister.ListByNamespace(svc.Namespace, labels.Set(svc.Spec.Selector).AsSelector())

if err != nil {
return 0, fmt.Errorf("error getting pod information: %w", err)
}
Expand Down Expand Up @@ -4021,7 +4004,6 @@ func (lbc *LoadBalancerController) getServiceForIngressBackend(backend *networki
var err error

svcObj, svcExists, err = lbc.getNamespacedInformer(namespace).svcLister.GetByKey(svcKey)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -4097,7 +4079,6 @@ func (lbc *LoadBalancerController) syncAppProtectPolicy(task task) {

ns, _, _ := cache.SplitMetaNamespaceKey(key)
obj, polExists, err = lbc.getNamespacedInformer(ns).appProtectPolicyLister.GetByKey(key)

if err != nil {
lbc.syncQueue.Requeue(task, err)
return
Expand Down Expand Up @@ -4129,7 +4110,6 @@ func (lbc *LoadBalancerController) syncAppProtectLogConf(task task) {

ns, _, _ := cache.SplitMetaNamespaceKey(key)
obj, confExists, err = lbc.getNamespacedInformer(ns).appProtectLogConfLister.GetByKey(key)

if err != nil {
lbc.syncQueue.Requeue(task, err)
return
Expand Down Expand Up @@ -4161,7 +4141,6 @@ func (lbc *LoadBalancerController) syncAppProtectUserSig(task task) {

ns, _, _ := cache.SplitMetaNamespaceKey(key)
obj, sigExists, err = lbc.getNamespacedInformer(ns).appProtectUserSigLister.GetByKey(key)

if err != nil {
lbc.syncQueue.Requeue(task, err)
return
Expand Down Expand Up @@ -4193,7 +4172,6 @@ func (lbc *LoadBalancerController) syncAppProtectDosPolicy(task task) {

ns, _, _ := cache.SplitMetaNamespaceKey(key)
obj, polExists, err = lbc.getNamespacedInformer(ns).appProtectDosPolicyLister.GetByKey(key)

if err != nil {
lbc.syncQueue.Requeue(task, err)
return
Expand Down Expand Up @@ -4223,7 +4201,6 @@ func (lbc *LoadBalancerController) syncAppProtectDosLogConf(task task) {

ns, _, _ := cache.SplitMetaNamespaceKey(key)
obj, confExists, err = lbc.getNamespacedInformer(ns).appProtectDosLogConfLister.GetByKey(key)

if err != nil {
lbc.syncQueue.Requeue(task, err)
return
Expand Down Expand Up @@ -4253,7 +4230,6 @@ func (lbc *LoadBalancerController) syncDosProtectedResource(task task) {

ns, _, _ := cache.SplitMetaNamespaceKey(key)
obj, confExists, err = lbc.getNamespacedInformer(ns).appProtectDosProtectedLister.GetByKey(key)

if err != nil {
lbc.syncQueue.Requeue(task, err)
return
Expand Down
8 changes: 0 additions & 8 deletions internal/k8s/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ func (su *statusUpdater) updateIngressWithStatus(ing networking.Ingress, status
var ingCopy *networking.Ingress
var exists bool
ingCopy, exists, err = su.getNamespacedInformer(ns).ingressLister.GetByKeySafe(key)

if err != nil {
glog.V(3).Infof("error getting ing from Store by key: %v", err)
return err
Expand Down Expand Up @@ -427,7 +426,6 @@ func (su *statusUpdater) UpdateTransportServerStatus(ts *conf_v1.TransportServer
var err error

tsLatest, exists, err = su.getNamespacedInformer(ts.Namespace).transportServerLister.Get(ts)

if err != nil {
glog.V(3).Infof("error getting TransportServer from Store: %v", err)
return err
Expand Down Expand Up @@ -475,7 +473,6 @@ func (su *statusUpdater) UpdateVirtualServerStatus(vs *conf_v1.VirtualServer, st
var err error

vsLatest, exists, err = su.getNamespacedInformer(vs.Namespace).virtualServerLister.Get(vs)

if err != nil {
glog.V(3).Infof("error getting VirtualServer from Store: %v", err)
return err
Expand Down Expand Up @@ -538,7 +535,6 @@ func (su *statusUpdater) UpdateVirtualServerRouteStatusWithReferencedBy(vsr *con
var err error

vsrLatest, exists, err = su.getNamespacedInformer(vsr.Namespace).virtualServerRouteLister.Get(vsr)

if err != nil {
glog.V(3).Infof("error getting VirtualServerRoute from Store: %v", err)
return err
Expand Down Expand Up @@ -578,7 +574,6 @@ func (su *statusUpdater) UpdateVirtualServerRouteStatus(vsr *conf_v1.VirtualServ
var err error

vsrLatest, exists, err = su.getNamespacedInformer(vsr.Namespace).virtualServerRouteLister.Get(vsr)

if err != nil {
glog.V(3).Infof("error getting VirtualServerRoute from Store: %v", err)
return err
Expand Down Expand Up @@ -614,7 +609,6 @@ func (su *statusUpdater) updateVirtualServerExternalEndpoints(vs *conf_v1.Virtua
var err error

vsLatest, exists, err = su.getNamespacedInformer(vs.Namespace).virtualServerLister.Get(vs)

if err != nil {
glog.V(3).Infof("error getting VirtualServer from Store: %v", err)
return err
Expand Down Expand Up @@ -642,7 +636,6 @@ func (su *statusUpdater) updateVirtualServerRouteExternalEndpoints(vsr *conf_v1.
var err error

vsrLatest, exists, err = su.getNamespacedInformer(vsr.Namespace).virtualServerRouteLister.Get(vsr)

if err != nil {
glog.V(3).Infof("error getting VirtualServerRoute from Store: %v", err)
return err
Expand Down Expand Up @@ -690,7 +683,6 @@ func (su *statusUpdater) UpdatePolicyStatus(pol *conf_v1.Policy, state string, r
var err error

polLatest, exists, err = su.getNamespacedInformer(pol.Namespace).policyLister.Get(pol)

if err != nil {
glog.V(3).Infof("error getting policy from Store: %v", err)
return err
Expand Down

0 comments on commit a8cf318

Please sign in to comment.