Skip to content

Commit

Permalink
Change CertificateExpireDate to type *metav1.time
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Louis Sergent committed Aug 31, 2022
1 parent e656933 commit 8dc1fe9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type ConfigurationState string
type InitClusterNode bool

// Certificate expire date contains the date when the certificate should be renewed
type CertificateExpireDate string
type CertificateExpireDate = *metav1.Time

// PKIBackend represents an interface implementing the PKIManager
type PKIBackend string
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions config/crd/bases/nifi.konpyutaika.com_nificlusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8445,6 +8445,7 @@ spec:
certificateExpireDate:
description: Certificate expire date contains the date when
the certificate should be renewed
format: date-time
type: string
configurationState:
description: ConfigurationState holds info about the config
Expand Down Expand Up @@ -8492,6 +8493,7 @@ spec:
ready
type: boolean
required:
- certificateExpireDate
- configurationState
- gracefulActionState
- initClusterNode
Expand Down
2 changes: 1 addition & 1 deletion controllers/nificluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (r *NifiClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
if err != nil {
return RequeueWithError(r.Log, err.Error(), err)
}
certRenewalTime := v1alpha1.CertificateExpireDate(cert.Status.RenewalTime.Time.Format(time.RFC3339))
certRenewalTime := v1alpha1.CertificateExpireDate(cert.Status.RenewalTime)

for nId := range instance.Spec.Nodes {
if err := k8sutil.UpdateNodeStatus(r.Client, []string{fmt.Sprint(instance.Spec.Nodes[nId].Id)}, instance, v1alpha1.IsInitClusterNode, r.Log); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions helm/nifikop/crds/nifi.konpyutaika.com_nificlusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8445,6 +8445,7 @@ spec:
certificateExpireDate:
description: Certificate expire date contains the date when
the certificate should be renewed
format: date-time
type: string
configurationState:
description: ConfigurationState holds info about the config
Expand Down Expand Up @@ -8492,6 +8493,7 @@ spec:
ready
type: boolean
required:
- certificateExpireDate
- configurationState
- gracefulActionState
- initClusterNode
Expand Down
22 changes: 15 additions & 7 deletions pkg/pki/certmanagerpki/certmanager_pki.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package certmanagerpki
import (
"context"
"fmt"
"time"

certv1 "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1"
certmeta "github.com/jetstack/cert-manager/pkg/apis/meta/v1"
Expand Down Expand Up @@ -49,10 +48,14 @@ func (c *certManager) IsCertificateExpired(ctx context.Context, pod *corev1.Pod,
return false
}

// Get certificate renewal w/ time format RFC3339: “2006-01-02T15:04:05Z07:00”
certRenewalTime := cert.Status.RenewalTime.Time.Format(time.RFC3339)
certRenewalTime := cert.Status.RenewalTime.Time
// certRenewalTime := metav1.Now().Time
certificateExpireDate := c.cluster.Status.NodesState[pod.Labels["nodeId"]].CertificateExpireDate
return string(certificateExpireDate) != certRenewalTime
certificateExpireDateTime := metav1.Now().Time
if certificateExpireDate != nil {
certificateExpireDateTime = certificateExpireDate.Time
}
return certificateExpireDateTime != certRenewalTime
}

func (c *certManager) UpdateCertificateStatusDate(ctx context.Context, pod *corev1.Pod, logger zap.Logger) error {
Expand All @@ -65,11 +68,16 @@ func (c *certManager) UpdateCertificateStatusDate(ctx context.Context, pod *core

nodeId := pod.Labels["nodeId"]

// Get certificate renewal w/ time format RFC3339: “2006-01-02T15:04:05Z07:00”
certRenewalTime := v1alpha1.CertificateExpireDate(cert.Status.RenewalTime.Time.Format(time.RFC3339))
certRenewalTime := v1alpha1.CertificateExpireDate(cert.Status.RenewalTime)
// test := metav1.NewTime(time.Now())
// certRenewalTime := v1alpha1.CertificateExpireDate(&test)
certificateExpireDate := c.cluster.Status.NodesState[nodeId].CertificateExpireDate
certificateExpireDateTime := metav1.Now().Time
if certificateExpireDate != nil {
certificateExpireDateTime = certificateExpireDate.Time
}

if string(certificateExpireDate) != string(certRenewalTime) {
if certificateExpireDateTime != certRenewalTime.Time {
if err := k8sutil.UpdateNodeStatus(c.client, []string{nodeId}, c.cluster, certRenewalTime, logger); err != nil {
logger.Error("Fail to update CertificateExpireDate", zap.Error(err))
return err
Expand Down

0 comments on commit 8dc1fe9

Please sign in to comment.