diff --git a/debugd/cdbg/cmd/root.go b/debugd/cdbg/cmd/root.go index e7f5fb651..fd410d8b0 100644 --- a/debugd/cdbg/cmd/root.go +++ b/debugd/cdbg/cmd/root.go @@ -15,13 +15,12 @@ It connects to CoreOS instances running debugd and deploys a self-compiled versi // Execute starts the CLI. func Execute() { - err := rootCmd.Execute() - if err != nil { + if err := rootCmd.Execute(); err != nil { os.Exit(1) } } func init() { rootCmd.PersistentFlags().String("dev-config", "", "debugd config file (required)") - rootCmd.MarkPersistentFlagRequired("dev-config") + _ = rootCmd.MarkPersistentFlagRequired("dev-config") } diff --git a/debugd/cdbg/state/state.go b/debugd/cdbg/state/state.go index bba3837f8..d8750cea2 100644 --- a/debugd/cdbg/state/state.go +++ b/debugd/cdbg/state/state.go @@ -25,7 +25,7 @@ func GetScalingGroupsFromConfig(stat state.ConstellationState, config *configc.C } } -func getAWSInstances(stat state.ConstellationState, config *configc.Config) (coordinators, nodes cmdc.ScalingGroup, err error) { +func getAWSInstances(stat state.ConstellationState, _ *configc.Config) (coordinators, nodes cmdc.ScalingGroup, err error) { coordinatorID, coordinator, err := stat.EC2Instances.GetOne() if err != nil { return @@ -77,7 +77,7 @@ func getGCPInstances(stat state.ConstellationState, config *configc.Config) (coo return } -func getAzureInstances(stat state.ConstellationState, config *configc.Config) (coordinators, nodes cmdc.ScalingGroup, err error) { +func getAzureInstances(stat state.ConstellationState, _ *configc.Config) (coordinators, nodes cmdc.ScalingGroup, err error) { _, coordinator, err := stat.AzureCoordinators.GetOne() if err != nil { return diff --git a/debugd/coordinator/streamer.go b/debugd/coordinator/streamer.go index 5db2c8bd0..551aacccc 100644 --- a/debugd/coordinator/streamer.go +++ b/debugd/coordinator/streamer.go @@ -69,7 +69,7 @@ func (f *FileStreamer) WriteStream(filename string, stream ReadChunkStream, show return fmt.Errorf("writing chunk to disk failed: %w", err) } if showProgress { - bar.Add(len(chunk.Content)) + _ = bar.Add(len(chunk.Content)) } } @@ -118,7 +118,7 @@ func (f *FileStreamer) ReadStream(filename string, stream WriteChunkStream, chun return fmt.Errorf("sending chunk failed: %w", err) } if showProgress { - bar.Add(n) + _ = bar.Add(n) } } } diff --git a/debugd/debugd/cmd/debugd/debugd.go b/debugd/debugd/cmd/debugd/debugd.go index c2683c931..dc74534c1 100644 --- a/debugd/debugd/cmd/debugd/debugd.go +++ b/debugd/debugd/cmd/debugd/debugd.go @@ -49,7 +49,9 @@ func main() { } sched := metadata.NewScheduler(fetcher, ssh, download) serv := server.New(ssh, serviceManager, streamer) - deploy.DeployDefaultServiceUnit(ctx, serviceManager) + if err := deploy.DeployDefaultServiceUnit(ctx, serviceManager); err != nil { + panic(err) + } wg.Add(1) go sched.Start(ctx, wg) diff --git a/debugd/debugd/deploy/download.go b/debugd/debugd/deploy/download.go index cdb878b4f..7d916a164 100644 --- a/debugd/debugd/deploy/download.go +++ b/debugd/debugd/deploy/download.go @@ -36,7 +36,7 @@ func New(dialer Dialer, serviceManager serviceManager, writer streamToFileWriter func (d *Download) DownloadCoordinator(ctx context.Context, ip string) error { serverAddr := net.JoinHostPort(ip, debugd.DebugdPort) // only retry download from same endpoint after backoff - if lastAttempt, ok := d.attemptedDownloads[serverAddr]; ok && time.Now().Sub(lastAttempt) < debugd.CoordinatorDownloadRetryBackoff { + if lastAttempt, ok := d.attemptedDownloads[serverAddr]; ok && time.Since(lastAttempt) < debugd.CoordinatorDownloadRetryBackoff { return nil } log.Printf("Trying to download coordinator from %s\n", ip) diff --git a/debugd/debugd/deploy/linux_user.go b/debugd/debugd/deploy/linux_user.go index 1238ef3af..dcce772aa 100644 --- a/debugd/debugd/deploy/linux_user.go +++ b/debugd/debugd/deploy/linux_user.go @@ -71,7 +71,6 @@ func (l *LinuxUserManager) getLinuxUser(username string) (LinuxUser, error) { Uid: uid, Gid: gid, }, nil - } // EnsureLinuxUserExists will try to create the user specified by username and call GetLinuxUser to retrieve user information. diff --git a/debugd/debugd/deploy/service.go b/debugd/debugd/deploy/service.go index d2d1f49ef..7965ded4e 100644 --- a/debugd/debugd/deploy/service.go +++ b/debugd/debugd/deploy/service.go @@ -137,8 +137,8 @@ func (s *ServiceManager) WriteSystemdUnitFile(ctx context.Context, unit SystemdU } // DeployDefaultServiceUnit will write the default "constellation.service" unit file. -func DeployDefaultServiceUnit(ctx context.Context, serviceManager *ServiceManager) { - serviceManager.WriteSystemdUnitFile(ctx, SystemdUnit{ +func DeployDefaultServiceUnit(ctx context.Context, serviceManager *ServiceManager) error { + return serviceManager.WriteSystemdUnitFile(ctx, SystemdUnit{ Name: debugd.CoordinatorSystemdUnitName, Contents: debugd.CoordinatorSystemdUnitContents, }) diff --git a/debugd/debugd/deploy/service_test.go b/debugd/debugd/deploy/service_test.go index 1e7b593ec..7ba366500 100644 --- a/debugd/debugd/deploy/service_test.go +++ b/debugd/debugd/deploy/service_test.go @@ -221,6 +221,7 @@ func (f *fakeDbusConn) StartUnitContext(ctx context.Context, name string, mode s return f.jobID, f.actionErr } + func (f *fakeDbusConn) StopUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) { f.inputs = append(f.inputs, dbusConnActionInput{name: name, mode: mode}) go func() { @@ -228,6 +229,7 @@ func (f *fakeDbusConn) StopUnitContext(ctx context.Context, name string, mode st }() return f.jobID, f.actionErr } + func (f *fakeDbusConn) RestartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) { f.inputs = append(f.inputs, dbusConnActionInput{name: name, mode: mode}) go func() { @@ -235,6 +237,7 @@ func (f *fakeDbusConn) RestartUnitContext(ctx context.Context, name string, mode }() return f.jobID, f.actionErr } + func (s *fakeDbusConn) ReloadContext(ctx context.Context) error { return s.actionErr } diff --git a/debugd/debugd/deploy/wrappers.go b/debugd/debugd/deploy/wrappers.go index 68d32652d..4c918a381 100644 --- a/debugd/debugd/deploy/wrappers.go +++ b/debugd/debugd/deploy/wrappers.go @@ -6,7 +6,7 @@ import ( "github.com/coreos/go-systemd/v22/dbus" ) -// wraps go-systemd dbus +// wraps go-systemd dbus. type dbusWrapper struct{} func (d *dbusWrapper) NewSystemdConnectionContext(ctx context.Context) (dbusConn, error) { @@ -26,12 +26,15 @@ type dbusConnWrapper struct { func (c *dbusConnWrapper) StartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) { return c.conn.StartUnitContext(ctx, name, mode, ch) } + func (c *dbusConnWrapper) StopUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) { return c.conn.StopUnitContext(ctx, name, mode, ch) } + func (c *dbusConnWrapper) RestartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) { return c.conn.RestartUnitContext(ctx, name, mode, ch) } + func (c *dbusConnWrapper) ReloadContext(ctx context.Context) error { return c.conn.ReloadContext(ctx) } diff --git a/debugd/debugd/metadata/scheduler.go b/debugd/debugd/metadata/scheduler.go index 378f15ef7..47b99df7e 100644 --- a/debugd/debugd/metadata/scheduler.go +++ b/debugd/debugd/metadata/scheduler.go @@ -103,7 +103,7 @@ func (s *Scheduler) downloadCoordinator(ctx context.Context, ips []string) { for _, ip := range ips { err := s.downloader.DownloadCoordinator(ctx, ip) if err != nil { - log.Printf("error occured while downloading coordinator from %v: %v\n", ip, err) + log.Printf("error occurred while downloading coordinator from %v: %v\n", ip, err) continue } // early exit since coordinator should only be downloaded once @@ -116,7 +116,7 @@ func (s *Scheduler) deploySSHKeys(ctx context.Context, keys []ssh.SSHKey) { for _, key := range keys { err := s.ssh.DeploySSHAuthorizedKey(ctx, key) if err != nil { - log.Printf("error occured while deploying ssh key %v: %v\n", key, err) + log.Printf("error occurred while deploying ssh key %v: %v\n", key, err) continue } } diff --git a/debugd/debugd/metadata/scheduler_test.go b/debugd/debugd/metadata/scheduler_test.go index 08c8f94e1..f22ed8929 100644 --- a/debugd/debugd/metadata/scheduler_test.go +++ b/debugd/debugd/metadata/scheduler_test.go @@ -47,7 +47,7 @@ func TestSchedulerStart(t *testing.T) { expectedDebugdDownloads: []string{"192.0.2.1", "192.0.2.2"}, }, - "if download is successfull, second download is not attempted": { + "if download is successful, second download is not attempted": { fetcher: stubFetcher{ ips: []string{"192.0.2.1", "192.0.2.2"}, }, diff --git a/debugd/debugd/server/server_test.go b/debugd/debugd/server/server_test.go index a912bc446..72a44f125 100644 --- a/debugd/debugd/server/server_test.go +++ b/debugd/debugd/server/server_test.go @@ -159,7 +159,7 @@ func TestUploadCoordinator(t *testing.T) { client := pb.NewDebugdClient(conn) stream, err := client.UploadCoordinator(context.Background()) require.NoError(err) - fakeWrite(stream, tc.uploadChunks) + require.NoError(fakeWrite(stream, tc.uploadChunks)) resp, err := stream.CloseAndRecv() grpcServ.GracefulStop() @@ -390,7 +390,9 @@ func (f *fakeStreamer) WriteStream(filename string, stream coordinator.ReadChunk func (f *fakeStreamer) ReadStream(filename string, stream coordinator.WriteChunkStream, chunksize uint, showProgress bool) error { f.readStreamFilename = filename for _, chunk := range f.readStreamChunks { - stream.Send(&pb.Chunk{Content: chunk}) + if err := stream.Send(&pb.Chunk{Content: chunk}); err != nil { + panic(err) + } } return f.readStreamErr }