Skip to content

Commit

Permalink
Merge pull request #369 from xiaods/dev
Browse files Browse the repository at this point in the history
update cmds
  • Loading branch information
xiaods authored Oct 24, 2024
2 parents df09a4f + dd8440c commit 9692409
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 71 deletions.
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ require (
github.com/go-bindata/go-bindata v3.1.2+incompatible
github.com/go-logr/logr v1.4.2
github.com/go-logr/stdr v1.2.3-0.20220714215716-96bad1d688c5
github.com/go-sql-driver/mysql v1.8.1
github.com/go-test/deep v1.0.7
github.com/golang/mock v1.6.0
github.com/google/uuid v1.6.0
Expand All @@ -101,9 +100,7 @@ require (
github.com/k3s-io/helm-controller v0.16.5
github.com/k3s-io/kine v0.13.2
github.com/klauspost/compress v1.17.10
github.com/lib/pq v1.10.9
github.com/libp2p/go-libp2p v0.33.2
github.com/mattn/go-sqlite3 v1.14.23
github.com/minio/minio-go/v7 v7.0.70
github.com/morikuni/aec v1.0.0
github.com/mwitkow/go-http-dialer v0.0.0-20161116154839-378f744fb2b8
Expand Down Expand Up @@ -249,6 +246,7 @@ require (
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gofrs/flock v0.8.1 // indirect
Expand Down Expand Up @@ -323,6 +321,7 @@ require (
github.com/mailru/easyjson v0.7.7 // indirect
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-sqlite3 v1.14.23 // indirect
github.com/miekg/dns v1.1.58 // indirect
github.com/miekg/pkcs11 v1.1.1 // indirect
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1085,8 +1085,6 @@ github.com/lestrrat-go/httpcc v1.0.1/go.mod h1:qiltp3Mt56+55GPVCbTdM9MlqhvzyuL6W
github.com/lestrrat-go/iter v1.0.1/go.mod h1:zIdgO1mRKhn8l9vrZJZz9TUMMFbQbLeTsbqPDrJ/OJc=
github.com/lestrrat-go/jwx v1.2.25/go.mod h1:zoNuZymNl5lgdcu6P7K6ie2QRll5HVfF4xwxBBK1NxY=
github.com/lestrrat-go/option v1.0.0/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/libopenstorage/openstorage v1.0.0 h1:GLPam7/0mpdP8ZZtKjbfcXJBTIA/T1O6CBErVEFEyIM=
github.com/libopenstorage/openstorage v1.0.0/go.mod h1:Sp1sIObHjat1BeXhfMqLZ14wnOzEhNx2YQedreMcUyc=
github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8=
Expand Down
7 changes: 7 additions & 0 deletions pkg/cli/cmds/cover_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !linux || !cover

package cmds

import "context"

func WriteCoverage(ctx context.Context) {}
32 changes: 32 additions & 0 deletions pkg/cli/cmds/cover_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//go:build linux && cover

package cmds

import (
"context"
"os"
"runtime/coverage"
"time"

"github.com/sirupsen/logrus"
)

// writeCoverage checks if GOCOVERDIR is set on startup and writes coverage files to that directory
// every 20 seconds. This is done to ensure that the coverage files are written even if the process is killed.
func WriteCoverage(ctx context.Context) {
if k, ok := os.LookupEnv("GOCOVERDIR"); ok {
for {
select {
case <-ctx.Done():
if err := coverage.WriteCountersDir(k); err != nil {
logrus.Warn(err)
}
return
case <-time.After(20 * time.Second):
if err := coverage.WriteCountersDir(k); err != nil {
logrus.Warn(err)
}
}
}
}
}
27 changes: 27 additions & 0 deletions pkg/cli/cmds/golang.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cmds

import (
"fmt"
"runtime"
"strings"

"github.com/sirupsen/logrus"
"github.com/xiaods/k8e/pkg/version"
)

func ValidateGolang() error {
k8sVersion, _, _ := strings.Cut(version.Version, "+")
if version.UpstreamGolang == "" {
return fmt.Errorf("kubernetes golang build version not set - see 'golang: upstream version' in https://github.com/kubernetes/kubernetes/blob/%s/build/dependencies.yaml", k8sVersion)
}
if v, _, _ := strings.Cut(runtime.Version(), " "); version.UpstreamGolang != v {
return fmt.Errorf("incorrect golang build version - kubernetes %s should be built with %s, runtime version is %s", k8sVersion, version.UpstreamGolang, v)
}
return nil
}

func MustValidateGolang() {
if err := ValidateGolang(); err != nil {
logrus.Fatalf("Failed to validate golang version: %v", err)
}
}
Loading

0 comments on commit 9692409

Please sign in to comment.