@@ -55,6 +55,7 @@ import (
55
55
"github.com/alibaba/higress/pkg/ingress/kube/secret"
56
56
"github.com/alibaba/higress/pkg/ingress/kube/util"
57
57
. "github.com/alibaba/higress/pkg/ingress/log"
58
+ k8serrors "k8s.io/apimachinery/pkg/api/errors"
58
59
)
59
60
60
61
var (
@@ -87,8 +88,6 @@ type controller struct {
87
88
secretController secret.SecretController
88
89
89
90
statusSyncer * statusSyncer
90
-
91
- configMgr * cert.ConfigMgr
92
91
}
93
92
94
93
// NewController creates a new Kubernetes controller
@@ -107,7 +106,6 @@ func NewController(localKubeClient, client kubeclient.Client, options common.Opt
107
106
IngressLog .Infof ("Skipping IngressClass, resource not supported for cluster %s" , options .ClusterId )
108
107
}
109
108
110
- configMgr , _ := cert .NewConfigMgr (options .SystemNamespace , client .Kube ())
111
109
c := & controller {
112
110
options : options ,
113
111
queue : q ,
@@ -118,7 +116,6 @@ func NewController(localKubeClient, client kubeclient.Client, options common.Opt
118
116
serviceInformer : serviceInformer .Informer (),
119
117
serviceLister : serviceInformer .Lister (),
120
118
secretController : secretController ,
121
- configMgr : configMgr ,
122
119
}
123
120
124
121
handler := controllers .LatestVersionHandlerFuncs (controllers .EnqueueForSelf (q ))
@@ -354,7 +351,7 @@ func extractTLSSecretName(host string, tls []ingress.IngressTLS) string {
354
351
return ""
355
352
}
356
353
357
- func (c * controller ) ConvertGateway (convertOptions * common.ConvertOptions , wrapper * common.WrapperConfig ) error {
354
+ func (c * controller ) ConvertGateway (convertOptions * common.ConvertOptions , wrapper * common.WrapperConfig , httpsCredentialConfig * cert. Config ) error {
358
355
if convertOptions == nil {
359
356
return fmt .Errorf ("convertOptions is nil" )
360
357
}
@@ -377,7 +374,6 @@ func (c *controller) ConvertGateway(convertOptions *common.ConvertOptions, wrapp
377
374
common .IncrementInvalidIngress (c .options .ClusterId , common .EmptyRule )
378
375
return fmt .Errorf ("invalid ingress rule %s:%s in cluster %s, either `defaultBackend` or `rules` must be specified" , cfg .Namespace , cfg .Name , c .options .ClusterId )
379
376
}
380
- httpsCredentialConfig , _ := c .configMgr .GetConfigFromConfigmap ()
381
377
for _ , rule := range ingressV1Beta .Rules {
382
378
// Need create builder for every rule.
383
379
domainBuilder := & common.IngressDomainBuilder {
@@ -429,10 +425,23 @@ func (c *controller) ConvertGateway(convertOptions *common.ConvertOptions, wrapp
429
425
// Get tls secret matching the rule host
430
426
secretName := extractTLSSecretName (rule .Host , ingressV1Beta .TLS )
431
427
secretNamespace := cfg .Namespace
432
- // If there is no matching secret, try to get it from configmap.
433
- if secretName == "" && httpsCredentialConfig != nil {
434
- secretName = httpsCredentialConfig .MatchSecretNameByDomain (rule .Host )
435
- secretNamespace = c .options .SystemNamespace
428
+ if secretName != "" {
429
+ if httpsCredentialConfig != nil && httpsCredentialConfig .FallbackForInvalidSecret {
430
+ _ , err := c .secretController .Lister ().Secrets (secretNamespace ).Get (secretName )
431
+ if err != nil {
432
+ if k8serrors .IsNotFound (err ) {
433
+ // If there is no matching secret, try to get it from configmap.
434
+ secretName = httpsCredentialConfig .MatchSecretNameByDomain (rule .Host )
435
+ secretNamespace = c .options .SystemNamespace
436
+ }
437
+ }
438
+ }
439
+ } else {
440
+ // If there is no matching secret, try to get it from configmap.
441
+ if httpsCredentialConfig != nil {
442
+ secretName = httpsCredentialConfig .MatchSecretNameByDomain (rule .Host )
443
+ secretNamespace = c .options .SystemNamespace
444
+ }
436
445
}
437
446
if secretName == "" {
438
447
// There no matching secret, so just skip.
0 commit comments