mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-04-28 11:06:13 -04:00
lint debugd
This commit is contained in:
parent
2503d6e132
commit
cece88b6a0
debugd
cdbg
coordinator
debugd
cmd/debugd
deploy
metadata
server
@ -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")
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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.
|
||||
|
@ -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,
|
||||
})
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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"},
|
||||
},
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user