Skip to content

Commit 06f83e9

Browse files
authored
Merge pull request kcp-dev#3272 from sttts/sttts-prow-artifacts
🌱 Configure prow artifacts correctly
2 parents 6663f2e + 25186ab commit 06f83e9

File tree

5 files changed

+45
-7
lines changed

5 files changed

+45
-7
lines changed

.prow.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ presubmits:
109109
- ./hack/run-with-prometheus.sh
110110
- make
111111
- test-e2e
112+
args:
113+
- ARTIFACT_DIR=$(ARTIFACTS) # propagate prow artifact directory
112114
env:
113115
- name: SUITES
114116
value: control-plane
@@ -137,6 +139,8 @@ presubmits:
137139
- ./hack/run-with-prometheus.sh
138140
- make
139141
- test-e2e
142+
args:
143+
- ARTIFACT_DIR=$(ARTIFACTS) # propagate prow artifact directory
140144
env:
141145
- name: SUITES
142146
value: control-plane
@@ -167,6 +171,8 @@ presubmits:
167171
- ./hack/run-with-prometheus.sh
168172
- make
169173
- test-e2e-shared-minimal
174+
args:
175+
- ARTIFACT_DIR=$(ARTIFACTS) # propagate prow artifact directory
170176
env:
171177
- name: SUITES
172178
value: control-plane
@@ -193,6 +199,8 @@ presubmits:
193199
- ./hack/run-with-prometheus.sh
194200
- make
195201
- test-e2e-sharded-minimal
202+
args:
203+
- ARTIFACT_DIR=$(ARTIFACTS) # propagate prow artifact directory
196204
env:
197205
- name: SUITES
198206
value: control-plane

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ test-e2e-shared-minimal: build-all
301301
mkdir -p "$(LOG_DIR)" "$(WORK_DIR)/.kcp"
302302
rm -f "$(WORK_DIR)/.kcp/ready-to-test"
303303
UNSAFE_E2E_HACK_DISABLE_ETCD_FSYNC=true NO_GORUN=1 \
304-
./bin/test-server --quiet --log-file-path="$(LOG_DIR)/kcp.log" $(TEST_SERVER_ARGS) -- --feature-gates=$(TEST_FEATURE_GATES) 2>&1 & PID=$$! && echo "PID $$PID" && \
304+
./bin/test-server --quiet --log-dir-path="$(LOG_DIR)" $(TEST_SERVER_ARGS) -- --feature-gates=$(TEST_FEATURE_GATES) 2>&1 & PID=$$! && echo "PID $$PID" && \
305305
trap 'kill -TERM $$PID' TERM INT EXIT && \
306306
while [ ! -f "$(WORK_DIR)/.kcp/ready-to-test" ]; do sleep 1; done && \
307307
echo 'Starting test(s)' && \

cmd/sharded-test-server/cache.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ func startCacheServer(ctx context.Context, logDirPath, workingDir string, synthe
6464
fmt.Fprintf(out, "running: %v\n", strings.Join(commandLine, " "))
6565
cmd := exec.CommandContext(ctx, commandLine[0], commandLine[1:]...) //nolint:gosec
6666

67-
logFilePath := filepath.Join(logDirPath, ".kcp-cache", "out.log")
67+
logFilePath := filepath.Join(".kcp-cache", "kcp.log")
68+
if logDirPath != "" {
69+
logFilePath = filepath.Join(logDirPath, "kcp-cache.log")
70+
}
6871
if err := os.MkdirAll(filepath.Dir(logFilePath), 0755); err != nil {
6972
return nil, "", err
7073
}

cmd/test-server/main.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import (
4848
//
4949
// $ go test -v --use-default-kcp-server
5050
func main() {
51-
flag.String("log-file-path", ".kcp/kcp.log", "Path to the log file")
51+
logDirPath := flag.String("log-dir-path", "", "Directory for log files. If empty, .kcp is used.")
5252
quiet := flag.Bool("quiet", false, "Suppress output of the subprocesses")
5353

5454
// split flags into --shard-* and everything else (generic). The former are
@@ -67,7 +67,7 @@ func main() {
6767
}
6868
flag.CommandLine.Parse(genericFlags) //nolint:errcheck
6969

70-
if err := start(shardFlags, *quiet); err != nil {
70+
if err := start(shardFlags, *logDirPath, *quiet); err != nil {
7171
var exitErr *exec.ExitError
7272
if errors.As(err, &exitErr) {
7373
os.Exit(exitErr.ExitCode())
@@ -77,7 +77,7 @@ func main() {
7777
}
7878
}
7979

80-
func start(shardFlags []string, quiet bool) error {
80+
func start(shardFlags []string, logDirPath string, quiet bool) error {
8181
// We use a shutdown context to know that it's time to gather metrics, before stopping the shard
8282
shutdownCtx, shutdownCancel := context.WithCancel(genericapiserver.SetupSignalContext())
8383
defer shutdownCancel()
@@ -98,7 +98,11 @@ func start(shardFlags []string, quiet bool) error {
9898
return fmt.Errorf("failed to create client-ca: %w", err)
9999
}
100100

101-
logFilePath := flag.Lookup("log-file-path").Value.String()
101+
logFilePath := filepath.Join(".kcp", "kcp.log")
102+
if logDirPath != "" {
103+
logFilePath = filepath.Join(logDirPath, "kcp.log")
104+
}
105+
102106
s := shard.NewShard(
103107
"kcp",
104108
".kcp",

test/e2e/framework/util.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"os"
3535
"path"
3636
"path/filepath"
37+
"regexp"
3738
"strconv"
3839
"strings"
3940
"sync"
@@ -161,15 +162,37 @@ func CreateTempDirForTest(t *testing.T, dirName string) (string, error) {
161162
}
162163

163164
// ScratchDirs determines where artifacts and data should live for a test server.
165+
// The passed subDir is appended to the artifact directory and should be unique
166+
// to the test.
164167
func ScratchDirs(t *testing.T) (string, string, error) {
165168
t.Helper()
166-
artifactDir, err := CreateTempDirForTest(t, "artifacts")
169+
170+
artifactDir, err := CreateTempDirForTest(t, toTestDir(t.Name()))
167171
if err != nil {
168172
return "", "", err
169173
}
170174
return artifactDir, t.TempDir(), nil
171175
}
172176

177+
// toTestDir converts a test name into a Unix-compatible directory name.
178+
func toTestDir(testName string) string {
179+
// Insert a dash before uppercase letters in the middle of the string
180+
reg := regexp.MustCompile(`([a-z0-9])([A-Z])`)
181+
safeName := reg.ReplaceAllString(testName, "${1}-${2}")
182+
183+
// Replace any remaining non-alphanumeric characters (except dashes and underscores) with underscores
184+
reg = regexp.MustCompile(`[^a-zA-Z0-9_-]+`)
185+
safeName = reg.ReplaceAllString(safeName, "_")
186+
187+
// Remove any leading or trailing underscores or dashes
188+
safeName = strings.Trim(safeName, "_-")
189+
190+
// Convert to lowercase (optional, depending on your preference)
191+
safeName = strings.ToLower(safeName)
192+
193+
return safeName
194+
}
195+
173196
func (c *kcpServer) CADirectory() string {
174197
return c.dataDir
175198
}

0 commit comments

Comments
 (0)