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
|
|
@ -105,7 +105,7 @@ type Storer interface {
|
|||
Run(stopCh chan struct{})
|
||||
|
||||
// GetIngressClass validates given ingress against ingress class configuration and returns the ingress class.
|
||||
GetIngressClass(ing *networkingv1.Ingress, icConfig *ingressclass.IngressClassConfiguration) (string, error)
|
||||
GetIngressClass(ing *networkingv1.Ingress, icConfig *ingressclass.Configuration) (string, error)
|
||||
}
|
||||
|
||||
// EventType type of event associated with an informer
|
||||
|
|
@ -242,7 +242,9 @@ type k8sStore struct {
|
|||
defaultSSLCertificate string
|
||||
}
|
||||
|
||||
// New creates a new object store to be used in the ingress controller
|
||||
// New creates a new object store to be used in the ingress controller.
|
||||
//
|
||||
//nolint:gocyclo // Ignore function complexity error.
|
||||
func New(
|
||||
namespace string,
|
||||
namespaceSelector labels.Selector,
|
||||
|
|
@ -252,9 +254,9 @@ func New(
|
|||
updateCh *channels.RingChannel,
|
||||
disableCatchAll bool,
|
||||
deepInspector bool,
|
||||
icConfig *ingressclass.IngressClassConfiguration,
|
||||
disableSyncEvents bool) Storer {
|
||||
|
||||
icConfig *ingressclass.Configuration,
|
||||
disableSyncEvents bool,
|
||||
) Storer {
|
||||
store := &k8sStore{
|
||||
informers: &Informer{},
|
||||
listers: &Lister{},
|
||||
|
|
@ -474,7 +476,8 @@ func New(
|
|||
_, errOld = store.GetIngressClass(oldIng, icConfig)
|
||||
classCur, errCur = store.GetIngressClass(curIng, icConfig)
|
||||
}
|
||||
if errOld != nil && errCur == nil {
|
||||
switch {
|
||||
case errOld != nil && errCur == nil:
|
||||
if hasCatchAllIngressRule(curIng.Spec) && disableCatchAll {
|
||||
klog.InfoS("ignoring update for catch-all ingress because of --disable-catch-all", "ingress", klog.KObj(curIng))
|
||||
return
|
||||
|
|
@ -482,11 +485,11 @@ func New(
|
|||
|
||||
klog.InfoS("creating ingress", "ingress", klog.KObj(curIng), "ingressclass", classCur)
|
||||
recorder.Eventf(curIng, corev1.EventTypeNormal, "Sync", "Scheduled for sync")
|
||||
} else if errOld == nil && errCur != nil {
|
||||
case errOld == nil && errCur != nil:
|
||||
klog.InfoS("removing ingress because of unknown ingressclass", "ingress", klog.KObj(curIng))
|
||||
ingDeleteHandler(old)
|
||||
return
|
||||
} else if errCur == nil && !reflect.DeepEqual(old, cur) {
|
||||
case errCur == nil && !reflect.DeepEqual(old, cur):
|
||||
if hasCatchAllIngressRule(curIng.Spec) && disableCatchAll {
|
||||
klog.InfoS("ignoring update for catch-all ingress and delete old one because of --disable-catch-all", "ingress", klog.KObj(curIng))
|
||||
ingDeleteHandler(old)
|
||||
|
|
@ -494,7 +497,7 @@ func New(
|
|||
}
|
||||
|
||||
recorder.Eventf(curIng, corev1.EventTypeNormal, "Sync", "Scheduled for sync")
|
||||
} else {
|
||||
default:
|
||||
klog.V(3).InfoS("No changes on ingress. Skipping update", "ingress", klog.KObj(curIng))
|
||||
return
|
||||
}
|
||||
|
|
@ -519,7 +522,10 @@ func New(
|
|||
|
||||
ingressClassEventHandler := cache.ResourceEventHandlerFuncs{
|
||||
AddFunc: func(obj interface{}) {
|
||||
ingressclass := obj.(*networkingv1.IngressClass)
|
||||
ingressclass, ok := obj.(*networkingv1.IngressClass)
|
||||
if !ok {
|
||||
klog.Errorf("unexpected type: %T", obj)
|
||||
}
|
||||
foundClassByName := false
|
||||
if icConfig.IngressClassByName && ingressclass.Name == icConfig.AnnotationValue {
|
||||
klog.InfoS("adding ingressclass as ingress-class-by-name is configured", "ingressclass", klog.KObj(ingressclass))
|
||||
|
|
@ -541,7 +547,10 @@ func New(
|
|||
}
|
||||
},
|
||||
DeleteFunc: func(obj interface{}) {
|
||||
ingressclass := obj.(*networkingv1.IngressClass)
|
||||
ingressclass, ok := obj.(*networkingv1.IngressClass)
|
||||
if !ok {
|
||||
klog.Errorf("unexpected type: %T", obj)
|
||||
}
|
||||
if ingressclass.Spec.Controller != icConfig.Controller {
|
||||
klog.InfoS("ignoring ingressclass as the spec.controller is not the same of this ingress", "ingressclass", klog.KObj(ingressclass))
|
||||
return
|
||||
|
|
@ -557,8 +566,14 @@ func New(
|
|||
}
|
||||
},
|
||||
UpdateFunc: func(old, cur interface{}) {
|
||||
oic := old.(*networkingv1.IngressClass)
|
||||
cic := cur.(*networkingv1.IngressClass)
|
||||
oic, ok := old.(*networkingv1.IngressClass)
|
||||
if !ok {
|
||||
klog.Errorf("unexpected type: %T", old)
|
||||
}
|
||||
cic, ok := cur.(*networkingv1.IngressClass)
|
||||
if !ok {
|
||||
klog.Errorf("unexpected type: %T", cur)
|
||||
}
|
||||
if cic.Spec.Controller != icConfig.Controller {
|
||||
klog.InfoS("ignoring ingressclass as the spec.controller is not the same of this ingress", "ingressclass", klog.KObj(cic))
|
||||
return
|
||||
|
|
@ -581,7 +596,10 @@ func New(
|
|||
|
||||
secrEventHandler := cache.ResourceEventHandlerFuncs{
|
||||
AddFunc: func(obj interface{}) {
|
||||
sec := obj.(*corev1.Secret)
|
||||
sec, ok := obj.(*corev1.Secret)
|
||||
if !ok {
|
||||
klog.Errorf("unexpected type: %T", obj)
|
||||
}
|
||||
key := k8s.MetaNamespaceKey(sec)
|
||||
|
||||
if store.defaultSSLCertificate == key {
|
||||
|
|
@ -608,7 +626,10 @@ func New(
|
|||
},
|
||||
UpdateFunc: func(old, cur interface{}) {
|
||||
if !reflect.DeepEqual(old, cur) {
|
||||
sec := cur.(*corev1.Secret)
|
||||
sec, ok := cur.(*corev1.Secret)
|
||||
if !ok {
|
||||
klog.Errorf("unexpected type: %T", cur)
|
||||
}
|
||||
key := k8s.MetaNamespaceKey(sec)
|
||||
|
||||
if !watchedNamespace(sec.Namespace) {
|
||||
|
|
@ -695,8 +716,14 @@ func New(
|
|||
}
|
||||
},
|
||||
UpdateFunc: func(old, cur interface{}) {
|
||||
oeps := old.(*discoveryv1.EndpointSlice)
|
||||
ceps := cur.(*discoveryv1.EndpointSlice)
|
||||
oeps, ok := old.(*discoveryv1.EndpointSlice)
|
||||
if !ok {
|
||||
klog.Errorf("unexpected type: %T", old)
|
||||
}
|
||||
ceps, ok := cur.(*discoveryv1.EndpointSlice)
|
||||
if !ok {
|
||||
klog.Errorf("unexpected type: %T", cur)
|
||||
}
|
||||
if !reflect.DeepEqual(ceps.Endpoints, oeps.Endpoints) {
|
||||
updateCh.In() <- Event{
|
||||
Type: UpdateEvent,
|
||||
|
|
@ -750,7 +777,10 @@ func New(
|
|||
|
||||
cmEventHandler := cache.ResourceEventHandlerFuncs{
|
||||
AddFunc: func(obj interface{}) {
|
||||
cfgMap := obj.(*corev1.ConfigMap)
|
||||
cfgMap, ok := obj.(*corev1.ConfigMap)
|
||||
if !ok {
|
||||
klog.Errorf("unexpected type: %T", obj)
|
||||
}
|
||||
key := k8s.MetaNamespaceKey(cfgMap)
|
||||
handleCfgMapEvent(key, cfgMap, "CREATE")
|
||||
},
|
||||
|
|
@ -759,7 +789,10 @@ func New(
|
|||
return
|
||||
}
|
||||
|
||||
cfgMap := cur.(*corev1.ConfigMap)
|
||||
cfgMap, ok := cur.(*corev1.ConfigMap)
|
||||
if !ok {
|
||||
klog.Errorf("unexpected type: %T", cur)
|
||||
}
|
||||
key := k8s.MetaNamespaceKey(cfgMap)
|
||||
handleCfgMapEvent(key, cfgMap, "UPDATE")
|
||||
},
|
||||
|
|
@ -767,7 +800,10 @@ func New(
|
|||
|
||||
serviceHandler := cache.ResourceEventHandlerFuncs{
|
||||
AddFunc: func(obj interface{}) {
|
||||
svc := obj.(*corev1.Service)
|
||||
svc, ok := obj.(*corev1.Service)
|
||||
if !ok {
|
||||
klog.Errorf("unexpected type: %T", obj)
|
||||
}
|
||||
if svc.Spec.Type == corev1.ServiceTypeExternalName {
|
||||
updateCh.In() <- Event{
|
||||
Type: CreateEvent,
|
||||
|
|
@ -776,7 +812,10 @@ func New(
|
|||
}
|
||||
},
|
||||
DeleteFunc: func(obj interface{}) {
|
||||
svc := obj.(*corev1.Service)
|
||||
svc, ok := obj.(*corev1.Service)
|
||||
if !ok {
|
||||
klog.Errorf("unexpected type: %T", obj)
|
||||
}
|
||||
if svc.Spec.Type == corev1.ServiceTypeExternalName {
|
||||
updateCh.In() <- Event{
|
||||
Type: DeleteEvent,
|
||||
|
|
@ -785,8 +824,14 @@ func New(
|
|||
}
|
||||
},
|
||||
UpdateFunc: func(old, cur interface{}) {
|
||||
oldSvc := old.(*corev1.Service)
|
||||
curSvc := cur.(*corev1.Service)
|
||||
oldSvc, ok := old.(*corev1.Service)
|
||||
if !ok {
|
||||
klog.Errorf("unexpected type: %T", old)
|
||||
}
|
||||
curSvc, ok := cur.(*corev1.Service)
|
||||
if !ok {
|
||||
klog.Errorf("unexpected type: %T", cur)
|
||||
}
|
||||
|
||||
if reflect.DeepEqual(oldSvc, curSvc) {
|
||||
return
|
||||
|
|
@ -821,7 +866,10 @@ func New(
|
|||
}
|
||||
|
||||
// do not wait for informers to read the configmap configuration
|
||||
ns, name, _ := k8s.ParseNameNS(configmap)
|
||||
ns, name, err := k8s.ParseNameNS(configmap)
|
||||
if err != nil {
|
||||
klog.Errorf("unexpected error parsing name and ns: %v", err)
|
||||
}
|
||||
cm, err := client.CoreV1().ConfigMaps(ns).Get(context.TODO(), name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
klog.Warningf("Unexpected error reading configuration configmap: %v", err)
|
||||
|
|
@ -837,10 +885,10 @@ func hasCatchAllIngressRule(spec networkingv1.IngressSpec) bool {
|
|||
return spec.DefaultBackend != nil
|
||||
}
|
||||
|
||||
func checkBadAnnotationValue(annotations map[string]string, badwords string) error {
|
||||
func checkBadAnnotationValue(annotationMap map[string]string, badwords string) error {
|
||||
arraybadWords := strings.Split(strings.TrimSpace(badwords), ",")
|
||||
|
||||
for annotation, value := range annotations {
|
||||
for annotation, value := range annotationMap {
|
||||
if strings.HasPrefix(annotation, fmt.Sprintf("%s/", parser.AnnotationsPrefix)) {
|
||||
for _, forbiddenvalue := range arraybadWords {
|
||||
if strings.Contains(value, forbiddenvalue) {
|
||||
|
|
@ -999,7 +1047,7 @@ func (s *k8sStore) GetService(key string) (*corev1.Service, error) {
|
|||
return s.listers.Service.ByKey(key)
|
||||
}
|
||||
|
||||
func (s *k8sStore) GetIngressClass(ing *networkingv1.Ingress, icConfig *ingressclass.IngressClassConfiguration) (string, error) {
|
||||
func (s *k8sStore) GetIngressClass(ing *networkingv1.Ingress, icConfig *ingressclass.Configuration) (string, error) {
|
||||
// First we try ingressClassName
|
||||
if !icConfig.IgnoreIngressClass && ing.Spec.IngressClassName != nil {
|
||||
iclass, err := s.listers.IngressClass.ByKey(*ing.Spec.IngressClassName)
|
||||
|
|
@ -1010,11 +1058,11 @@ func (s *k8sStore) GetIngressClass(ing *networkingv1.Ingress, icConfig *ingressc
|
|||
}
|
||||
|
||||
// Then we try annotation
|
||||
if ingressclass, ok := ing.GetAnnotations()[ingressclass.IngressKey]; ok {
|
||||
if ingressclass != icConfig.AnnotationValue {
|
||||
if class, ok := ing.GetAnnotations()[ingressclass.IngressKey]; ok {
|
||||
if class != icConfig.AnnotationValue {
|
||||
return "", fmt.Errorf("ingress class annotation is not equal to the expected by Ingress Controller")
|
||||
}
|
||||
return ingressclass, nil
|
||||
return class, nil
|
||||
}
|
||||
|
||||
// Then we accept if the WithoutClass is enabled
|
||||
|
|
@ -1055,7 +1103,10 @@ func (s *k8sStore) ListIngresses() []*ingress.Ingress {
|
|||
// filter ingress rules
|
||||
ingresses := make([]*ingress.Ingress, 0)
|
||||
for _, item := range s.listers.IngressWithAnnotation.List() {
|
||||
ing := item.(*ingress.Ingress)
|
||||
ing, ok := item.(*ingress.Ingress)
|
||||
if !ok {
|
||||
klog.Errorf("unexpected type: %T", item)
|
||||
}
|
||||
ingresses = append(ingresses, ing)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue