Skip to content

Commit

Permalink
Merge pull request #1094 from jlebon/pr/openstack-neednet
Browse files Browse the repository at this point in the history
fetch-offline: immediately return ErrNeedNet on OpenStack
  • Loading branch information
jlebon authored Sep 16, 2020
2 parents 4d7f5fb + 2e2e285 commit f05bc76
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
17 changes: 7 additions & 10 deletions internal/providers/cloudstack/cloudstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,23 @@ const (
)

func FetchConfig(f *resource.Fetcher) (types.Config, report.Report, error) {
// The fetch-offline approach doesn't work well here because of the "split
// personality" of this provider. See:
// https://github.com/coreos/ignition/issues/1081
if f.Offline {
return types.Config{}, report.Report{}, resource.ErrNeedNet
}

var data []byte
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)

sawErrNeedNet := false

dispatch := func(name string, fn func() ([]byte, error)) {
raw, err := fn()
if err != nil {
switch err {
case context.Canceled:
case context.DeadlineExceeded:
f.Logger.Err("timed out while fetching config from %s", name)
case resource.ErrNeedNet:
sawErrNeedNet = true
fallthrough
default:
f.Logger.Err("failed to fetch config from %s: %v", name, err)
}
Expand All @@ -86,11 +88,6 @@ func FetchConfig(f *resource.Fetcher) (types.Config, report.Report, error) {

<-ctx.Done()
if ctx.Err() == context.DeadlineExceeded {
// Did we hit neednet? If so, propagate that up instead. The OS should
// retry fetching again once networking is up.
if sawErrNeedNet {
return types.Config{}, report.Report{}, resource.ErrNeedNet
}
f.Logger.Info("neither config drive nor metadata service were available in time. Continuing without a config...")
}

Expand Down
17 changes: 7 additions & 10 deletions internal/providers/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,23 @@ var (
)

func FetchConfig(f *resource.Fetcher) (types.Config, report.Report, error) {
// The fetch-offline approach doesn't work well here because of the "split
// personality" of this provider. See:
// https://github.com/coreos/ignition/issues/1081
if f.Offline {
return types.Config{}, report.Report{}, resource.ErrNeedNet
}

var data []byte
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)

sawErrNeedNet := false

dispatch := func(name string, fn func() ([]byte, error)) {
raw, err := fn()
if err != nil {
switch err {
case context.Canceled:
case context.DeadlineExceeded:
f.Logger.Err("timed out while fetching config from %s", name)
case resource.ErrNeedNet:
sawErrNeedNet = true
fallthrough
default:
f.Logger.Err("failed to fetch config from %s: %v", name, err)
}
Expand All @@ -91,11 +93,6 @@ func FetchConfig(f *resource.Fetcher) (types.Config, report.Report, error) {

<-ctx.Done()
if ctx.Err() == context.DeadlineExceeded {
// Did we hit neednet? If so, propagate that up instead. The OS should
// retry fetching again once networking is up.
if sawErrNeedNet {
return types.Config{}, report.Report{}, resource.ErrNeedNet
}
f.Logger.Info("neither config drive nor metadata service were available in time. Continuing without a config...")
}

Expand Down

0 comments on commit f05bc76

Please sign in to comment.