Skip to content

Commit

Permalink
Merge pull request #16206 from spowelljr/checkForScannerErrors
Browse files Browse the repository at this point in the history
cleanup: Check for scanner errors
  • Loading branch information
medyagh authored Apr 11, 2023
2 parents fb2f4f7 + 5dd0f26 commit 9d9403c
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 25 deletions.
3 changes: 3 additions & 0 deletions cmd/minikube/cmd/config/addons_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func TestAddonsList(t *testing.T) {
pipeCount += strings.Count(buf.Text(), "|")
got += buf.Text()
}
if err := buf.Err(); err != nil {
t.Errorf("failed to read stdout: %v", err)
}
// The lines we pull should look something like
// |------------|------------|(------|)
// | ADDON NAME | MAINTAINER |( DOCS |)
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func readEventLog(name string) ([]cloudevents.Event, time.Time, error) {
events = append(events, ev)
}

return events, st.ModTime(), nil
return events, st.ModTime(), scanner.Err()
}

// clusterState converts Status structs into a ClusterState struct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ func main() {
validDate = true
write(dw, line)
}
if err := s.Err(); err != nil {
log.Fatalf("failed to read file: %v", err)
}

if err := dw.Flush(); err != nil {
log.Fatalf("failed to flush data writer: %v", err)
}
if err := s.Err(); err != nil {
log.Fatalf("scanner had an error: %v", err)
}
if err := data.Close(); err != nil {
log.Fatalf("failed to close source file: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/drivers/kic/oci/network_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func networkNamesByLabel(ociBin string, label string) ([]string, error) {
lines = append(lines, strings.TrimSpace(scanner.Text()))
}

return lines, nil
return lines, scanner.Err()
}

// DeleteAllKICKNetworksByLabel deletes all networks that have a specific label
Expand Down
16 changes: 11 additions & 5 deletions pkg/drivers/kic/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,12 @@ func inspect(ociBin string, containerNameOrID, format string) ([]string, error)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
if scanErr := scanner.Err(); scanErr != nil {
klog.Warningf("failed to read output: %v", scanErr)
if err == nil {
err = scanErr
}
}
return lines, err
}

Expand Down Expand Up @@ -473,6 +479,9 @@ func isUsernsRemapEnabled(ociBin string) bool {
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
if err := scanner.Err(); err != nil {
klog.Warningf("failed to read output: %v", err)
}

if len(lines) > 0 {
if strings.Contains(lines[0], "name=userns") {
Expand Down Expand Up @@ -533,7 +542,7 @@ func ListContainersByLabel(ctx context.Context, ociBin string, label string, war
names = append(names, n)
}
}
return names, err
return names, s.Err()
}

// ListImagesRepository returns all the images names
Expand All @@ -554,10 +563,7 @@ func ListImagesRepository(ctx context.Context, ociBin string) ([]string, error)
names = append(names, n)
}
}
if err := s.Err(); err != nil {
return nil, err
}
return names, nil
return names, s.Err()
}

// PointToHostDockerDaemon will unset env variables that point to docker inside minikube
Expand Down
6 changes: 6 additions & 0 deletions pkg/drivers/kic/oci/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ func allVolumesByLabel(ociBin string, label string) ([]string, error) {
vols = append(vols, v)
}
}
if scanErr := s.Err(); scanErr != nil {
klog.Warningf("failed to read output: %v", scanErr)
if err == nil {
err = scanErr
}
}
return vols, err
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ func outputKubeadmInitSteps(logs io.Reader, wg *sync.WaitGroup) {

nextStepIndex++
}
if err := scanner.Err(); err != nil {
klog.Warningf("failed to read logs: %v", err)
}
wg.Done()
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/command/command_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func teePrefix(prefix string, r io.Reader, w io.Writer, logger func(format strin
if line.Len() > 0 {
logger("%s%s", prefix, line.String())
}
return nil
return scanner.Err()
}

// fileExists checks that the same file exists on the other end
Expand Down
7 changes: 7 additions & 0 deletions pkg/minikube/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ func FindProblems(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.C
problems = append(problems, l)
}
}
if err := scanner.Err(); err != nil {
klog.Warningf("failed to read output: %v", err)
}
if len(problems) > 0 {
pMap[name] = problems
}
Expand Down Expand Up @@ -198,6 +201,10 @@ func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.Cluster
for scanner.Scan() {
l += scanner.Text() + "\n"
}
if err := scanner.Err(); err != nil {
klog.Errorf("failed to read output: %v", err)
failed = append(failed, name)
}
out.Styled(style.Empty, l)
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/minikube/registry/drvs/hyperv/powershell.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func parseLines(stdout string) []string {
for s.Scan() {
resp = append(resp, s.Text())
}
if err := s.Err(); err != nil {
klog.Warningf("failed to read stdout: %v", err)
}

return resp
}
3 changes: 3 additions & 0 deletions pkg/minikube/sshutil/sshutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ func KnownHost(host string, knownHosts string) bool {
}
}
}
if err := scanner.Err(); err != nil {
klog.Warningf("failed to read file: %v", err)
}

return false
}
3 changes: 3 additions & 0 deletions pkg/minikube/tunnel/kic/ssh_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ func logOutput(r io.Reader, service string) {
for s.Scan() {
klog.Infof("%s tunnel: %s", service, s.Text())
}
if err := s.Err(); err != nil {
klog.Warningf("failed to read: %v", err)
}
}

func (c *sshConn) stop() error {
Expand Down
22 changes: 9 additions & 13 deletions test/integration/aaa_download_only_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ import (

// TestDownloadOnly makes sure the --download-only parameter in minikube start caches the appropriate images and tarballs.
func TestDownloadOnly(t *testing.T) {
// Stores the startup run result for later error messages
var rrr *RunResult
profile := UniqueProfileName("download-only")
ctx, cancel := context.WithTimeout(context.Background(), Minutes(30))
defer Cleanup(t, profile, cancel)
Expand All @@ -69,10 +67,6 @@ func TestDownloadOnly(t *testing.T) {
// --force to avoid uid check
args := append([]string{"start", "-o=json", "--download-only", "-p", profile, "--force", "--alsologtostderr", fmt.Sprintf("--kubernetes-version=%s", v), fmt.Sprintf("--container-runtime=%s", containerRuntime)}, StartArgs()...)
rt, err := Run(t, exec.CommandContext(ctx, Target(), args...))
if rrr == nil {
// Preserve the initial run-result for debugging
rrr = rt
}
if err != nil {
t.Errorf("failed to download only. args: %q %v", args, err)
}
Expand All @@ -91,6 +85,9 @@ func TestDownloadOnly(t *testing.T) {
}
}
}
if err := s.Err(); err != nil {
t.Errorf("failed to read output: %v", err)
}
})

preloadExists := false
Expand All @@ -101,15 +98,14 @@ func TestDownloadOnly(t *testing.T) {
}
// Driver does not matter here, since the only exception is none driver,
// which cannot occur here.
if download.PreloadExists(v, containerRuntime, "docker", true) {
// Just make sure the tarball path exists
if _, err := os.Stat(download.TarballPath(v, containerRuntime)); err != nil {
t.Errorf("failed to verify preloaded tarball file exists: %v", err)
}
preloadExists = true
} else {
if !download.PreloadExists(v, containerRuntime, "docker", true) {
t.Skip("No preload image")
}
// Just make sure the tarball path exists
if _, err := os.Stat(download.TarballPath(v, containerRuntime)); err != nil {
t.Errorf("failed to verify preloaded tarball file exists: %v", err)
}
preloadExists = true
})

t.Run("cached-images", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ func auditContains(substr string) (bool, error) {
return true, nil
}
}
return false, nil
return false, s.Err()
}

0 comments on commit 9d9403c

Please sign in to comment.