Skip to content

Commit

Permalink
more lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
soneillf5 committed Dec 7, 2021
1 parent e09b093 commit c05cec6
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 54 deletions.
2 changes: 1 addition & 1 deletion internal/configs/parsing_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func GetMapKeyAsUint64(m map[string]string, key string, context apiObject, nonZe
}

// GetMapKeyAsStringSlice tries to find and parse a key in the map as string slice splitting it on delimiter.
func GetMapKeyAsStringSlice(m map[string]string, key string, context apiObject, delimiter string) ([]string, bool, error) {
func GetMapKeyAsStringSlice(m map[string]string, key string, _ apiObject, delimiter string) ([]string, bool, error) {
if str, exists := m[key]; exists {
slice := strings.Split(str, delimiter)
return slice, exists, nil
Expand Down
1 change: 1 addition & 0 deletions internal/configs/version2/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ type EgressMTLS struct {
SSLName string
}

// OIDC holds OIDC configuration data.
type OIDC struct {
AuthEndpoint string
ClientID string
Expand Down
4 changes: 2 additions & 2 deletions internal/configs/warnings.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ func (w Warnings) Add(warnings Warnings) {
}
}

// Adds a warning for the specified object using the provided format and arguments.
// AddWarningf Adds a warning for the specified object using the provided format and arguments.
func (w Warnings) AddWarningf(obj runtime.Object, msgFmt string, args ...interface{}) {
w[obj] = append(w[obj], fmt.Sprintf(msgFmt, args...))
}

// Adds a warning for the specified object.
// AddWarning Adds a warning for the specified object.
func (w Warnings) AddWarning(obj runtime.Object, msg string) {
w[obj] = append(w[obj], msg)
}
10 changes: 5 additions & 5 deletions internal/k8s/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3048,23 +3048,23 @@ type testReferenceChecker struct {
onlyTransportServers bool
}

func (rc *testReferenceChecker) IsReferencedByIngress(namespace string, name string, ing *networking.Ingress) bool {
func (rc *testReferenceChecker) IsReferencedByIngress(namespace string, name string, _ *networking.Ingress) bool {
return rc.onlyIngresses && namespace == rc.resourceNamespace && name == rc.resourceName
}

func (rc *testReferenceChecker) IsReferencedByMinion(namespace string, name string, ing *networking.Ingress) bool {
func (rc *testReferenceChecker) IsReferencedByMinion(namespace string, name string, _ *networking.Ingress) bool {
return rc.onlyMinions && namespace == rc.resourceNamespace && name == rc.resourceName
}

func (rc *testReferenceChecker) IsReferencedByVirtualServer(namespace string, name string, vs *conf_v1.VirtualServer) bool {
func (rc *testReferenceChecker) IsReferencedByVirtualServer(namespace string, name string, _ *conf_v1.VirtualServer) bool {
return rc.onlyVirtualServers && namespace == rc.resourceNamespace && name == rc.resourceName
}

func (rc *testReferenceChecker) IsReferencedByVirtualServerRoute(namespace string, name string, vsr *conf_v1.VirtualServerRoute) bool {
func (rc *testReferenceChecker) IsReferencedByVirtualServerRoute(namespace string, name string, _ *conf_v1.VirtualServerRoute) bool {
return rc.onlyVirtualServerRoutes && namespace == rc.resourceNamespace && name == rc.resourceName
}

func (rc *testReferenceChecker) IsReferencedByTransportServer(namespace string, name string, ts *conf_v1alpha1.TransportServer) bool {
func (rc *testReferenceChecker) IsReferencedByTransportServer(namespace string, name string, _ *conf_v1alpha1.TransportServer) bool {
return rc.onlyTransportServers && namespace == rc.resourceNamespace && name == rc.resourceName
}

Expand Down
4 changes: 3 additions & 1 deletion internal/k8s/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ type LoadBalancerController struct {
metricsCollector collectors.ControllerCollector
globalConfigurationValidator *validation.GlobalConfigurationValidator
transportServerValidator *validation.TransportServerValidator
spiffeController *spiffeController
spiffeController *SpiffeController
internalRoutesEnabled bool
syncLock sync.Mutex
isNginxReady bool
Expand Down Expand Up @@ -1381,6 +1381,7 @@ func (lbc *LoadBalancerController) updateTransportServerStatusAndEventsOnDelete(
}
}

// UpdateVirtualServerStatusAndEventsOnDelete updates the virtual server status and events
func (lbc *LoadBalancerController) UpdateVirtualServerStatusAndEventsOnDelete(vsConfig *VirtualServerConfiguration, changeError string, deleteErr error) {
eventType := api_v1.EventTypeWarning
eventTitle := "Rejected"
Expand Down Expand Up @@ -1422,6 +1423,7 @@ func (lbc *LoadBalancerController) UpdateVirtualServerStatusAndEventsOnDelete(vs
// for each VSR, a dedicated problem exists
}

// UpdateIngressStatusAndEventsOnDelete updates the ingress status and events.
func (lbc *LoadBalancerController) UpdateIngressStatusAndEventsOnDelete(ingConfig *IngressConfiguration, changeError string, deleteErr error) {
eventTitle := "Rejected"
eventWarningMessage := ""
Expand Down
24 changes: 12 additions & 12 deletions internal/k8s/reference_checkers.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ func (rc *secretReferenceChecker) IsReferencedByVirtualServer(secretNamespace st
return false
}

func (rc *secretReferenceChecker) IsReferencedByVirtualServerRoute(secretNamespace string, secretName string, vsr *v1.VirtualServerRoute) bool {
func (rc *secretReferenceChecker) IsReferencedByVirtualServerRoute(_ string, _ string, _ *v1.VirtualServerRoute) bool {
return false
}

func (rc *secretReferenceChecker) IsReferencedByTransportServer(secretNamespace string, secretName string, ts *conf_v1alpha1.TransportServer) bool {
func (rc *secretReferenceChecker) IsReferencedByTransportServer(_ string, _ string, _ *conf_v1alpha1.TransportServer) bool {
return false
}

Expand Down Expand Up @@ -173,11 +173,11 @@ func newPolicyReferenceChecker() *policyReferenceChecker {
return &policyReferenceChecker{}
}

func (rc *policyReferenceChecker) IsReferencedByIngress(policyNamespace string, policyName string, ing *networking.Ingress) bool {
func (rc *policyReferenceChecker) IsReferencedByIngress(_ string, _ string, _ *networking.Ingress) bool {
return false
}

func (rc *policyReferenceChecker) IsReferencedByMinion(policyNamespace string, policyName string, ing *networking.Ingress) bool {
func (rc *policyReferenceChecker) IsReferencedByMinion(_ string, _ string, _ *networking.Ingress) bool {
return false
}

Expand Down Expand Up @@ -205,7 +205,7 @@ func (rc *policyReferenceChecker) IsReferencedByVirtualServerRoute(policyNamespa
return false
}

func (rc *policyReferenceChecker) IsReferencedByTransportServer(policyNamespace string, policyName string, ts *conf_v1alpha1.TransportServer) bool {
func (rc *policyReferenceChecker) IsReferencedByTransportServer(_ string, _ string, _ *conf_v1alpha1.TransportServer) bool {
return false
}

Expand All @@ -231,19 +231,19 @@ func (rc *appProtectResourceReferenceChecker) IsReferencedByIngress(namespace st
return false
}

func (rc *appProtectResourceReferenceChecker) IsReferencedByMinion(namespace string, name string, ing *networking.Ingress) bool {
func (rc *appProtectResourceReferenceChecker) IsReferencedByMinion(_ string, _ string, _ *networking.Ingress) bool {
return false
}

func (rc *appProtectResourceReferenceChecker) IsReferencedByVirtualServer(namespace string, name string, vs *v1.VirtualServer) bool {
func (rc *appProtectResourceReferenceChecker) IsReferencedByVirtualServer(_ string, _ string, _ *v1.VirtualServer) bool {
return false
}

func (rc *appProtectResourceReferenceChecker) IsReferencedByVirtualServerRoute(namespace string, name string, vsr *v1.VirtualServerRoute) bool {
func (rc *appProtectResourceReferenceChecker) IsReferencedByVirtualServerRoute(_ string, _ string, _ *v1.VirtualServerRoute) bool {
return false
}

func (rc *appProtectResourceReferenceChecker) IsReferencedByTransportServer(namespace string, name string, ts *conf_v1alpha1.TransportServer) bool {
func (rc *appProtectResourceReferenceChecker) IsReferencedByTransportServer(_ string, _ string, _ *conf_v1alpha1.TransportServer) bool {
return false
}

Expand Down Expand Up @@ -278,7 +278,7 @@ func (rc *dosResourceReferenceChecker) IsReferencedByIngress(namespace string, n
return res == namespace+"/"+name || (namespace == ing.Namespace && res == name)
}

func (rc *dosResourceReferenceChecker) IsReferencedByMinion(namespace string, name string, ing *networking.Ingress) bool {
func (rc *dosResourceReferenceChecker) IsReferencedByMinion(_ string, _ string, _ *networking.Ingress) bool {
return false
}

Expand All @@ -294,10 +294,10 @@ func (rc *dosResourceReferenceChecker) IsReferencedByVirtualServer(namespace str
return false
}

func (rc *dosResourceReferenceChecker) IsReferencedByVirtualServerRoute(namespace string, name string, vsr *v1.VirtualServerRoute) bool {
func (rc *dosResourceReferenceChecker) IsReferencedByVirtualServerRoute(_ string, _ string, _ *v1.VirtualServerRoute) bool {
return false
}

func (rc *dosResourceReferenceChecker) IsReferencedByTransportServer(namespace string, name string, ts *conf_v1alpha1.TransportServer) bool {
func (rc *dosResourceReferenceChecker) IsReferencedByTransportServer(_ string, _ string, _ *conf_v1alpha1.TransportServer) bool {
return false
}
2 changes: 1 addition & 1 deletion internal/k8s/secrets/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (s *FakeSecretStore) AddOrUpdateSecret(secret *api_v1.Secret) {
}

// DeleteSecret is a fake implementation of DeleteSecret.
func (s *FakeSecretStore) DeleteSecret(key string) {
func (s *FakeSecretStore) DeleteSecret(_ string) {
}

// GetSecret is a fake implementation of GetSecret.
Expand Down
11 changes: 6 additions & 5 deletions internal/k8s/spiffe.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@ import (
"github.com/spiffe/go-spiffe/workload"
)

type spiffeController struct {
// SpiffeController controls spiffe
type SpiffeController struct {
watcher *spiffeWatcher
client *workload.X509SVIDClient
}

// NewSpiffeController creates the spiffeWatcher and the Spiffe Workload API Client,
// returns an error if the client cannot connect to the Spire Agent.
func NewSpiffeController(sync func(*workload.X509SVIDs), spireAgentAddr string) (*spiffeController, error) {
func NewSpiffeController(sync func(*workload.X509SVIDs), spireAgentAddr string) (*SpiffeController, error) {
watcher := &spiffeWatcher{sync: sync}
client, err := workload.NewX509SVIDClient(watcher, workload.WithAddr("unix://"+spireAgentAddr))
if err != nil {
return nil, fmt.Errorf("failed to create Spiffe Workload API Client: %w", err)
}
sc := &spiffeController{
sc := &SpiffeController{
watcher: watcher,
client: client,
}
Expand All @@ -33,7 +34,7 @@ func NewSpiffeController(sync func(*workload.X509SVIDs), spireAgentAddr string)
// Start starts the Spiffe Workload API Client and waits for the Spiffe certs to be written to disk.
// If the certs are not available after 30 seconds an error is returned.
// On success, calls onStart function and kicks off the Spiffe Controller's run loop.
func (sc *spiffeController) Start(stopCh <-chan struct{}, onStart func()) error {
func (sc *SpiffeController) Start(stopCh <-chan struct{}, onStart func()) error {
glog.V(3).Info("Starting SPIFFE Workload API Client")
err := sc.client.Start()
if err != nil {
Expand Down Expand Up @@ -62,7 +63,7 @@ func (sc *spiffeController) Start(stopCh <-chan struct{}, onStart func()) error
}

// Run waits until a message is sent on the stop channel and stops the Spiffe Workload API Client.
func (sc *spiffeController) Run(stopCh <-chan struct{}) {
func (sc *SpiffeController) Run(stopCh <-chan struct{}) {
<-stopCh
err := sc.client.Stop()
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions internal/metrics/collectors/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,16 @@ func NewControllerFakeCollector() *ControllerFakeCollector {
}

// Register implements a fake Register
func (cc *ControllerFakeCollector) Register(registry *prometheus.Registry) error { return nil }
func (cc *ControllerFakeCollector) Register(_ *prometheus.Registry) error { return nil }

// SetIngresses implements a fake SetIngresses
func (cc *ControllerFakeCollector) SetIngresses(ingressType string, count int) {}
func (cc *ControllerFakeCollector) SetIngresses(_ string, _ int) {}

// SetVirtualServers implements a fake SetVirtualServers
func (cc *ControllerFakeCollector) SetVirtualServers(count int) {}
func (cc *ControllerFakeCollector) SetVirtualServers(_ int) {}

// SetVirtualServerRoutes implements a fake SetVirtualServerRoutes
func (cc *ControllerFakeCollector) SetVirtualServerRoutes(count int) {}
func (cc *ControllerFakeCollector) SetVirtualServerRoutes(_ int) {}

// SetTransportServers implements a fake SetTransportServers
func (cc *ControllerFakeCollector) SetTransportServers(int, int, int) {}
6 changes: 3 additions & 3 deletions internal/metrics/collectors/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ func NewManagerFakeCollector() *ManagerFakeCollector {
}

// Register implements a fake Register
func (nc *ManagerFakeCollector) Register(registry *prometheus.Registry) error { return nil }
func (nc *ManagerFakeCollector) Register(_ *prometheus.Registry) error { return nil }

// IncNginxReloadCount implements a fake IncNginxReloadCount
func (nc *ManagerFakeCollector) IncNginxReloadCount(isEndPointUpdate bool) {}
func (nc *ManagerFakeCollector) IncNginxReloadCount(_ bool) {}

// IncNginxReloadErrors implements a fake IncNginxReloadErrors
func (nc *ManagerFakeCollector) IncNginxReloadErrors() {}

// UpdateLastReloadTime implements a fake UpdateLastReloadTime
func (nc *ManagerFakeCollector) UpdateLastReloadTime(ms time.Duration) {}
func (nc *ManagerFakeCollector) UpdateLastReloadTime(_ time.Duration) {}
26 changes: 13 additions & 13 deletions internal/nginx/fake_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ func (*FakeManager) DeleteStreamConfig(name string) {
}

// CreateTLSPassthroughHostsConfig provides a fake implementation of CreateTLSPassthroughHostsConfig.
func (*FakeManager) CreateTLSPassthroughHostsConfig(content []byte) {
func (*FakeManager) CreateTLSPassthroughHostsConfig(_ []byte) {
glog.V(3).Infof("Writing TLS Passthrough Hosts config file")
}

// CreateSecret provides a fake implementation of CreateSecret.
func (fm *FakeManager) CreateSecret(name string, content []byte, mode os.FileMode) string {
func (fm *FakeManager) CreateSecret(name string, _ []byte, _ os.FileMode) string {
glog.V(3).Infof("Writing secret %v", name)
return fm.GetFilenameForSecret(name)
}
Expand All @@ -91,7 +91,7 @@ func (fm *FakeManager) GetFilenameForSecret(name string) string {
}

// CreateDHParam provides a fake implementation of CreateDHParam.
func (fm *FakeManager) CreateDHParam(content string) (string, error) {
func (fm *FakeManager) CreateDHParam(_ string) (string, error) {
glog.V(3).Infof("Writing dhparam file")
return fm.dhparamFilename, nil
}
Expand All @@ -103,12 +103,12 @@ func (*FakeManager) Version() string {
}

// Start provides a fake implementation of Start.
func (*FakeManager) Start(done chan error) {
func (*FakeManager) Start(_ chan error) {
glog.V(3).Info("Starting nginx")
}

// Reload provides a fake implementation of Reload.
func (*FakeManager) Reload(isEndpointsUpdate bool) error {
func (*FakeManager) Reload(_ bool) error {
glog.V(3).Infof("Reloading nginx")
return nil
}
Expand All @@ -119,16 +119,16 @@ func (*FakeManager) Quit() {
}

// UpdateConfigVersionFile provides a fake implementation of UpdateConfigVersionFile.
func (*FakeManager) UpdateConfigVersionFile(openTracing bool) {
func (*FakeManager) UpdateConfigVersionFile(_ bool) {
glog.V(3).Infof("Writing config version")
}

// SetPlusClients provides a fake implementation of SetPlusClients.
func (*FakeManager) SetPlusClients(plusClient *client.NginxClient, plusConfigVersionCheckClient *http.Client) {
func (*FakeManager) SetPlusClients(_ *client.NginxClient, _ *http.Client) {
}

// UpdateServersInPlus provides a fake implementation of UpdateServersInPlus.
func (*FakeManager) UpdateServersInPlus(upstream string, servers []string, config ServerConfig) error {
func (*FakeManager) UpdateServersInPlus(upstream string, servers []string, _ ServerConfig) error {
glog.V(3).Infof("Updating servers of %v: %v", upstream, servers)
return nil
}
Expand All @@ -140,18 +140,18 @@ func (*FakeManager) UpdateStreamServersInPlus(upstream string, servers []string)
}

// CreateOpenTracingTracerConfig creates a fake implementation of CreateOpenTracingTracerConfig.
func (*FakeManager) CreateOpenTracingTracerConfig(content string) error {
func (*FakeManager) CreateOpenTracingTracerConfig(_ string) error {
glog.V(3).Infof("Writing OpenTracing tracer config file")

return nil
}

// SetOpenTracing creates a fake implementation of SetOpenTracing.
func (*FakeManager) SetOpenTracing(openTracing bool) {
func (*FakeManager) SetOpenTracing(_ bool) {
}

// AppProtectAgentStart is a fake implementation of AppProtectAgentStart
func (*FakeManager) AppProtectAgentStart(apaDone chan error, debug bool) {
func (*FakeManager) AppProtectAgentStart(_ chan error, _ bool) {
glog.V(3).Infof("Starting FakeAppProtectAgent")
}

Expand All @@ -161,7 +161,7 @@ func (*FakeManager) AppProtectAgentQuit() {
}

// AppProtectPluginStart is a fake implementtion AppProtectPluginStart
func (*FakeManager) AppProtectPluginStart(appDone chan error) {
func (*FakeManager) AppProtectPluginStart(_ chan error) {
glog.V(3).Infof("Starting FakeAppProtectPlugin")
}

Expand All @@ -176,6 +176,6 @@ func (*FakeManager) AppProtectDosAgentQuit() {
}

// AppProtectDosAgentStart is a fake implementation of AppProtectAgentStart
func (*FakeManager) AppProtectDosAgentStart(apdaDone chan error, debug bool, maxDaemon int, maxWorkers int, memory int) {
func (*FakeManager) AppProtectDosAgentStart(_ chan error, _ bool, _ int, _ int, _ int) {
glog.V(3).Infof("Starting FakeAppProtectDosAgent")
}
12 changes: 8 additions & 4 deletions internal/nginx/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ import (
)

const (
ReloadForEndpointsUpdate = true // ReloadForEndpointsUpdate means that is caused by an endpoints update.
ReloadForOtherUpdate = false // ReloadForOtherUpdate means that a reload is caused by an update for a resource(s) other than endpoints.
TLSSecretFileMode = 0o600 // TLSSecretFileMode defines the default filemode for files with TLS Secrets.
JWKSecretFileMode = 0o644 // JWKSecretFileMode defines the default filemode for files with JWK Secrets.
// ReloadForEndpointsUpdate means that is caused by an endpoints update.
ReloadForEndpointsUpdate = true
// ReloadForOtherUpdate means that a reload is caused by an update for a resource(s) other than endpoints.
ReloadForOtherUpdate = false
// TLSSecretFileMode defines the default filemode for files with TLS Secrets.
TLSSecretFileMode = 0o600
// JWKSecretFileMode defines the default filemode for files with JWK Secrets.
JWKSecretFileMode = 0o644
configFileMode = 0o644
jsonFileForOpenTracingTracer = "/var/lib/nginx/tracer-config.json"
nginxBinaryPath = "/usr/sbin/nginx"
Expand Down
2 changes: 1 addition & 1 deletion internal/nginx/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

type Transport struct{}

func (c Transport) RoundTrip(req *http.Request) (*http.Response, error) {
func (c Transport) RoundTrip(_ *http.Request) (*http.Response, error) {
return &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString("42")),
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/configuration/register.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package configuration

const (
// GroupName is the name of the group.
GroupName = "k8s.nginx.org"
)
Loading

0 comments on commit c05cec6

Please sign in to comment.