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
|
|
@ -66,12 +66,12 @@ type SSLCert struct {
|
|||
}
|
||||
|
||||
// GetObjectKind implements the ObjectKind interface as a noop
|
||||
func (s SSLCert) GetObjectKind() schema.ObjectKind {
|
||||
func (s *SSLCert) GetObjectKind() schema.ObjectKind {
|
||||
return schema.EmptyObjectKind
|
||||
}
|
||||
|
||||
// Identifier returns a the couple issuer / serial number if they both exist, an empty string otherwise
|
||||
func (s SSLCert) Identifier() string {
|
||||
func (s *SSLCert) Identifier() string {
|
||||
if s.Certificate != nil {
|
||||
if s.Certificate.SerialNumber != nil {
|
||||
return fmt.Sprintf("%s-%s", s.Certificate.Issuer.SerialNumber, s.Certificate.SerialNumber.String())
|
||||
|
|
@ -81,7 +81,7 @@ func (s SSLCert) Identifier() string {
|
|||
}
|
||||
|
||||
// HashInclude defines if a field should be used or not to calculate the hash
|
||||
func (s SSLCert) HashInclude(field string, v interface{}) (bool, error) {
|
||||
func (s *SSLCert) HashInclude(field string, _ interface{}) (bool, error) {
|
||||
switch field {
|
||||
case "PemSHA", "CASHA", "ExpireTime":
|
||||
return true, nil
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ type Configuration struct {
|
|||
|
||||
DefaultSSLCertificate *SSLCert `json:"-"`
|
||||
|
||||
StreamSnippets []string
|
||||
StreamSnippets []string `json:"StreamSnippets"`
|
||||
}
|
||||
|
||||
// Backend describes one or more remote server/s (endpoints) associated with a service
|
||||
|
|
@ -129,7 +129,7 @@ type TrafficShapingPolicy struct {
|
|||
}
|
||||
|
||||
// HashInclude defines if a field should be used or not to calculate the hash
|
||||
func (s Backend) HashInclude(field string, v interface{}) (bool, error) {
|
||||
func (b *Backend) HashInclude(field string, _ interface{}) (bool, error) {
|
||||
switch field {
|
||||
case "Endpoints":
|
||||
return false, nil
|
||||
|
|
@ -410,5 +410,4 @@ type Ingress struct {
|
|||
}
|
||||
|
||||
// GeneralConfig holds the definition of lua general configuration data
|
||||
type GeneralConfig struct {
|
||||
}
|
||||
type GeneralConfig struct{}
|
||||
|
|
|
|||
|
|
@ -80,58 +80,58 @@ func (c1 *Configuration) Equal(c2 *Configuration) bool {
|
|||
}
|
||||
|
||||
// Equal tests for equality between two Backend types
|
||||
func (b1 *Backend) Equal(b2 *Backend) bool {
|
||||
if b1 == b2 {
|
||||
func (b *Backend) Equal(newB *Backend) bool {
|
||||
if b == newB {
|
||||
return true
|
||||
}
|
||||
if b1 == nil || b2 == nil {
|
||||
if b == nil || newB == nil {
|
||||
return false
|
||||
}
|
||||
if b1.Name != b2.Name {
|
||||
if b.Name != newB.Name {
|
||||
return false
|
||||
}
|
||||
if b1.NoServer != b2.NoServer {
|
||||
if b.NoServer != newB.NoServer {
|
||||
return false
|
||||
}
|
||||
|
||||
if b1.Service != b2.Service {
|
||||
if b1.Service == nil || b2.Service == nil {
|
||||
if b.Service != newB.Service {
|
||||
if b.Service == nil || newB.Service == nil {
|
||||
return false
|
||||
}
|
||||
if b1.Service.GetNamespace() != b2.Service.GetNamespace() {
|
||||
if b.Service.GetNamespace() != newB.Service.GetNamespace() {
|
||||
return false
|
||||
}
|
||||
if b1.Service.GetName() != b2.Service.GetName() {
|
||||
if b.Service.GetName() != newB.Service.GetName() {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if b1.Port != b2.Port {
|
||||
if b.Port != newB.Port {
|
||||
return false
|
||||
}
|
||||
if b1.SSLPassthrough != b2.SSLPassthrough {
|
||||
if b.SSLPassthrough != newB.SSLPassthrough {
|
||||
return false
|
||||
}
|
||||
if !(&b1.SessionAffinity).Equal(&b2.SessionAffinity) {
|
||||
if !(&b.SessionAffinity).Equal(&newB.SessionAffinity) {
|
||||
return false
|
||||
}
|
||||
if b1.UpstreamHashBy != b2.UpstreamHashBy {
|
||||
if b.UpstreamHashBy != newB.UpstreamHashBy {
|
||||
return false
|
||||
}
|
||||
if b1.LoadBalancing != b2.LoadBalancing {
|
||||
if b.LoadBalancing != newB.LoadBalancing {
|
||||
return false
|
||||
}
|
||||
|
||||
match := compareEndpoints(b1.Endpoints, b2.Endpoints)
|
||||
match := compareEndpoints(b.Endpoints, newB.Endpoints)
|
||||
if !match {
|
||||
return false
|
||||
}
|
||||
|
||||
if !b1.TrafficShapingPolicy.Equal(b2.TrafficShapingPolicy) {
|
||||
if !b.TrafficShapingPolicy.Equal(&newB.TrafficShapingPolicy) {
|
||||
return false
|
||||
}
|
||||
|
||||
return sets.StringElementsMatch(b1.AlternativeBackends, b2.AlternativeBackends)
|
||||
return sets.StringElementsMatch(b.AlternativeBackends, newB.AlternativeBackends)
|
||||
}
|
||||
|
||||
// Equal tests for equality between two SessionAffinityConfig types
|
||||
|
|
@ -243,7 +243,7 @@ func (e1 *Endpoint) Equal(e2 *Endpoint) bool {
|
|||
}
|
||||
|
||||
// Equal checks for equality between two TrafficShapingPolicies
|
||||
func (tsp1 TrafficShapingPolicy) Equal(tsp2 TrafficShapingPolicy) bool {
|
||||
func (tsp1 *TrafficShapingPolicy) Equal(tsp2 *TrafficShapingPolicy) bool {
|
||||
if tsp1.Weight != tsp2.Weight {
|
||||
return false
|
||||
}
|
||||
|
|
@ -335,6 +335,8 @@ func (s1 *Server) Equal(s2 *Server) bool {
|
|||
}
|
||||
|
||||
// Equal tests for equality between two Location types
|
||||
//
|
||||
//nolint:gocyclo // Ignore function complexity error
|
||||
func (l1 *Location) Equal(l2 *Location) bool {
|
||||
if l1 == l2 {
|
||||
return true
|
||||
|
|
@ -550,39 +552,39 @@ func (l4b1 *L4Backend) Equal(l4b2 *L4Backend) bool {
|
|||
}
|
||||
|
||||
// Equal tests for equality between two SSLCert types
|
||||
func (s1 *SSLCert) Equal(s2 *SSLCert) bool {
|
||||
if s1 == s2 {
|
||||
func (s *SSLCert) Equal(newS *SSLCert) bool {
|
||||
if s == newS {
|
||||
return true
|
||||
}
|
||||
if s1 == nil || s2 == nil {
|
||||
if s == nil || newS == nil {
|
||||
return false
|
||||
}
|
||||
if s1.CASHA != s2.CASHA {
|
||||
if s.CASHA != newS.CASHA {
|
||||
return false
|
||||
}
|
||||
if s1.CRLSHA != s2.CRLSHA {
|
||||
if s.CRLSHA != newS.CRLSHA {
|
||||
return false
|
||||
}
|
||||
if s1.PemSHA != s2.PemSHA {
|
||||
if s.PemSHA != newS.PemSHA {
|
||||
return false
|
||||
}
|
||||
if s1.CAFileName != s2.CAFileName {
|
||||
if s.CAFileName != newS.CAFileName {
|
||||
return false
|
||||
}
|
||||
if s1.CRLFileName != s2.CRLFileName {
|
||||
if s.CRLFileName != newS.CRLFileName {
|
||||
return false
|
||||
}
|
||||
if !s1.ExpireTime.Equal(s2.ExpireTime) {
|
||||
if !s.ExpireTime.Equal(newS.ExpireTime) {
|
||||
return false
|
||||
}
|
||||
if s1.PemCertKey != s2.PemCertKey {
|
||||
if s.PemCertKey != newS.PemCertKey {
|
||||
return false
|
||||
}
|
||||
if s1.UID != s2.UID {
|
||||
if s.UID != newS.UID {
|
||||
return false
|
||||
}
|
||||
|
||||
return sets.StringElementsMatch(s1.CN, s2.CN)
|
||||
return sets.StringElementsMatch(s.CN, newS.CN)
|
||||
}
|
||||
|
||||
var compareEndpointsFunc = func(e1, e2 interface{}) bool {
|
||||
|
|
|
|||
|
|
@ -25,19 +25,29 @@ import (
|
|||
)
|
||||
|
||||
func TestEqualConfiguration(t *testing.T) {
|
||||
ap, _ := filepath.Abs("../../../test/manifests/configuration-a.json")
|
||||
ap, err := filepath.Abs("../../../test/manifests/configuration-a.json")
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
a, err := readJSON(ap)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error reading JSON file: %v", err)
|
||||
}
|
||||
|
||||
bp, _ := filepath.Abs("../../../test/manifests/configuration-b.json")
|
||||
bp, err := filepath.Abs("../../../test/manifests/configuration-b.json")
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
b, err := readJSON(bp)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error reading JSON file: %v", err)
|
||||
}
|
||||
|
||||
cp, _ := filepath.Abs("../../../test/manifests/configuration-c.json")
|
||||
cp, err := filepath.Abs("../../../test/manifests/configuration-c.json")
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
c, err := readJSON(cp)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error reading JSON file: %v", err)
|
||||
|
|
@ -84,15 +94,18 @@ func TestL4ServiceElementsMatch(t *testing.T) {
|
|||
{[]L4Service{{Port: 80}}, []L4Service{{Port: 80}}, true},
|
||||
{
|
||||
[]L4Service{
|
||||
{Port: 80, Endpoints: []Endpoint{{Address: "1.1.1.1"}}}},
|
||||
{Port: 80, Endpoints: []Endpoint{{Address: "1.1.1.1"}}},
|
||||
},
|
||||
[]L4Service{{Port: 80}},
|
||||
false,
|
||||
},
|
||||
{
|
||||
[]L4Service{
|
||||
{Port: 80, Endpoints: []Endpoint{{Address: "1.1.1.1"}, {Address: "1.1.1.2"}}}},
|
||||
{Port: 80, Endpoints: []Endpoint{{Address: "1.1.1.1"}, {Address: "1.1.1.2"}}},
|
||||
},
|
||||
[]L4Service{
|
||||
{Port: 80, Endpoints: []Endpoint{{Address: "1.1.1.2"}, {Address: "1.1.1.1"}}}},
|
||||
{Port: 80, Endpoints: []Endpoint{{Address: "1.1.1.2"}, {Address: "1.1.1.1"}}},
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue