Skip to content

Commit

Permalink
fix: azure hostname definition
Browse files Browse the repository at this point in the history
Fixes:
* Node hostname has a different place in metadata config.
* Do not reboot if machine-config is empty.

Signed-off-by: Serge Logvinov <serge.logvinov@sinextra.dev>
Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
  • Loading branch information
sergelogvinov authored and smira committed May 23, 2022
1 parent 33a631f commit 1156daa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions internal/app/machined/pkg/runtime/v1alpha1/platform/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ const (
// https://blogs.msdn.microsoft.com/mast/2015/05/18/what-is-the-ip-address-168-63-129-16/
AzureInternalEndpoint = "http://168.63.129.16"
// AzureHostnameEndpoint is the local endpoint for the hostname.
AzureHostnameEndpoint = "http://169.254.169.254/metadata/instance/compute/name?api-version=2021-05-01&format=text"
AzureHostnameEndpoint = "http://169.254.169.254/metadata/instance/compute/osProfile/computerName?api-version=2021-12-13&format=text"
// AzureInterfacesEndpoint is the local endpoint to get external IPs.
AzureInterfacesEndpoint = "http://169.254.169.254/metadata/instance/network/interface?api-version=2021-05-01"
AzureInterfacesEndpoint = "http://169.254.169.254/metadata/instance/network/interface?api-version=2021-12-13"

mnt = "/mnt"
)
Expand Down Expand Up @@ -155,6 +155,7 @@ func (a *Azure) KernelArgs() procfs.Parameters {
}

// configFromCD handles looking for devices and trying to mount/fetch xml to get the custom data.
//nolint:gocyclo
func (a *Azure) configFromCD() ([]byte, error) {
devList, err := ioutil.ReadDir("/dev")
if err != nil {
Expand Down Expand Up @@ -196,12 +197,16 @@ func (a *Azure) configFromCD() ([]byte, error) {
return nil, err
}

b64CustomData, err := base64.StdEncoding.DecodeString(ovfEnvData.CustomData)
if err != nil {
return nil, err
if len(ovfEnvData.CustomData) > 0 {
b64CustomData, err := base64.StdEncoding.DecodeString(ovfEnvData.CustomData)
if err != nil {
return nil, err
}

return b64CustomData, nil
}

return b64CustomData, nil
return nil, errors.ErrNoConfigSource
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/azure"
)

//go:embed metadata.json
//go:embed testdata/metadata.json
var rawMetadata []byte

//go:embed expected.yaml
//go:embed testdata/expected.yaml
var expectedNetworkConfig string

func TestParseMetadata(t *testing.T) {
Expand Down

0 comments on commit 1156daa

Please sign in to comment.