chore: ran go fmt

This commit is contained in:
Jennifer Power
2021-06-10 12:27:38 -04:00
parent 5cec0b644a
commit 2f9f2ac774
14 changed files with 58 additions and 56 deletions

View File

@@ -12,8 +12,8 @@ import (
)
type createOpts struct {
driver string
outputFile string
driver string
outputFile string
configFile string
}
@@ -112,4 +112,4 @@ func newTarZstd() *archiver.TarZstd {
ContinueOnError: false,
},
}
}
}

View File

@@ -11,20 +11,20 @@ import (
func Test_createOpts_Run(t *testing.T) {
p := v1alpha1.Package{
TypeMeta: metav1.TypeMeta{
TypeMeta: metav1.TypeMeta{
Kind: "Package",
APIVersion: "hauler.cattle.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Name: "test",
},
Spec: v1alpha1.PackageSpec{
Spec: v1alpha1.PackageSpec{
Fleet: v1alpha1.Fleet{Version: "0.3.5"},
Driver: v1alpha1.Driver{
Kind: "k3s",
Kind: "k3s",
Version: "v1.21.1+k3s1",
},
Paths: []string{
Paths: []string{
//"../../../testdata/docker-registry",
"../../../testdata/rawmanifests",
},
@@ -37,7 +37,7 @@ func Test_createOpts_Run(t *testing.T) {
t.Fatalf("failed to write test config file: %v", err)
}
defer os.Remove("create_test.package.yaml")
type fields struct {
driver string
outputFile string
@@ -69,4 +69,4 @@ func Test_createOpts_Run(t *testing.T) {
}
})
}
}
}

View File

@@ -7,7 +7,7 @@ import (
)
type ociOpts struct {
insecure bool
insecure bool
plainHTTP bool
}
@@ -19,7 +19,7 @@ func NewOCICommand() *cobra.Command {
opts := ociOpts{}
cmd := &cobra.Command{
Use: "oci",
Use: "oci",
Short: "oci stuff",
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
@@ -39,4 +39,4 @@ func NewOCICommand() *cobra.Command {
func (o *ociOpts) resolver() (remotes.Resolver, error) {
resolver := docker.NewResolver(docker.ResolverOptions{PlainHTTP: true})
return resolver, nil
}
}

View File

@@ -12,17 +12,17 @@ type ociPullOpts struct {
ociOpts
sourceRef string
outDir string
outDir string
}
func NewOCIPullCommand() *cobra.Command {
opts := ociPullOpts{}
cmd := &cobra.Command{
Use: "pull",
Short: "oci pull",
Use: "pull",
Short: "oci pull",
Aliases: []string{"p"},
Args: cobra.MinimumNArgs(1),
Args: cobra.MinimumNArgs(1),
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.PreRun()
},
@@ -64,4 +64,4 @@ func (o *ociPullOpts) Run() error {
logrus.Infof("pulled %s with digest: %s", o.sourceRef, desc.Digest)
return nil
}
}

View File

@@ -2,9 +2,9 @@ package app
import (
"context"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/deislabs/oras/pkg/content"
"github.com/deislabs/oras/pkg/oras"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"os"
@@ -14,17 +14,17 @@ type ociPushOpts struct {
ociOpts
targetRef string
pathRef string
pathRef string
}
func NewOCIPushCommand() *cobra.Command {
opts := ociPushOpts{}
cmd := &cobra.Command{
Use: "push",
Short: "oci push",
Use: "push",
Short: "oci push",
Aliases: []string{"p"},
Args: cobra.MinimumNArgs(2),
Args: cobra.MinimumNArgs(2),
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.PreRun()
},
@@ -71,4 +71,4 @@ func (o *ociPushOpts) Run() error {
logrus.Infof("pushed %s to %s with digest: %s", o.pathRef, o.targetRef, desc.Digest)
return nil
}
}

View File

@@ -14,17 +14,19 @@ type Drive interface {
}
type Driver struct {
Kind string `json:"kind"`
Kind string `json:"kind"`
Version string `json:"version"`
}
type k3s struct {
dataDir string
etcDir string
etcDir string
}
//TODO: Don't hardcode this
func (k k3s) BinURL() string { return "https://github.com/k3s-io/k3s/releases/download/v1.21.1%2Bk3s1/k3s" }
func (k k3s) BinURL() string {
return "https://github.com/k3s-io/k3s/releases/download/v1.21.1%2Bk3s1/k3s"
}
func (k k3s) Images() ([]string, error) {
//TODO: Replace this with a query to images.txt on release page
@@ -40,17 +42,18 @@ func (k k3s) Images() ([]string, error) {
}, nil
}
func (k k3s) ImagesDir() string { return filepath.Join(k.dataDir, "agent/images") }
func (k k3s) ImagesDir() string { return filepath.Join(k.dataDir, "agent/images") }
func (k k3s) ManifestsDir() string { return filepath.Join(k.dataDir, "server/manifests") }
func (k k3s) ConfigFile() string { return filepath.Join(k.etcDir, "config.yaml") }
func (k k3s) ConfigFile() string { return filepath.Join(k.etcDir, "config.yaml") }
//TODO: Implement rke2 as a driver
type rke2 struct {}
type rke2 struct{}
func (r rke2) Images() ([]string, error) { return []string{}, nil }
func (r rke2) BinURL() string { return "" }
func (r rke2) ImagesDir() string { return "" }
func (r rke2) ManifestsDir() string { return "" }
func (r rke2) ConfigFile() string { return "" }
func (r rke2) BinURL() string { return "" }
func (r rke2) ImagesDir() string { return "" }
func (r rke2) ManifestsDir() string { return "" }
func (r rke2) ConfigFile() string { return "" }
//NewDriver will return the appropriate driver given a kind, defaults to k3s
func NewDriver(kind string) Drive {
@@ -63,7 +66,7 @@ func NewDriver(kind string) Drive {
default:
d = k3s{
dataDir: "/var/lib/rancher/k3s",
etcDir: "/etc/rancher/k3s",
etcDir: "/etc/rancher/k3s",
}
}

View File

@@ -9,4 +9,4 @@ type Fleet struct {
//TODO: These should be identified from the chart version
func (f Fleet) Images() ([]string, error) {
return []string{"rancher/gitjob:v0.1.15", "rancher/fleet:v0.3.5", "rancher/fleet-agent:v0.3.5"}, nil
}
}

View File

@@ -6,13 +6,13 @@ import (
const (
BundlesDir = "bundles"
LayoutDir = "layout"
BinDir = "bin"
ChartDir = "charts"
LayoutDir = "layout"
BinDir = "bin"
ChartDir = "charts"
)
type Package struct {
metav1.TypeMeta `json:",inline"`
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec PackageSpec `json:"spec"`

View File

@@ -110,7 +110,7 @@ func start(ctx context.Context, d v1alpha1.Drive) ([]byte, error) {
cmd := exec.Command("/bin/sh", "/opt/hauler/bin/k3s-init.sh")
//General rule of thumb is keep as much configuration in config.yaml as possible, only set script args here
cmd.Env = append(os.Environ(), []string{
cmd.Env = append(os.Environ(), []string{
"INSTALL_K3S_SKIP_DOWNLOAD=true",
"INSTALL_K3S_SELINUX_WARN=true",
"INSTALL_K3S_SKIP_SELINUX_RPM=true",
@@ -138,7 +138,7 @@ func waitForDriver(ctx context.Context, cfg *rest.Config) error {
return errors.New("timed out waiting for driver")
}
time.Sleep(5*time.Second)
time.Sleep(5 * time.Second)
}
logrus.Infof("waiting for k3s to be ready")
@@ -233,7 +233,6 @@ func installFleet(ctx context.Context, fsys fs.PkgFs, cfg *rest.Config) error {
return nil
}
//installChart is a helper function to install a chart located _on disk_
//TODO: This is probably wrong since it makes several fleet assumptions
func installChart(cf *genericclioptions.ConfigFlags, path string, name string, namespace string) (*release.Release, error) {

View File

@@ -118,10 +118,10 @@ func (p PkgFs) AddImage(ref name.Reference, img v1.Image) error {
//For ref: https://github.com/helm/helm/blob/bf486a25cdc12017c7dac74d1582a8a16acd37ea/pkg/action/pull.go#L75
func (p PkgFs) AddChart(ref string, version string) error {
d := downloader.ChartDownloader{
Out: nil,
Verify: downloader.VerifyNever,
Getters: getter.All(cli.New()), // TODO: Probably shouldn't do this...
Options: []getter.Option{
Out: nil,
Verify: downloader.VerifyNever,
Getters: getter.All(cli.New()), // TODO: Probably shouldn't do this...
Options: []getter.Option{
getter.WithInsecureSkipVerifyTLS(true),
},
}
@@ -226,4 +226,4 @@ func (p PkgFs) MoveChart() error {
}
return copy.Copy(p.Chart().path(), "/var/lib/rancher/k3s/server/static/charts/hauler")
}
}

View File

@@ -10,11 +10,11 @@ import (
func NewKubeConfig() (*rest.Config, error) {
loadingRules := &clientcmd.ClientConfigLoadingRules{
Precedence: []string{
Precedence: []string{
filepath.Join("/etc/rancher/k3s/k3s.yaml"),
filepath.Join("/etc/rancher/rke2/rke2.yaml"),
},
WarnIfAllMissing: true,
WarnIfAllMissing: true,
}
cfgOverrides := &clientcmd.ConfigOverrides{}

View File

@@ -22,7 +22,7 @@ type StatusChecker struct {
client client.Client
interval time.Duration
timeout time.Duration
timeout time.Duration
}
func NewStatusChecker(kubeConfig *rest.Config, interval time.Duration, timeout time.Duration) (*StatusChecker, error) {
@@ -35,7 +35,7 @@ func NewStatusChecker(kubeConfig *rest.Config, interval time.Duration, timeout t
if err != nil {
return nil, err
}
return &StatusChecker{
poller: polling.NewStatusPoller(c, restMapper),
client: c,
@@ -50,7 +50,7 @@ func (c *StatusChecker) WaitForCondition(objs ...object.ObjMetadata) error {
eventsChan := c.poller.Poll(ctx, objs, polling.Options{
PollInterval: c.interval,
UseCache: true,
UseCache: true,
})
coll := collector.NewResourceStatusCollector(objs)

View File

@@ -6,9 +6,9 @@ import (
"github.com/containerd/containerd/remotes"
"github.com/containerd/containerd/remotes/docker"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/deislabs/oras/pkg/content"
"github.com/deislabs/oras/pkg/oras"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/sirupsen/logrus"
)

View File

@@ -10,7 +10,7 @@ import (
)
type dir struct {
Path string
Path string
Permission os.FileMode
}
@@ -48,7 +48,7 @@ func (l FSLayout) Create() error {
//AddDir will add a folder to the FSLayout
func (l *FSLayout) AddDir(relPath string, perm os.FileMode) {
l.dirs = append(l.dirs, dir{
Path: relPath,
Path: relPath,
Permission: perm,
})
}