From a4cf1b5849ca5901477d38c89da9816e2198da74 Mon Sep 17 00:00:00 2001 From: Dave Riddle Date: Thu, 17 Nov 2022 13:09:37 -0600 Subject: [PATCH] Formatting Signed-off-by: Dave Riddle --- pkg/client/logs.go | 4 +++- pkg/client/logs_test.go | 2 +- pkg/client/results/processing.go | 10 ++++++---- pkg/client/results/reader_unix.go | 1 - pkg/client/results/reader_windows.go | 1 - pkg/client/run.go | 3 +-- pkg/client/run_test.go | 6 +++--- pkg/discovery/summary.go | 6 +++--- pkg/plugin/aggregation/run.go | 16 ++++++++-------- pkg/plugin/driver/base_test.go | 2 +- pkg/plugin/interface.go | 1 - pkg/plugin/interface_test.go | 14 +++++++------- scripts/build_funcs.sh | 2 +- test/integration/testdata/issue1688.yaml | 2 +- 14 files changed, 35 insertions(+), 35 deletions(-) diff --git a/pkg/client/logs.go b/pkg/client/logs.go index 2a490db85..9f583439f 100644 --- a/pkg/client/logs.go +++ b/pkg/client/logs.go @@ -175,7 +175,9 @@ func getPodsToStreamLogs(client kubernetes.Interface, cfg *LogConfig, podCh chan } // watchPodsToStreamLogs creates a watch for the desired pods and, as it gets events for new pods will add them onto the pod channel. -// If a plugin name has been provided, retrieve the pods with only the plugin label matching that plugin name. If no pods are found, +// +// If a plugin name has been provided, retrieve the pods with only the plugin label matching that plugin name. If no pods are found, +// // or no plugin has been specified, retrieve all pods within the namespace. It will return an error if unable to create the watcher // but will continue to add pods to the channel in a separate go routine. func watchPodsToStreamLogs(client kubernetes.Interface, cfg *LogConfig, podCh chan *v1.Pod) error { diff --git a/pkg/client/logs_test.go b/pkg/client/logs_test.go index 60ec5da38..ccc34bc9a 100644 --- a/pkg/client/logs_test.go +++ b/pkg/client/logs_test.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/pkg/client/results/processing.go b/pkg/client/results/processing.go index aea291e20..c2afab5eb 100644 --- a/pkg/client/results/processing.go +++ b/pkg/client/results/processing.go @@ -78,11 +78,13 @@ func hasCustomValues(items ...Item) bool { // AggregateStatus defines the aggregation rules for status according to the following rules: // If only pass/fail/unknown values are found, we apply very basic rules: -// - failure + * = failure -// - unknown + [pass|unknown] = unknown -// - empty list = unknown +// - failure + * = failure +// - unknown + [pass|unknown] = unknown +// - empty list = unknown +// // If we find other values (e.g. from manual results typically) then we just combine/count them: -// - foo + bar = 'foo: 1, bar:1' +// - foo + bar = 'foo: 1, bar:1' +// // useCustom is specified rather than looking for custom values because different branches of the // result tree may have/not have those values. So instead, we should look down the tree initially to decide. func AggregateStatus(useCustom bool, items ...Item) string { diff --git a/pkg/client/results/reader_unix.go b/pkg/client/results/reader_unix.go index 6a4b6a932..8315c14fc 100644 --- a/pkg/client/results/reader_unix.go +++ b/pkg/client/results/reader_unix.go @@ -1,5 +1,4 @@ //go:build aix || darwin || dragonfly || freebsd || (js && wasm) || linux || nacl || netbsd || openbsd || solaris -// +build aix darwin dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris /* Copyright 2018 Heptio Inc. diff --git a/pkg/client/results/reader_windows.go b/pkg/client/results/reader_windows.go index a8ad63130..2c0c500e7 100644 --- a/pkg/client/results/reader_windows.go +++ b/pkg/client/results/reader_windows.go @@ -1,5 +1,4 @@ //go:build windows -// +build windows /* Copyright 2018 Heptio Inc. diff --git a/pkg/client/run.go b/pkg/client/run.go index 25561b8eb..392fd8e35 100644 --- a/pkg/client/run.go +++ b/pkg/client/run.go @@ -30,13 +30,13 @@ import ( "github.com/sirupsen/logrus" "github.com/vmware-tanzu/sonobuoy/pkg/plugin/aggregation" "golang.org/x/term" + corev1 "k8s.io/api/core/v1" kubeerror "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/yaml" "k8s.io/client-go/kubernetes/scheme" - corev1 "k8s.io/api/core/v1" ) const ( @@ -307,7 +307,6 @@ func humanReadableStatus(str string) string { } } - func getPodStatus(pod corev1.Pod) string { const ContainersNotReady = "ContainersNotReady" if pod.Status.Phase != corev1.PodRunning && pod.Status.Phase != corev1.PodSucceeded { diff --git a/pkg/client/run_test.go b/pkg/client/run_test.go index f2c12afea..64f2ee86b 100644 --- a/pkg/client/run_test.go +++ b/pkg/client/run_test.go @@ -17,11 +17,11 @@ limitations under the License. package client import ( - "os" - "strings" "encoding/json" - "reflect" corev1 "k8s.io/api/core/v1" + "os" + "reflect" + "strings" "testing" ) diff --git a/pkg/discovery/summary.go b/pkg/discovery/summary.go index 70c8cdfa2..feb95b9a3 100644 --- a/pkg/discovery/summary.go +++ b/pkg/discovery/summary.go @@ -112,9 +112,9 @@ func ReadPodHealth(r *results.Reader) (HealthInfo, error) { return health, nil } -//ReadHealthSummary reads the core_v1_nodes.json file from ClusterResourceLocation -//and returns a summary of the health fo the cluster, ready to be saved -//tarballRootDir is the directory that will be used to provide the contents of the tarball +// ReadHealthSummary reads the core_v1_nodes.json file from ClusterResourceLocation +// and returns a summary of the health fo the cluster, ready to be saved +// tarballRootDir is the directory that will be used to provide the contents of the tarball func ReadHealthSummary(tarballRootDir string) (ClusterSummary, error) { summary := ClusterSummary{} nodes := &v1.NodeList{} diff --git a/pkg/plugin/aggregation/run.go b/pkg/plugin/aggregation/run.go index 652e1bb31..ebd2d355a 100644 --- a/pkg/plugin/aggregation/run.go +++ b/pkg/plugin/aggregation/run.go @@ -63,14 +63,14 @@ func (t *timeoutErr) Error() string { return t.e.Error() } // // Basic workflow: // -// 1. Create the aggregator object (`aggr`) to keep track of results -// 2. Launch the HTTP server with the aggr's HandleHTTPResult function as the -// callback -// 3. Run all the aggregation plugins, monitoring each one in a goroutine, -// configuring them to send failure results through a shared channel -// 4. Hook the shared monitoring channel up to aggr's IngestResults() function -// 5. Block until aggr shows all results accounted for (results come in through -// the HTTP callback), stopping the HTTP server on completion +// 1. Create the aggregator object (`aggr`) to keep track of results +// 2. Launch the HTTP server with the aggr's HandleHTTPResult function as the +// callback +// 3. Run all the aggregation plugins, monitoring each one in a goroutine, +// configuring them to send failure results through a shared channel +// 4. Hook the shared monitoring channel up to aggr's IngestResults() function +// 5. Block until aggr shows all results accounted for (results come in through +// the HTTP callback), stopping the HTTP server on completion func Run(client kubernetes.Interface, plugins []plugin.Interface, cfg plugin.AggregationConfig, progressPort, pluginResultsDir, namespace, outdir string) error { // Construct a list of things we'll need to dispatch if len(plugins) == 0 { diff --git a/pkg/plugin/driver/base_test.go b/pkg/plugin/driver/base_test.go index 91259006c..065a67e9c 100644 --- a/pkg/plugin/driver/base_test.go +++ b/pkg/plugin/driver/base_test.go @@ -206,7 +206,7 @@ func TestCreateWorkerContainerDefinition(t *testing.T) { }, } expectedEnvVars = append(expectedEnvVars, presetPluginEnv...) - + for _, e := range expectedEnvVars { if !envContains(container.Env, e) { return fmt.Errorf("expected container environment to contain %q", e) diff --git a/pkg/plugin/interface.go b/pkg/plugin/interface.go index a4344ed44..0e1adcaf0 100644 --- a/pkg/plugin/interface.go +++ b/pkg/plugin/interface.go @@ -288,7 +288,6 @@ func (s ProgressUpdate) Key() string { // Corresponding to S = ProgressUpdate.Completed, F = len(ProgressUpdate.Failures), // and ProgressUpdate.Total - S - F respectively // and the ", Remaining: R" part is printed only if R is not negative -// func (s *ProgressUpdate) FormatPluginProgress() (output string) { //Minumum size of each field, in characters minSize := 3 diff --git a/pkg/plugin/interface_test.go b/pkg/plugin/interface_test.go index 68b574b8b..13f91f140 100644 --- a/pkg/plugin/interface_test.go +++ b/pkg/plugin/interface_test.go @@ -57,34 +57,34 @@ func TestCombineUpdates(t *testing.T) { func TestProgressUpdateFormatting(t *testing.T) { testCases := []struct { desc string - p ProgressUpdate + p ProgressUpdate expect string }{ { desc: "Zero total should produce NO 'Remaining:'", - p: ProgressUpdate{Node: "nonempty", Completed: 1, Failures: []string{"c", "d"}, Message: "bar"}, + p: ProgressUpdate{Node: "nonempty", Completed: 1, Failures: []string{"c", "d"}, Message: "bar"}, expect: "Passed: 1, Failed: 2", }, { desc: "When Total matches the total, Remaining SHOULD printed", - p: ProgressUpdate{Node: "nonempty", Completed: 1, Total: 3, Failures: []string{"c", "d"}, Message: "bar"}, + p: ProgressUpdate{Node: "nonempty", Completed: 1, Total: 3, Failures: []string{"c", "d"}, Message: "bar"}, expect: "Passed: 1, Failed: 2, Remaining: 0", }, { desc: "When Total is less than failures+completed, Remaining should NOT be printed", - p: ProgressUpdate{Node: "nonempty", Completed: 2, Total: 1, Failures: []string{"c"}, Message: "bar"}, + p: ProgressUpdate{Node: "nonempty", Completed: 2, Total: 1, Failures: []string{"c"}, Message: "bar"}, expect: "Passed: 2, Failed: 1", }, { desc: "When Total is more than failures+completed, Remaining SHOULD be printed", - p: ProgressUpdate{Node: "nonempty", Completed: 2, Total: 50, Failures: []string{"c", "d"}, Message: "bar"}, + p: ProgressUpdate{Node: "nonempty", Completed: 2, Total: 50, Failures: []string{"c", "d"}, Message: "bar"}, expect: "Passed: 2, Failed: 2, Remaining: 46", }, { desc: "When total is negative, Remaining should NOT be printed", - p: ProgressUpdate{Node: "nonempty", Completed: 2, Total: -1, Failures: []string{"c", "d"}, Message: "bar"}, + p: ProgressUpdate{Node: "nonempty", Completed: 2, Total: -1, Failures: []string{"c", "d"}, Message: "bar"}, expect: "Passed: 2, Failed: 2", }, } for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { - if got := tc.p.FormatPluginProgress(); got != tc.expect{ + if got := tc.p.FormatPluginProgress(); got != tc.expect { t.Fatalf("\n\n%s: expected '%s', got '%s'\n", tc.desc, tc.expect, got) } }) diff --git a/scripts/build_funcs.sh b/scripts/build_funcs.sh index f9a73ea9c..0de8f773b 100755 --- a/scripts/build_funcs.sh +++ b/scripts/build_funcs.sh @@ -394,4 +394,4 @@ update_cli_docs() { mkdir -p "${output}" echo "Generating new docs..." ./sonobuoy gen cli "${output}" -} \ No newline at end of file +} diff --git a/test/integration/testdata/issue1688.yaml b/test/integration/testdata/issue1688.yaml index 901038252..c74d0d3a0 100644 --- a/test/integration/testdata/issue1688.yaml +++ b/test/integration/testdata/issue1688.yaml @@ -177,4 +177,4 @@ spec: targetPort: 8080 selector: sonobuoy-component: aggregator - type: ClusterIP \ No newline at end of file + type: ClusterIP