-
Notifications
You must be signed in to change notification settings - Fork 546
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support overlays for imager. The `Install` interface is not wired yet, it will be done as a different PR. This should be a no-op for existing imager. Part of: #8350 Signed-off-by: Noel Georgi <git@frezbo.dev>
- Loading branch information
Showing
9 changed files
with
361 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
// Package executor implements overlay.Installer | ||
package executor | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"os/exec" | ||
|
||
"gopkg.in/yaml.v2" | ||
|
||
"github.com/siderolabs/talos/pkg/machinery/overlay" | ||
) | ||
|
||
var _ overlay.Installer = (*Options)(nil) | ||
|
||
// Options executor options. | ||
type Options struct { | ||
commandPath string | ||
} | ||
|
||
// New returns a new overlay installer executor. | ||
func New(commandPath string) *Options { | ||
return &Options{ | ||
commandPath: commandPath, | ||
} | ||
} | ||
|
||
// GetOptions returns the options for the overlay installer. | ||
func (o *Options) GetOptions(extra overlay.InstallExtraOptions) (overlay.Options, error) { | ||
// parse extra as yaml | ||
extraYAML, err := yaml.Marshal(extra) | ||
if err != nil { | ||
return overlay.Options{}, fmt.Errorf("failed to marshal extra: %w", err) | ||
} | ||
|
||
out, err := o.execute(bytes.NewReader(extraYAML), "get-options") | ||
if err != nil { | ||
return overlay.Options{}, fmt.Errorf("failed to run overlay installer: %w", err) | ||
} | ||
|
||
var options overlay.Options | ||
|
||
if err := yaml.Unmarshal(out, &options); err != nil { | ||
return overlay.Options{}, fmt.Errorf("failed to unmarshal overlay options: %w", err) | ||
} | ||
|
||
return options, nil | ||
} | ||
|
||
// Install installs the overlay. | ||
func (o *Options) Install(options overlay.InstallOptions) error { | ||
optionsBytes, err := yaml.Marshal(&options) | ||
if err != nil { | ||
return fmt.Errorf("failed to marshal options: %w", err) | ||
} | ||
|
||
if _, err := o.execute(bytes.NewReader(optionsBytes), "install"); err != nil { | ||
return fmt.Errorf("failed to run overlay installer: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (o *Options) execute(stdin io.Reader, args ...string) ([]byte, error) { | ||
cmd := exec.Command(o.commandPath, args...) | ||
cmd.Stdin = stdin | ||
|
||
var stdOut, stdErr bytes.Buffer | ||
|
||
cmd.Stdout = &stdOut | ||
cmd.Stderr = &stdErr | ||
|
||
if err := cmd.Run(); err != nil { | ||
return nil, fmt.Errorf("failed to run overlay installer: %w, stdErr: %s", err, stdErr.Bytes()) | ||
} | ||
|
||
return stdOut.Bytes(), nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.