Skip to content

Commit 1bd272b

Browse files
author
Yuvaraj Kakaraparthi
committed
api refactor
1 parent c6f1a13 commit 1bd272b

16 files changed

+119
-51
lines changed

api/v1alpha3/conversion.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func (src *MachineHealthCheck) ConvertTo(dstRaw conversion.Hub) error {
244244
dst.Spec.UnhealthyRange = restored.Spec.UnhealthyRange
245245
}
246246

247-
dst.Spec.CertificatesMinExpiryDuration = restored.Spec.CertificatesMinExpiryDuration
247+
dst.Spec.Certificates = restored.Spec.Certificates
248248
return nil
249249
}
250250

api/v1alpha3/zz_generated.conversion.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha4/conversion.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func (src *MachineHealthCheck) ConvertTo(dstRaw conversion.Hub) error {
278278
return err
279279
}
280280

281-
dst.Spec.CertificatesMinExpiryDuration = restored.Spec.CertificatesMinExpiryDuration
281+
dst.Spec.Certificates = restored.Spec.Certificates
282282
return nil
283283
}
284284

api/v1alpha4/zz_generated.conversion.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta1/clusterclass_types.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ type MachineHealthCheckClass struct {
166166
// +optional
167167
NodeStartupTimeout *metav1.Duration `json:"nodeStartupTimeout,omitempty"`
168168

169-
// Machines whose certificates are not valid for at least the specified duration will be remediated.
169+
// Certificates contains the information needed to validate the health of machine certificates.
170170
// +optional
171-
CertificatesMinExpiryDuration *metav1.Duration `json:"certificatesMinExpiryDuration,omitempty"`
171+
Certificates *Certificates `json:"certificates,omitempty"`
172172

173173
// RemediationTemplate is a reference to a remediation template
174174
// provided by an infrastructure provider.

api/v1beta1/machinehealthcheck_types.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ type MachineHealthCheckSpec struct {
6161
// +optional
6262
NodeStartupTimeout *metav1.Duration `json:"nodeStartupTimeout,omitempty"`
6363

64-
// Machines whose certificates are not valid for at least the specified duration will be remediated.
64+
// Certificates contains the information needed to validate the health of machine certificates.
6565
// +optional
66-
CertificatesMinExpiryDuration *metav1.Duration `json:"certificatesMinExpiryDuration,omitempty"`
66+
Certificates *Certificates `json:"certificates,omitempty"`
6767

6868
// RemediationTemplate is a reference to a remediation template
6969
// provided by an infrastructure provider.
@@ -77,6 +77,16 @@ type MachineHealthCheckSpec struct {
7777

7878
// ANCHOR_END: MachineHealthCHeckSpec
7979

80+
// ANCHOR: Certificates
81+
82+
type Certificates struct {
83+
// ExpiresWithinDays is the number of days after which certificates is considered to be expired.
84+
// +optional
85+
ExpiresWithinDays *int `json:"expiresWithinDays,omitempty"`
86+
}
87+
88+
// ANCHOR_END: Certificates
89+
8090
// ANCHOR: UnhealthyCondition
8191

8292
// UnhealthyCondition represents a Node condition type and value with a timeout

api/v1beta1/zz_generated.deepcopy.go

+28-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta1/zz_generated.openapi.go

+28-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bootstrap/kubeadm/types/upstreamv1beta1/zz_generated.deepcopy.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bootstrap/kubeadm/types/upstreamv1beta2/zz_generated.deepcopy.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bootstrap/kubeadm/types/upstreamv1beta3/zz_generated.deepcopy.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/cluster.x-k8s.io_clusterclasses.yaml

+19-8
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,15 @@ spec:
419419
if the ControlPlane provider template referenced above is Machine
420420
based and supports setting replicas.
421421
properties:
422-
certificatesMinExpiryDuration:
423-
description: Machines whose certificates are not valid for
424-
at least the specified duration will be remediated.
425-
type: string
422+
certificates:
423+
description: Certificates contains the information needed
424+
to validate the health of machine certificates.
425+
properties:
426+
expiresWithinDays:
427+
description: ExpiresWithinDays is the number of days after
428+
which certificates is considered to be expired.
429+
type: integer
430+
type: object
426431
maxUnhealthy:
427432
anyOf:
428433
- type: integer
@@ -1002,10 +1007,16 @@ spec:
10021007
description: MachineHealthCheck defines a MachineHealthCheck
10031008
for this MachineDeploymentClass.
10041009
properties:
1005-
certificatesMinExpiryDuration:
1006-
description: Machines whose certificates are not valid
1007-
for at least the specified duration will be remediated.
1008-
type: string
1010+
certificates:
1011+
description: Certificates contains the information needed
1012+
to validate the health of machine certificates.
1013+
properties:
1014+
expiresWithinDays:
1015+
description: ExpiresWithinDays is the number of
1016+
days after which certificates is considered to
1017+
be expired.
1018+
type: integer
1019+
type: object
10091020
maxUnhealthy:
10101021
anyOf:
10111022
- type: integer

config/crd/bases/cluster.x-k8s.io_machinehealthchecks.yaml

+9-4
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,15 @@ spec:
585585
spec:
586586
description: Specification of machine health check policy
587587
properties:
588-
certificatesMinExpiryDuration:
589-
description: Machines whose certificates are not valid for at least
590-
the specified duration will be remediated.
591-
type: string
588+
certificates:
589+
description: Certificates contains the information needed to validate
590+
the health of machine certificates.
591+
properties:
592+
expiresWithinDays:
593+
description: ExpiresWithinDays is the number of days after which
594+
certificates is considered to be expired.
595+
type: integer
596+
type: object
592597
clusterName:
593598
description: ClusterName is the name of the Cluster this object belongs
594599
to.

internal/controllers/machinehealthcheck/machinehealthcheck_targets.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@ func (t *healthCheckTarget) needsRemediation(logger logr.Logger, timeoutForMachi
185185
}
186186

187187
// check certificate expiration
188-
if t.MHC.Spec.CertificatesMinExpiryDuration != nil {
188+
if t.MHC.Spec.Certificates != nil && t.MHC.Spec.Certificates.ExpiresWithinDays != nil {
189189
// Check only if the certificate expiry information is available.
190190
if t.Machine.Status.CertificatesExpiryDate != nil {
191191
certificatesExpireAt := t.Machine.Status.CertificatesExpiryDate.Time
192-
if now.Add(t.MHC.Spec.CertificatesMinExpiryDuration.Duration).After(certificatesExpireAt) {
192+
if now.Add(time.Duration(*t.MHC.Spec.Certificates.ExpiresWithinDays) * time.Hour * 24).After(certificatesExpireAt) {
193193
expiresIn := certificatesExpireAt.Sub(now)
194194
expiredInRoundedToMinutes := expiresIn.Round(time.Minute)
195195
conditions.MarkFalse(t.Machine, clusterv1.MachineHealthCheckSucceededCondition, clusterv1.CertificateExpiryReason, clusterv1.ConditionSeverityWarning, "Certificates expire in %s", expiredInRoundedToMinutes.String())

internal/controllers/machinehealthcheck/machinehealthcheck_targets_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
corev1 "k8s.io/api/core/v1"
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2626
"k8s.io/client-go/tools/record"
27+
"k8s.io/utils/pointer"
2728
ctrl "sigs.k8s.io/controller-runtime"
2829
"sigs.k8s.io/controller-runtime/pkg/client"
2930
"sigs.k8s.io/controller-runtime/pkg/client/fake"
@@ -210,7 +211,6 @@ func TestHealthCheckTargets(t *testing.T) {
210211
timeoutForMachineToHaveNode := 10 * time.Minute
211212
disabledTimeoutForMachineToHaveNode := time.Duration(0)
212213

213-
oneWeekDuration := &metav1.Duration{Duration: time.Hour * 24 * 7}
214214
twoDaysFromNow := time.Now().Add(time.Hour * 24 * 2)
215215

216216
// Create a test MHC
@@ -236,7 +236,9 @@ func TestHealthCheckTargets(t *testing.T) {
236236
Timeout: metav1.Duration{Duration: 5 * time.Minute},
237237
},
238238
},
239-
CertificatesMinExpiryDuration: oneWeekDuration,
239+
Certificates: &clusterv1.Certificates{
240+
ExpiresWithinDays: pointer.Int(7),
241+
},
240242
},
241243
}
242244

internal/controllers/topology/cluster/desired_state.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -845,14 +845,14 @@ func computeMachineHealthCheck(healthCheckTarget client.Object, selector *metav1
845845
Namespace: healthCheckTarget.GetNamespace(),
846846
},
847847
Spec: clusterv1.MachineHealthCheckSpec{
848-
ClusterName: clusterName,
849-
Selector: *selector,
850-
UnhealthyConditions: check.UnhealthyConditions,
851-
MaxUnhealthy: check.MaxUnhealthy,
852-
UnhealthyRange: check.UnhealthyRange,
853-
NodeStartupTimeout: check.NodeStartupTimeout,
854-
CertificatesMinExpiryDuration: check.CertificatesMinExpiryDuration,
855-
RemediationTemplate: check.RemediationTemplate,
848+
ClusterName: clusterName,
849+
Selector: *selector,
850+
UnhealthyConditions: check.UnhealthyConditions,
851+
MaxUnhealthy: check.MaxUnhealthy,
852+
UnhealthyRange: check.UnhealthyRange,
853+
NodeStartupTimeout: check.NodeStartupTimeout,
854+
Certificates: check.Certificates,
855+
RemediationTemplate: check.RemediationTemplate,
856856
},
857857
}
858858

0 commit comments

Comments
 (0)