-
Notifications
You must be signed in to change notification settings - Fork 79
/
cattle.go
44 lines (37 loc) · 1.06 KB
/
cattle.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
package main
import (
"github.com/rancher/external-dns/utils"
rancher "github.com/rancher/go-rancher/v2"
)
type CattleClient struct {
rancherClient *rancher.RancherClient
}
func NewCattleClient(cattleUrl string, accessKey string, secretKey string) (*CattleClient, error) {
client, err := rancher.NewRancherClient(&rancher.ClientOpts{
Url: cattleUrl,
AccessKey: accessKey,
SecretKey: secretKey,
})
if err != nil {
return nil, err
}
return &CattleClient{
rancherClient: client,
}, nil
}
func (c *CattleClient) UpdateServiceDomainName(metadataRecord utils.MetadataDnsRecord) error {
event := &rancher.ExternalDnsEvent{
EventType: "dns.update",
ExternalId: metadataRecord.DnsRecord.Fqdn,
ServiceName: metadataRecord.ServiceName,
StackName: metadataRecord.StackName,
Fqdn: utils.UnFqdn(metadataRecord.DnsRecord.Fqdn),
}
_, err := c.rancherClient.ExternalDnsEvent.Create(event)
return err
}
func (c *CattleClient) TestConnect() error {
opts := &rancher.ListOpts{}
_, err := c.rancherClient.ExternalDnsEvent.List(opts)
return err
}