fix(): use publich ip addresses
This commit is contained in:
		| @@ -1,7 +1,6 @@ | ||||
| package internal | ||||
|  | ||||
| import ( | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"time" | ||||
|  | ||||
| @@ -24,7 +23,7 @@ func GenConfig() (cfg *Config, err error) { | ||||
| 		Silent:             true, | ||||
| 		AutoReloadInterval: time.Minute}).Load(cfg, "config.json") | ||||
| 	if err != nil { | ||||
| 		return nil, errors.New(fmt.Sprintf("Error generating Config: %s", err.Error())) | ||||
| 		return nil, fmt.Errorf("error generating Config: %s", err.Error()) | ||||
| 	} | ||||
| 	return cfg, nil | ||||
|  | ||||
|   | ||||
| @@ -2,7 +2,6 @@ package internal | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
|  | ||||
| 	"github.com/hetznercloud/hcloud-go/hcloud" | ||||
| @@ -16,11 +15,11 @@ func GetAllNodes(cfg *Config) ([]*hcloud.Server, error) { | ||||
| 			LabelSelector: cfg.LabelSelector, | ||||
| 		}}) | ||||
| 	if err != nil { | ||||
| 		return nil, errors.New(fmt.Sprintf("Error listing Hetzner Nodes: %s", err.Error())) | ||||
| 		return nil, fmt.Errorf("error listing Hetzner Nodes: %s", err.Error()) | ||||
| 	} | ||||
|  | ||||
| 	if servers == nil { | ||||
| 		return nil, errors.New(fmt.Sprintf("No Nodes found with label selector: %s", cfg.LabelSelector)) | ||||
| 		return nil, fmt.Errorf("no Nodes found with label selector: %s", cfg.LabelSelector) | ||||
| 	} | ||||
| 	return servers, nil | ||||
|  | ||||
| @@ -29,13 +28,13 @@ func GetAllNodes(cfg *Config) ([]*hcloud.Server, error) { | ||||
| func GetAllIps(servers []*hcloud.Server) ([]string, error) { | ||||
| 	ips := make([]string, len(servers)) | ||||
| 	for i, instance := range servers { | ||||
| 		if len(instance.PrivateNet) == 0 || instance.PrivateNet[0].IP == nil { | ||||
| 			return []string{""}, errors.New(fmt.Sprintf("Instance %s has no attached IP", instance.Name)) | ||||
| 		if instance.PublicNet.IPv4.IP == nil { | ||||
| 			return []string{""}, fmt.Errorf("instance %s has no public Addresses", instance.Name) | ||||
| 		} | ||||
| 		log.WithFields(log.Fields{ | ||||
| 			"Caller": "GetAllIps", | ||||
| 		}).Info(fmt.Sprintf("Found IP: %s", instance.PrivateNet[0].IP.String())) | ||||
| 		ips[i] = instance.PrivateNet[0].IP.String() | ||||
| 		ips[i] = instance.PublicNet.IPv4.IP.String() | ||||
| 	} | ||||
| 	return ips, nil | ||||
| } | ||||
|   | ||||
| @@ -18,7 +18,7 @@ func TestGetAllIps(t *testing.T) { | ||||
| 		Name:   "Test2", | ||||
| 	}) | ||||
|  | ||||
| 	expectedError := "Instance Test has no attached IP" | ||||
| 	expectedError := "instance Test has no public Addresses" | ||||
| 	_, err := GetAllIps(servers) | ||||
| 	if err == nil { | ||||
| 		t.Error("GetAllIps did not error with missing data") | ||||
|   | ||||
| @@ -3,7 +3,6 @@ package internal | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"context" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"html/template" | ||||
|  | ||||
| @@ -45,20 +44,20 @@ func RecreateIPPoolCrd(cfg *Config, name string, ips []string) error { | ||||
| 	routeclient, err := createRestClient() | ||||
|  | ||||
| 	if err != nil { | ||||
| 		return errors.New(fmt.Sprintf("Error creating REST Client: %v", err.Error())) | ||||
| 		return fmt.Errorf("error creating REST Client: %v", err.Error()) | ||||
| 	} | ||||
|  | ||||
| 	body, err := generateIpPool(name, ips) | ||||
|  | ||||
| 	if err != nil { | ||||
| 		return errors.New(fmt.Sprintf("Error generating CRD: %v", err.Error())) | ||||
| 		return fmt.Errorf("error generating CRD: %v", err.Error()) | ||||
| 	} | ||||
|  | ||||
| 	decode := scheme.Codecs.UniversalDeserializer().Decode | ||||
|  | ||||
| 	obj, _, err := decode([]byte(body), nil, nil) | ||||
| 	if err != nil { | ||||
| 		return errors.New(fmt.Sprintf("Could not deserialize CRD: %v", err.Error())) | ||||
| 		return fmt.Errorf("could not deserialize CRD: %v", err.Error()) | ||||
| 	} | ||||
|  | ||||
| 	res := routeclient.Post(). | ||||
| @@ -70,7 +69,7 @@ func RecreateIPPoolCrd(cfg *Config, name string, ips []string) error { | ||||
| 	res.StatusCode(&status) | ||||
|  | ||||
| 	if status >= 200 && status <= 400 { | ||||
| 		return errors.New(fmt.Sprintf("Failed to post CRD to kube api: %v", res.Error().Error())) | ||||
| 		return fmt.Errorf("failed to post CRD to kube api: %v", res.Error().Error()) | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| @@ -79,7 +78,7 @@ func RecreateIPPoolCrd(cfg *Config, name string, ips []string) error { | ||||
| func createRestClient() (*rest.RESTClient, error) { | ||||
| 	k8s_config, err := rest.InClusterConfig() | ||||
| 	if err != nil { | ||||
| 		return nil, errors.New(fmt.Sprintf("Could not create in cluster k8s config: %v", err)) | ||||
| 		return nil, fmt.Errorf("could not create in cluster k8s config: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	k8s_config.APIPath = "/apis" | ||||
| @@ -88,7 +87,7 @@ func createRestClient() (*rest.RESTClient, error) { | ||||
| 	routeclient, err := rest.RESTClientFor(k8s_config) | ||||
|  | ||||
| 	if err != nil { | ||||
| 		return nil, errors.New(fmt.Sprintf("Could not create k8s client: %v", err)) | ||||
| 		return nil, fmt.Errorf("could not create k8s client: %v", err) | ||||
| 	} | ||||
| 	return routeclient, nil | ||||
|  | ||||
| @@ -101,12 +100,12 @@ func generateIpPool(name string, ips []string) (string, error) { | ||||
| 	} | ||||
| 	tmpl, err := template.New("ippool").Parse(IP_POOL_TEMPLATE) | ||||
| 	if err != nil { | ||||
| 		return "", errors.New(fmt.Sprintf("Errors in ippool template: %s", err.Error())) | ||||
| 		return "", fmt.Errorf("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 ippool template: %s", err.Error())) | ||||
| 		return "", fmt.Errorf("could not render ippool template: %s", err.Error()) | ||||
| 	} | ||||
| 	return buf.String(), nil | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user