Skip to content

Commit

Permalink
Merge pull request #4455 from stoyanr/automated-cherry-pick-of-#4454-…
Browse files Browse the repository at this point in the history
…upstream-release-v1.26

[release-v1.26] Automated cherry pick of #4454: Ensure backup entry name is generated only once using non-empty strings
  • Loading branch information
timuthy committed Jul 30, 2021
2 parents 1979839 + 259f5e8 commit 9c603a7
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 12 deletions.
4 changes: 1 addition & 3 deletions pkg/operation/botanist/backupentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
"github.com/gardener/gardener/pkg/operation/botanist/component"
corebackupentry "github.com/gardener/gardener/pkg/operation/botanist/component/backupentry"
gutil "github.com/gardener/gardener/pkg/utils/gardener"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
)
Expand All @@ -36,7 +34,7 @@ func (b *Botanist) DefaultCoreBackupEntry() component.DeployMigrateWaiter {
b.K8sGardenClient.Client(),
&corebackupentry.Values{
Namespace: b.Shoot.Info.Namespace,
Name: gutil.GenerateBackupEntryName(b.Shoot.Info.Status.TechnicalID, b.Shoot.Info.Status.UID),
Name: b.Shoot.BackupEntryName,
ShootPurpose: b.Shoot.Info.Spec.Purpose,
OwnerReference: ownerRef,
SeedName: b.Shoot.Info.Spec.SeedName,
Expand Down
3 changes: 1 addition & 2 deletions pkg/operation/botanist/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/gardener/gardener/pkg/operation/botanist/component/etcd"
"github.com/gardener/gardener/pkg/utils"
"github.com/gardener/gardener/pkg/utils/flow"
gutil "github.com/gardener/gardener/pkg/utils/gardener"
kutil "github.com/gardener/gardener/pkg/utils/kubernetes"

hvpav1alpha1 "github.com/gardener/hvpa-controller/api/v1alpha1"
Expand Down Expand Up @@ -106,7 +105,7 @@ func (b *Botanist) DeployEtcd(ctx context.Context) error {
b.Shoot.Components.ControlPlane.EtcdMain.SetBackupConfig(&etcd.BackupConfig{
Provider: b.Seed.Info.Spec.Backup.Provider,
SecretRefName: genericactuator.BackupSecretName,
Prefix: gutil.GenerateBackupEntryName(b.Shoot.Info.Status.TechnicalID, b.Shoot.Info.Status.UID),
Prefix: b.Shoot.BackupEntryName,
Container: string(secret.Data[genericactuator.DataKeyBackupBucketName]),
FullSnapshotSchedule: snapshotSchedule,
})
Expand Down
3 changes: 2 additions & 1 deletion pkg/operation/botanist/etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ var _ = Describe("Etcd", func() {
UID: shootUID,
},
},
SeedNamespace: namespace,
SeedNamespace: namespace,
BackupEntryName: namespace + "--" + string(shootUID),
}

etcdMain.EXPECT().SetSecrets(etcd.Secrets{
Expand Down
4 changes: 1 addition & 3 deletions pkg/operation/care/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/gardener/gardener/pkg/operation/common"
"github.com/gardener/gardener/pkg/operation/shoot"
"github.com/gardener/gardener/pkg/utils/flow"
gutil "github.com/gardener/gardener/pkg/utils/gardener"
kutil "github.com/gardener/gardener/pkg/utils/kubernetes"
"github.com/gardener/gardener/pkg/utils/kubernetes/health"

Expand Down Expand Up @@ -163,8 +162,7 @@ func (h *Health) retrieveExtensions(ctx context.Context) ([]runtime.Object, erro
// Get BackupEntries separately as they are not namespaced i.e., they cannot be narrowed down
// to a shoot namespace like other extension resources above.
be := &extensionsv1alpha1.BackupEntry{}
beName := gutil.GenerateBackupEntryName(h.shoot.Info.Status.TechnicalID, h.shoot.Info.Status.UID)
if err := h.seedClient.Client().Get(ctx, kutil.Key(beName), be); client.IgnoreNotFound(err) != nil {
if err := h.seedClient.Client().Get(ctx, kutil.Key(h.shoot.BackupEntryName), be); client.IgnoreNotFound(err) != nil {
return nil, err
}
extensions = append(extensions, be)
Expand Down
7 changes: 7 additions & 0 deletions pkg/operation/shoot/shoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,13 @@ func (b *Builder) Build(ctx context.Context, c client.Client) (*Shoot, error) {

shoot.Purpose = gardencorev1beta1helper.GetPurpose(shootObject)

// Determine backup entry name
backupEntryName, err := gutil.GenerateBackupEntryName(shootObject.Status.TechnicalID, shootObject.UID)
if err != nil {
return nil, err
}
shoot.BackupEntryName = backupEntryName

return shoot, nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/operation/shoot/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type Shoot struct {
NodeLocalDNSEnabled bool
Networks *Networks
ExposureClass *gardencorev1alpha1.ExposureClass
BackupEntryName string

Components *Components
ETCDEncryption *etcdencryption.EncryptionConfig
Expand Down
11 changes: 9 additions & 2 deletions pkg/utils/gardener/backupentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package gardener

import (
"fmt"
"strings"

"k8s.io/apimachinery/pkg/types"
Expand All @@ -23,8 +24,14 @@ import (
var backupEntryDelimiter = "--"

// GenerateBackupEntryName returns BackupEntry resource name created from provided <seedNamespace> and <shootUID>.
func GenerateBackupEntryName(shootTechnicalID string, shootUID types.UID) string {
return shootTechnicalID + backupEntryDelimiter + string(shootUID)
func GenerateBackupEntryName(shootTechnicalID string, shootUID types.UID) (string, error) {
if shootTechnicalID == "" {
return "", fmt.Errorf("can't generate backup entry name with an empty shoot technical ID")
}
if shootUID == "" {
return "", fmt.Errorf("can't generate backup entry name with an empty shoot UID")
}
return shootTechnicalID + backupEntryDelimiter + string(shootUID), nil
}

// ExtractShootDetailsFromBackupEntryName returns Shoot resource technicalID its UID from provided <backupEntryName>.
Expand Down
14 changes: 13 additions & 1 deletion pkg/utils/gardener/backupentry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,19 @@ var _ = Describe("BackupEntry", func() {

Describe("#GenerateBackupEntryName", func() {
It("should compute the correct name", func() {
Expect(GenerateBackupEntryName(shootTechnicalID, shootUID)).To(Equal(backupEntryName))
result, err := GenerateBackupEntryName(shootTechnicalID, shootUID)
Expect(err).To(Not(HaveOccurred()))
Expect(result).To(Equal(backupEntryName))
})

It("should fail if the shoot technical ID is empty", func() {
_, err := GenerateBackupEntryName("", shootUID)
Expect(err).To(HaveOccurred())
})

It("should fail if the shoot UID is empty", func() {
_, err := GenerateBackupEntryName(shootTechnicalID, "")
Expect(err).To(HaveOccurred())
})
})

Expand Down

0 comments on commit 9c603a7

Please sign in to comment.