Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve repo tooling #805

Merged
merged 6 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/build/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (c *BuildContext) buildImage(dir string) error {
// ensure we will delete it
if containerID != "" {
defer func() {
exec.Command("docker", "rm", "-f", "-v", containerID).Run()
_ = exec.Command("docker", "rm", "-f", "-v", containerID).Run()
}()
}
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/cluster/create/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ func WithConfigFile(path string) ClusterOption {
// WithV1Alpha3 configures creating the cluster with a v1alpha3 config
func WithV1Alpha3(cluster *v1alpha3.Cluster) ClusterOption {
return func(o *internaltypes.ClusterOptions) (*internaltypes.ClusterOptions, error) {
o.Config = internalencoding.V1Alpha3ToInternal(cluster)
return o, nil
cfg, err := internalencoding.V1Alpha3ToInternal(cluster)
o.Config = cfg
return o, err
}
}

Expand Down
13 changes: 8 additions & 5 deletions pkg/internal/apis/config/encoding/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ func AddToScheme(scheme *runtime.Scheme) {
}

// V1Alpha3ToInternal converts to the internal API version
func V1Alpha3ToInternal(cluster *v1alpha3.Cluster) *config.Cluster {
func V1Alpha3ToInternal(cluster *v1alpha3.Cluster) (*config.Cluster, error) {
// apply defaults
Scheme.Default(cluster)
// the convert
out := &config.Cluster{}
// TODO: error handling??
BenTheElder marked this conversation as resolved.
Show resolved Hide resolved
Scheme.Convert(cluster, out, nil)
return out
return out, Scheme.Convert(cluster, out, nil)
}

// Load reads the file at path and attempts to convert into a `kind` Config; the file
Expand Down Expand Up @@ -93,15 +92,19 @@ func Load(path string) (*config.Cluster, error) {
}

// converts back to the latest API version to apply defaults
Scheme.Convert(cfg, latestPublicConfig, nil)
if err := Scheme.Convert(cfg, latestPublicConfig, nil); err != nil {
return nil, err
}
}

// apply defaults
Scheme.Default(latestPublicConfig)

// converts to internal config
var cfg = &config.Cluster{}
Scheme.Convert(latestPublicConfig, cfg, nil)
if err := Scheme.Convert(latestPublicConfig, cfg, nil); err != nil {
return nil, err
}

// unmarshal the file content into a `kind` Config
return cfg, nil
Expand Down
9 changes: 7 additions & 2 deletions pkg/internal/build/kube/bazelbuildbits.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ func (b *BazelBuildBits) Build() error {
if err != nil {
return err
}
os.Chdir(b.kubeRoot)
// make sure we cd back when done
defer os.Chdir(cwd)
defer func() {
// TODO(bentheelder): set return error?
_ = os.Chdir(cwd)
}()
if err := os.Chdir(b.kubeRoot); err != nil {
return err
}

// TODO(bentheelder): we assume the host arch, but cross compiling should
// be possible now
Expand Down
9 changes: 7 additions & 2 deletions pkg/internal/build/kube/dockerbuildbits.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ func (b *DockerBuildBits) Build() error {
if err != nil {
return err
}
os.Chdir(b.kubeRoot)
// make sure we cd back when done
defer os.Chdir(cwd)
defer func() {
// TODO(bentheelder): set return error?
_ = os.Chdir(cwd)
}()
if err := os.Chdir(b.kubeRoot); err != nil {
return err
}

// the PR that added `make quick-release-images` added this script,
// we can use it's presence to detect if that target exists
Expand Down
9 changes: 7 additions & 2 deletions pkg/internal/build/kube/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ func buildVersionFile(kubeRoot string) (string, error) {
if err != nil {
return "", err
}
os.Chdir(kubeRoot)
// make sure we cd back when done
defer os.Chdir(cwd)
defer func() {
// TODO(bentheelder): set return error?
_ = os.Chdir(cwd)
}()
if err := os.Chdir(kubeRoot); err != nil {
return "", err
}

// get the version output
cmd := exec.Command("hack/print-workspace-status.sh")
Expand Down
4 changes: 2 additions & 2 deletions pkg/internal/cluster/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func Cluster(ctx *context.Context, options ...create.ClusterOption) error {
// In case of errors nodes are deleted (except if retain is explicitly set)
log.Error(err)
if !opts.Retain {
delete.Cluster(ctx)
_ = delete.Cluster(ctx)
}
return err
}
Expand Down Expand Up @@ -111,7 +111,7 @@ func Cluster(ctx *context.Context, options ...create.ClusterOption) error {
for _, action := range actionsToRun {
if err := action.Execute(actionsContext); err != nil {
if !opts.Retain {
delete.Cluster(ctx)
_ = delete.Cluster(ctx)
}
return err
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/internal/cluster/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ func Collect(nodes []nodes.Node, dir string) error {
// helper to run a cmd and write the output to path
execToPath := func(cmd exec.Cmd, path string) error {
realPath := prefixedPath(path)
os.MkdirAll(filepath.Dir(realPath), os.ModePerm)
if err := os.MkdirAll(filepath.Dir(realPath), os.ModePerm); err != nil {
return err
}
f, err := os.Create(realPath)
if err != nil {
return err
Expand Down Expand Up @@ -70,12 +72,14 @@ func Collect(nodes []nodes.Node, dir string) error {
// grab all logs under /var/log (pods and containers)
cmd := node.Command("tar", "--hard-dereference", "-C", "/var/log", "-chf", "-", ".")

exec.RunWithStdoutReader(cmd, func(outReader io.Reader) error {
if err := exec.RunWithStdoutReader(cmd, func(outReader io.Reader) error {
if err := untar(outReader, filepath.Join(dir, name)); err != nil {
return errors.Wrapf(err, "Untarring %q: %v", name, err)
}
return nil
})
}); err != nil {
return err
}

fns = append(fns, func() error {
return concurrent.Coalesce(
Expand Down
6 changes: 5 additions & 1 deletion pkg/internal/util/kustomize/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ func Build(resources, patches []string, patchesJSON6902 []config.PatchJSON6902)
}
}

memFS.WriteFile(filepath.Join(fakeDir, "kustomization.yaml"), kustomization.Bytes())
if err := memFS.WriteFile(
filepath.Join(fakeDir, "kustomization.yaml"), kustomization.Bytes(),
); err != nil {
return "", err
}

// now we can build the kustomization
var out bytes.Buffer
Expand Down
4 changes: 3 additions & 1 deletion pkg/log/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ var _ io.Writer = &StatusFriendlyWriter{}

func (ww *StatusFriendlyWriter) Write(p []byte) (n int, err error) {
ww.status.spinner.Stop()
ww.inner.Write([]byte("\r"))
if _, err := ww.inner.Write([]byte("\r")); err != nil {
return 0, err
}
n, err = ww.inner.Write(p)
ww.status.spinner.Start()
return n, err
Expand Down