Skip to content

Commit

Permalink
fix: change the error when the defaul class and ingClassName are nill
Browse files Browse the repository at this point in the history
  • Loading branch information
yasinlachiny committed Jan 9, 2023
1 parent b8641e1 commit f0b82e3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
Empty file removed d
Empty file.
2 changes: 1 addition & 1 deletion pkg/ingress/class_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (l *defaultClassLoader) Load(ctx context.Context, ing *networking.Ingress)
if defaultClass != "" {
ing.Spec.IngressClassName = &defaultClass
} else {
return ClassConfiguration{}, err
return ClassConfiguration{}, nil
}
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/ingress/class_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package ingress

import (
"context"
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/golang/mock/gomock"
"github.com/google/go-cmp/cmp"
Expand All @@ -18,7 +20,6 @@ import (
"sigs.k8s.io/aws-load-balancer-controller/pkg/webhook"
testclient "sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
"testing"
)

func Test_defaultClassLoader_Load(t *testing.T) {
Expand Down Expand Up @@ -59,7 +60,7 @@ func Test_defaultClassLoader_Load(t *testing.T) {
},
},
},
wantErr: errors.New("invalid ingress class: spec.ingressClassName is nil"),
wantErr: nil,
},
{
name: "when IngressClass not found",
Expand Down
14 changes: 5 additions & 9 deletions pkg/ingress/group_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,29 +206,25 @@ func (m *defaultGroupLoader) classifyIngress(ctx context.Context, ing *networkin
IngClassConfig: ClassConfiguration{},
}, false, nil
}

ingClassConfig, err := m.classLoader.Load(ctx, ing)
if err != nil {
return ClassifiedIngress{
Ing: ing,
IngClassConfig: ClassConfiguration{},
}, false, err
}
if matchesIngressClass := ingClassConfig.IngClass != nil; matchesIngressClass {
if ingClassConfig.IngClass.Spec.Controller == ingressClassControllerALB {
return ClassifiedIngress{
Ing: ing,
IngClassConfig: ingClassConfig,
}, true, nil
}

if matchesIngressClass := ingClassConfig.IngClass != nil && ingClassConfig.IngClass.Spec.Controller == ingressClassControllerALB; matchesIngressClass {
return ClassifiedIngress{
Ing: ing,
IngClassConfig: ingClassConfig,
}, false, nil
}, true, nil
}

return ClassifiedIngress{
Ing: ing,
IngClassConfig: ClassConfiguration{},
IngClassConfig: ingClassConfig,
}, m.manageIngressesWithoutIngressClass, nil
}

Expand Down

0 comments on commit f0b82e3

Please sign in to comment.