Skip to content

Commit

Permalink
Add reconcile operation for Seed, Reconcile backupbuckets on seed r…
Browse files Browse the repository at this point in the history
…econciliation (gardener#8347)

* Increase seed generation on Reconcile operation annotation.

* Reconcile backupbucket on seed reconciliation

* Inject backup-secret hash into the gardenlet pod annotations

* Address PR review feedback
  • Loading branch information
shafeeqes authored Aug 16, 2023
1 parent a095dd8 commit 3a2e7d3
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
1 change: 1 addition & 0 deletions pkg/apis/core/validation/seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
)
availableSeedOperations = sets.New(
v1beta1constants.SeedOperationRenewGardenAccessSecrets,
v1beta1constants.GardenerOperationReconcile,
)
)

Expand Down
14 changes: 13 additions & 1 deletion pkg/gardenlet/controller/managedseed/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
"github.com/gardener/gardener/pkg/controllerutils"
gardenletv1alpha1 "github.com/gardener/gardener/pkg/gardenlet/apis/config/v1alpha1"
gardenletbootstraputil "github.com/gardener/gardener/pkg/gardenlet/bootstrap/util"
"github.com/gardener/gardener/pkg/utils"
gardenerutils "github.com/gardener/gardener/pkg/utils/gardener"
kubernetesutils "github.com/gardener/gardener/pkg/utils/kubernetes"
)
Expand Down Expand Up @@ -487,9 +488,13 @@ func (a *actuator) reconcileSeedSecrets(ctx context.Context, log logr.Logger, sp

// If backup is specified, create or update the backup secret if it doesn't exist or is owned by the managed seed
if spec.Backup != nil {
var checksum string

// Get backup secret
backupSecret, err := kubernetesutils.GetSecretByReference(ctx, a.gardenClient, &spec.Backup.SecretRef)
if client.IgnoreNotFound(err) != nil {
if err == nil {
checksum = utils.ComputeSecretChecksum(backupSecret.Data)[:8]
} else if client.IgnoreNotFound(err) != nil {
return err
}

Expand All @@ -508,7 +513,14 @@ func (a *actuator) reconcileSeedSecrets(ctx context.Context, log logr.Logger, sp
}); err != nil {
return err
}

checksum = utils.ComputeSecretChecksum(secret.Data)[:8]
}

// Inject backup-secret hash into the pod annotations
managedSeed.Spec.Gardenlet.Deployment.PodAnnotations = utils.MergeStringMaps[string](managedSeed.Spec.Gardenlet.Deployment.PodAnnotations, map[string]string{
"checksum/seed-backup-secret": spec.Backup.SecretRef.Name + "-" + checksum,
})
}

// If secret reference is specified and the static token kubeconfig is enabled,
Expand Down
1 change: 1 addition & 0 deletions pkg/gardenlet/controller/seed/seed/reconciler_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ func deployBackupBucketInGarden(ctx context.Context, k8sGardenClient client.Clie
ownerRef := metav1.NewControllerRef(seed, gardencorev1beta1.SchemeGroupVersion.WithKind("Seed"))

_, err := controllerutils.CreateOrGetAndStrategicMergePatch(ctx, k8sGardenClient, backupBucket, func() error {
metav1.SetMetaDataAnnotation(&backupBucket.ObjectMeta, v1beta1constants.GardenerOperation, v1beta1constants.GardenerOperationReconcile)
backupBucket.OwnerReferences = []metav1.OwnerReference{*ownerRef}
backupBucket.Spec = gardencorev1beta1.BackupBucketSpec{
Provider: gardencorev1beta1.BackupBucketProvider{
Expand Down
3 changes: 3 additions & 0 deletions pkg/registry/core/seed/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ func mustIncreaseGeneration(oldSeed, newSeed *core.Seed) bool {
switch newSeed.Annotations[v1beta1constants.GardenerOperation] {
case v1beta1constants.SeedOperationRenewGardenAccessSecrets:
return true
case v1beta1constants.GardenerOperationReconcile:
delete(newSeed.Annotations, v1beta1constants.GardenerOperation)
return true
}
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/registry/core/seed/strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ var _ = Describe("Strategy", func() {
Expect(newSeed.Generation).To(Equal(oldSeed.Generation + 1))
})

It("should bump the generation and remove the annotation if the operation annotation was set to reconcile", func() {
metav1.SetMetaDataAnnotation(&newSeed.ObjectMeta, "gardener.cloud/operation", "reconcile")

strategy.PrepareForUpdate(ctx, newSeed, oldSeed)

Expect(newSeed.Generation).To(Equal(oldSeed.Generation + 1))
Expect(newSeed.Annotations).NotTo(ContainElement("gardener.cloud/operation"))
})

It("should not bump the generation if the operation annotation didn't change", func() {
metav1.SetMetaDataAnnotation(&oldSeed.ObjectMeta, "gardener.cloud/operation", "renew-garden-access-secrets")
metav1.SetMetaDataAnnotation(&newSeed.ObjectMeta, "gardener.cloud/operation", "renew-garden-access-secrets")
Expand Down
21 changes: 17 additions & 4 deletions test/integration/gardenlet/managedseed/managedseed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var _ = Describe("ManagedSeed controller test", func() {
shootKubeconfigSecret *corev1.Secret
shootSecretBinding *gardencorev1beta1.SecretBinding
shootCloudProviderSecret *corev1.Secret
backupSecret *corev1.Secret
backupSecretName, seedSecretName string

reconcileShoot = func() {
Expand All @@ -58,7 +59,7 @@ var _ = Describe("ManagedSeed controller test", func() {
By("Verify if seed secrets are created")
EventuallyWithOffset(1, func(g Gomega) {
g.Expect(testClient.Get(ctx, client.ObjectKeyFromObject(managedSeed), managedSeed)).To(Succeed())
g.Expect(testClient.Get(ctx, client.ObjectKey{Name: backupSecretName, Namespace: gardenNamespaceGarden.Name}, &corev1.Secret{})).To(Succeed())
g.Expect(testClient.Get(ctx, client.ObjectKeyFromObject(backupSecret), backupSecret)).To(Succeed())
g.Expect(testClient.Get(ctx, client.ObjectKey{Name: seedSecretName, Namespace: gardenNamespaceGarden.Name}, &corev1.Secret{})).To(Succeed())
}).Should(Succeed())
}
Expand All @@ -79,7 +80,12 @@ var _ = Describe("ManagedSeed controller test", func() {
g.Expect(testClient.Get(ctx, client.ObjectKey{Name: "gardenlet-kubeconfig-bootstrap", Namespace: gardenNamespaceShoot}, &corev1.Secret{})).To(Succeed())
g.Expect(testClient.Get(ctx, client.ObjectKey{Name: "gardenlet", Namespace: gardenNamespaceShoot}, &corev1.Service{})).To(Succeed())
g.Expect(testClient.Get(ctx, client.ObjectKey{Name: "gardenlet", Namespace: gardenNamespaceShoot}, &corev1.ServiceAccount{})).To(Succeed())
g.Expect(testClient.Get(ctx, client.ObjectKey{Name: "gardenlet", Namespace: gardenNamespaceShoot}, &appsv1.Deployment{})).To(Succeed())

gardenletDeployment := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "gardenlet", Namespace: gardenNamespaceShoot}}
g.Expect(testClient.Get(ctx, client.ObjectKeyFromObject(gardenletDeployment), gardenletDeployment)).To(Succeed())
g.Expect(gardenletDeployment.Spec.Template.Annotations).To(HaveKeyWithValue(
"checksum/seed-backup-secret", backupSecret.Name+"-"+utils.ComputeSecretChecksum(backupSecret.Data)[:8],
))
}).Should(Succeed())
}
)
Expand All @@ -92,6 +98,13 @@ var _ = Describe("ManagedSeed controller test", func() {
backupSecretName = "backup-" + utils.ComputeSHA256Hex([]byte(uuid.NewUUID()))[:8]
seedSecretName = "seed-" + utils.ComputeSHA256Hex([]byte(uuid.NewUUID()))[:8]

backupSecret = &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: backupSecretName,
Namespace: gardenNamespaceGarden.Name,
},
}

gardenletConfig, err := encoding.EncodeGardenletConfiguration(&gardenletv1alpha1.GardenletConfiguration{
TypeMeta: metav1.TypeMeta{
APIVersion: gardenletv1alpha1.SchemeGroupVersion.String(),
Expand All @@ -115,8 +128,8 @@ var _ = Describe("ManagedSeed controller test", func() {
Provider: "test",
Region: pointer.String("bar"),
SecretRef: corev1.SecretReference{
Name: backupSecretName,
Namespace: gardenNamespaceGarden.Name,
Name: backupSecret.Name,
Namespace: backupSecret.Namespace,
},
},
SecretRef: &corev1.SecretReference{
Expand Down

0 comments on commit 3a2e7d3

Please sign in to comment.