Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
Fix various nits
Browse files Browse the repository at this point in the history
  • Loading branch information
hakman committed Dec 7, 2022
1 parent ac16af0 commit 2484433
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 29 deletions.
2 changes: 1 addition & 1 deletion etcd-manager/cmd/etcd-dump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func runDump(backupFile string, out string) error {
break
}

exitError, exitState := process.ExitState()
exitState, exitError := process.ExitState()
if exitError != nil || exitState != nil {
return fmt.Errorf("etcd process exited (state=%v): %w", exitState, exitError)
}
Expand Down
3 changes: 1 addition & 2 deletions etcd-manager/pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ func (m *EtcdController) maybeBackup(ctx context.Context, clusterSpec *protoetcd
}

func randomToken() string {
b := make([]byte, 16, 16)
b := make([]byte, 16)
_, err := io.ReadFull(crypto_rand.Reader, b)
if err != nil {
klog.Fatalf("error generating random token: %v", err)
Expand Down Expand Up @@ -956,7 +956,6 @@ func (m *EtcdController) removeNodeFromCluster(ctx context.Context, clusterSpec
klog.Infof("peer %v is unhealthy, but waiting for %s (currently %s)", member, removeUnhealthyDeadline, age)
continue
}

}

victim = member
Expand Down
6 changes: 2 additions & 4 deletions etcd-manager/pkg/controller/reconcile_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ func (m *EtcdController) updatePeerURLs(ctx context.Context, peerID privateapi.P

func normalize(in []string) []string {
var c []string
for _, s := range in {
c = append(c, s)
}
c = append(c, in...)
sort.Strings(c)
return c
}
Expand Down Expand Up @@ -145,7 +143,7 @@ func (m *EtcdController) reconcileTLS(ctx context.Context, clusterState *etcdClu
}
}

if node.TlsEnabled == false {
if !node.TlsEnabled {
request := &protoetcd.ReconfigureRequest{
Header: m.buildHeader(),
Quarantined: p.info.EtcdState.Quarantined,
Expand Down
4 changes: 2 additions & 2 deletions etcd-manager/pkg/etcd/etcdprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ type etcdProcess struct {
IgnoreListenMetricsURLs bool
}

func (p *etcdProcess) ExitState() (error, *os.ProcessState) {
func (p *etcdProcess) ExitState() (*os.ProcessState, error) {
p.mutex.Lock()
defer p.mutex.Unlock()

return p.exitError, p.exitState
return p.exitState, p.exitError
}

func (p *etcdProcess) Stop() error {
Expand Down
6 changes: 3 additions & 3 deletions etcd-manager/pkg/etcd/etcdserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (s *EtcdServer) runOnce() error {

// Check that etcd process is still running
if s.process != nil {
exitError, exitState := s.process.ExitState()
exitState, exitError := s.process.ExitState()
if exitError != nil || exitState != nil {
klog.Warningf("etcd process exited (error=%v, state=%v)", exitError, exitState)

Expand Down Expand Up @@ -514,10 +514,10 @@ func (s *EtcdServer) DoBackup(ctx context.Context, request *protoetcd.DoBackupRe
}

if request.Storage == "" {
return nil, fmt.Errorf("Storage is required")
return nil, fmt.Errorf("request Storage is required")
}
if request.Info == nil {
return nil, fmt.Errorf("Info is required")
return nil, fmt.Errorf("request Info is required")
}
backupStore, err := backup.NewStore(request.Storage)
if err != nil {
Expand Down
4 changes: 1 addition & 3 deletions etcd-manager/pkg/etcd/pki.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ func (p *etcdProcess) createKeypairs(peersCA *pki.CA, clientsCA *pki.CA, pkiDir

// etcd 3.2 does some deeper client-certiifcate validation, so we want to include our client IP address
// (as the DNS name might not be immediately ready, see https://github.com/kopeio/etcd-manager/issues/371)
for _, ip := range peerClientIPs {
certConfig.AltNames.IPs = append(certConfig.AltNames.IPs, ip)
}
certConfig.AltNames.IPs = append(certConfig.AltNames.IPs, peerClientIPs...)
klog.Infof("adding peerClientIPs %v", peerClientIPs)

if err := addAltNames(&certConfig, me.PeerUrls); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions etcd-manager/pkg/etcd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ func (s *EtcdServer) DoRestore(ctx context.Context, request *protoetcd.DoRestore
}

if request.Storage == "" {
return nil, fmt.Errorf("Storage is required")
return nil, fmt.Errorf("request Storage is required")
}
if request.BackupName == "" {
return nil, fmt.Errorf("BackupName is required")
return nil, fmt.Errorf("request BackupName is required")
}

backupStore, err := backup.NewStore(request.Storage)
Expand Down Expand Up @@ -219,7 +219,7 @@ func copyEtcd(ctx context.Context, source *etcdProcess, dest etcdclient.NodeSink
break
}

exitError, exitState := source.ExitState()
exitState, exitError := source.ExitState()
if exitError != nil || exitState != nil {
return fmt.Errorf("source etcd process exited (state=%v): %w", exitState, exitError)
}
Expand Down
8 changes: 2 additions & 6 deletions etcd-manager/pkg/pki/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,9 @@ func ensureKeypair(store MutableKeypair, config certutil.Config, signer *CA) (*K
var expectedNames []string
var actualNames []string

for _, s := range config.AltNames.DNSNames {
expectedNames = append(expectedNames, s)
}
expectedNames = append(expectedNames, config.AltNames.DNSNames...)

for _, s := range cert.DNSNames {
actualNames = append(actualNames, s)
}
actualNames = append(actualNames, cert.DNSNames...)

sort.Strings(expectedNames)
sort.Strings(actualNames)
Expand Down
2 changes: 1 addition & 1 deletion etcd-manager/pkg/privateapi/leadership.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (s *Server) AssertLeadership(ctx context.Context, leadershipToken string) e
}

func randomToken() string {
b := make([]byte, 16, 16)
b := make([]byte, 16)
_, err := io.ReadFull(crypto_rand.Reader, b)
if err != nil {
klog.Fatalf("error generating random token: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions etcd-manager/pkg/privateapi/peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func (s *Server) Peers() []*PeerInfo {

for _, peer := range s.peers {
lastInfo, status := peer.status(s.HealthyTimeout)
if status == false {
if !status {
continue
}
infos = append(infos, lastInfo)
Expand All @@ -392,7 +392,7 @@ func (s *Server) GetPeerClient(peerId PeerId) (*grpc.ClientConn, error) {
s.mutex.Unlock()

_, status := peer.status(s.HealthyTimeout)
if status == false {
if !status {
return nil, fmt.Errorf("peer %q is not healthy", peerId)
}

Expand Down
3 changes: 1 addition & 2 deletions etcd-manager/test/integration/harness/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ func (h *TestHarness) WaitForBackup(t *testing.T, timeout time.Duration) {
}
wantBackups := len(backups) + 1

description := fmt.Sprintf("wait for new backup")
h.WaitFor(timeout, description, func() error {
h.WaitFor(timeout, "wait for new backup", func() error {
backups, err := backupStore.ListBackups()
if err != nil {
return fmt.Errorf("error listing backups: %w", err)
Expand Down

0 comments on commit 2484433

Please sign in to comment.