Skip to content

Commit

Permalink
feat: bump go-common
Browse files Browse the repository at this point in the history
Needed for #55

Signed-off-by: Tim Serong <[email protected]>
  • Loading branch information
tserong authored and Vicente-Cheng committed Aug 23, 2024
1 parent 9f7bc62 commit 30a0bd4
Show file tree
Hide file tree
Showing 127 changed files with 9,917 additions and 6,514 deletions.
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ replace (
require (
github.com/ehazlett/simplelog v0.0.0-20200226020431-d374894e92a4
github.com/godbus/dbus/v5 v5.1.0
github.com/harvester/go-common v0.0.0-20231214093547-3e3f7fdd879a
github.com/harvester/go-common v0.0.0-20240822134235-198df47889ca
github.com/mudler/yip v1.1.0
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.16.0
Expand All @@ -36,7 +36,6 @@ require (
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.9.0
github.com/twpayne/go-vfs v1.7.2
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 // indirect
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0
k8s.io/api v0.30.3
k8s.io/apimachinery v0.30.3
Expand All @@ -48,7 +47,7 @@ require (
github.com/fsnotify/fsnotify v1.7.0
github.com/harvester/webhook v0.1.4
github.com/urfave/cli/v2 v2.3.0
golang.org/x/sys v0.19.0
golang.org/x/sys v0.20.0
gopkg.in/yaml.v3 v3.0.1
)

Expand Down Expand Up @@ -94,7 +93,7 @@ require (
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rancher/dynamiclistener v0.3.5 // indirect
github.com/rancher/wrangler v1.1.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
Expand Down
14 changes: 6 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/harvester/go-common v0.0.0-20231214093547-3e3f7fdd879a h1:4TQVNT8HzY+xh7hXlclfxt/kaBoz1nMvOmmXIX2JTmg=
github.com/harvester/go-common v0.0.0-20231214093547-3e3f7fdd879a/go.mod h1:xCmR8h47sSSz+vqDjGkSh5kMr3WqXZKruZyir/i166o=
github.com/harvester/go-common v0.0.0-20240822134235-198df47889ca h1:gUgeAQ9NSFEBqVkKJxTmbhbob/6CWu/iDlD4V40IpdU=
github.com/harvester/go-common v0.0.0-20240822134235-198df47889ca/go.mod h1:UNh9xAFqna6F2Fk4m4TTNWV0xaORlFwH7B+DepHT/gI=
github.com/harvester/webhook v0.1.4 h1:6g5MkYXlGm0wABQ/Dm8g5sM7WAtPq2aiWOH9wmf2vUQ=
github.com/harvester/webhook v0.1.4/go.mod h1:vfRPB26WHSPxMF/ONpUVzaEaewTUxpP9qAqu1ZyonR0=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand Down Expand Up @@ -257,8 +257,8 @@ github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUo
github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU=
github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY=
github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY=
github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg=
github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM=
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/rancher/dynamiclistener v0.3.5 h1:5TaIHvkDGmZKvc96Huur16zfTKOiLhDtK4S+WV0JA6A=
github.com/rancher/dynamiclistener v0.3.5/go.mod h1:dW/YF6/m2+uEyJ5VtEcd9THxda599HP6N9dSXk81+k0=
github.com/rancher/lasso v0.0.0-20240705194423-b2a060d103c1 h1:vv1jDlYbd4KhGbPNxmjs8CYgEHUrQm2bMtmULfXJ6iw=
Expand Down Expand Up @@ -347,8 +347,6 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 h1:hNQpMuAJe5CtcUqCXaWga3FHu+kQvCqcsoVaQgSV60o=
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down Expand Up @@ -477,8 +475,8 @@ golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q=
Expand Down
23 changes: 12 additions & 11 deletions pkg/controller/nodeconfig/config/ntp.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
"strings"
"sync"

gocommon "github.com/harvester/go-common"
"github.com/harvester/go-common/files"
"github.com/harvester/go-common/sys"
"github.com/mudler/yip/pkg/schema"
ctlnode "github.com/rancher/wrangler/v3/pkg/generated/controllers/core/v1"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -80,7 +81,7 @@ func (handler *NTPHandler) DoNTPUpdate(forceUpdate bool) (bool, error) {
_, err := os.Stat(timesyncdConfigOriginPath)
if os.IsNotExist(err) {
logrus.Infof("Backup original ntp config ...")
if _, err := gocommon.BackupFileToDirWithSuffix(timesyncdConfigPath, "", "origin"); err != nil {
if _, err := files.BackupFileToDirWithSuffix(timesyncdConfigPath, "", "origin"); err != nil {
return false, fmt.Errorf("backup the original ntp config failed. err: %v", err)
}
}
Expand Down Expand Up @@ -128,7 +129,7 @@ func (handler *NTPHandler) updateNTPConfig() error {
return fmt.Errorf("generate NTP Config Raw Buffer failed. err: %v", err)
}

tempNTPConfigName, err := gocommon.GenerateTempFileWithDir([]byte(raw), "timesyncd.conf", utils.SystemdConfigPath)
tempNTPConfigName, err := files.GenerateTempFileWithDir([]byte(raw), "timesyncd.conf", utils.SystemdConfigPath)
if err != nil {
return fmt.Errorf("generate temp NTP config failed. err: %v", err)
}
Expand Down Expand Up @@ -179,7 +180,7 @@ func (handler *NTPHandler) UpdateNodeNTPAnnotation() error {
}

func (handler *NTPHandler) backupNTPConfig() error {
if _, err := gocommon.BackupFile(timesyncdConfigPath); err != nil {
if _, err := files.BackupFile(timesyncdConfigPath); err != nil {
return fmt.Errorf("backup NTP config failed. err: %v", err)
}
return nil
Expand Down Expand Up @@ -212,7 +213,7 @@ func NTPConfigRollback() error {

func (handler *NTPHandler) RestartService() error {
logrus.Infof("Restart systemd-timesyncd service ...")
return gocommon.RestartService(systemdTimesyncdService)
return sys.RestartService(systemdTimesyncdService)
}

// make NTP configuration persistence, using 99_settings.yaml to make sure we are later than 99_oem.yaml
Expand All @@ -235,7 +236,7 @@ func (handler *NTPHandler) UpdateNTPConfigPersistence() error {
}
} else {
// backup current config
if _, err := gocommon.BackupFile(settingsOEMPath); err != nil {
if _, err := files.BackupFile(settingsOEMPath); err != nil {
return fmt.Errorf("backup NTP OEM file failed. err: %v", err)
}
// load and overwrite
Expand All @@ -253,7 +254,7 @@ func (handler *NTPHandler) UpdateNTPConfigPersistence() error {
}
}
logrus.Infof("Prepare to update settings to persistent file: %+v", settings)
tmpFileName, err := gocommon.GenerateYAMLTempFileWithDir(settings, "settings", oemPath)
tmpFileName, err := files.GenerateYAMLTempFileWithDir(settings, "settings", oemPath)
if err != nil {
return fmt.Errorf("generate temp YAML file failed. err: %v", err)
}
Expand Down Expand Up @@ -290,7 +291,7 @@ func RemovePersistentNTPConfig() error {
if _, found := yipConfig.Stages[yipStageInitramfs]; !found {
// this moment, we only have `initramfs` stage, so we could remove all OEM settings files.
logrus.Infof("No `initramfs` stage found, remove all OEM settings files.")
return gocommon.RemoveFiles(settingsOEMPath, settingsOEMPathBackupPath)
return files.RemoveFiles(settingsOEMPath, settingsOEMPathBackupPath)
}

for id, stage := range yipConfig.Stages[yipStageInitramfs] {
Expand All @@ -305,18 +306,18 @@ func RemovePersistentNTPConfig() error {
stages = append(stages[:pos], stages[pos+1:]...)
if len(stages) == 0 {
logrus.Infof("No other stages found, remove all OEM settings files.")
return gocommon.RemoveFiles(settingsOEMPath, settingsOEMPathBackupPath)
return files.RemoveFiles(settingsOEMPath, settingsOEMPathBackupPath)
}
yipConfig.Stages[yipStageInitramfs] = stages
}

// we still have other stages, so we need to backup/update OEM settings files
if _, err := gocommon.BackupFile(settingsOEMPath); err != nil {
if _, err := files.BackupFile(settingsOEMPath); err != nil {
return fmt.Errorf("backup NTP OEM file failed. err: %v", err)
}

logrus.Infof("Prepare to update new settings to persistent files: %+v", yipConfig)
tmpFileName, err := gocommon.GenerateYAMLTempFileWithDir(yipConfig, "settings", oemPath)
tmpFileName, err := files.GenerateYAMLTempFileWithDir(yipConfig, "settings", oemPath)
if err != nil {
return fmt.Errorf("generate temp YAML file failed. err: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/nodeconfig/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"sync"
"time"

gocommon "github.com/harvester/go-common"
"github.com/harvester/go-common/common"
ctlnode "github.com/rancher/wrangler/v3/pkg/generated/controllers/core/v1"
"github.com/sirupsen/logrus"

Expand Down Expand Up @@ -134,7 +134,7 @@ func (c *Controller) OnNodeConfigRemove(key string, nodecfg *nodeconfigv1.NodeCo

func enqueueJitter() time.Duration {
baseDelay := 7
randNum, err := gocommon.GenRandNumber(3)
randNum, err := common.GenRandNumber(3)
if err != nil {
logrus.Errorf("Failed to generate random number, use `0` as randNumber: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/monitor/cloudinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/fsnotify/fsnotify"
gocommon "github.com/harvester/go-common"
"github.com/harvester/go-common/sys"
ctlnodev1 "github.com/rancher/wrangler/v3/pkg/generated/controllers/core/v1"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -39,7 +39,7 @@ func NewCloudInitMonitor(ctx context.Context, monitorName, nodeName string, clou

func (m *CloudInitMonitor) startMonitor() {
go func() {
gocommon.WatchFileChange(m.ctx, gocommon.FSNotifyHandlerFunc(m.handleFSNotify), []string{cloudinit.Directory})
sys.WatchFileChange(m.ctx, sys.FSNotifyHandlerFunc(m.handleFSNotify), []string{cloudinit.Directory})
}()
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/monitor/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"

"github.com/fsnotify/fsnotify"
gocommon "github.com/harvester/go-common"
"github.com/harvester/go-common/sys"
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down Expand Up @@ -36,10 +36,10 @@ func NewConfigFileMonitor(ctx context.Context, nodecfg ctlv1.NodeConfigControlle

func (monitor *ConfigFileMonitor) startMonitor() {
go func() {
handler := gocommon.FSNotifyHandlerFunc(func(event fsnotify.Event) {
handler := sys.FSNotifyHandlerFunc(func(event fsnotify.Event) {
monitor.genericHandler(event.Name)
})
gocommon.WatchFileChange(monitor.Context, gocommon.AnyOf(gocommon.FSNotifyHandlerFunc(handler), fsnotify.Write), monitorTargets)
sys.WatchFileChange(monitor.Context, sys.AnyOf(sys.FSNotifyHandlerFunc(handler), fsnotify.Write), monitorTargets)
}()
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/monitor/ntp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/godbus/dbus/v5"
gocommon "github.com/harvester/go-common"
"github.com/harvester/go-common/sys"
ctlnode "github.com/rancher/wrangler/v3/pkg/generated/controllers/core/v1"
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -90,10 +90,10 @@ func (monitor *NTPMonitor) startMonitor() {
logrus.Infof("Start WatchDbus Signal...")

go func() {
gocommon.WatchDBusSignal(monitor.Context, utils.DbusPropertiesIface, utils.DbusTimedate1ObjectPath, monitor.handleTimedate1Signal)
sys.WatchDBusSignal(monitor.Context, utils.DbusPropertiesIface, utils.DbusTimedate1ObjectPath, monitor.handleTimedate1Signal)
}()
go func() {
gocommon.WatchDBusSignal(monitor.Context, utils.DbusPropertiesIface, utils.DbusTimesync1ObjectPath, monitor.handleTimesync1Signal)
sys.WatchDBusSignal(monitor.Context, utils.DbusPropertiesIface, utils.DbusTimesync1ObjectPath, monitor.handleTimesync1Signal)
}()
go func() {
defer monitor.ticker.Stop()
Expand Down
19 changes: 0 additions & 19 deletions vendor/github.com/harvester/go-common/.golangci.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions vendor/github.com/harvester/go-common/README.md

This file was deleted.

73 changes: 73 additions & 0 deletions vendor/github.com/harvester/go-common/common/ns.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 0 additions & 22 deletions vendor/github.com/harvester/go-common/gocommon.go

This file was deleted.

Loading

0 comments on commit 30a0bd4

Please sign in to comment.