mirror of
https://github.com/rancher/rke.git
synced 2025-08-16 05:53:00 +00:00
Save cluster state to k8s on cert rotation
In addition to storing it on the disk
This commit is contained in:
parent
6bc2e1e8f8
commit
72fd42b8d2
24
cmd/cert.go
24
cmd/cert.go
@ -3,6 +3,7 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
@ -159,8 +160,9 @@ func rebuildClusterWithRotatedCertificates(ctx context.Context,
|
|||||||
if err := kubeCluster.SetUpHosts(ctx, flags); err != nil {
|
if err := kubeCluster.SetUpHosts(ctx, flags); err != nil {
|
||||||
return APIURL, caCrt, clientCert, clientKey, nil, err
|
return APIURL, caCrt, clientCert, clientKey, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save new State
|
// Save new State
|
||||||
if err := kubeCluster.UpdateClusterCurrentState(ctx, clusterState); err != nil {
|
if err := saveClusterState(ctx, kubeCluster, clusterState); err != nil {
|
||||||
return APIURL, caCrt, clientCert, clientKey, nil, err
|
return APIURL, caCrt, clientCert, clientKey, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,6 +204,26 @@ func rebuildClusterWithRotatedCertificates(ctx context.Context,
|
|||||||
return APIURL, caCrt, clientCert, clientKey, kubeCluster.Certificates, nil
|
return APIURL, caCrt, clientCert, clientKey, kubeCluster.Certificates, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func saveClusterState(ctx context.Context, kubeCluster *cluster.Cluster, clusterState *cluster.FullState) error {
|
||||||
|
var err error
|
||||||
|
if err = kubeCluster.UpdateClusterCurrentState(ctx, clusterState); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Attempt to store cluster full state to Kubernetes
|
||||||
|
for i := 1; i <= 3; i++ {
|
||||||
|
err = cluster.SaveFullStateToKubernetes(ctx, kubeCluster, clusterState)
|
||||||
|
if err != nil {
|
||||||
|
time.Sleep(time.Second * time.Duration(2))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
logrus.Warnf("Failed to save full cluster state to Kubernetes")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func rotateRKECertificates(ctx context.Context, kubeCluster *cluster.Cluster, flags cluster.ExternalFlags, rkeFullState *cluster.FullState) (*cluster.FullState, error) {
|
func rotateRKECertificates(ctx context.Context, kubeCluster *cluster.Cluster, flags cluster.ExternalFlags, rkeFullState *cluster.FullState) (*cluster.FullState, error) {
|
||||||
log.Infof(ctx, "Rotating Kubernetes cluster certificates")
|
log.Infof(ctx, "Rotating Kubernetes cluster certificates")
|
||||||
currentCluster, err := kubeCluster.GetClusterState(ctx, rkeFullState)
|
currentCluster, err := kubeCluster.GetClusterState(ctx, rkeFullState)
|
||||||
|
Loading…
Reference in New Issue
Block a user