@@ -9,9 +9,11 @@ import (
99
1010 "github.com/go-logr/logr"
1111 "github.com/kong/go-kong/kong"
12+ "github.com/samber/lo"
1213 corev1 "k8s.io/api/core/v1"
1314 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1415
16+ "github.com/kong/kubernetes-ingress-controller/v3/internal/annotations"
1517 "github.com/kong/kubernetes-ingress-controller/v3/internal/dataplane/kongstate"
1618 "github.com/kong/kubernetes-ingress-controller/v3/internal/gatewayapi"
1719 "github.com/kong/kubernetes-ingress-controller/v3/internal/logging"
@@ -55,11 +57,21 @@ func (t *Translator) getGatewayCerts() []certWrapper {
5557 return certs
5658 }
5759 for _ , gateway := range gateways {
58- statuses := make (map [gatewayapi.SectionName ]gatewayapi.ListenerStatus , len (gateway .Status .Listeners ))
59- for _ , status := range gateway .Status .Listeners {
60- statuses [status .Name ] = status
60+ gwc , err := s .GetGatewayClass (string (gateway .Spec .GatewayClassName ))
61+ if err != nil {
62+ logger .Error (err , "Failed to get GatewayClass for Gateway, skipping" , "gateway" , gateway .Name , "gateway_class" , gateway .Spec .GatewayClassName )
63+ continue
6164 }
6265
66+ // Skip the gateway when the gateway's GatewayClass is not controlled by the KIC instance.
67+ if gwc .Spec .ControllerName != gatewayapi .GatewayController (t .gatewayControllerName ) {
68+ continue
69+ }
70+
71+ statuses := lo .SliceToMap (gateway .Status .Listeners , func (status gatewayapi.ListenerStatus ) (gatewayapi.SectionName , gatewayapi.ListenerStatus ) {
72+ return status .Name , status
73+ })
74+
6375 for _ , listener := range gateway .Spec .Listeners {
6476 status , ok := statuses [listener .Name ]
6577 if ! ok {
@@ -72,14 +84,18 @@ func (t *Translator) getGatewayCerts() []certWrapper {
7284 continue
7385 }
7486
75- // Check if listener is marked as programmed
76- if ! util .CheckCondition (
77- status .Conditions ,
78- util .ConditionType (gatewayapi .ListenerConditionProgrammed ),
79- util .ConditionReason (gatewayapi .ListenerReasonProgrammed ),
80- metav1 .ConditionTrue ,
81- gateway .Generation ,
82- ) {
87+ // Check if listener is marked as programmed when the gateway's GatewayClass has the "Unmanaged" annotation.
88+ // If the GatewayClass does not have the annotation, the gateway is considered to be managed by other components (for example Kong Operator),
89+ // so we do not check the "Programmed" condition before extracting the certificate from the listener
90+ // to prevent unexpected deletion of certificates when the instance is managed by Kong Operator.
91+ if annotations .ExtractUnmanagedGatewayClassMode (gwc .Annotations ) != "" &&
92+ ! util .CheckCondition (
93+ status .Conditions ,
94+ util .ConditionType (gatewayapi .ListenerConditionProgrammed ),
95+ util .ConditionReason (gatewayapi .ListenerReasonProgrammed ),
96+ metav1 .ConditionTrue ,
97+ gateway .Generation ,
98+ ) {
8399 continue
84100 }
85101
0 commit comments