mirror of
https://github.com/hauler-dev/hauler.git
synced 2026-08-19 04:16:27 +00:00
move create/bootstrap to pkg subcommand, rename to build and run
This commit is contained in:
@@ -1,90 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/rancherfederal/hauler/pkg/bootstrap"
|
||||
"github.com/rancherfederal/hauler/pkg/driver"
|
||||
"github.com/rancherfederal/hauler/pkg/packager"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
)
|
||||
|
||||
type deployOpts struct {
|
||||
*rootOpts
|
||||
|
||||
haulerDir string
|
||||
}
|
||||
|
||||
// NewBootstrapCommand new a new sub command of haulerctl that bootstraps a cluster
|
||||
func NewBootstrapCommand() *cobra.Command {
|
||||
opts := &deployOpts{
|
||||
rootOpts: &ro,
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "bootstrap",
|
||||
Short: "Single-command install of a k3s cluster with known tools running inside of it",
|
||||
Long: `Single-command install of a k3s cluster with known tools running inside of it. Tools
|
||||
include an OCI registry and Git server`,
|
||||
Aliases: []string{"b", "boot"},
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return opts.Run(args[0])
|
||||
},
|
||||
}
|
||||
|
||||
f := cmd.Flags()
|
||||
f.StringVarP(&opts.haulerDir, "hauler-dir", "", "/opt/hauler", "Directory to install hauler components in")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Run performs the operation.
|
||||
func (o *deployOpts) Run(packagePath string) error {
|
||||
o.logger.Infof("Bootstrapping from '%s'", packagePath)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
tmpdir, err := os.MkdirTemp("", "hauler")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.Remove(tmpdir)
|
||||
o.logger.Debugf("Using temporary working directory: %s", tmpdir)
|
||||
|
||||
a := packager.NewArchiver()
|
||||
err = packager.Unpackage(a, packagePath, tmpdir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b, err := bootstrap.NewBooter(tmpdir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d := driver.NewDriver(b.Package.Spec.Driver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.logger.Infof("Performing pre %s boot steps", b.Package.Spec.Driver.Type)
|
||||
if err := b.PreBoot(ctx, d, o.logger); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.logger.Infof("Booting %s", b.Package.Spec.Driver.Type)
|
||||
if err := b.Boot(ctx, d, o.logger); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.logger.Infof("Performing post %s boot steps", b.Package.Spec.Driver.Type)
|
||||
if err := b.PostBoot(ctx, d, o.logger); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.logger.Infof("Success! You can access the cluster with '/opt/hauler/bin/kubectl'")
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/rancherfederal/hauler/pkg/apis/hauler.cattle.io/v1alpha1"
|
||||
"github.com/rancherfederal/hauler/pkg/driver"
|
||||
"github.com/rancherfederal/hauler/pkg/packager"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
type createOpts struct {
|
||||
*rootOpts
|
||||
|
||||
driver string
|
||||
outputFile string
|
||||
configFile string
|
||||
}
|
||||
|
||||
// NewCreateCommand creates a new sub command under
|
||||
// haulerctl for creating dependency artifacts for bootstraps
|
||||
func NewCreateCommand() *cobra.Command {
|
||||
opts := &createOpts{
|
||||
rootOpts: &ro,
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "package all dependencies into a compressed archive",
|
||||
Long: `package all dependencies into a compressed archive used by deploy.
|
||||
|
||||
Container images, git repositories, and more, packaged and ready to be served within an air gap.`,
|
||||
Aliases: []string{"c"},
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
return opts.PreRun()
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return opts.Run()
|
||||
},
|
||||
}
|
||||
|
||||
f := cmd.Flags()
|
||||
f.StringVarP(&opts.driver, "driver", "d", "k3s",
|
||||
"IDriver type to use for package (k3s or rke2)")
|
||||
f.StringVarP(&opts.outputFile, "output", "o", "haul.tar.zst",
|
||||
"package output location relative to the current directory (haul.tar.zst)")
|
||||
f.StringVarP(&opts.configFile, "config", "c", "./package.yaml",
|
||||
"config file")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (o *createOpts) PreRun() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run performs the operation.
|
||||
func (o *createOpts) Run() error {
|
||||
o.logger.Infof("Creating new deployable bundle using driver: %s", o.driver)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
if _, err := os.Stat(o.configFile); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
bundleData, err := os.ReadFile(o.configFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var p v1alpha1.Package
|
||||
err = yaml.Unmarshal(bundleData, &p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tmpdir, err := os.MkdirTemp("", "hauler")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.RemoveAll(tmpdir)
|
||||
|
||||
pkgr := packager.NewPackager(tmpdir, o.logger)
|
||||
|
||||
o.logger.Infof("Packaging driver (%s %s) artifacts...", p.Spec.Driver.Version, p.Spec.Driver.Type)
|
||||
d := driver.NewDriver(p.Spec.Driver)
|
||||
if err = pkgr.PackageDriver(ctx, d); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.logger.Infof("Packaging fleet artifacts...")
|
||||
if err = pkgr.PackageFleet(ctx, p.Spec.Fleet); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.logger.Infof("Packaging images and manifests defined in specified paths...")
|
||||
if _, err = pkgr.PackageBundles(ctx, p.Spec.Paths...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
a := packager.NewArchiver()
|
||||
o.logger.Infof("Archiving and compressing package to: %s.%s", o.outputFile, a.String())
|
||||
if err = pkgr.Archive(a, p, o.outputFile); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/rancherfederal/hauler/pkg/apis/hauler.cattle.io/v1alpha1"
|
||||
"io/ioutil"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"os"
|
||||
"sigs.k8s.io/yaml"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_createOpts_Run(t *testing.T) {
|
||||
l, _ := setupCliLogger(os.Stdout, "debug")
|
||||
tro := rootOpts{l}
|
||||
|
||||
p := v1alpha1.Package{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Package",
|
||||
APIVersion: "hauler.cattle.io/v1alpha1",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test",
|
||||
},
|
||||
Spec: v1alpha1.PackageSpec{
|
||||
Fleet: v1alpha1.Fleet{Version: "0.3.5"},
|
||||
Driver: v1alpha1.Driver{
|
||||
Type: "k3s",
|
||||
Version: "v1.21.1+k3s1",
|
||||
},
|
||||
Paths: []string{
|
||||
"../../../testdata/docker-registry",
|
||||
"../../../testdata/rawmanifests",
|
||||
},
|
||||
Images: []string{},
|
||||
},
|
||||
}
|
||||
|
||||
data, _ := yaml.Marshal(p)
|
||||
if err := ioutil.WriteFile("create_test.package.yaml", data, 0644); err != nil {
|
||||
t.Fatalf("failed to write test config file: %v", err)
|
||||
}
|
||||
defer os.Remove("create_test.package.yaml")
|
||||
|
||||
type fields struct {
|
||||
rootOpts *rootOpts
|
||||
driver string
|
||||
outputFile string
|
||||
configFile string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "should work",
|
||||
fields: fields{
|
||||
rootOpts: &tro,
|
||||
driver: "k3s",
|
||||
outputFile: "package",
|
||||
configFile: "./create_test.package.yaml",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
o := &createOpts{
|
||||
rootOpts: tt.fields.rootOpts,
|
||||
driver: tt.fields.driver,
|
||||
outputFile: tt.fields.outputFile,
|
||||
configFile: tt.fields.configFile,
|
||||
}
|
||||
if err := o.Run(); (err != nil) != tt.wantErr {
|
||||
t.Errorf("Run() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,8 @@ func NewPkgCommand() *cobra.Command {
|
||||
},
|
||||
}
|
||||
|
||||
cmd.AddCommand(NewPkgCreateCommand())
|
||||
cmd.AddCommand(NewPkgBootCommand())
|
||||
cmd.AddCommand(NewPkgBuildCommand())
|
||||
cmd.AddCommand(NewPkgRunCommand())
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
package app
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
type pkgBootOpts struct {
|
||||
cfgFile string
|
||||
}
|
||||
|
||||
func NewPkgBootCommand() *cobra.Command {
|
||||
opts := pkgBootOpts{}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "boot",
|
||||
Short: "",
|
||||
Long: "",
|
||||
Aliases: []string{"b", "bootstrap"},
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
return opts.PreRun()
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return opts.Run()
|
||||
},
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (o *pkgBootOpts) PreRun() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *pkgBootOpts) Run() error {
|
||||
return nil
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package app
|
||||
import (
|
||||
"context"
|
||||
"github.com/rancherfederal/hauler/pkg/apis/hauler.cattle.io/v1alpha1"
|
||||
"github.com/rancherfederal/hauler/pkg/driver"
|
||||
"github.com/rancherfederal/hauler/pkg/packager"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -10,9 +12,12 @@ import (
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
type pkgCreateOpts struct {
|
||||
type pkgBuildOpts struct {
|
||||
*rootOpts
|
||||
|
||||
cfgFile string
|
||||
|
||||
name string
|
||||
driver string
|
||||
driverVersion string
|
||||
|
||||
@@ -22,14 +27,16 @@ type pkgCreateOpts struct {
|
||||
paths []string
|
||||
}
|
||||
|
||||
func NewPkgCreateCommand() *cobra.Command {
|
||||
opts := pkgCreateOpts{}
|
||||
func NewPkgBuildCommand() *cobra.Command {
|
||||
opts := pkgBuildOpts{
|
||||
rootOpts: &ro,
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "create",
|
||||
Use: "build",
|
||||
Short: "",
|
||||
Long: "",
|
||||
Aliases: []string{"c"},
|
||||
Aliases: []string{"b"},
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
return opts.PreRun()
|
||||
},
|
||||
@@ -39,6 +46,8 @@ func NewPkgCreateCommand() *cobra.Command {
|
||||
}
|
||||
|
||||
f := cmd.PersistentFlags()
|
||||
f.StringVarP(&opts.name, "name", "n", "pkg",
|
||||
"name of the pkg to create, will dicate file name")
|
||||
f.StringVarP(&opts.cfgFile, "config", "c", "./pkg.yaml",
|
||||
"path to config file")
|
||||
f.StringVarP(&opts.driver, "driver", "d", "k3s",
|
||||
@@ -55,7 +64,7 @@ func NewPkgCreateCommand() *cobra.Command {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (o *pkgCreateOpts) PreRun() error {
|
||||
func (o *pkgBuildOpts) PreRun() error {
|
||||
_, err := os.Stat(o.cfgFile)
|
||||
if os.IsNotExist(err) {
|
||||
logrus.Infof("Could not find %s, creating one", o.cfgFile)
|
||||
@@ -65,7 +74,7 @@ func (o *pkgCreateOpts) PreRun() error {
|
||||
APIVersion: "",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "",
|
||||
Name: o.name,
|
||||
},
|
||||
Spec: v1alpha1.PackageSpec{
|
||||
Fleet: v1alpha1.Fleet{
|
||||
@@ -96,11 +105,47 @@ func (o *pkgCreateOpts) PreRun() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *pkgCreateOpts) Run() error {
|
||||
func (o *pkgBuildOpts) Run() error {
|
||||
o.logger.Infof("Building package")
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
_ = ctx
|
||||
cfgData, err := os.ReadFile(o.cfgFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var p v1alpha1.Package
|
||||
if err := yaml.Unmarshal(cfgData, &p); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tmpdir, err := os.MkdirTemp("", "hauler")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pkgr := packager.NewPackager(tmpdir, o.logger)
|
||||
|
||||
d := driver.NewDriver(p.Spec.Driver)
|
||||
if dErr := pkgr.PackageDriver(ctx, d); dErr != nil {
|
||||
return dErr
|
||||
}
|
||||
|
||||
if fErr := pkgr.PackageFleet(ctx, p.Spec.Fleet); fErr != nil {
|
||||
return fErr
|
||||
}
|
||||
|
||||
if _, bErr := pkgr.PackageBundles(ctx, p.Spec.Paths...); bErr != nil {
|
||||
return bErr
|
||||
}
|
||||
|
||||
a := packager.NewArchiver()
|
||||
if aErr := pkgr.Archive(a, p, o.name); aErr != nil {
|
||||
return aErr
|
||||
}
|
||||
|
||||
o.logger.Successf("Finished building package")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_pkgBuildOpts_Run(t *testing.T) {
|
||||
l, _ := setupCliLogger(os.Stdout, "debug")
|
||||
tro := rootOpts{l}
|
||||
|
||||
type fields struct {
|
||||
rootOpts *rootOpts
|
||||
cfgFile string
|
||||
name string
|
||||
driver string
|
||||
driverVersion string
|
||||
fleetVersion string
|
||||
images []string
|
||||
paths []string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "should work",
|
||||
fields: fields{
|
||||
rootOpts: &tro,
|
||||
cfgFile: "pkg.yaml",
|
||||
name: "k3s",
|
||||
driver: "k3s",
|
||||
driverVersion: "v1.21.1+k3s1",
|
||||
fleetVersion: "0.3.5",
|
||||
images: nil,
|
||||
paths: []string{
|
||||
"../../../testdata/docker-registry",
|
||||
"../../../testdata/rawmanifests",
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
o := &pkgBuildOpts{
|
||||
rootOpts: tt.fields.rootOpts,
|
||||
cfgFile: tt.fields.cfgFile,
|
||||
name: tt.fields.name,
|
||||
driver: tt.fields.driver,
|
||||
driverVersion: tt.fields.driverVersion,
|
||||
fleetVersion: tt.fields.fleetVersion,
|
||||
images: tt.fields.images,
|
||||
paths: tt.fields.paths,
|
||||
}
|
||||
|
||||
if err := o.PreRun(); err != nil {
|
||||
t.Errorf("PreRun() error = %v", err)
|
||||
}
|
||||
defer os.Remove(o.cfgFile)
|
||||
|
||||
if err := o.Run(); (err != nil) != tt.wantErr {
|
||||
t.Errorf("Run() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/rancherfederal/hauler/pkg/bootstrap"
|
||||
"github.com/rancherfederal/hauler/pkg/driver"
|
||||
"github.com/rancherfederal/hauler/pkg/packager"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
)
|
||||
|
||||
type pkgRunOpts struct {
|
||||
*rootOpts
|
||||
|
||||
cfgFile string
|
||||
}
|
||||
|
||||
func NewPkgRunCommand() *cobra.Command {
|
||||
opts := pkgRunOpts{
|
||||
rootOpts: &ro,
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "run",
|
||||
Short: "",
|
||||
Long: "",
|
||||
Aliases: []string{"r"},
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
return opts.PreRun()
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return opts.Run(args[0])
|
||||
},
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (o *pkgRunOpts) PreRun() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *pkgRunOpts) Run(pkgPath string) error {
|
||||
o.logger.Infof("Running from '%s'", pkgPath)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
tmpdir, err := os.MkdirTemp("", "hauler")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o.logger.Debugf("Using temporary working directory: %s", tmpdir)
|
||||
|
||||
a := packager.NewArchiver()
|
||||
|
||||
if err := packager.Unpackage(a, pkgPath, tmpdir); err != nil {
|
||||
return err
|
||||
}
|
||||
o.logger.Debugf("Unpackaged %s", pkgPath)
|
||||
|
||||
b, err := bootstrap.NewBooter(tmpdir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d := driver.NewDriver(b.Package.Spec.Driver)
|
||||
|
||||
if preErr := b.PreBoot(ctx, d, o.logger); preErr != nil {
|
||||
return preErr
|
||||
}
|
||||
|
||||
if bErr := b.Boot(ctx, d, o.logger); bErr != nil {
|
||||
return bErr
|
||||
}
|
||||
|
||||
if postErr := b.PostBoot(ctx, d, o.logger); postErr != nil {
|
||||
return postErr
|
||||
}
|
||||
|
||||
o.logger.Successf("Access the cluster with '/opt/hauler/bin/kubectl'")
|
||||
return nil
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
homedir "github.com/mitchellh/go-homedir"
|
||||
@@ -72,7 +71,6 @@ func NewRootCommand() *cobra.Command {
|
||||
|
||||
cmd.AddCommand(NewPkgCommand())
|
||||
cmd.AddCommand(NewCreateCommand())
|
||||
cmd.AddCommand(NewBootstrapCommand())
|
||||
|
||||
f := cmd.PersistentFlags()
|
||||
f.StringVarP(&loglevel, "loglevel", "l", "info",
|
||||
@@ -111,11 +109,5 @@ func initConfig() {
|
||||
func setupCliLogger(out io.Writer, level string) (log.Logger, error) {
|
||||
l := log.NewLogger(out)
|
||||
|
||||
lvl, err := logrus.ParseLevel(level)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
l.SetLevel(lvl)
|
||||
return l, nil
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@ require (
|
||||
github.com/imdario/mergo v0.3.12
|
||||
github.com/klauspost/compress v1.13.0 // indirect
|
||||
github.com/klauspost/pgzip v1.2.5 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.13 // indirect
|
||||
github.com/mholt/archiver/v3 v3.5.0
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/opencontainers/image-spec v1.0.2-0.20190823105129-775207bd45b6
|
||||
github.com/opencontainers/runc v1.0.0-rc93 // indirect
|
||||
github.com/otiai10/copy v1.6.0
|
||||
github.com/pelletier/go-toml v1.8.1 // indirect
|
||||
github.com/pterm/pterm v0.12.24
|
||||
github.com/rancher/fleet v0.3.5
|
||||
github.com/rancher/fleet/pkg/apis v0.0.0
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
@@ -33,7 +33,6 @@ require (
|
||||
github.com/ulikunitz/xz v0.5.10 // indirect
|
||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
|
||||
golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect
|
||||
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
|
||||
google.golang.org/genproto v0.0.0-20210524171403-669157292da3 // indirect
|
||||
google.golang.org/grpc v1.38.0 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
|
||||
@@ -194,6 +194,8 @@ github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:l
|
||||
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
|
||||
github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 h1:4daAzAu0S6Vi7/lbWECcX0j45yZReDZ56BQsrVBOEEY=
|
||||
github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535/go.mod h1:oGkLhpf+kjZl6xBf758TQhh5XrAeiJv/7FRz/2spLIg=
|
||||
github.com/atomicgo/cursor v0.0.1 h1:xdogsqa6YYlLfM+GyClC/Lchf7aiMerFiZQn7soTOoU=
|
||||
github.com/atomicgo/cursor v0.0.1/go.mod h1:cBON2QmmrysudxNBFthvMtN32r3jxVRIvzkUiF/RuIk=
|
||||
github.com/auth0/go-jwt-middleware v0.0.0-20170425171159-5493cabe49f7/go.mod h1:LWMyo4iOLWXHGdBki7NIht1kHru/0wM179h+d3g8ATM=
|
||||
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
|
||||
github.com/aws/aws-sdk-go v1.15.11/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0=
|
||||
@@ -686,6 +688,8 @@ github.com/googleapis/gnostic v0.3.1/go.mod h1:on+2t9HRStVgn95RSsFWFz+6Q0Snyqv1a
|
||||
github.com/googleapis/gnostic v0.4.1/go.mod h1:LRhVm6pbyptWbWbuZ38d1eyptfvIytN3ir6b65WBswg=
|
||||
github.com/googleapis/gnostic v0.5.5 h1:9fHAtK0uDfpveeqqo1hkEZJcFvYXAiCN3UutL8F9xHw=
|
||||
github.com/googleapis/gnostic v0.5.5/go.mod h1:7+EbHbldMins07ALC74bsA81Ovc97DwqyJO1AENw9kA=
|
||||
github.com/gookit/color v1.4.2 h1:tXy44JFSFkKnELV6WaMo/lLfu/meqITX3iAV52do7lk=
|
||||
github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ=
|
||||
github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
@@ -1167,6 +1171,8 @@ github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O
|
||||
github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4=
|
||||
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
|
||||
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
|
||||
github.com/pterm/pterm v0.12.24 h1:VM23UV0UddFxHaEN14SCIIYcr4SE5VnoK80AnoeuGbg=
|
||||
github.com/pterm/pterm v0.12.24/go.mod h1:PhQ89w4i95rhgE+xedAoqous6K9X+r6aSOI2eFF7DZI=
|
||||
github.com/qri-io/starlib v0.4.2-0.20200213133954-ff2e8cd5ef8d h1:K6eOUihrFLdZjZnA4XlRp864fmWXv9YTIk7VPLhRacA=
|
||||
github.com/qri-io/starlib v0.4.2-0.20200213133954-ff2e8cd5ef8d/go.mod h1:7DPO4domFU579Ga6E61sB9VFNaniPVwJP5C4bBCu3wA=
|
||||
github.com/quasilyte/go-consistent v0.0.0-20190521200055-c6f3937de18c/go.mod h1:5STLWrekHfjyYwxBRVRXNOSewLJ3PWfDJd1VyTS21fI=
|
||||
@@ -1355,6 +1361,8 @@ github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMx
|
||||
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
|
||||
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca h1:1CFlNzQhALwjS9mBAUkycX616GzgsuYUOCHA5+HSlXI=
|
||||
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg=
|
||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
|
||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
|
||||
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
|
||||
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
@@ -1647,6 +1655,7 @@ golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 h1:JWgyZ1qgdTaF3N3oxC+MdTV7qvEEgHo3otj+HB5CM7Q=
|
||||
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
||||
+13
-16
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/rancherfederal/hauler/pkg/driver"
|
||||
"github.com/rancherfederal/hauler/pkg/fs"
|
||||
"github.com/rancherfederal/hauler/pkg/log"
|
||||
"github.com/sirupsen/logrus"
|
||||
"helm.sh/helm/v3/pkg/chart/loader"
|
||||
"io"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
@@ -46,9 +45,7 @@ func NewBooter(pkgPath string) (*booter, error) {
|
||||
}
|
||||
|
||||
func (b booter) PreBoot(ctx context.Context, d driver.Driver, logger log.Logger) error {
|
||||
l := logger.WithFields(logrus.Fields{
|
||||
"phase": "preboot",
|
||||
})
|
||||
logger.Infof("Beginning pre boot")
|
||||
|
||||
//TODO: Feel like there's a better way to do this
|
||||
if err := b.moveBin(); err != nil {
|
||||
@@ -67,18 +64,18 @@ func (b booter) PreBoot(ctx context.Context, d driver.Driver, logger log.Logger)
|
||||
return err
|
||||
}
|
||||
|
||||
l.Infof("Creating driver configuration")
|
||||
logger.Debugf("Writing %s config", d.Name())
|
||||
if err := d.WriteConfig(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Successf("Completed pre boot")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b booter) Boot(ctx context.Context, d driver.Driver, logger log.Logger) error {
|
||||
l := logger.WithFields(logrus.Fields{
|
||||
"phase": "boot",
|
||||
})
|
||||
logger.Infof("Beginning boot")
|
||||
|
||||
var stdoutBuf, stderrBuf bytes.Buffer
|
||||
out := io.MultiWriter(os.Stdout, &stdoutBuf, &stderrBuf)
|
||||
@@ -88,19 +85,18 @@ func (b booter) Boot(ctx context.Context, d driver.Driver, logger log.Logger) er
|
||||
return err
|
||||
}
|
||||
|
||||
l.Infof("Waiting for driver core components to provision...")
|
||||
logger.Infof("Waiting for driver core components to provision...")
|
||||
waitErr := waitForDriver(ctx, d)
|
||||
if waitErr != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Successf("Completed boot")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b booter) PostBoot(ctx context.Context, d driver.Driver, logger log.Logger) error {
|
||||
l := logger.WithFields(logrus.Fields{
|
||||
"phase": "postboot",
|
||||
})
|
||||
logger.Infof("Beginning post boot")
|
||||
|
||||
cf := genericclioptions.NewConfigFlags(true)
|
||||
cf.KubeConfig = stringptr(d.KubeConfigPath())
|
||||
@@ -111,13 +107,13 @@ func (b booter) PostBoot(ctx context.Context, d driver.Driver, logger log.Logger
|
||||
return err
|
||||
}
|
||||
|
||||
l.Infof("Installing fleet crds")
|
||||
logger.Infof("Installing fleet crds")
|
||||
fleetCrdRelease, fleetCrdErr := installChart(cf, fleetCrdChart, "fleet-crd", "fleet-system", nil)
|
||||
if fleetCrdErr != nil {
|
||||
return fleetCrdErr
|
||||
}
|
||||
|
||||
l.Infof("Successfully installed '%s' to namespace '%s'", fleetCrdRelease.Name, fleetCrdRelease.Namespace)
|
||||
logger.Infof("Successfully installed '%s' to namespace '%s'", fleetCrdRelease.Name, fleetCrdRelease.Namespace)
|
||||
|
||||
fleetChartPath := b.fs.Chart().Path(fmt.Sprintf("fleet-%s.tgz", b.Package.Spec.Fleet.Version))
|
||||
fleetChart, err := loader.Load(fleetChartPath)
|
||||
@@ -125,14 +121,15 @@ func (b booter) PostBoot(ctx context.Context, d driver.Driver, logger log.Logger
|
||||
return err
|
||||
}
|
||||
|
||||
l.Infof("Installing fleet")
|
||||
logger.Infof("Installing fleet")
|
||||
fleetRelease, fleetErr := installChart(cf, fleetChart, "fleet", "fleet-system", nil)
|
||||
if fleetErr != nil {
|
||||
return fleetErr
|
||||
}
|
||||
|
||||
l.Infof("Successfully installed '%s' to namespace '%s'", fleetRelease.Name, fleetRelease.Namespace)
|
||||
logger.Infof("Successfully installed '%s' to namespace '%s'", fleetRelease.Name, fleetRelease.Namespace)
|
||||
|
||||
logger.Successf("Completed post boot")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
+39
-7
@@ -1,7 +1,7 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/pterm/pterm"
|
||||
"io"
|
||||
)
|
||||
|
||||
@@ -10,12 +10,12 @@ type Logger interface {
|
||||
Infof(string, ...interface{})
|
||||
Warnf(string, ...interface{})
|
||||
Debugf(string, ...interface{})
|
||||
|
||||
WithFields(logrus.Fields) *logrus.Entry
|
||||
Successf(string, ...interface{})
|
||||
}
|
||||
|
||||
type standardLogger struct {
|
||||
*logrus.Logger
|
||||
//TODO: Actually check this
|
||||
level string
|
||||
}
|
||||
|
||||
type Event struct {
|
||||
@@ -28,10 +28,42 @@ var (
|
||||
)
|
||||
|
||||
func NewLogger(out io.Writer) *standardLogger {
|
||||
logger := logrus.New()
|
||||
logger.SetOutput(out)
|
||||
return &standardLogger{}
|
||||
}
|
||||
|
||||
return &standardLogger{logger}
|
||||
func (l *standardLogger) Errorf(format string, args ...interface{}) {
|
||||
l.logf("error", format, args...)
|
||||
}
|
||||
|
||||
func (l *standardLogger) Infof(format string, args ...interface{}) {
|
||||
l.logf("info", format, args...)
|
||||
}
|
||||
|
||||
func (l *standardLogger) Warnf(format string, args ...interface{}) {
|
||||
l.logf("warn", format, args...)
|
||||
}
|
||||
|
||||
func (l *standardLogger) Debugf(format string, args ...interface{}) {
|
||||
l.logf("debug", format, args...)
|
||||
}
|
||||
|
||||
func (l *standardLogger) Successf(format string, args ...interface{}) {
|
||||
l.logf("success", format, args...)
|
||||
}
|
||||
|
||||
func (l *standardLogger) logf(level string, format string, args ...interface{}) {
|
||||
switch level {
|
||||
case "debug":
|
||||
pterm.Debug.Printfln(format, args...)
|
||||
case "info":
|
||||
pterm.Info.Printfln(format, args...)
|
||||
case "warn":
|
||||
pterm.Warning.Printfln(format, args...)
|
||||
case "success":
|
||||
pterm.Success.Printfln(format, args...)
|
||||
default:
|
||||
pterm.Error.Printfln("%s is not a valid log level", level)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *standardLogger) InvalidArg(arg string) {
|
||||
|
||||
Reference in New Issue
Block a user