Skip to content

Commit

Permalink
Rotate kubeconfig before it expires
Browse files Browse the repository at this point in the history
  • Loading branch information
ttreptow committed Jan 6, 2025
1 parent 053adab commit d835bb9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions controlplane/internal/controllers/rke2controlplane_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controllers
import (
"context"
"fmt"
"sigs.k8s.io/cluster-api/util/certs"
"strings"
"time"

Expand Down Expand Up @@ -55,6 +56,7 @@ import (
"github.com/rancher/cluster-api-provider-rke2/pkg/registration"
"github.com/rancher/cluster-api-provider-rke2/pkg/rke2"
"github.com/rancher/cluster-api-provider-rke2/pkg/secret"
capikubeconfig "sigs.k8s.io/cluster-api/util/kubeconfig"
)

const (
Expand Down Expand Up @@ -812,6 +814,19 @@ func (r *RKE2ControlPlaneReconciler) reconcileKubeconfig(
return ctrl.Result{}, nil
}

needsRotation, err := capikubeconfig.NeedsClientCertRotation(configSecret, certs.ClientCertificateRenewalDuration)
if err != nil {
return ctrl.Result{}, err
}

if needsRotation {
logger.Info("Rotating kubeconfig secret")
err = kubeconfig.CreateSecretWithOwner(ctx, r.Client, clusterName, endpoint.String(), controllerOwnerRef)
if err != nil {
return ctrl.Result{}, errors.Wrap(err, "failed to regenerate kubeconfig")
}
}

return ctrl.Result{}, nil
}

Expand Down

0 comments on commit d835bb9

Please sign in to comment.