rewrite to ippool patcher
This commit is contained in:
@@ -11,29 +11,26 @@ import (
|
||||
"k8s.io/client-go/rest"
|
||||
)
|
||||
|
||||
var CRD_TEMPLATE = `
|
||||
var IP_POOL_TEMPLATE = `
|
||||
{
|
||||
"apiVersion": "externaldns.k8s.io/v1alpha1",
|
||||
"kind": "DNSEndpoint",
|
||||
"apiVersion": "cilium.io/v2alpha1",
|
||||
"kind": "CiliumLoadBalancerIPPool",
|
||||
"metadata": {
|
||||
"name": "{{ .Name }}",
|
||||
"annotations": {
|
||||
"external.dns/provider": "cf"
|
||||
"argocd.argoproj.io/tracking-id": "cilium-lb:cilium.io/CiliumLoadBalancerIPPool:kube-system/covidnetes-pool"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"endpoints": [
|
||||
"blocks": [
|
||||
{{- range $i, $ip := .IPs }}
|
||||
{{- if $i}},{{ end }}
|
||||
{
|
||||
"dnsName": "mail",
|
||||
"recordTTL": 180,
|
||||
"recordType": "A",
|
||||
"targets": [
|
||||
{{ range .IPs -}}
|
||||
"{{ . }}",
|
||||
{{ end -}}
|
||||
]
|
||||
"cidr": "{{ $ip }}"
|
||||
}
|
||||
]
|
||||
{{- end }}
|
||||
],
|
||||
"disabled": false
|
||||
}
|
||||
}
|
||||
`
|
||||
@@ -43,7 +40,7 @@ type CrdConfig struct {
|
||||
IPs []string
|
||||
}
|
||||
|
||||
func RecreateDnsCrd(cfg *Config, name string, ips []string) error {
|
||||
func RecreateIPPoolCrd(cfg *Config, name string, ips []string) error {
|
||||
|
||||
routeclient, err := createRestClient()
|
||||
|
||||
@@ -51,7 +48,7 @@ func RecreateDnsCrd(cfg *Config, name string, ips []string) error {
|
||||
return errors.New(fmt.Sprintf("Error creating REST Client: %v", err.Error()))
|
||||
}
|
||||
|
||||
body, err := generateCrd(name, ips)
|
||||
body, err := generateIpPool(name, ips)
|
||||
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("Error generating CRD: %v", err.Error()))
|
||||
@@ -65,7 +62,6 @@ func RecreateDnsCrd(cfg *Config, name string, ips []string) error {
|
||||
}
|
||||
|
||||
res := routeclient.Post().
|
||||
Namespace(cfg.Namespace).
|
||||
Resource("routes").
|
||||
Body(&obj).
|
||||
Do(context.TODO())
|
||||
@@ -98,19 +94,19 @@ func createRestClient() (*rest.RESTClient, error) {
|
||||
|
||||
}
|
||||
|
||||
func generateCrd(name string, ips []string) (string, error) {
|
||||
func generateIpPool(name string, ips []string) (string, error) {
|
||||
config := CrdConfig{
|
||||
Name: name,
|
||||
IPs: ips,
|
||||
}
|
||||
tmpl, err := template.New("crd").Parse(CRD_TEMPLATE)
|
||||
tmpl, err := template.New("ippool").Parse(IP_POOL_TEMPLATE)
|
||||
if err != nil {
|
||||
return "", errors.New(fmt.Sprintf("Errors in crd template: %s", err.Error()))
|
||||
return "", errors.New(fmt.Sprintf("Errors in ippool template: %s", err.Error()))
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
err = tmpl.Execute(&buf, &config)
|
||||
if err != nil {
|
||||
return "", errors.New(fmt.Sprintf("Could not render crd template: %s", err.Error()))
|
||||
return "", errors.New(fmt.Sprintf("Could not render ippool template: %s", err.Error()))
|
||||
}
|
||||
return buf.String(), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user