Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
smira committed Apr 9, 2021
1 parent 37a5edf commit 72af230
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
27 changes: 27 additions & 0 deletions cmd/installer/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
package cmd

import (
"errors"
"fmt"
"log"

"github.com/spf13/cobra"

"github.com/talos-systems/talos/cmd/installer/pkg/install"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform"
"github.com/talos-systems/talos/pkg/machinery/config/configloader"
"github.com/talos-systems/talos/pkg/version"
)

Expand Down Expand Up @@ -49,5 +52,29 @@ func runInstallCmd() (err error) {
return err
}

config, err := configloader.NewFromStdin()
if err != nil {
if errors.Is(err, configloader.ErrNoConfig) {
log.Printf("machine configuration missing, skipping validation")
} else {
return fmt.Errorf("error loading machine configuration: %w", err)
}
} else {
var warnings []string

warnings, err = config.Validate(p.Mode())
if err != nil {
return fmt.Errorf("machine configuration is invalid: %w", err)
}

if len(warnings) > 0 {
log.Printf("WARNING: config validation:")

for _, warning := range warnings {
log.Printf(" %s", warning)
}
}
}

return install.Install(p, seq, options)
}
8 changes: 6 additions & 2 deletions pkg/machinery/config/configloader/configloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package configloader

import (
"bytes"
"errors"
"fmt"
"io"
"io/ioutil"
Expand All @@ -17,6 +18,9 @@ import (
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1"
)

// ErrNoConfig is returned when no configuration was found in the input.
var ErrNoConfig = errors.New("config not found")

// newConfig initializes and returns a Configurator.
func newConfig(source []byte) (config config.Provider, err error) {
dec := decoder.NewDecoder(source)
Expand All @@ -34,7 +38,7 @@ func newConfig(source []byte) (config config.Provider, err error) {
}
}

return nil, fmt.Errorf("config not found")
return nil, ErrNoConfig
}

// NewFromFile will take a filepath and attempt to parse a config file from it.
Expand All @@ -58,7 +62,7 @@ func NewFromStdin() (config.Provider, error) {

config, err := NewFromBytes(buf.Bytes())
if err != nil {
return nil, fmt.Errorf("failed load config from stdin: %v", err)
return nil, fmt.Errorf("failed load config from stdin: %w", err)
}

return config, nil
Expand Down

0 comments on commit 72af230

Please sign in to comment.