Skip to content

Commit

Permalink
go lint
Browse files Browse the repository at this point in the history
Signed-off-by: weizhoublue <[email protected]>
  • Loading branch information
weizhoublue committed Dec 26, 2024
1 parent c49ac4b commit c7811b5
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ require (
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.61.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/spf13/cobra v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/vishvananda/netns v0.0.5 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ github.com/prometheus/common v0.61.0 h1:3gv/GThfX0cV2lpO7gkTUwZru38mxevy90Bj8YFS
github.com/prometheus/common v0.61.0/go.mod h1:zr29OCN/2BsJRaFwG8QOBr41D6kkchKbpeNH7pAjb/s=
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sasha-s/go-deadlock v0.3.5 h1:tNCOEEDG6tBqrNDOX35j/7hL5FcFViG6awUGROb2NsU=
github.com/sasha-s/go-deadlock v0.3.5/go.mod h1:bugP6EGbdGYObIlx7pUZtWqlvo8k9H6vCBBsiChJQ5U=
Expand Down
5 changes: 4 additions & 1 deletion pkg/agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ func LoadAgentConfig(k8sClient *kubernetes.Clientset) (*AgentConfig, error) {

// Add bmc scheme and set GroupVersion
scheme := runtime.NewScheme()
bmcv1beta1.AddToScheme(scheme)
err = bmcv1beta1.AddToScheme(scheme)
if err != nil {
return nil, fmt.Errorf("failed to add bmc scheme: %v", err)
}
restConfig.GroupVersion = &bmcv1beta1.SchemeGroupVersion
restConfig.APIPath = "/apis"
restConfig.NegotiatedSerializer = serializer.NewCodecFactory(scheme)
Expand Down
11 changes: 8 additions & 3 deletions pkg/agent/hoststatus/HostStatusReconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/spidernet-io/bmc/pkg/agent/hoststatus/data"
bmcv1beta1 "github.com/spidernet-io/bmc/pkg/k8s/apis/bmc.spidernet.io/v1beta1"

//"github.com/spidernet-io/bmc/pkg/lock"
"github.com/spidernet-io/bmc/pkg/log"
"github.com/spidernet-io/bmc/pkg/redfish"
Expand All @@ -24,8 +25,13 @@ var hostStatusLock = &sync.Mutex{}

// ------------------------------ update the spec.info of the hoststatus

// this is called by UpdateHostStatusAtInterval and UpdateHostStatusWrapper
func (c *hostStatusController) UpdateHostStatusInfo(name string, d *data.HostConnectCon) error {

// local lock for updateing each hostStatus
hostStatusLock.Lock()
defer hostStatusLock.Unlock()

// 创建 redfish 客户端
client := redfish.NewClient(*d, log.Logger)

Expand Down Expand Up @@ -83,6 +89,7 @@ func (c *hostStatusController) UpdateHostStatusInfo(name string, d *data.HostCon
return nil
}

// this is called by UpdateHostStatusAtInterval and
func (c *hostStatusController) UpdateHostStatusWrapper(name string) error {
syncData := make(map[string]data.HostConnectCon)

Expand All @@ -103,12 +110,10 @@ func (c *hostStatusController) UpdateHostStatusWrapper(name string) error {
}

for item, t := range syncData {
hostStatusLock.Lock()
log.Logger.Debugf("update status of the hostStatus %s ", item)
if err := c.UpdateHostStatusInfo(item, &t); err != nil {
log.Logger.Errorf("failed to update HostStatus %s: %v", item, err)
}
hostStatusLock.Unlock()
}

return nil
Expand Down Expand Up @@ -137,7 +142,7 @@ func (c *hostStatusController) UpdateHostStatusAtInterval() {

// ------------------------------ hoststatus 的 reconcile , 触发更新

// 缓存 hostStatus 数据到本地,并行更新 status.info 信息
// 缓存 hostStatus 数据本地,并行更新 status.info 信息
func (c *hostStatusController) processHostStatus(hostStatus *bmcv1beta1.HostStatus, logger *zap.SugaredLogger) error {

logger.Debugf("Processing Existed HostStatus: %s (Type: %s, IP: %s, Health: %v)",
Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/hoststatus/dhcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (c *hostStatusController) handleDHCPAdd(client dhcptypes.ClientInfo) error
log.Logger.Debugf("Processing DHCP add event - IP: %s, MAC: %s, Active: %v, Lease: %s -> %s",
client.IP, client.MAC, client.Active, client.StartTime, client.EndTime)

if c.config.AgentObjSpec.Feature.DhcpServerConfig != nil && c.config.AgentObjSpec.Feature.DhcpServerConfig.EnableDhcpDiscovery == false {
if c.config.AgentObjSpec.Feature.DhcpServerConfig != nil && !c.config.AgentObjSpec.Feature.DhcpServerConfig.EnableDhcpDiscovery {
log.Logger.Warnf("DhcpDiscovery is disabled, so ignore DHCP add event - IP: %s, MAC: %s, Active: %v, Lease: %s -> %s",
client.IP, client.MAC, client.Active, client.StartTime, client.EndTime)
return nil
Expand Down Expand Up @@ -160,7 +160,7 @@ func (c *hostStatusController) handleDHCPDelete(client dhcptypes.ClientInfo) err
name := formatHostStatusName(c.config.ClusterAgentName, client.IP)
log.Logger.Debugf("Processing DHCP delete event - IP: %s, MAC: %s", client.IP, client.MAC)

if c.config.AgentObjSpec.Feature.DhcpServerConfig != nil && c.config.AgentObjSpec.Feature.DhcpServerConfig.EnableDhcpDiscovery == false {
if c.config.AgentObjSpec.Feature.DhcpServerConfig != nil && !c.config.AgentObjSpec.Feature.DhcpServerConfig.EnableDhcpDiscovery {
log.Logger.Warnf("DhcpDiscovery is disabled, so ignore DHCP delete event - IP: %s, MAC: %s, Active: %v, Lease: %s -> %s",
client.IP, client.MAC, client.Active, client.StartTime, client.EndTime)
return nil
Expand Down
3 changes: 2 additions & 1 deletion pkg/lock/lock_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ package lock
import (
"bytes"
"fmt"
deadlock "github.com/sasha-s/go-deadlock"
"io"
"os"
"runtime/debug"
"time"

deadlock "github.com/sasha-s/go-deadlock"
)

const (
Expand Down
1 change: 0 additions & 1 deletion pkg/redfish/getinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func setData(result map[string]string, key, value string) {
} else {
result[key] = value
}
return
}

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/redfish/power.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *redfishClient) Power(bootCmd string) error {
BootSourceOverrideEnabled: redfish.OnceBootSourceOverrideEnabled,
}
c.logger.Infof("pxe reboot %s for System: %+v \n", c.config.Endpoint, system.Name)
err := system.SetBoot(bootOverride)
err = system.SetBoot(bootOverride)
if err != nil {
return fmt.Errorf("failed to set boot option")
}
Expand Down
2 changes: 2 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ github.com/prometheus/common/model
github.com/prometheus/procfs
github.com/prometheus/procfs/internal/fs
github.com/prometheus/procfs/internal/util
# github.com/rogpeppe/go-internal v1.13.1
## explicit; go 1.22
# github.com/sasha-s/go-deadlock v0.3.5
## explicit
github.com/sasha-s/go-deadlock
Expand Down

0 comments on commit c7811b5

Please sign in to comment.