@@ -84,16 +84,16 @@ func (m *defaultGroupLoader) Load(ctx context.Context, groupID GroupID) (Group,
84
84
85
85
var members []ClassifiedIngress
86
86
var inactiveMembers []* networking.Ingress
87
- finalizer := buildGroupFinalizer (groupID )
88
87
for index := range ingList .Items {
89
88
ing := & ingList .Items [index ]
90
- classifiedIngress , isGroupMember , err := m .isGroupMember (ctx , groupID , ing )
89
+ membershipType , classifiedIng , err := m .checkGroupMembershipType (ctx , groupID , ing )
91
90
if err != nil {
92
- return Group {}, errors .Wrapf (err , "ingress : %v" , k8s .NamespacedName (ing ))
91
+ return Group {}, errors .Wrapf (err , "Ingress : %v" , k8s .NamespacedName (ing ))
93
92
}
94
- if isGroupMember {
95
- members = append (members , classifiedIngress )
96
- } else if m .containsGroupFinalizer (groupID , finalizer , ing ) {
93
+ switch membershipType {
94
+ case groupMembershipTypeActiveMember :
95
+ members = append (members , classifiedIng )
96
+ case groupMembershipTypeInactiveMember :
97
97
inactiveMembers = append (inactiveMembers , ing )
98
98
}
99
99
}
@@ -128,22 +128,47 @@ func (m *defaultGroupLoader) LoadGroupIDsPendingFinalization(_ context.Context,
128
128
return groupIDs
129
129
}
130
130
131
- // isGroupMember checks whether specified Ingress is member of specific IngressGroup.
132
- // If it's group member, a valid ClassifiedIngress will be returned as well.
133
- // NOTE: this function should only error out when it's not certain whether the specified ingress is group member. (e.g. due to APIServer failures).
134
- func (m * defaultGroupLoader ) isGroupMember (ctx context.Context , groupID GroupID , ing * networking.Ingress ) (ClassifiedIngress , bool , error ) {
135
- classifiedIngress , ingGroupID , err := m .loadGroupIDIfAnyHelper (ctx , ing )
131
+ type groupMembershipType int
132
+
133
+ const (
134
+ groupMembershipTypeNone = iota
135
+ groupMembershipTypeActiveMember
136
+ groupMembershipTypeInactiveMember
137
+ )
138
+
139
+ // checkGroupMembership checks whether specified Ingress is members of specific IngressGroup.
140
+ // If it's active group member, a valid ClassifiedIngress will be returned as well.
141
+ func (m * defaultGroupLoader ) checkGroupMembershipType (ctx context.Context , groupID GroupID , ing * networking.Ingress ) (groupMembershipType , ClassifiedIngress , error ) {
142
+ groupFinalizer := buildGroupFinalizer (groupID )
143
+ hasGroupFinalizer := m .containsGroupFinalizer (groupID , groupFinalizer , ing )
144
+ classifiedIng , ingGroupID , err := m .loadGroupIDIfAnyHelper (ctx , ing )
136
145
if err != nil {
137
- if errors .Is (err , ErrInvalidIngressClass ) || errors .Is (err , errInvalidIngressGroup ) {
138
- return ClassifiedIngress {}, false , nil
146
+ // tolerate ErrInvalidIngressClass for Ingresses that hasn't belongs to the group yet.
147
+ // for Ingresses that was belongs to the group, we error out to avoid remove the Ingress from IngressGroup since the IngressClass might be accidentally modified.
148
+ // see https://github.com/kubernetes-sigs/aws-load-balancer-controller/issues/2731
149
+ if errors .Is (err , ErrInvalidIngressClass ) {
150
+ if hasGroupFinalizer {
151
+ return groupMembershipTypeNone , ClassifiedIngress {}, errors .Wrapf (err , "Ingress has invalid IngressClass configuration" )
152
+ }
153
+ return groupMembershipTypeNone , ClassifiedIngress {}, nil
154
+ }
155
+
156
+ // tolerate errInvalidIngressGroup error since an Ingress with a wrong IngressGroup name means to leave the IngressGroup anyway.
157
+ if errors .Is (err , errInvalidIngressGroup ) {
158
+ if hasGroupFinalizer {
159
+ return groupMembershipTypeInactiveMember , ClassifiedIngress {}, nil
160
+ }
161
+ return groupMembershipTypeNone , ClassifiedIngress {}, nil
139
162
}
140
- return ClassifiedIngress {}, false , err
163
+ return groupMembershipTypeNone , ClassifiedIngress {}, err
141
164
}
142
- if ingGroupID == nil {
143
- return ClassifiedIngress {}, false , nil
165
+
166
+ if ingGroupID != nil && * ingGroupID == groupID {
167
+ return groupMembershipTypeActiveMember , classifiedIng , nil
168
+ } else if hasGroupFinalizer {
169
+ return groupMembershipTypeInactiveMember , ClassifiedIngress {}, nil
144
170
}
145
- groupIDMatches := groupID == * ingGroupID
146
- return classifiedIngress , groupIDMatches , nil
171
+ return groupMembershipTypeNone , ClassifiedIngress {}, nil
147
172
}
148
173
149
174
// loadGroupIDIfAnyHelper loads the groupID for Ingress if Ingress belong to any IngressGroup, along with the ClassifiedIngress object.
0 commit comments