commit
08cc716de5
@ -0,0 +1,24 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"opendev.org/airship/airshipctl/pkg/bootstrap/isogen"
|
||||
"opendev.org/airship/airshipctl/pkg/environment"
|
||||
)
|
||||
|
||||
// NewISOGenCommand creates a new command for ISO image creation
|
||||
func NewISOGenCommand(parent *cobra.Command, rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
settings := &isogen.Settings{AirshipCTLSettings: rootSettings}
|
||||
imageGen := &cobra.Command{
|
||||
Use: "isogen",
|
||||
Short: "Generate bootstrap ISO image",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return isogen.GenerateBootstrapIso(settings, args, cmd.OutOrStdout())
|
||||
},
|
||||
}
|
||||
|
||||
settings.InitFlags(imageGen)
|
||||
|
||||
return imageGen
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package bootstrap_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"opendev.org/airship/airshipctl/cmd/bootstrap"
|
||||
"opendev.org/airship/airshipctl/testutil"
|
||||
)
|
||||
|
||||
func TestBootstrap(t *testing.T) {
|
||||
tests := []*testutil.CmdTest{
|
||||
{
|
||||
Name: "bootstrap-cmd-with-defaults",
|
||||
CmdLine: "",
|
||||
Cmd: bootstrap.NewBootstrapCommand(nil),
|
||||
},
|
||||
{
|
||||
Name: "bootstrap-isogen-cmd-with-help",
|
||||
CmdLine: "isogen --help",
|
||||
Cmd: bootstrap.NewBootstrapCommand(nil),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
testutil.RunTest(t, tt)
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
Bootstrap ephemeral Kubernetes cluster
|
||||
|
||||
Usage:
|
||||
bootstrap [command]
|
||||
|
||||
Available Commands:
|
||||
help Help about any command
|
||||
isogen Generate bootstrap ISO image
|
||||
|
||||
Flags:
|
||||
-h, --help help for bootstrap
|
||||
|
||||
Use "bootstrap [command] --help" for more information about a command.
|
@ -0,0 +1,8 @@
|
||||
Generate bootstrap ISO image
|
||||
|
||||
Usage:
|
||||
bootstrap isogen [flags]
|
||||
|
||||
Flags:
|
||||
-c, --config string Configuration file path for ISO builder container.
|
||||
-h, --help help for isogen
|
@ -0,0 +1,28 @@
|
||||
package isogen
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"opendev.org/airship/airshipctl/pkg/util"
|
||||
)
|
||||
|
||||
// ErrNotImplemented returned for not implemented features
|
||||
var ErrNotImplemented = errors.New("Error. Not implemented")
|
||||
|
||||
// GenerateBootstrapIso will generate data for cloud init and start ISO builder container
|
||||
func GenerateBootstrapIso(settings *Settings, args []string, out io.Writer) error {
|
||||
if settings.IsogenConfigFile == "" {
|
||||
fmt.Fprintln(out, "Reading config file location from global settings is not supported")
|
||||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
cfg := Config{}
|
||||
|
||||
if err := util.ReadYAMLFile(settings.IsogenConfigFile, &cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("Under construction")
|
||||
return nil
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package isogen
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"opendev.org/airship/airshipctl/pkg/environment"
|
||||
)
|
||||
|
||||
// Settings settings for isogen command
|
||||
type Settings struct {
|
||||
*environment.AirshipCTLSettings
|
||||
|
||||
// Configuration file (YAML-formatted) path for ISO builder container.
|
||||
IsogenConfigFile string
|
||||
}
|
||||
|
||||
// InitFlags adds falgs and their default settings for isogen command
|
||||
func (i *Settings) InitFlags(cmd *cobra.Command) {
|
||||
flags := cmd.Flags()
|
||||
flags.StringVarP(&i.IsogenConfigFile, "config", "c", "", "Configuration file path for ISO builder container.")
|
||||
}
|
||||
|
||||
// Config ISO builder container configuration
|
||||
type Config struct {
|
||||
// Configuration parameters for container
|
||||
Container Container `json:"container,omitempty"`
|
||||
// Configuration parameters for ISO builder
|
||||
Builder Builder `json:"builder,omitempty"`
|
||||
}
|
||||
|
||||
// Container parameters
|
||||
type Container struct {
|
||||
// Container volume directory binding.
|
||||
Volume string `json:"volume,omitempty"`
|
||||
// ISO generator container image URL
|
||||
Image string `json:"image,omitempty"`
|
||||
// Container Runtime Interface driver
|
||||
ContainerRuntime string `json:"containerRuntime,omitempty"`
|
||||
}
|
||||
|
||||
// Builder parameters
|
||||
type Builder struct {
|
||||
// Cloud Init user-data file name placed to the container volume root
|
||||
UserDataFileName string `json:"userDataFileName,omitempty"`
|
||||
// Cloud Init network-config file name placed to the container volume root
|
||||
NetworkConfigFileName string `json:"networkConfigFileName,omitempty"`
|
||||
// File name for output metadata
|
||||
OutputMetadataFileName string `json:"outputMetadataFileName,omitempty"`
|
||||
}
|
||||
|
||||
// ToYAML serializes confid to YAML
|
||||
func (c *Config) ToYAML() ([]byte, error) {
|
||||
return yaml.Marshal(c)
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
// ReadYAMLFile reads YAML-formatted configuration file and
|
||||
// de-serializes it to a given object
|
||||
func ReadYAMLFile(filePath string, cfg interface{}) error {
|
||||
data, err := ioutil.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return yaml.Unmarshal(data, cfg)
|
||||
}
|
Loading…
Reference in new issue