Skip to content

Commit

Permalink
golang lint
Browse files Browse the repository at this point in the history
Signed-off-by: weizhoublue <[email protected]>
  • Loading branch information
weizhoublue committed Dec 25, 2024
1 parent 6dcc7eb commit 4d13ad6
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 34 deletions.
3 changes: 1 addition & 2 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import (
)

var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
scheme = runtime.NewScheme()
)

func init() {
Expand Down
6 changes: 5 additions & 1 deletion pkg/agent/hoststatus/HostStatusEvent.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ func (c *hostStatusController) processHostStatus(hostStatus *bmcv1beta1.HostStat
Username: username,
Password: password,
})

// update the crd
c.UpdateHostStatusWrapper(hostStatus.Name)
if err := c.UpdateHostStatusWrapper(hostStatus.Name); err != nil {
log.Logger.Errorf("failed to update HostStatus %s: %v", hostStatus.Name, err)
return err
}

log.Logger.Debugf("Successfully processed HostStatus %s", hostStatus.Name)
return nil
Expand Down
4 changes: 3 additions & 1 deletion pkg/agent/hoststatus/HostStatusUpdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ func (c *hostStatusController) UpdateHostStatusWrapper(name string) error {
for name, t := range syncData {
hostStatusLock.Lock()
log.Logger.Debugf("update status of the hostStatus %s ", name)
c.UpdateHostStatusCr(&t)
if err := c.UpdateHostStatusCr(&t); err != nil {
log.Logger.Errorf("failed to update HostStatus %s: %v", name, err)
}
hostStatusLock.Unlock()
}

Expand Down
16 changes: 12 additions & 4 deletions pkg/agent/hoststatus/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,17 @@ func (c *hostStatusController) Run(ctx context.Context) error {
cache.Indexers{},
)

hostEndpointInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
_, err := hostEndpointInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: c.handleHostEndpointAdd,
UpdateFunc: func(old, new interface{}) {
c.handleHostEndpointAdd(new)
},
DeleteFunc: c.handleHostEndpointDelete,
})
if err != nil {
log.Logger.Errorf("failed to add event handler for HostEndpoint: %v", err)
return err
}

c.informer = hostEndpointInformer

Expand All @@ -108,11 +112,15 @@ func (c *hostStatusController) Run(ctx context.Context) error {
cache.Indexers{},
)

hostStatusInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
_, err = hostStatusInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: c.handleHostStatusAdd,
UpdateFunc: c.handleHostStatusUpdate,
DeleteFunc: c.handleHostStatusDelete,
})
if err != nil {
log.Logger.Errorf("failed to add event handler for HostStatus: %v", err)
return err
}

c.statusInformer = hostStatusInformer

Expand Down Expand Up @@ -157,8 +165,8 @@ func (c *hostStatusController) Run(ctx context.Context) error {
}
}()

go func(){
c.UpdateHostStatusAtInterval()
go func() {
c.UpdateHostStatusAtInterval()
}()

log.Logger.Debug("Both goroutines started")
Expand Down
4 changes: 3 additions & 1 deletion pkg/dhcpserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ func (s *dhcpServer) Stop() error {
log.Logger.Errorf("failed to stop DHCP server: %v", err)
return err
}
s.cmd.Wait()
if err := s.cmd.Wait(); err != nil {
log.Logger.Errorf("failed to wait for DHCP server: %v", err)
}
s.cmd = nil
log.Logger.Info("DHCP server stopped successfully")

Expand Down
23 changes: 0 additions & 23 deletions pkg/dhcpserver/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"os/exec"
"strings"
"text/template"
"time"
)

// configureInterface configures the network interface with the specified IP address
Expand Down Expand Up @@ -311,23 +310,6 @@ func GetDhcpClients(leaseFilePath string) ([]types.ClientInfo, error) {
return clients, nil
}

// parseDhcpTime parses time from DHCP lease file format
// Format example: "starts 3 2024/12/18 10:00:00;"
func parseDhcpTime(line string) (time.Time, error) {
parts := strings.Fields(line)
if len(parts) < 4 {
return time.Time{}, fmt.Errorf("invalid time format")
}

// Combine date and time parts
timeStr := parts[2] + " " + parts[3]
// Remove trailing semicolon if present
timeStr = strings.TrimSuffix(timeStr, ";")

// Parse the combined string
return time.Parse("2006/01/02 15:04:05", timeStr)
}

// printDhcpLogTail prints the last 50 lines of the DHCP server log file
func (s *dhcpServer) printDhcpLogTail() error {
// Check if log file exists
Expand All @@ -349,8 +331,3 @@ func (s *dhcpServer) printDhcpLogTail() error {

return nil
}

// getLeaseFilePath returns the path to the DHCP lease file for this server instance
func (s *dhcpServer) getLeaseFilePath() string {
return s.leaseFilePath
}
3 changes: 1 addition & 2 deletions pkg/webhook/hostoperation/hostoperation_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import (
)

type HostOperationWebhook struct {
Client client.Client
decoder *admission.Decoder
Client client.Client
}

func (h *HostOperationWebhook) SetupWebhookWithManager(mgr ctrl.Manager) error {
Expand Down

0 comments on commit 4d13ad6

Please sign in to comment.