Skip to content

Commit

Permalink
Fix issue with empty host tree in hosts.toml
Browse files Browse the repository at this point in the history
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
  • Loading branch information
brandond committed Apr 1, 2024
1 parent 0dcf21c commit d2b9983
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions remotes/docker/config/hosts.go
Expand Up @@ -376,11 +376,6 @@ func parseHostsFile(baseDir string, b []byte) ([]hostConfig, error) {
HostConfigs map[string]hostFileConfig `toml:"host"`
}{}

orderedHosts, err := getSortedHosts(tree)
if err != nil {
return nil, err
}

var (
hosts []hostConfig
)
Expand All @@ -389,15 +384,24 @@ func parseHostsFile(baseDir string, b []byte) ([]hostConfig, error) {
return nil, err
}

// Parse hosts array
for _, host := range orderedHosts {
config := c.HostConfigs[host]

parsed, err := parseHostConfig(host, baseDir, config)
// The HostConfigs map is unordered, so we need to return the hosts sorted by
// line number in the file to honor the order requested by the user.
if len(c.HostConfigs) > 0 {
orderedHosts, err = getSortedHosts(tree)

Check failure on line 390 in remotes/docker/config/hosts.go

View workflow job for this annotation

GitHub Actions / CodeQL-Build

undefined: orderedHosts

Check failure on line 390 in remotes/docker/config/hosts.go

View workflow job for this annotation

GitHub Actions / Linters (ubuntu-20.04)

undefined: orderedHosts

Check failure on line 390 in remotes/docker/config/hosts.go

View workflow job for this annotation

GitHub Actions / Linters (ubuntu-20.04)

undefined: orderedHosts

Check failure on line 390 in remotes/docker/config/hosts.go

View workflow job for this annotation

GitHub Actions / Linters (ubuntu-20.04)

undefined: orderedHosts

Check failure on line 390 in remotes/docker/config/hosts.go

View workflow job for this annotation

GitHub Actions / Manpages

undefined: orderedHosts
if err != nil {
return nil, err
}
hosts = append(hosts, parsed)

// Parse hosts array
for _, host := range orderedHosts {

Check failure on line 396 in remotes/docker/config/hosts.go

View workflow job for this annotation

GitHub Actions / CodeQL-Build

undefined: orderedHosts

Check failure on line 396 in remotes/docker/config/hosts.go

View workflow job for this annotation

GitHub Actions / Linters (ubuntu-20.04)

undefined: orderedHosts) (typecheck)

Check failure on line 396 in remotes/docker/config/hosts.go

View workflow job for this annotation

GitHub Actions / Linters (ubuntu-20.04)

undefined: orderedHosts) (typecheck)

Check failure on line 396 in remotes/docker/config/hosts.go

View workflow job for this annotation

GitHub Actions / Linters (ubuntu-20.04)

undefined: orderedHosts) (typecheck)

Check failure on line 396 in remotes/docker/config/hosts.go

View workflow job for this annotation

GitHub Actions / Manpages

undefined: orderedHosts
config := c.HostConfigs[host]

parsed, err := parseHostConfig(host, baseDir, config)
if err != nil {
return nil, err
}
hosts = append(hosts, parsed)
}
}

// Parse root host config and append it as the last element
Expand Down

0 comments on commit d2b9983

Please sign in to comment.