Skip to content

Commit

Permalink
Added force rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
akgalwas committed Oct 20, 2023
1 parent 0dcff61 commit 453ae3d
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions internal/controller/gardener_cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (controller *GardenerClusterController) createOrRotateSecret(ctx context.Co
return true, err
}

if !secretNeedsToBeRotated(existingSecret, controller.rotationPeriod) {
if !secretNeedsToBeRotated(cluster, existingSecret, controller.rotationPeriod) {
return false, nil
}

Expand All @@ -205,10 +205,15 @@ func (controller *GardenerClusterController) createOrRotateSecret(ctx context.Co
return true, controller.createNewSecret(ctx, kubeconfig, cluster, lastSyncTime)
}

func secretNeedsToBeRotated(secret *corev1.Secret, rotationPeriod time.Duration) bool {
func secretNeedsToBeRotated(cluster *imv1.GardenerCluster, secret *corev1.Secret, rotationPeriod time.Duration) bool {
return secretRotationTimePassed(secret, rotationPeriod) || secretRotationForced(cluster)
}

func secretRotationTimePassed(secret *corev1.Secret, rotationPeriod time.Duration) bool {
if secret == nil {
return true
}

annotations := secret.GetAnnotations()

_, found := annotations[lastKubeconfigSyncAnnotation]
Expand All @@ -228,6 +233,17 @@ func secretNeedsToBeRotated(secret *corev1.Secret, rotationPeriod time.Duration)
return alreadyValidFor.Minutes() >= rotationPeriod.Minutes()
}

func secretRotationForced(cluster *imv1.GardenerCluster) bool {
annotations := cluster.GetAnnotations()
if annotations == nil {
return false
}

_, found := annotations[forceKubeconfigRotationAnnotation]

return found
}

func (controller *GardenerClusterController) createNewSecret(ctx context.Context, kubeconfig string, cluster *imv1.GardenerCluster, lastSyncTime time.Time) error {
controller.log.Info("Creating a new kubeconfig secret")
newSecret := controller.newSecret(*cluster, kubeconfig, lastSyncTime)
Expand Down

0 comments on commit 453ae3d

Please sign in to comment.