-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for Hetzner cloud metadata
- Loading branch information
Showing
6 changed files
with
76 additions
and
18 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
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package metadata | ||
|
||
import ( | ||
"gopkg.in/yaml.v2" | ||
"k8s.io/klog/v2" | ||
"net/http" | ||
) | ||
|
||
const hetznerInstanceMetadataURL = "http://169.254.169.254/hetzner/v1/metadata" | ||
|
||
type hetznerInstanceMetadata struct { | ||
AvailabilityZone string `yaml:"availability-zone"` | ||
InstanceId string `yaml:"instance-id"` | ||
PublicIPv4 string `yaml:"public-ipv4"` | ||
LocalIPv4 string `yaml:"local-ipv4"` | ||
Region string `yaml:"region"` | ||
} | ||
|
||
func getHetznerMetadata() *CloudMetadata { | ||
r, _ := http.NewRequest(http.MethodGet, hetznerInstanceMetadataURL, nil) | ||
resp, err := httpGetWithTimeout(r) | ||
if err != nil { | ||
klog.Errorln(err) | ||
return nil | ||
} | ||
defer resp.Body.Close() | ||
md := &hetznerInstanceMetadata{} | ||
decoder := yaml.NewDecoder(resp.Body) | ||
if err := decoder.Decode(md); err != nil { | ||
klog.Errorln("failed to unmarshall response of Hetzner metadata service:", err) | ||
return nil | ||
} | ||
res := &CloudMetadata{ | ||
Provider: CloudProviderHetzner, | ||
InstanceId: md.InstanceId, | ||
Region: md.Region, | ||
AvailabilityZone: md.AvailabilityZone, | ||
LocalIPv4: md.LocalIPv4, | ||
PublicIPv4: md.PublicIPv4, | ||
} | ||
return res | ||
} |
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