@@ -9,9 +9,11 @@ import (
9
9
10
10
"github.com/go-logr/logr"
11
11
"github.com/kong/go-kong/kong"
12
+ "github.com/samber/lo"
12
13
corev1 "k8s.io/api/core/v1"
13
14
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14
15
16
+ "github.com/kong/kubernetes-ingress-controller/v3/internal/annotations"
15
17
"github.com/kong/kubernetes-ingress-controller/v3/internal/dataplane/kongstate"
16
18
"github.com/kong/kubernetes-ingress-controller/v3/internal/gatewayapi"
17
19
"github.com/kong/kubernetes-ingress-controller/v3/internal/logging"
@@ -55,11 +57,21 @@ func (t *Translator) getGatewayCerts() []certWrapper {
55
57
return certs
56
58
}
57
59
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
61
64
}
62
65
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
+
63
75
for _ , listener := range gateway .Spec .Listeners {
64
76
status , ok := statuses [listener .Name ]
65
77
if ! ok {
@@ -72,14 +84,18 @@ func (t *Translator) getGatewayCerts() []certWrapper {
72
84
continue
73
85
}
74
86
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
+ ) {
83
99
continue
84
100
}
85
101
0 commit comments