-
Notifications
You must be signed in to change notification settings - Fork 431
/
zone_reconciler.go
78 lines (63 loc) · 2.84 KB
/
zone_reconciler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
Copyright 2022 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package privatedns
import (
"context"
"github.com/pkg/errors"
"sigs.k8s.io/cluster-api-provider-azure/azure"
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
)
func (s *Service) reconcileZone(ctx context.Context, zoneSpec azure.ResourceSpecGetter) (managed bool, err error) {
ctx, log, done := tele.StartSpanWithLogger(ctx, "privatedns.Service.reconcileZone")
defer done()
managed, err = s.isPrivateDNSManaged(ctx, zoneSpec)
if err != nil {
if azure.ResourceNotFound(err) {
managed = true
} else {
return managed, err
}
}
if !managed {
log.V(1).Info("Skipping reconciliation of unmanaged private DNS zone", "private DNS", zoneSpec.ResourceName())
// TODO: Remove this log in future release. This is only required because older clusters created before https://github.com/kubernetes-sigs/cluster-api-provider-azure/pull/1791 will not have capz ownership tags.
log.V(1).Info("Tag the DNS manually from azure to manage it with capz."+
"Please see https://capz.sigs.k8s.io/topics/custom-dns.html#manage-dns-via-capz-tool", "private DNS", zoneSpec.ResourceName())
return managed, nil
}
_, err = s.zoneReconciler.CreateResource(ctx, zoneSpec, serviceName)
return managed, err
}
func (s *Service) deleteZone(ctx context.Context, zoneSpec azure.ResourceSpecGetter) (managed bool, err error) {
ctx, log, done := tele.StartSpanWithLogger(ctx, "privatedns.Service.deleteZone")
defer done()
// Skip deleting the private DNS zone when it's not managed by capz.
isManaged, err := s.isPrivateDNSManaged(ctx, zoneSpec)
if err != nil {
if azure.ResourceNotFound(err) {
// already deleted or doesn't exist, cleanup status and return.
s.Scope.DeleteLongRunningOperationState(zoneSpec.ResourceName(), serviceName)
return managed, nil
}
return managed, errors.Wrapf(err, "could not get private DNS zone state of %s in resource group %s", zoneSpec.ResourceName(), zoneSpec.ResourceGroupName())
}
if !isManaged {
log.V(1).Info("Skipping deletion of unmanaged private DNS zone", "private DNS", zoneSpec.ResourceName())
return managed, nil
}
// if we reach here, it means that this vnet link is managed by capz.
managed = true
// Delete the private DNS zone, which also deletes all records
err = s.zoneReconciler.DeleteResource(ctx, zoneSpec, serviceName)
return managed, err
}