This commit is contained in:
parent
24be598758
commit
6a63daab73
@ -82,17 +82,17 @@ func CreateNewAgent(cfg *config.Config) (*hcloud.Server, error) {
|
|||||||
keys = append(keys, key)
|
keys = append(keys, key)
|
||||||
}
|
}
|
||||||
img, _, err := client.Image.GetByNameAndArchitecture(context.Background(), "docker-ce", "x86")
|
img, _, err := client.Image.GetByNameAndArchitecture(context.Background(), "docker-ce", "x86")
|
||||||
|
utils.CheckError(err, "GetImageByNameAndArchitecture")
|
||||||
loc, _, err := client.Location.GetByName(context.Background(), cfg.HcloudRegion)
|
loc, _, err := client.Location.GetByName(context.Background(), cfg.HcloudRegion)
|
||||||
|
utils.CheckError(err, "GetRegionByName")
|
||||||
pln, _, err := client.ServerType.GetByName(context.Background(), cfg.HcloudInstanceType)
|
pln, _, err := client.ServerType.GetByName(context.Background(), cfg.HcloudInstanceType)
|
||||||
|
utils.CheckError(err, "GetServerTypeByName")
|
||||||
dc, _, err := client.Datacenter.GetByName(context.Background(), cfg.HcloudDatacenter)
|
dc, _, err := client.Datacenter.GetByName(context.Background(), cfg.HcloudDatacenter)
|
||||||
|
utils.CheckError(err, "GetDatacenterByName")
|
||||||
labels := map[string]string{}
|
labels := map[string]string{}
|
||||||
labels["Role"] = "WoodpeckerAgent"
|
labels["Role"] = "WoodpeckerAgent"
|
||||||
labels["ControledBy"] = "WoodpeckerAutoscaler"
|
labels["ControledBy"] = "WoodpeckerAutoscaler"
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New(fmt.Sprintf("Could not parse agent spec: %s", err.Error()))
|
|
||||||
}
|
|
||||||
|
|
||||||
networkConf := hcloud.ServerCreatePublicNet{
|
networkConf := hcloud.ServerCreatePublicNet{
|
||||||
EnableIPv4: !cfg.HcloudIPv6Only,
|
EnableIPv4: !cfg.HcloudIPv6Only,
|
||||||
EnableIPv6: true,
|
EnableIPv6: true,
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import "math/rand"
|
import (
|
||||||
|
"math/rand"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
|
||||||
@ -15,3 +19,11 @@ func RandStringBytes(n int) string {
|
|||||||
func BoolPointer(b bool) *bool {
|
func BoolPointer(b bool) *bool {
|
||||||
return &b
|
return &b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckError(err error, caller string) {
|
||||||
|
if err != nil {
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"Caller": caller,
|
||||||
|
}).Warnf("Error from hetzner API: %s", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user