-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #369 from xiaods/dev
update cmds
- Loading branch information
Showing
7 changed files
with
208 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
Oops, something went wrong.