Fix golangci-lint errors (#10196)
* Fix golangci-lint errors Signed-off-by: z1cheng <imchench@gmail.com> * Fix dupl errors Signed-off-by: z1cheng <imchench@gmail.com> * Fix comments Signed-off-by: z1cheng <imchench@gmail.com> * Fix errcheck lint errors Signed-off-by: z1cheng <imchench@gmail.com> * Fix assert in e2e test Signed-off-by: z1cheng <imchench@gmail.com> * Not interrupt the waitForPodsReady Signed-off-by: z1cheng <imchench@gmail.com> * Replace string with constant Signed-off-by: z1cheng <imchench@gmail.com> * Fix comments Signed-off-by: z1cheng <imchench@gmail.com> * Revert write file permision Signed-off-by: z1cheng <imchench@gmail.com> --------- Signed-off-by: z1cheng <imchench@gmail.com>
This commit is contained in:
parent
46d87d3462
commit
b3060bfbd0
253 changed files with 2434 additions and 2113 deletions
|
|
@ -26,8 +26,8 @@ import (
|
|||
"github.com/fsnotify/fsnotify"
|
||||
)
|
||||
|
||||
// FileWatcher is an interface we use to watch changes in files
|
||||
type FileWatcher interface {
|
||||
// Watcher is an interface we use to watch changes in files
|
||||
type Watcher interface {
|
||||
Close() error
|
||||
}
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ type OSFileWatcher struct {
|
|||
}
|
||||
|
||||
// NewFileWatcher creates a new FileWatcher
|
||||
func NewFileWatcher(file string, onEvent func()) (FileWatcher, error) {
|
||||
func NewFileWatcher(file string, onEvent func()) (Watcher, error) {
|
||||
fw := OSFileWatcher{
|
||||
file: file,
|
||||
onEvent: onEvent,
|
||||
|
|
|
|||
|
|
@ -17,4 +17,4 @@ limitations under the License.
|
|||
package file
|
||||
|
||||
// ReadWriteByUser defines linux permission to read and write files for the owner user
|
||||
const ReadWriteByUser = 0700
|
||||
const ReadWriteByUser = 0o700
|
||||
|
|
|
|||
|
|
@ -33,12 +33,10 @@ const (
|
|||
DefaultSSLDirectory = "/etc/ingress-controller/ssl"
|
||||
)
|
||||
|
||||
var (
|
||||
directories = []string{
|
||||
DefaultSSLDirectory,
|
||||
AuthDirectory,
|
||||
}
|
||||
)
|
||||
var directories = []string{
|
||||
DefaultSSLDirectory,
|
||||
AuthDirectory,
|
||||
}
|
||||
|
||||
// CreateRequiredDirectories verifies if the required directories to
|
||||
// start the ingress controller exist and creates the missing ones.
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ func GetRemovedIngresses(rucfg, newcfg *ingress.Configuration) []string {
|
|||
|
||||
// IsDynamicConfigurationEnough returns whether a Configuration can be
|
||||
// dynamically applied, without reloading the backend.
|
||||
func IsDynamicConfigurationEnough(newcfg *ingress.Configuration, oldcfg *ingress.Configuration) bool {
|
||||
func IsDynamicConfigurationEnough(newcfg, oldcfg *ingress.Configuration) bool {
|
||||
copyOfRunningConfig := *oldcfg
|
||||
copyOfPcfg := *newcfg
|
||||
|
||||
|
|
@ -133,21 +133,21 @@ func IsDynamicConfigurationEnough(newcfg *ingress.Configuration, oldcfg *ingress
|
|||
// clearL4serviceEndpoints is a helper function to clear endpoints from the ingress configuration since they should be ignored when
|
||||
// checking if the new configuration changes can be applied dynamically.
|
||||
func clearL4serviceEndpoints(config *ingress.Configuration) {
|
||||
var clearedTCPL4Services []ingress.L4Service
|
||||
var clearedUDPL4Services []ingress.L4Service
|
||||
for _, service := range config.TCPEndpoints {
|
||||
clearedTCPL4Services := make([]ingress.L4Service, 0, len(config.TCPEndpoints))
|
||||
clearedUDPL4Services := make([]ingress.L4Service, 0, len(config.UDPEndpoints))
|
||||
for i := range config.TCPEndpoints {
|
||||
copyofService := ingress.L4Service{
|
||||
Port: service.Port,
|
||||
Backend: service.Backend,
|
||||
Port: config.TCPEndpoints[i].Port,
|
||||
Backend: config.TCPEndpoints[i].Backend,
|
||||
Endpoints: []ingress.Endpoint{},
|
||||
Service: nil,
|
||||
}
|
||||
clearedTCPL4Services = append(clearedTCPL4Services, copyofService)
|
||||
}
|
||||
for _, service := range config.UDPEndpoints {
|
||||
for i := range config.UDPEndpoints {
|
||||
copyofService := ingress.L4Service{
|
||||
Port: service.Port,
|
||||
Backend: service.Backend,
|
||||
Port: config.UDPEndpoints[i].Port,
|
||||
Backend: config.UDPEndpoints[i].Backend,
|
||||
Endpoints: []ingress.Endpoint{},
|
||||
Service: nil,
|
||||
}
|
||||
|
|
@ -160,7 +160,7 @@ func clearL4serviceEndpoints(config *ingress.Configuration) {
|
|||
// clearCertificates is a helper function to clear Certificates from the ingress configuration since they should be ignored when
|
||||
// checking if the new configuration changes can be applied dynamically if dynamic certificates is on
|
||||
func clearCertificates(config *ingress.Configuration) {
|
||||
var clearedServers []*ingress.Server
|
||||
clearedServers := make([]*ingress.Server, 0, len(config.Servers))
|
||||
for _, server := range config.Servers {
|
||||
copyOfServer := *server
|
||||
copyOfServer.SSLCert = nil
|
||||
|
|
@ -169,16 +169,16 @@ func clearCertificates(config *ingress.Configuration) {
|
|||
config.Servers = clearedServers
|
||||
}
|
||||
|
||||
type redirect struct {
|
||||
type Redirect struct {
|
||||
From string
|
||||
To string
|
||||
SSLCert *ingress.SSLCert
|
||||
}
|
||||
|
||||
// BuildRedirects build the redirects of servers based on configurations and certificates
|
||||
func BuildRedirects(servers []*ingress.Server) []*redirect {
|
||||
func BuildRedirects(servers []*ingress.Server) []*Redirect {
|
||||
names := sets.Set[string]{}
|
||||
redirectServers := make([]*redirect, 0)
|
||||
redirectServers := make([]*Redirect, 0)
|
||||
|
||||
for _, srv := range servers {
|
||||
if !srv.RedirectFromToWWW {
|
||||
|
|
@ -212,7 +212,7 @@ func BuildRedirects(servers []*ingress.Server) []*redirect {
|
|||
continue
|
||||
}
|
||||
|
||||
r := &redirect{
|
||||
r := &Redirect{
|
||||
From: from,
|
||||
To: to,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ limitations under the License.
|
|||
|
||||
package process
|
||||
|
||||
// ProcessController defines a common interface for a process to be controlled,
|
||||
// Controller defines a common interface for a process to be controlled,
|
||||
// like the configurer, the webhook or the proper ingress controller
|
||||
type ProcessController interface {
|
||||
type Controller interface {
|
||||
Start()
|
||||
Stop() error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ type exiter func(code int)
|
|||
|
||||
// HandleSigterm receives a ProcessController interface and deals with
|
||||
// the graceful shutdown
|
||||
func HandleSigterm(ngx ProcessController, delay int, exit exiter) {
|
||||
func HandleSigterm(ngx Controller, delay int, exit exiter) {
|
||||
signalChan := make(chan os.Signal, 1)
|
||||
signal.Notify(signalChan, syscall.SIGTERM)
|
||||
<-signalChan
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ func (f *FakeProcess) exiterFunc(code int) {
|
|||
}
|
||||
|
||||
func sendDelayedSignal(delay time.Duration) error {
|
||||
time.Sleep(delay * time.Second)
|
||||
time.Sleep(delay)
|
||||
return syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
|
||||
}
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ func TestHandleSigterm(t *testing.T) {
|
|||
process := &FakeProcess{shouldError: tt.shouldError}
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
go func() {
|
||||
err := sendDelayedSignal(2) // Send a signal after 2 seconds
|
||||
err := sendDelayedSignal(2 * time.Second) // Send a signal after 2 seconds
|
||||
if err != nil {
|
||||
t.Errorf("error sending delayed signal: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import (
|
|||
"runtime"
|
||||
)
|
||||
|
||||
// NumCPU ...
|
||||
// NumCPU returns the number of logical CPUs usable by the current process.
|
||||
func NumCPU() int {
|
||||
return runtime.NumCPU()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,23 +20,20 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
testCasesElementMatch = []struct {
|
||||
listA []string
|
||||
listB []string
|
||||
expected bool
|
||||
}{
|
||||
{nil, nil, true},
|
||||
{[]string{"1"}, nil, false},
|
||||
{[]string{"1"}, []string{"1"}, true},
|
||||
{[]string{"1", "2", "1"}, []string{"1", "1", "2"}, true},
|
||||
{[]string{"1", "3", "1"}, []string{"1", "1", "2"}, false},
|
||||
{[]string{"1", "1"}, []string{"1", "2"}, false},
|
||||
}
|
||||
)
|
||||
var testCasesElementMatch = []struct {
|
||||
listA []string
|
||||
listB []string
|
||||
expected bool
|
||||
}{
|
||||
{nil, nil, true},
|
||||
{[]string{"1"}, nil, false},
|
||||
{[]string{"1"}, []string{"1"}, true},
|
||||
{[]string{"1", "2", "1"}, []string{"1", "1", "2"}, true},
|
||||
{[]string{"1", "3", "1"}, []string{"1", "1", "2"}, false},
|
||||
{[]string{"1", "1"}, []string{"1", "2"}, false},
|
||||
}
|
||||
|
||||
func TestElementsMatch(t *testing.T) {
|
||||
|
||||
for _, testCase := range testCasesElementMatch {
|
||||
result := StringElementsMatch(testCase.listA, testCase.listB)
|
||||
if result != testCase.expected {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue