Skip to content

Commit 2c72c36

Browse files
authored
Control the start of event reporting for expiring certificates (#2232)
1 parent 8edda88 commit 2c72c36

File tree

7 files changed

+31
-7
lines changed

7 files changed

+31
-7
lines changed

examples/kustomization/base/tenant.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ spec:
224224
## Enable automatic Kubernetes based certificate generation and signing as explained in
225225
## https://kubernetes.io/docs/tasks/tls/managing-tls-in-a-cluster
226226
requestAutoCert: true
227+
# The minimum number of days to expiry before an alert for an expiring certificate is fired.
228+
# In the below example, if a given certificate will expire in 7 days then expiration events will only be triggered 1 day before expiry
229+
# certExpiryAlertThreshold: 1
227230
## Prometheus setup for MinIO Tenant.
228231
# prometheus:
229232
# image: "" # defaults to quay.io/prometheus/prometheus:RELEASE.2024-07-16T23-46-41Z

helm/operator/templates/minio.min.io_tenants.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,9 @@ spec:
875875
type: string
876876
type: array
877877
type: object
878+
certExpiryAlertThreshold:
879+
format: int32
880+
type: integer
878881
configuration:
879882
properties:
880883
name:

helm/tenant/templates/tenant.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ spec:
9494
externalCertSecret: {{- toYaml . | nindent 6 }}
9595
{{- end }}
9696
requestAutoCert: {{ dig "certificate" "requestAutoCert" false . }}
97+
{{- if ((.certificate).certExpiryAlertThreshold) }}
98+
certExpiryAlertThreshold: {{ ((.certificate).certExpiryAlertThreshold) }}
99+
{{- end }}
97100
{{- if dig "s3" "bucketDNS" false . }}
98101
{{- fail "Value 'tenant.s3.bucketDNS' is deprecated since Operator v4.3.2, use 'tenant.features.bucketDNS' instead" }}
99102
{{- end }}

helm/tenant/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ tenant:
268268
# Enable automatic Kubernetes based `certificate generation and signing <https://kubernetes.io/docs/tasks/tls/managing-tls-in-a-cluster>`__
269269
requestAutoCert: true
270270
###
271+
# The minimum number of days to expiry before an alert for an expiring certificate is fired.
272+
# In the below example, if a given certificate will expire in 7 days then expiration events will only be triggered 1 day before expiry
273+
# certExpiryAlertThreshold: 1
274+
###
271275
# This field is used only when ``requestAutoCert: true``.
272276
# Use this field to set CommonName for the auto-generated certificate.
273277
# MinIO defaults to using the internal Kubernetes DNS name for the pod

pkg/apis/minio.min.io/v2/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ type TenantSpec struct {
235235
// +optional
236236
RequestAutoCert *bool `json:"requestAutoCert,omitempty"`
237237

238+
// CertExpiryAlertThreshold is the minimum number of days to expiry before an alert for an expiring certificate is fired.
239+
// +optional
240+
CertExpiryAlertThreshold *int32 `json:"certExpiryAlertThreshold,omitempty"`
241+
238242
// Liveness Probe for container liveness. Container will be restarted if the probe fails.
239243
// +optional
240244
Liveness *corev1.Probe `json:"liveness,omitempty"`

pkg/controller/custom.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,27 @@ func (c *Controller) getCustomCertificates(ctx context.Context, tenant *miniov2.
102102
}
103103
// Register event in case of certificate expiring
104104
expiresIn := time.Until(cert.NotAfter)
105-
expiresInDays := int64(expiresIn.Hours() / 24)
105+
expiresInDays := int32(expiresIn.Hours() / 24)
106106
expiresInHours := int64(math.Mod(expiresIn.Hours(), 24))
107107
expiresInMinutes := int64(math.Mod(expiresIn.Minutes(), 60))
108108
expiresInSeconds := int64(math.Mod(expiresIn.Seconds(), 60))
109109
expiresInHuman := fmt.Sprintf("%v days, %v hours, %v minutes, %v seconds", expiresInDays, expiresInHours, expiresInMinutes, expiresInSeconds)
110110

111-
if expiresInDays >= 10 && expiresInDays < 30 {
112-
c.recorder.Event(tenant, corev1.EventTypeWarning, "CertificateExpiring", fmt.Sprintf("%s certificate '%s' is expiring in %d days", certType, secret.Name, expiresInDays))
113-
}
114-
if expiresInDays > 0 && expiresInDays < 10 {
115-
c.recorder.Event(tenant, corev1.EventTypeWarning, "CertificateExpiryImminent", fmt.Sprintf("%s certificate '%s' is expiring in %d days", certType, secret.Name, expiresInDays))
111+
if tenant.Spec.CertExpiryAlertThreshold == nil || expiresInDays < *tenant.Spec.CertExpiryAlertThreshold {
112+
if expiresInDays >= 10 && expiresInDays < 30 {
113+
c.recorder.Event(tenant, corev1.EventTypeWarning, "CertificateExpiring", fmt.Sprintf("%s certificate '%s' is expiring in %d days", certType, secret.Name, expiresInDays))
114+
}
115+
if expiresInDays > 0 && expiresInDays < 10 {
116+
c.recorder.Event(tenant, corev1.EventTypeWarning, "CertificateExpiryImminent", fmt.Sprintf("%s certificate '%s' is expiring in %d days", certType, secret.Name, expiresInDays))
117+
}
118+
if expiresIn <= 0 {
119+
c.recorder.Event(tenant, corev1.EventTypeWarning, "CertificateExpired", fmt.Sprintf("%s certificate '%s' has expired", certType, secret.Name))
120+
}
116121
}
117122
if expiresIn > 0 && expiresIn < 24*time.Hour {
118123
expiresInHuman = fmt.Sprintf("%v hours, %v minutes, and %v seconds", expiresInHours, expiresInMinutes, expiresInSeconds)
119124
}
120125
if expiresIn <= 0 {
121-
c.recorder.Event(tenant, corev1.EventTypeWarning, "CertificateExpired", fmt.Sprintf("%s certificate '%s' has expired", certType, secret.Name))
122126
expiresInHuman = "EXPIRED"
123127
}
124128

resources/base/crds/minio.min.io_tenants.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,9 @@ spec:
875875
type: string
876876
type: array
877877
type: object
878+
certExpiryAlertThreshold:
879+
format: int32
880+
type: integer
878881
configuration:
879882
properties:
880883
name:

0 commit comments

Comments
 (0)