-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gh-144 create health probe CR from DNSRecord reconciler
Signed-off-by: Maskym Vavilov <[email protected]>
- Loading branch information
1 parent
4f702b9
commit ec73121
Showing
21 changed files
with
1,294 additions
and
348 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ spec: | |
- /manager | ||
args: | ||
- --leader-elect | ||
- --enable-probes | ||
env: | ||
- name: WATCH_NAMESPACES | ||
value: "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package common | ||
|
||
import ( | ||
"sigs.k8s.io/external-dns/endpoint" | ||
|
||
"github.com/kuadrant/dns-operator/api/v1alpha1" | ||
) | ||
|
||
type DNSTreeNode struct { | ||
Name string | ||
Children []*DNSTreeNode | ||
DataSets []DNSTreeNodeData | ||
} | ||
|
||
type DNSTreeNodeData struct { | ||
RecordType string | ||
SetIdentifier string | ||
RecordTTL endpoint.TTL | ||
Labels endpoint.Labels | ||
ProviderSpecific endpoint.ProviderSpecific | ||
Targets []string | ||
} | ||
|
||
func (n *DNSTreeNode) RemoveNode(deleteNode *DNSTreeNode) { | ||
for i, node := range n.Children { | ||
if node.Name == deleteNode.Name { | ||
n.Children = append(n.Children[:i], n.Children[i+1:]...) | ||
return | ||
} | ||
|
||
// no children matched, try on each child | ||
node.RemoveNode(deleteNode) | ||
} | ||
} | ||
|
||
// GetLeafsTargets returns IP or CNAME of the leafs of a tree. | ||
func GetLeafsTargets(node *DNSTreeNode, targets *[]string) *[]string { | ||
// no children means this is pointing to an IP or a host outside of the DNS Record | ||
if len(node.Children) == 0 { | ||
*targets = append(*targets, node.Name) | ||
return nil | ||
} | ||
for _, child := range node.Children { | ||
GetLeafsTargets(child, targets) | ||
} | ||
return targets | ||
} | ||
|
||
func ToEndpoints(node *DNSTreeNode, endpoints *[]*endpoint.Endpoint) *[]*endpoint.Endpoint { | ||
// no children means this is pointing to an IP or a host outside of the DNS Record | ||
if len(node.Children) == 0 { | ||
return endpoints | ||
} | ||
targets := []string{} | ||
for _, child := range node.Children { | ||
targets = append(targets, child.Name) | ||
ToEndpoints(child, endpoints) | ||
} | ||
|
||
if node.DataSets == nil { | ||
*endpoints = append(*endpoints, &endpoint.Endpoint{ | ||
DNSName: node.Name, | ||
Targets: targets, | ||
}) | ||
return endpoints | ||
} | ||
|
||
for _, data := range node.DataSets { | ||
*endpoints = append(*endpoints, &endpoint.Endpoint{ | ||
DNSName: node.Name, | ||
Targets: data.Targets, | ||
RecordType: data.RecordType, | ||
RecordTTL: data.RecordTTL, | ||
SetIdentifier: data.SetIdentifier, | ||
Labels: data.Labels, | ||
ProviderSpecific: data.ProviderSpecific, | ||
}) | ||
} | ||
return endpoints | ||
} | ||
|
||
func MakeTreeFromDNSRecord(record *v1alpha1.DNSRecord) *DNSTreeNode { | ||
rootNode := &DNSTreeNode{Name: record.Spec.RootHost} | ||
populateNode(rootNode, record) | ||
return rootNode | ||
} | ||
|
||
func populateNode(node *DNSTreeNode, record *v1alpha1.DNSRecord) { | ||
node.DataSets = findDataSets(node.Name, record) | ||
|
||
children := findChildren(node.Name, record) | ||
if len(children) == 0 { | ||
return | ||
} | ||
|
||
for _, c := range children { | ||
populateNode(c, record) | ||
} | ||
node.Children = children | ||
} | ||
|
||
func findChildren(name string, record *v1alpha1.DNSRecord) []*DNSTreeNode { | ||
nodes := []*DNSTreeNode{} | ||
targets := map[string]string{} | ||
for _, ep := range record.Spec.Endpoints { | ||
if ep.DNSName == name { | ||
for _, t := range ep.Targets { | ||
targets[t] = t | ||
} | ||
} | ||
} | ||
for _, t := range targets { | ||
nodes = append(nodes, &DNSTreeNode{Name: t}) | ||
} | ||
|
||
return nodes | ||
} | ||
|
||
func findDataSets(name string, record *v1alpha1.DNSRecord) []DNSTreeNodeData { | ||
dataSets := []DNSTreeNodeData{} | ||
for _, ep := range record.Spec.Endpoints { | ||
if ep.DNSName == name { | ||
dataSets = append(dataSets, DNSTreeNodeData{ | ||
RecordType: ep.RecordType, | ||
RecordTTL: ep.RecordTTL, | ||
SetIdentifier: ep.SetIdentifier, | ||
Labels: ep.Labels, | ||
ProviderSpecific: ep.ProviderSpecific, | ||
Targets: ep.Targets, | ||
}) | ||
} | ||
} | ||
return dataSets | ||
} |
Oops, something went wrong.