Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-v1.32] Automated cherry pick of #4815: Fix owner DNSRecords stuck in states different from Succeeded #4858

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions pkg/operation/botanist/component/extensions/dnsrecord/dnsrecord.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"time"

gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -174,11 +175,16 @@ func (c *dnsRecord) deploy(ctx context.Context, operation string) (extensionsv1a
return nil, err
}
} else {
// DNSRecord already exists, just update the timestamp annotation.
// If the object is still annotated with the operation annotation (e.g. not reconciled yet) this will send a watch
// event to the extension controller triggering a new reconciliation.
patch := client.MergeFrom(c.dnsRecord.DeepCopy())
metav1.SetMetaDataAnnotation(&c.dnsRecord.ObjectMeta, v1beta1constants.GardenerTimestamp, TimeNow().UTC().String())
if c.dnsRecord.Status.LastOperation != nil && c.dnsRecord.Status.LastOperation.State != gardencorev1beta1.LastOperationStateSucceeded {
// If the DNSRecord is not yet Succeeded, reconcile it again.
_ = mutateFn()
} else {
// Otherwise, just update the timestamp annotation.
// If the object is still annotated with the operation annotation (e.g. not reconciled yet) this will send a watch
// event to the extension controller triggering a new reconciliation.
metav1.SetMetaDataAnnotation(&c.dnsRecord.ObjectMeta, v1beta1constants.GardenerTimestamp, TimeNow().UTC().String())
}
if err := c.client.Patch(ctx, c.dnsRecord, patch); err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ var _ = Describe("DNSRecord", func() {
It("should deploy the DNSRecord resource and its secret", func() {
Expect(dnsRecord.Deploy(ctx)).To(Succeed())

dns := &extensionsv1alpha1.DNSRecord{}
err := c.Get(ctx, client.ObjectKey{Name: name, Namespace: namespace}, dns)
deployedDNS := &extensionsv1alpha1.DNSRecord{}
err := c.Get(ctx, client.ObjectKey{Name: name, Namespace: namespace}, deployedDNS)
Expect(err).NotTo(HaveOccurred())
Expect(dns).To(DeepEqual(&extensionsv1alpha1.DNSRecord{
Expect(deployedDNS).To(DeepEqual(&extensionsv1alpha1.DNSRecord{
TypeMeta: metav1.TypeMeta{
APIVersion: extensionsv1alpha1.SchemeGroupVersion.String(),
Kind: extensionsv1alpha1.DNSRecordResource,
Expand All @@ -180,10 +180,10 @@ var _ = Describe("DNSRecord", func() {
Spec: dns.Spec,
}))

secret := &corev1.Secret{}
err = c.Get(ctx, client.ObjectKey{Name: secretName, Namespace: namespace}, secret)
deployedSecret := &corev1.Secret{}
err = c.Get(ctx, client.ObjectKey{Name: secretName, Namespace: namespace}, deployedSecret)
Expect(err).NotTo(HaveOccurred())
Expect(secret).To(DeepEqual(&corev1.Secret{
Expect(deployedSecret).To(DeepEqual(&corev1.Secret{
TypeMeta: metav1.TypeMeta{
APIVersion: corev1.SchemeGroupVersion.String(),
Kind: "Secret",
Expand Down Expand Up @@ -225,10 +225,10 @@ var _ = Describe("DNSRecord", func() {

Expect(dnsRecord.Deploy(ctx)).To(Succeed())

dns := &extensionsv1alpha1.DNSRecord{}
err := c.Get(ctx, client.ObjectKey{Name: name, Namespace: namespace}, dns)
deployedDNS := &extensionsv1alpha1.DNSRecord{}
err := c.Get(ctx, client.ObjectKey{Name: name, Namespace: namespace}, deployedDNS)
Expect(err).NotTo(HaveOccurred())
Expect(dns).To(DeepEqual(&extensionsv1alpha1.DNSRecord{
Expect(deployedDNS).To(DeepEqual(&extensionsv1alpha1.DNSRecord{
TypeMeta: metav1.TypeMeta{
APIVersion: extensionsv1alpha1.SchemeGroupVersion.String(),
Kind: extensionsv1alpha1.DNSRecordResource,
Expand All @@ -246,6 +246,49 @@ var _ = Describe("DNSRecord", func() {
}))
})

It("should deploy the DNSRecord resource if ReconcileOnce is true and the DNSRecord is not Succeeded", func() {
values.ReconcileOnce = true
dnsRecord = dnsrecord.New(log, c, values, dnsrecord.DefaultInterval, dnsrecord.DefaultSevereThreshold, dnsrecord.DefaultTimeout)

existingDNS := dns.DeepCopy()
delete(existingDNS.Annotations, v1beta1constants.GardenerOperation)
metav1.SetMetaDataAnnotation(&existingDNS.ObjectMeta, v1beta1constants.GardenerTimestamp, now.UTC().Add(-time.Second).String())
existingDNS.Spec.Zone = pointer.String("other-zone")
existingDNS.Status.LastOperation = &gardencorev1beta1.LastOperation{
State: gardencorev1beta1.LastOperationStateError,
}
Expect(c.Create(ctx, existingDNS)).To(Succeed())

Expect(dnsRecord.Deploy(ctx)).To(Succeed())

deployedDNS := &extensionsv1alpha1.DNSRecord{}
err := c.Get(ctx, client.ObjectKey{Name: name, Namespace: namespace}, deployedDNS)
Expect(err).NotTo(HaveOccurred())
Expect(deployedDNS).To(DeepEqual(&extensionsv1alpha1.DNSRecord{
TypeMeta: metav1.TypeMeta{
APIVersion: extensionsv1alpha1.SchemeGroupVersion.String(),
Kind: extensionsv1alpha1.DNSRecordResource,
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
ResourceVersion: "2",
Annotations: map[string]string{
v1beta1constants.GardenerOperation: v1beta1constants.GardenerOperationReconcile,
v1beta1constants.GardenerTimestamp: now.UTC().String(),
},
},
Spec: dns.Spec,
Status: extensionsv1alpha1.DNSRecordStatus{
DefaultStatus: extensionsv1alpha1.DefaultStatus{
LastOperation: &gardencorev1beta1.LastOperation{
State: gardencorev1beta1.LastOperationStateError,
},
},
},
}))
})

It("should update the timestamp annotation if ReconcileOnce is true and the DNSRecord is found", func() {
values.ReconcileOnce = true
dnsRecord = dnsrecord.New(log, c, values, dnsrecord.DefaultInterval, dnsrecord.DefaultSevereThreshold, dnsrecord.DefaultTimeout)
Expand All @@ -256,10 +299,10 @@ var _ = Describe("DNSRecord", func() {

Expect(dnsRecord.Deploy(ctx)).To(Succeed())

dns := &extensionsv1alpha1.DNSRecord{}
err := c.Get(ctx, client.ObjectKey{Name: name, Namespace: namespace}, dns)
deployedDNS := &extensionsv1alpha1.DNSRecord{}
err := c.Get(ctx, client.ObjectKey{Name: name, Namespace: namespace}, deployedDNS)
Expect(err).NotTo(HaveOccurred())
Expect(dns).To(DeepEqual(&extensionsv1alpha1.DNSRecord{
Expect(deployedDNS).To(DeepEqual(&extensionsv1alpha1.DNSRecord{
TypeMeta: metav1.TypeMeta{
APIVersion: extensionsv1alpha1.SchemeGroupVersion.String(),
Kind: extensionsv1alpha1.DNSRecordResource,
Expand Down