-
Notifications
You must be signed in to change notification settings - Fork 22
/
handler.go
64 lines (56 loc) · 1.91 KB
/
handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* SPDX-FileCopyrightText: 2019 SAP SE or an SAP affiliate company and Gardener contributors
*
* SPDX-License-Identifier: Apache-2.0
*/
package ingress
import (
"fmt"
networkingv1 "k8s.io/api/networking/v1"
networkingv1beta1 "k8s.io/api/networking/v1beta1"
"github.com/gardener/controller-manager-library/pkg/controllermanager/controller"
"github.com/gardener/controller-manager-library/pkg/logger"
"github.com/gardener/controller-manager-library/pkg/resources"
"github.com/gardener/cert-management/pkg/cert/source"
ctrlsource "github.com/gardener/cert-management/pkg/controller/source"
)
// CIngressSource is the ingress CertSource
type CIngressSource struct {
source.DefaultCertSource
}
// NewIngressSource creates a CertSource
func NewIngressSource(_ controller.Interface) (source.CertSource, error) {
return &CIngressSource{DefaultCertSource: source.DefaultCertSource{Events: map[resources.ClusterObjectKey]map[string]string{}}}, nil
}
// GetCertsInfo returns CertsInfo for the given object
func (s *CIngressSource) GetCertsInfo(logger logger.LogContext, objData resources.ObjectData) (*source.CertsInfo, error) {
return ctrlsource.GetCertsInfoByCollector(logger, objData, func(data resources.ObjectData) ([]*ctrlsource.TLSData, error) {
var array []*ctrlsource.TLSData
switch data := data.(type) {
case *networkingv1beta1.Ingress:
if data.Spec.TLS == nil {
return nil, nil
}
for _, item := range data.Spec.TLS {
array = append(array, &ctrlsource.TLSData{
SecretName: item.SecretName,
Hosts: item.Hosts,
})
}
return array, nil
case *networkingv1.Ingress:
if data.Spec.TLS == nil {
return nil, nil
}
for _, item := range data.Spec.TLS {
array = append(array, &ctrlsource.TLSData{
SecretName: item.SecretName,
Hosts: item.Hosts,
})
}
return array, nil
default:
return nil, fmt.Errorf("unexpected ingress type: %#v", data)
}
})
}