/
domainmapping_lifecycle.go
180 lines (153 loc) · 7.38 KB
/
domainmapping_lifecycle.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
Copyright 2020 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1alpha1
import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
netv1alpha1 "knative.dev/networking/pkg/apis/networking/v1alpha1"
"knative.dev/pkg/apis"
)
var domainMappingCondSet = apis.NewLivingConditionSet(
DomainMappingConditionDomainClaimed,
DomainMappingConditionReferenceResolved,
DomainMappingConditionIngressReady,
DomainMappingConditionCertificateProvisioned,
)
// GetConditionSet retrieves the condition set for this resource. Implements the KRShaped interface.
func (*DomainMapping) GetConditionSet() apis.ConditionSet {
return domainMappingCondSet
}
// GetGroupVersionKind returns the GroupVersionKind.
func (dm *DomainMapping) GetGroupVersionKind() schema.GroupVersionKind {
return SchemeGroupVersion.WithKind("DomainMapping")
}
// IsReady returns true if the DomainMapping is ready.
func (dms *DomainMappingStatus) IsReady() bool {
return domainMappingCondSet.Manage(dms).IsHappy()
}
// IsReady returns true if the Status condition DomainMappingConditionReady
// is true and the latest spec has been observed.
func (dm *DomainMapping) IsReady() bool {
dms := dm.Status
return dms.ObservedGeneration == dm.Generation &&
dms.GetCondition(DomainMappingConditionReady).IsTrue()
}
// InitializeConditions sets the initial values to the conditions.
func (dms *DomainMappingStatus) InitializeConditions() {
domainMappingCondSet.Manage(dms).InitializeConditions()
}
const (
// AutoTLSNotEnabledMessage is the message which is set on the
// DomainMappingConditionCertificateProvisioned condition when it is set to True
// because AutoTLS was not enabled.
AutoTLSNotEnabledMessage = "autoTLS is not enabled"
// TLSCertificateProvidedExternally indicates that a TLS secret won't be created or managed
// instead a reference to an existing TLS secret should have been provided in the DomainMapping spec
TLSCertificateProvidedExternally = "TLS certificate was provided externally"
)
// MarkTLSNotEnabled sets DomainMappingConditionCertificateProvisioned to true when
// certificate provisioning was skipped because TLS was not enabled.
func (dms *DomainMappingStatus) MarkTLSNotEnabled(msg string) {
domainMappingCondSet.Manage(dms).MarkTrueWithReason(DomainMappingConditionCertificateProvisioned,
"TLSNotEnabled", msg)
}
func (dms *DomainMappingStatus) MarkCertificateNotRequired(msg string) {
domainMappingCondSet.Manage(dms).MarkTrueWithReason(DomainMappingConditionCertificateProvisioned,
"CertificateExternallyProvided", msg)
}
// MarkCertificateReady marks the DomainMappingConditionCertificateProvisioned
// condition to indicate that the Certificate is ready.
func (dms *DomainMappingStatus) MarkCertificateReady(name string) {
domainMappingCondSet.Manage(dms).MarkTrue(DomainMappingConditionCertificateProvisioned)
}
// MarkCertificateNotReady marks the DomainMappingConditionCertificateProvisioned
// condition to indicate that the Certificate is not ready.
func (dms *DomainMappingStatus) MarkCertificateNotReady(name string) {
domainMappingCondSet.Manage(dms).MarkUnknown(DomainMappingConditionCertificateProvisioned,
"CertificateNotReady",
"Certificate %s is not ready.", name)
}
// MarkCertificateNotOwned changes the DomainMappingConditionCertificateProvisioned
// status to be false with the reason being that there is an existing
// certificate with the name we wanted to use.
func (dms *DomainMappingStatus) MarkCertificateNotOwned(name string) {
domainMappingCondSet.Manage(dms).MarkFalse(DomainMappingConditionCertificateProvisioned,
"CertificateNotOwned",
"There is an existing certificate %s that we don't own.", name)
}
// MarkCertificateProvisionFailed marks the
// DomainMappingConditionCertificateProvisioned condition to indicate that the
// Certificate provisioning failed.
func (dms *DomainMappingStatus) MarkCertificateProvisionFailed(name string) {
domainMappingCondSet.Manage(dms).MarkFalse(DomainMappingConditionCertificateProvisioned,
"CertificateProvisionFailed",
"Certificate %s failed to be provisioned.", name)
}
// MarkHTTPDowngrade sets DomainMappingConditionCertificateProvisioned to true when plain
// HTTP is enabled even when Certificate is not ready.
func (dms *DomainMappingStatus) MarkHTTPDowngrade(name string) {
domainMappingCondSet.Manage(dms).MarkTrueWithReason(DomainMappingConditionCertificateProvisioned,
"HTTPDowngrade",
"Certificate %s is not ready downgrade HTTP.", name)
}
// MarkIngressNotConfigured changes the IngressReady condition to be unknown to reflect
// that the Ingress does not yet have a Status.
func (dms *DomainMappingStatus) MarkIngressNotConfigured() {
domainMappingCondSet.Manage(dms).MarkUnknown(DomainMappingConditionIngressReady,
"IngressNotConfigured", "Ingress has not yet been reconciled.")
}
// MarkDomainClaimed updates the DomainMappingConditionDomainClaimed condition
// to indicate that the domain was successfully claimed.
func (dms *DomainMappingStatus) MarkDomainClaimed() {
domainMappingCondSet.Manage(dms).MarkTrue(DomainMappingConditionDomainClaimed)
}
// MarkDomainClaimNotOwned updates the DomainMappingConditionDomainClaimed
// condition to indicate that the domain is already in use by another
// DomainMapping.
func (dms *DomainMappingStatus) MarkDomainClaimNotOwned() {
domainMappingCondSet.Manage(dms).MarkFalse(DomainMappingConditionDomainClaimed, "DomainAlreadyClaimed",
"The domain name is already in use by another DomainMapping")
}
// MarkDomainClaimFailed updates the DomainMappingConditionDomainClaimed
// condition to indicate that creating the ClusterDomainClaim failed.
func (dms *DomainMappingStatus) MarkDomainClaimFailed(reason string) {
domainMappingCondSet.Manage(dms).MarkFalse(DomainMappingConditionDomainClaimed, "DomainClaimFailed", reason)
}
// MarkReferenceResolved sets the DomainMappingConditionReferenceResolved
// condition to true.
func (dms *DomainMappingStatus) MarkReferenceResolved() {
domainMappingCondSet.Manage(dms).MarkTrue(DomainMappingConditionReferenceResolved)
}
// MarkReferenceNotResolved sets the DomainMappingConditionReferenceResolved
// condition to false.
func (dms *DomainMappingStatus) MarkReferenceNotResolved(reason string) {
domainMappingCondSet.Manage(dms).MarkFalse(DomainMappingConditionReferenceResolved, "ResolveFailed", reason)
}
// PropagateIngressStatus updates the DomainMappingConditionIngressReady
// condition according to the underlying Ingress's status.
func (dms *DomainMappingStatus) PropagateIngressStatus(cs netv1alpha1.IngressStatus) {
cc := cs.GetCondition(netv1alpha1.IngressConditionReady)
if cc == nil {
dms.MarkIngressNotConfigured()
return
}
m := domainMappingCondSet.Manage(dms)
switch cc.Status {
case corev1.ConditionTrue:
m.MarkTrue(DomainMappingConditionIngressReady)
case corev1.ConditionFalse:
m.MarkFalse(DomainMappingConditionIngressReady, cc.Reason, cc.Message)
case corev1.ConditionUnknown:
m.MarkUnknown(DomainMappingConditionIngressReady, cc.Reason, cc.Message)
}
}