-
Notifications
You must be signed in to change notification settings - Fork 22
/
interface.go
119 lines (98 loc) · 3.46 KB
/
interface.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* SPDX-FileCopyrightText: 2019 SAP SE or an SAP affiliate company and Gardener contributors
*
* SPDX-License-Identifier: Apache-2.0
*/
package source
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"github.com/gardener/controller-manager-library/pkg/controllermanager/controller"
"github.com/gardener/controller-manager-library/pkg/controllermanager/controller/reconcile"
"github.com/gardener/controller-manager-library/pkg/logger"
"github.com/gardener/controller-manager-library/pkg/resources"
api "github.com/gardener/cert-management/pkg/apis/cert/v1alpha1"
)
// CertInfo contains basic certificate data.
type CertInfo struct {
SecretNamespace *string
SecretName string
Domains []string
IssuerName *string
FollowCNAME bool
SecretLabels map[string]string
PreferredChain string
PrivateKeyAlgorithm string
PrivateKeySize int
Annotations map[string]string
}
// CertsInfo contains a map of CertInfo.
type CertsInfo struct {
Certs map[string]CertInfo
}
// CertFeedback is an interface for reporting certificate status.
type CertFeedback interface {
Succeeded()
Pending(info *CertInfo, msg string)
Ready(info *CertInfo, msg string)
Failed(info *CertInfo, err error)
}
// CertSource is...
type CertSource interface {
Start() error
Setup() error
CreateCertFeedback(logger logger.LogContext, obj resources.Object) CertFeedback
GetCertsInfo(logger logger.LogContext, objData resources.ObjectData) (*CertsInfo, error)
Delete(logger logger.LogContext, obj resources.Object) reconcile.Status
Deleted(logger logger.LogContext, key resources.ClusterObjectKey)
}
// CertSourceType provides basic functionalilty.
type CertSourceType interface {
Name() string
GroupKind() schema.GroupKind
Create(controller.Interface) (CertSource, error)
}
// CertTargetExtractor is type for extractor.
type CertTargetExtractor func(logger logger.LogContext, objData resources.ObjectData) (string, error)
// CertSourceCreator is type for creator.
type CertSourceCreator func(controller.Interface) (CertSource, error)
// CertState contains internal certificate state.
type CertState struct {
// Spec is original spec from CR.
Spec api.CertificateSpec
// State is the state string.
State string
// Message is the optional status or error message.
Message *string
// CreationTimestamp contains the creation timestamp of the certificate.
CreationTimestamp metav1.Time
}
// CertCurrentState contains the current state.
type CertCurrentState struct {
CertStates map[string]*CertState
}
// ContainsSecretName returns true if name is in map.
func (s *CertCurrentState) ContainsSecretName(name string) bool {
_, ok := s.CertStates[name]
return ok
}
// NewCertSourceTypeForExtractor creates CertSourceType for extractor.
func NewCertSourceTypeForExtractor(name string, kind schema.GroupKind, handler CertTargetExtractor) CertSourceType {
return &handlercertsourcetype{certsourcetype{name, kind}, NewDefaultCertSource(handler)}
}
// NewCertSourceTypeForCreator creates CertSourceType for creator.
func NewCertSourceTypeForCreator(name string, kind schema.GroupKind, handler CertSourceCreator) CertSourceType {
return &creatorcertsourcetype{certsourcetype{name, kind}, handler}
}
type certsourcetype struct {
name string
kind schema.GroupKind
}
type handlercertsourcetype struct {
certsourcetype
DefaultCertSource
}
type creatorcertsourcetype struct {
certsourcetype
handler CertSourceCreator
}