Skip to content

Commit be65579

Browse files
committed
update v2
1 parent 718c0fd commit be65579

File tree

14 files changed

+198
-196
lines changed

14 files changed

+198
-196
lines changed

internal/controller/consumer_controller.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/apache/apisix-ingress-controller/internal/controller/indexer"
3636
"github.com/apache/apisix-ingress-controller/internal/controller/status"
3737
"github.com/apache/apisix-ingress-controller/internal/provider"
38+
"github.com/apache/apisix-ingress-controller/internal/utils"
3839
)
3940

4041
// ConsumerReconciler reconciles a Gateway object.
@@ -215,11 +216,7 @@ func (r *ConsumerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
215216
statusErr = err
216217
}
217218

218-
rk := provider.ResourceKind{
219-
Kind: consumer.Kind,
220-
Namespace: consumer.Namespace,
221-
Name: consumer.Name,
222-
}
219+
rk := utils.NamespacedNameKind(consumer)
223220

224221
if err := ProcessGatewayProxy(r.Client, tctx, gateway, rk); err != nil {
225222
r.Log.Error(err, "failed to process gateway proxy", "gateway", gateway)

internal/controller/gateway_controller.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"github.com/apache/apisix-ingress-controller/internal/controller/indexer"
3838
"github.com/apache/apisix-ingress-controller/internal/controller/status"
3939
"github.com/apache/apisix-ingress-controller/internal/provider"
40+
"github.com/apache/apisix-ingress-controller/internal/utils"
4041
)
4142

4243
// GatewayReconciler reconciles a Gateway object.
@@ -142,11 +143,7 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
142143

143144
var addrs []gatewayv1.GatewayStatusAddress
144145

145-
rk := provider.ResourceKind{
146-
Kind: gateway.Kind,
147-
Namespace: gateway.Namespace,
148-
Name: gateway.Name,
149-
}
146+
rk := utils.NamespacedNameKind(gateway)
150147

151148
gatewayProxy, ok := tctx.GatewayProxies[rk]
152149
if !ok {
@@ -175,6 +172,13 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
175172
return ctrl.Result{}, err
176173
}
177174

175+
if err := r.Provider.Update(ctx, tctx, gateway); err != nil {
176+
acceptStatus = conditionStatus{
177+
status: false,
178+
msg: err.Error(),
179+
}
180+
}
181+
178182
accepted := SetGatewayConditionAccepted(gateway, acceptStatus.status, acceptStatus.msg)
179183
programmed := SetGatewayConditionProgrammed(gateway, conditionProgrammedStatus, conditionProgrammedMsg)
180184
if accepted || programmed || len(addrs) > 0 || len(listenerStatuses) > 0 {
@@ -203,10 +207,6 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
203207
return ctrl.Result{}, nil
204208
}
205209

206-
if err := r.Provider.Update(ctx, tctx, gateway); err != nil {
207-
return ctrl.Result{}, fmt.Errorf("failed to update gateway %s: %w", req.NamespacedName, err)
208-
}
209-
210210
return ctrl.Result{}, nil
211211
}
212212

@@ -410,12 +410,7 @@ func (r *GatewayReconciler) listReferenceGrantsForGateway(ctx context.Context, o
410410
}
411411

412412
func (r *GatewayReconciler) processInfrastructure(tctx *provider.TranslateContext, gateway *gatewayv1.Gateway) error {
413-
rk := provider.ResourceKind{
414-
Kind: gateway.Kind,
415-
Namespace: gateway.Namespace,
416-
Name: gateway.Name,
417-
}
418-
return ProcessGatewayProxy(r.Client, tctx, gateway, rk)
413+
return ProcessGatewayProxy(r.Client, tctx, gateway, utils.NamespacedNameKind(gateway))
419414
}
420415

421416
func (r *GatewayReconciler) processListenerConfig(tctx *provider.TranslateContext, gateway *gatewayv1.Gateway) {

internal/controller/httproute_controller.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
"github.com/apache/apisix-ingress-controller/internal/controller/indexer"
4545
"github.com/apache/apisix-ingress-controller/internal/controller/status"
4646
"github.com/apache/apisix-ingress-controller/internal/provider"
47+
"github.com/apache/apisix-ingress-controller/internal/utils"
4748
)
4849

4950
// HTTPRouteReconciler reconciles a GatewayClass object.
@@ -169,11 +170,7 @@ func (r *HTTPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
169170
tctx := provider.NewDefaultTranslateContext(ctx)
170171

171172
tctx.RouteParentRefs = hr.Spec.ParentRefs
172-
rk := provider.ResourceKind{
173-
Kind: hr.Kind,
174-
Namespace: hr.Namespace,
175-
Name: hr.Name,
176-
}
173+
rk := utils.NamespacedNameKind(hr)
177174
for _, gateway := range gateways {
178175
if err := ProcessGatewayProxy(r.Client, tctx, gateway.Gateway, rk); err != nil {
179176
acceptStatus.status = false
@@ -225,9 +222,6 @@ func (r *HTTPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
225222
hr.Status.Parents = append(hr.Status.Parents, parentStatus)
226223
}
227224

228-
r.Log.Info("updating HTTPRoute status start", "key", req.NamespacedName,
229-
"status", hr.Status)
230-
231225
r.Updater.Update(status.Update{
232226
NamespacedName: NamespacedName(hr),
233227
Resource: &gatewayv1.HTTPRoute{},
@@ -238,8 +232,6 @@ func (r *HTTPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
238232
panic(err)
239233
}
240234
hCopy := h.DeepCopy()
241-
r.Log.Info("updating HTTPRoute status", "key", req.NamespacedName,
242-
"status", hr.Status)
243235
hCopy.Status = hr.Status
244236
return hCopy
245237
}),

internal/controller/ingress_controller.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343
"github.com/apache/apisix-ingress-controller/internal/controller/indexer"
4444
"github.com/apache/apisix-ingress-controller/internal/controller/status"
4545
"github.com/apache/apisix-ingress-controller/internal/provider"
46+
"github.com/apache/apisix-ingress-controller/internal/utils"
4647
)
4748

4849
// IngressReconciler reconciles a Ingress object.
@@ -601,11 +602,7 @@ func (r *IngressReconciler) processBackendService(tctx *provider.TranslateContex
601602
func (r *IngressReconciler) updateStatus(ctx context.Context, tctx *provider.TranslateContext, ingress *networkingv1.Ingress, ingressClass *networkingv1.IngressClass) error {
602603
var loadBalancerStatus networkingv1.IngressLoadBalancerStatus
603604

604-
ingressClassKind := provider.ResourceKind{
605-
Kind: ingressClass.Kind,
606-
Namespace: ingressClass.Namespace,
607-
Name: ingressClass.Name,
608-
}
605+
ingressClassKind := utils.NamespacedNameKind(ingressClass)
609606

610607
gatewayProxy, ok := tctx.GatewayProxies[ingressClassKind]
611608
if !ok {
@@ -689,17 +686,8 @@ func (r *IngressReconciler) processIngressClassParameters(ctx context.Context, t
689686
return nil
690687
}
691688

692-
ingressClassKind := provider.ResourceKind{
693-
Kind: ingressClass.Kind,
694-
Namespace: ingressClass.Namespace,
695-
Name: ingressClass.Name,
696-
}
697-
698-
ingressKind := provider.ResourceKind{
699-
Kind: ingress.Kind,
700-
Namespace: ingress.Namespace,
701-
Name: ingress.Name,
702-
}
689+
ingressClassKind := utils.NamespacedNameKind(ingressClass)
690+
ingressKind := utils.NamespacedNameKind(ingress)
703691

704692
parameters := ingressClass.Spec.Parameters
705693
// check if the parameters reference GatewayProxy

internal/controller/ingressclass_controller.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/apache/apisix-ingress-controller/api/v1alpha1"
3333
"github.com/apache/apisix-ingress-controller/internal/controller/indexer"
3434
"github.com/apache/apisix-ingress-controller/internal/provider"
35+
"github.com/apache/apisix-ingress-controller/internal/utils"
3536
)
3637

3738
// IngressClassReconciler reconciles a IngressClass object.
@@ -196,11 +197,7 @@ func (r *IngressClassReconciler) processInfrastructure(tctx *provider.TranslateC
196197
return fmt.Errorf("failed to get gateway proxy: %w", err)
197198
}
198199

199-
rk := provider.ResourceKind{
200-
Kind: ingressClass.Kind,
201-
Namespace: ingressClass.Namespace,
202-
Name: ingressClass.Name,
203-
}
200+
rk := utils.NamespacedNameKind(ingressClass)
204201

205202
tctx.GatewayProxies[rk] = *gatewayProxy
206203
tctx.ResourceParentRefs[rk] = append(tctx.ResourceParentRefs[rk], rk)

internal/controller/utils.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
networkingv1 "k8s.io/api/networking/v1"
3131
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3232
"k8s.io/apimachinery/pkg/labels"
33-
"k8s.io/apimachinery/pkg/types"
33+
k8stypes "k8s.io/apimachinery/pkg/types"
3434
"sigs.k8s.io/controller-runtime/pkg/client"
3535
"sigs.k8s.io/controller-runtime/pkg/event"
3636
"sigs.k8s.io/controller-runtime/pkg/predicate"
@@ -41,6 +41,8 @@ import (
4141
"github.com/apache/apisix-ingress-controller/api/v1alpha1"
4242
"github.com/apache/apisix-ingress-controller/internal/controller/config"
4343
"github.com/apache/apisix-ingress-controller/internal/provider"
44+
"github.com/apache/apisix-ingress-controller/internal/types"
45+
"github.com/apache/apisix-ingress-controller/internal/utils"
4446
)
4547

4648
const (
@@ -772,7 +774,7 @@ func getListenerStatus(
772774
break
773775
}
774776

775-
secretNN := types.NamespacedName{
777+
secretNN := k8stypes.NamespacedName{
776778
Namespace: string(*cmp.Or(ref.Namespace, (*gatewayv1.Namespace)(&gateway.Namespace))),
777779
Name: string(ref.Name),
778780
}
@@ -855,7 +857,7 @@ func SplitMetaNamespaceKey(key string) (namespace, name string, err error) {
855857
return "", "", fmt.Errorf("unexpected key format: %q", key)
856858
}
857859

858-
func ProcessGatewayProxy(r client.Client, tctx *provider.TranslateContext, gateway *gatewayv1.Gateway, rk provider.ResourceKind) error {
860+
func ProcessGatewayProxy(r client.Client, tctx *provider.TranslateContext, gateway *gatewayv1.Gateway, rk types.NamespacedNameKind) error {
859861
if gateway == nil {
860862
return nil
861863
}
@@ -864,11 +866,7 @@ func ProcessGatewayProxy(r client.Client, tctx *provider.TranslateContext, gatew
864866
return nil
865867
}
866868

867-
gatewayKind := provider.ResourceKind{
868-
Kind: gateway.Kind,
869-
Namespace: gateway.Namespace,
870-
Name: gateway.Name,
871-
}
869+
gatewayKind := utils.NamespacedNameKind(gateway)
872870

873871
ns := gateway.GetNamespace()
874872
paramRef := infra.ParametersRef
@@ -910,7 +908,7 @@ func ProcessGatewayProxy(r client.Client, tctx *provider.TranslateContext, gatew
910908
"gatewayproxy", gatewayProxy.Name,
911909
"secret", secretRef.Name)
912910

913-
tctx.Secrets[types.NamespacedName{
911+
tctx.Secrets[k8stypes.NamespacedName{
914912
Namespace: ns,
915913
Name: secretRef.Name,
916914
}] = secret
@@ -1148,8 +1146,8 @@ func checkReferenceGrant(ctx context.Context, cli client.Client, obj v1beta1.Ref
11481146
return false
11491147
}
11501148

1151-
func NamespacedName(obj client.Object) types.NamespacedName {
1152-
return types.NamespacedName{
1149+
func NamespacedName(obj client.Object) k8stypes.NamespacedName {
1150+
return k8stypes.NamespacedName{
11531151
Namespace: obj.GetNamespace(),
11541152
Name: obj.GetName(),
11551153
}

0 commit comments

Comments
 (0)