Skip to content

Commit 7a6a943

Browse files
committed
Move k8sMaintainer code to its own dir
Signed-off-by: Brett Tofel <[email protected]>
1 parent ac43416 commit 7a6a943

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ lint-custom: custom-linter-build #EXHELP Call custom linter for the project
122122

123123
.PHONY: k8s-maintainer #EXHELP this tool also calls `go mod tidy` but also allows us maintain k8s.io/kubernetes` changes bumping related staging modules (e.g., `k8s.io/api`, `k8s.io/apimachinery) as needed
124124
k8s-maintainer:
125-
go run hack/tools/k8sMaintainer.go
125+
go run hack/tools/k8smaintainer/main.go
126126

127127
.PHONY: tidy
128128
tidy: k8s-maintainer #HELP Update dependencies.
File renamed without changes.

hack/tools/k8sMaintainer.go hack/tools/k8smaintainer/main.go

+26-1
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,37 @@ func main() {
2828
flag.BoolVar(&debug, "debug", false, "Enable debug output")
2929
flag.Parse()
3030

31-
if err := fixGoMod("go.mod"); err != nil {
31+
mainGoMod := getMainGoModPath()
32+
33+
if err := fixGoMod(mainGoMod); err != nil {
3234
fmt.Fprintf(os.Stderr, "fixGoMod failed: %v\n", err)
3335
os.Exit(1)
3436
}
3537
}
3638

39+
func getMainGoModPath() string {
40+
rootDir := findProjectRoot()
41+
return fmt.Sprintf("%s/go.mod", rootDir)
42+
}
43+
44+
func findProjectRoot() string {
45+
cwd, err := os.Getwd()
46+
if err != nil {
47+
fmt.Fprintf(os.Stderr, "failed to get working directory: %v\n", err)
48+
os.Exit(1)
49+
}
50+
51+
for cwd != "/" {
52+
if _, err := os.Stat(fmt.Sprintf("%s/go.mod", cwd)); err == nil {
53+
return cwd
54+
}
55+
cwd = cwd[:strings.LastIndex(cwd, "/")]
56+
}
57+
fmt.Fprintln(os.Stderr, "Error: Could not find project root with go.mod")
58+
os.Exit(1)
59+
return ""
60+
}
61+
3762
// fixGoMod is the main entrypoint. It does a 2‐phase approach:
3863
//
3964
// Remove old k8s.io/* replace lines, rewrite + tidy so they’re really gone.

0 commit comments

Comments
 (0)