diff --git a/Dockerfile b/Dockerfile index 166a31686..1e5f22413 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,12 +13,10 @@ # limitations under the License. FROM BASEIMAGE -MAINTAINER Timothy St. Clair "tstclair@heptio.com" +MAINTAINER John Schnake "jschnake@vmware.com" CMD1 ADD BINARY /sonobuoy -ADD scripts/run_master.sh /run_master.sh -ADD scripts/run_single_node_worker.sh /run_single_node_worker.sh WORKDIR / -CMD ["/bin/sh", "-c", "/run_master.sh"] +CMD /sonobuoy aggregator --no-exit -v 3 --logtostderr diff --git a/cmd/sonobuoy/app/worker.go b/cmd/sonobuoy/app/worker.go index 78d472fee..b85f03247 100644 --- a/cmd/sonobuoy/app/worker.go +++ b/cmd/sonobuoy/app/worker.go @@ -30,13 +30,13 @@ import ( "syscall" "time" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" - "github.com/spf13/cobra" - "github.com/vmware-tanzu/sonobuoy/pkg/errlog" "github.com/vmware-tanzu/sonobuoy/pkg/plugin" "github.com/vmware-tanzu/sonobuoy/pkg/plugin/aggregation" "github.com/vmware-tanzu/sonobuoy/pkg/worker" + + "github.com/pkg/errors" + "github.com/sirupsen/logrus" + "github.com/spf13/cobra" ) // NewCmdWorker is the cobra command that acts as the entrypoint for Sonobuoy when running @@ -50,24 +50,34 @@ func NewCmdWorker() *cobra.Command { Args: cobra.ExactArgs(0), } - workerCmd.AddCommand(singleNodeCmd) - workerCmd.AddCommand(globalCmd) + workerCmd.AddCommand(newSingleNodeCmd()) + workerCmd.AddCommand(newGlobalCmd()) return workerCmd } -var globalCmd = &cobra.Command{ - Use: "global", - Short: "Submit results scoped to the whole cluster", - Run: runGatherGlobal, - Args: cobra.ExactArgs(0), +func newGlobalCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "global", + Short: "Submit results scoped to the whole cluster", + RunE: runGatherGlobal, + Args: cobra.ExactArgs(0), + } + + return cmd } -var singleNodeCmd = &cobra.Command{ - Use: "single-node", - Short: "Submit results scoped to a single node", - Run: runGatherSingleNode, - Args: cobra.ExactArgs(0), +func newSingleNodeCmd() *cobra.Command { + var sleep int64 + cmd := &cobra.Command{ + Use: "single-node", + Short: "Submit results scoped to a single node", + RunE: runGatherSingleNode(&sleep), + Args: cobra.ExactArgs(0), + } + + cmd.Flags().Int64Var(&sleep, "sleep", 0, "After sending results, keeps the process alive for N seconds to avoid restarting the container. If N<0, Sonobuoy sleeps forever.") + return cmd } // sigHandler returns a channel that will receive a message after the timeout @@ -115,19 +125,30 @@ func loadAndValidateConfig() (*plugin.WorkerConfig, error) { return cfg, nil } -func runGatherSingleNode(cmd *cobra.Command, args []string) { - err := runGather(false) - if err != nil { - errlog.LogError(err) - os.Exit(1) - } +func runGatherGlobal(cmd *cobra.Command, args []string) error { + return runGather(true) } -func runGatherGlobal(cmd *cobra.Command, args []string) { - err := runGather(true) - if err != nil { - errlog.LogError(err) - os.Exit(1) +// runGatherSingleNode returns a closure which will run the data gathering and then sleep +// for the specified amount of seconds. +func runGatherSingleNode(sleep *int64) func(cmd *cobra.Command, args []string) error { + return func(cmd *cobra.Command, args []string) error { + err := runGather(false) + + switch { + case sleep == nil || *sleep == 0: + // No sleep. + case *sleep < 0: + // Sleep forever. + logrus.Infof("Results transmitted to aggregator. Sleeping forever.") + for { + time.Sleep(60 * time.Minute) + } + case *sleep > 0: + logrus.Infof("Results transmitted to aggregator. Sleeping for %v seconds", *sleep) + time.Sleep(time.Duration(*sleep) * time.Second) + } + return err } } diff --git a/main.go b/main.go index 6c3eca0f1..51a45042c 100644 --- a/main.go +++ b/main.go @@ -20,12 +20,13 @@ import ( "os" "github.com/vmware-tanzu/sonobuoy/cmd/sonobuoy/app" + "github.com/vmware-tanzu/sonobuoy/pkg/errlog" ) func main() { err := app.NewSonobuoyCommand().Execute() if err != nil { - // Execute takes care of printing the error + errlog.LogError(err) os.Exit(1) } } diff --git a/pkg/client/testdata/custom-systemd-logs-image.golden b/pkg/client/testdata/custom-systemd-logs-image.golden index d1a670f35..3681600a7 100644 --- a/pkg/client/testdata/custom-systemd-logs-image.golden +++ b/pkg/client/testdata/custom-systemd-logs-image.golden @@ -74,11 +74,7 @@ metadata: namespace: spec: containers: - - command: - - /bin/bash - - -c - - /sonobuoy master --no-exit=true -v 3 --logtostderr - env: + - env: - name: SONOBUOY_ADVERTISE_IP valueFrom: fieldRef: diff --git a/pkg/client/testdata/default-plugins-via-nil-selection.golden b/pkg/client/testdata/default-plugins-via-nil-selection.golden index 62ad5b6de..ff17d4d26 100644 --- a/pkg/client/testdata/default-plugins-via-nil-selection.golden +++ b/pkg/client/testdata/default-plugins-via-nil-selection.golden @@ -92,11 +92,7 @@ metadata: namespace: sonobuoy spec: containers: - - command: - - /bin/bash - - -c - - /sonobuoy master --no-exit=true -v 3 --logtostderr - env: + - env: - name: SONOBUOY_ADVERTISE_IP valueFrom: fieldRef: diff --git a/pkg/client/testdata/default-pod-spec.golden b/pkg/client/testdata/default-pod-spec.golden index 4bea11d1e..122985d1c 100644 --- a/pkg/client/testdata/default-pod-spec.golden +++ b/pkg/client/testdata/default-pod-spec.golden @@ -117,11 +117,7 @@ metadata: namespace: spec: containers: - - command: - - /bin/bash - - -c - - /sonobuoy master --no-exit=true -v 3 --logtostderr - env: + - env: - name: SONOBUOY_ADVERTISE_IP valueFrom: fieldRef: diff --git a/pkg/client/testdata/default.golden b/pkg/client/testdata/default.golden index 62ad5b6de..ff17d4d26 100644 --- a/pkg/client/testdata/default.golden +++ b/pkg/client/testdata/default.golden @@ -92,11 +92,7 @@ metadata: namespace: sonobuoy spec: containers: - - command: - - /bin/bash - - -c - - /sonobuoy master --no-exit=true -v 3 --logtostderr - env: + - env: - name: SONOBUOY_ADVERTISE_IP valueFrom: fieldRef: diff --git a/pkg/client/testdata/e2e-default.golden b/pkg/client/testdata/e2e-default.golden index 7c691e0f3..d4daf08af 100644 --- a/pkg/client/testdata/e2e-default.golden +++ b/pkg/client/testdata/e2e-default.golden @@ -63,11 +63,7 @@ metadata: namespace: sonobuoy spec: containers: - - command: - - /bin/bash - - -c - - /sonobuoy master --no-exit=true -v 3 --logtostderr - env: + - env: - name: SONOBUOY_ADVERTISE_IP valueFrom: fieldRef: diff --git a/pkg/client/testdata/e2e-progress-custom-port.golden b/pkg/client/testdata/e2e-progress-custom-port.golden index 23898153e..56f71eb44 100644 --- a/pkg/client/testdata/e2e-progress-custom-port.golden +++ b/pkg/client/testdata/e2e-progress-custom-port.golden @@ -66,11 +66,7 @@ metadata: namespace: spec: containers: - - command: - - /bin/bash - - -c - - /sonobuoy master --no-exit=true -v 3 --logtostderr - env: + - env: - name: SONOBUOY_ADVERTISE_IP valueFrom: fieldRef: diff --git a/pkg/client/testdata/e2e-progress-vs-user-defined.golden b/pkg/client/testdata/e2e-progress-vs-user-defined.golden index fa7e4e8f7..672e62fa3 100644 --- a/pkg/client/testdata/e2e-progress-vs-user-defined.golden +++ b/pkg/client/testdata/e2e-progress-vs-user-defined.golden @@ -66,11 +66,7 @@ metadata: namespace: spec: containers: - - command: - - /bin/bash - - -c - - /sonobuoy master --no-exit=true -v 3 --logtostderr - env: + - env: - name: SONOBUOY_ADVERTISE_IP valueFrom: fieldRef: diff --git a/pkg/client/testdata/e2e-progress.golden b/pkg/client/testdata/e2e-progress.golden index 83750e529..a2832b893 100644 --- a/pkg/client/testdata/e2e-progress.golden +++ b/pkg/client/testdata/e2e-progress.golden @@ -66,11 +66,7 @@ metadata: namespace: spec: containers: - - command: - - /bin/bash - - -c - - /sonobuoy master --no-exit=true -v 3 --logtostderr - env: + - env: - name: SONOBUOY_ADVERTISE_IP valueFrom: fieldRef: diff --git a/pkg/client/testdata/envoverrides.golden b/pkg/client/testdata/envoverrides.golden index 13e2bfea3..5b77d4c21 100644 --- a/pkg/client/testdata/envoverrides.golden +++ b/pkg/client/testdata/envoverrides.golden @@ -66,11 +66,7 @@ metadata: namespace: spec: containers: - - command: - - /bin/bash - - -c - - /sonobuoy master --no-exit=true -v 3 --logtostderr - env: + - env: - name: SONOBUOY_ADVERTISE_IP valueFrom: fieldRef: diff --git a/pkg/client/testdata/goRunnerRemoved.golden b/pkg/client/testdata/goRunnerRemoved.golden index 64a4c1fe0..0fea1bd3f 100644 --- a/pkg/client/testdata/goRunnerRemoved.golden +++ b/pkg/client/testdata/goRunnerRemoved.golden @@ -61,11 +61,7 @@ metadata: namespace: spec: containers: - - command: - - /bin/bash - - -c - - /sonobuoy master --no-exit=true -v 3 --logtostderr - env: + - env: - name: SONOBUOY_ADVERTISE_IP valueFrom: fieldRef: diff --git a/pkg/client/testdata/imagePullSecrets.golden b/pkg/client/testdata/imagePullSecrets.golden index 40c4c9eed..428bdba56 100644 --- a/pkg/client/testdata/imagePullSecrets.golden +++ b/pkg/client/testdata/imagePullSecrets.golden @@ -63,11 +63,7 @@ metadata: namespace: spec: containers: - - command: - - /bin/bash - - -c - - /sonobuoy master --no-exit=true -v 3 --logtostderr - env: + - env: - name: SONOBUOY_ADVERTISE_IP valueFrom: fieldRef: diff --git a/pkg/client/testdata/manual-custom-plugin-plus-e2e.golden b/pkg/client/testdata/manual-custom-plugin-plus-e2e.golden index 1d4d7520a..4cb22a8b9 100644 --- a/pkg/client/testdata/manual-custom-plugin-plus-e2e.golden +++ b/pkg/client/testdata/manual-custom-plugin-plus-e2e.golden @@ -70,11 +70,7 @@ metadata: namespace: spec: containers: - - command: - - /bin/bash - - -c - - /sonobuoy master --no-exit=true -v 3 --logtostderr - env: + - env: - name: SONOBUOY_ADVERTISE_IP valueFrom: fieldRef: diff --git a/pkg/client/testdata/manual-custom-plugin-plus-systemd.golden b/pkg/client/testdata/manual-custom-plugin-plus-systemd.golden index 57c8aa89e..00c3445ba 100644 --- a/pkg/client/testdata/manual-custom-plugin-plus-systemd.golden +++ b/pkg/client/testdata/manual-custom-plugin-plus-systemd.golden @@ -80,11 +80,7 @@ metadata: namespace: spec: containers: - - command: - - /bin/bash - - -c - - /sonobuoy master --no-exit=true -v 3 --logtostderr - env: + - env: - name: SONOBUOY_ADVERTISE_IP valueFrom: fieldRef: diff --git a/pkg/client/testdata/manual-custom-plugin.golden b/pkg/client/testdata/manual-custom-plugin.golden index 52661b1b1..18f7f5ed7 100644 --- a/pkg/client/testdata/manual-custom-plugin.golden +++ b/pkg/client/testdata/manual-custom-plugin.golden @@ -51,11 +51,7 @@ metadata: namespace: spec: containers: - - command: - - /bin/bash - - -c - - /sonobuoy master --no-exit=true -v 3 --logtostderr - env: + - env: - name: SONOBUOY_ADVERTISE_IP valueFrom: fieldRef: diff --git a/pkg/client/testdata/manual-e2e.golden b/pkg/client/testdata/manual-e2e.golden index f0531bc82..9f8da50be 100644 --- a/pkg/client/testdata/manual-e2e.golden +++ b/pkg/client/testdata/manual-e2e.golden @@ -63,11 +63,7 @@ metadata: namespace: spec: containers: - - command: - - /bin/bash - - -c - - /sonobuoy master --no-exit=true -v 3 --logtostderr - env: + - env: - name: SONOBUOY_ADVERTISE_IP valueFrom: fieldRef: diff --git a/pkg/client/testdata/no-plugins-via-selection.golden b/pkg/client/testdata/no-plugins-via-selection.golden index d289c59d9..40c481335 100644 --- a/pkg/client/testdata/no-plugins-via-selection.golden +++ b/pkg/client/testdata/no-plugins-via-selection.golden @@ -43,11 +43,7 @@ metadata: namespace: sonobuoy spec: containers: - - command: - - /bin/bash - - -c - - /sonobuoy master --no-exit=true -v 3 --logtostderr - env: + - env: - name: SONOBUOY_ADVERTISE_IP valueFrom: fieldRef: diff --git a/pkg/client/testdata/plugins-and-pluginSelection.golden b/pkg/client/testdata/plugins-and-pluginSelection.golden index 568a9399d..34f995044 100644 --- a/pkg/client/testdata/plugins-and-pluginSelection.golden +++ b/pkg/client/testdata/plugins-and-pluginSelection.golden @@ -58,11 +58,7 @@ metadata: namespace: sonobuoy spec: containers: - - command: - - /bin/bash - - -c - - /sonobuoy master --no-exit=true -v 3 --logtostderr - env: + - env: - name: SONOBUOY_ADVERTISE_IP valueFrom: fieldRef: diff --git a/pkg/client/testdata/ssh.golden b/pkg/client/testdata/ssh.golden index 862a17af3..646d3fc6d 100644 --- a/pkg/client/testdata/ssh.golden +++ b/pkg/client/testdata/ssh.golden @@ -87,11 +87,7 @@ metadata: namespace: spec: containers: - - command: - - /bin/bash - - -c - - /sonobuoy master --no-exit=true -v 3 --logtostderr - env: + - env: - name: SONOBUOY_ADVERTISE_IP valueFrom: fieldRef: diff --git a/pkg/client/testdata/systemd-logs-default.golden b/pkg/client/testdata/systemd-logs-default.golden index 217d30f5a..58eb06d23 100644 --- a/pkg/client/testdata/systemd-logs-default.golden +++ b/pkg/client/testdata/systemd-logs-default.golden @@ -73,11 +73,7 @@ metadata: namespace: sonobuoy spec: containers: - - command: - - /bin/bash - - -c - - /sonobuoy master --no-exit=true -v 3 --logtostderr - env: + - env: - name: SONOBUOY_ADVERTISE_IP valueFrom: fieldRef: diff --git a/pkg/client/testdata/use-existing-pod-spec.golden b/pkg/client/testdata/use-existing-pod-spec.golden index 26aee7d41..2fa7fe304 100644 --- a/pkg/client/testdata/use-existing-pod-spec.golden +++ b/pkg/client/testdata/use-existing-pod-spec.golden @@ -53,11 +53,7 @@ metadata: namespace: spec: containers: - - command: - - /bin/bash - - -c - - /sonobuoy master --no-exit=true -v 3 --logtostderr - env: + - env: - name: SONOBUOY_ADVERTISE_IP valueFrom: fieldRef: diff --git a/pkg/plugin/driver/daemonset/daemonset.go b/pkg/plugin/driver/daemonset/daemonset.go index 42ca7be3e..0bcc5391d 100644 --- a/pkg/plugin/driver/daemonset/daemonset.go +++ b/pkg/plugin/driver/daemonset/daemonset.go @@ -40,6 +40,11 @@ import ( const ( // pollingInterval is the time between polls when monitoring the job status. pollingInterval = 10 * time.Second + + // defaultSleepSeconds is the time after the plugin finishes for which Sonobuoy will sleep. + // The sleep functions as a way to prevent the daemonset from restarting the container once the + // process completes. There is currently no way to have a "run-once daemonset". + defaultSleepSeconds = "3600" ) // Plugin is a plugin driver that dispatches containers to each node, @@ -152,7 +157,7 @@ func (p *Plugin) createDaemonSetDefinition(hostname string, cert *tls.Certificat podSpec.Containers = append(podSpec.Containers, p.Definition.Spec.Container, - p.CreateWorkerContainerDefintion(hostname, cert, []string{"/run_single_node_worker.sh"}, []string{}, progressPort), + p.CreateWorkerContainerDefintion(hostname, cert, []string{"/sonobuoy", "worker", "single-node", "-v=5", "--logtostderr", "--sleep=" + defaultSleepSeconds}, []string{}, progressPort), ) if len(p.ImagePullSecrets) > 0 { diff --git a/pkg/templates/manifest.go b/pkg/templates/manifest.go index 2ce0b8f3b..cab396e74 100644 --- a/pkg/templates/manifest.go +++ b/pkg/templates/manifest.go @@ -123,11 +123,7 @@ metadata: {{- end }} spec: containers: - - command: - - /bin/bash - - -c - - /sonobuoy master --no-exit=true -v 3 --logtostderr - env: + - env: - name: SONOBUOY_ADVERTISE_IP valueFrom: fieldRef: diff --git a/scripts/run_master.sh b/scripts/run_master.sh deleted file mode 100755 index 44de85fbe..000000000 --- a/scripts/run_master.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -########################################################################## -# Copyright 2017 Heptio Inc. -# -# 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 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -RESULTS_DIR="${RESULTS_DIR:-/tmp/sonobuoy}" -# It's ok for these env vars to be unbound -RESULTS_DIR="${RESULTS_DIR}" SONOBUOY_CONFIG="${SONOBUOY_CONFIG}" SONOBUOY_ADVERTISE_IP="${SONOBUOY_ADVERTISE_IP}" /sonobuoy master -v 3 --logtostderr - -echo -n "${RESULTS_DIR}/$(ls -t "${RESULTS_DIR}" | grep -v done | head -n 1)" > "${RESULTS_DIR}"/done \ No newline at end of file diff --git a/scripts/run_single_node_worker.sh b/scripts/run_single_node_worker.sh deleted file mode 100755 index 2d42eb8ad..000000000 --- a/scripts/run_single_node_worker.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -########################################################################## -# Copyright 2017 Heptio Inc. -# -# 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 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -/sonobuoy worker single-node -v 5 --logtostderr -sleep 3600