Skip to content

Commit d29d82d

Browse files
committed
loads of improvements, can now actually start the agent without it crashing immediately
On-behalf-of: @SAP [email protected]
1 parent 9687d7e commit d29d82d

File tree

9 files changed

+578
-44
lines changed

9 files changed

+578
-44
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/_build/
22
/_tools/
33
/vendor/
4+
/.kcp.e2e/
5+
/.e2e/
46
.cover
57
*.kubeconfig
68
*.pem

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.22.0
55
require (
66
github.com/Masterminds/sprig/v3 v3.3.0
77
github.com/evanphx/json-patch/v5 v5.9.0
8+
github.com/go-logr/logr v1.4.2
89
github.com/go-logr/zapr v1.3.0
910
github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20240817110845-a9eb9752bfeb
1011
github.com/kcp-dev/client-go v0.0.0-20240912145314-f5949d81732a
@@ -45,7 +46,6 @@ require (
4546
github.com/fatih/color v1.18.0 // indirect
4647
github.com/fsnotify/fsnotify v1.7.0 // indirect
4748
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
48-
github.com/go-logr/logr v1.4.2 // indirect
4949
github.com/go-openapi/jsonpointer v0.19.6 // indirect
5050
github.com/go-openapi/jsonreference v0.20.2 // indirect
5151
github.com/go-openapi/swag v0.22.4 // indirect

hack/ci/run-e2e-tests.sh

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717
set -euo pipefail
1818
source hack/lib.sh
1919

20+
# have a place to store things
21+
if [ -z "${ARTIFACTS:-}" ]; then
22+
ARTIFACTS=.e2e/artifacts
23+
mkdir -p "$ARTIFACTS"
24+
fi
25+
26+
echodate "Build artifacts will be placed in $ARTIFACTS."
27+
export ARTIFACTS="$(realpath "$ARTIFACTS")"
28+
2029
# build the agent, we will start it many times during the tests
2130
echodate "Building the api-syncagent…"
2231
make build
@@ -31,27 +40,44 @@ KUBEBUILDER_ASSETS="$(realpath "$KUBEBUILDER_ASSETS")"
3140
make _tools/kcp
3241

3342
KCP_ROOT_DIRECTORY=.kcp.e2e
34-
KCP_LOGFILE=kcp.e2e.log
43+
KCP_LOGFILE="$ARTIFACTS/kcp.log"
44+
KCP_TOKENFILE=hack/ci/testdata/e2e-kcp.tokens
3545

3646
echodate "Starting kcp…"
3747
rm -rf "$KCP_ROOT_DIRECTORY" "$KCP_LOGFILE"
3848
_tools/kcp start \
49+
-v4 \
50+
--token-auth-file "$KCP_TOKENFILE" \
3951
--root-directory "$KCP_ROOT_DIRECTORY" 1>"$KCP_LOGFILE" 2>&1 &
4052

4153
stop_kcp() {
42-
echodate "Stopping kcp processes…"
54+
echodate "Stopping kcp processes (set \$KEEP_KCP=true to not do this)"
4355
pkill -e kcp
4456
}
45-
append_trap stop_kcp EXIT
57+
58+
if [[ -v KEEP_KCP ]] && $KEEP_KCP; then
59+
echodate "\$KEEP_KCP is set, will not stop kcp once the script is finished."
60+
else
61+
append_trap stop_kcp EXIT
62+
fi
63+
64+
# make the token available to the Go tests
65+
export KCP_AGENT_TOKEN="$(grep e2e "$KCP_TOKENFILE" | cut -f1 -d,)"
4666

4767
# Wait for kcp to be ready; this env name is also hardcoded in the Go tests.
4868
export KCP_KUBECONFIG="$KCP_ROOT_DIRECTORY/admin.kubeconfig"
4969

50-
if ! retry_linear 3 20 kubectl --kubeconfig "$KCP_KUBECONFIG" get logicalcluster; then
70+
# the tenancy API becomes available pretty late during startup, so it's a good readiness check
71+
if ! retry_linear 3 20 kubectl --kubeconfig "$KCP_KUBECONFIG" get workspaces; then
5172
echodate "kcp never became ready."
5273
exit 1
5374
fi
5475

76+
# makes it easier to reference thesefiles from various _test.go files.
77+
export ROOT_DIRECTORY="$(realpath .)"
78+
export KCP_KUBECONFIG="$(realpath "$KCP_KUBECONFIG")"
79+
export AGENT_BINARY="$(realpath _build/api-syncagent)"
80+
5581
# time to run the tests
5682
echodate "Running e2e tests…"
5783
(set -x; go test -tags e2e -timeout 2h -v ./test/e2e/...)

hack/ci/testdata/e2e-kcp.tokens

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
topphemmelig,api-syncagent-e2e,1111-2222-3333-4444,"api-syncagents"

hack/ci/testdata/kcp-kind-values.yaml

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//go:build e2e
2+
3+
/*
4+
Copyright 2025 The KCP Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package apiresourceschema
20+
21+
import (
22+
"context"
23+
"testing"
24+
"time"
25+
26+
"github.com/go-logr/logr"
27+
28+
"github.com/kcp-dev/api-syncagent/test/utils"
29+
30+
ctrlruntime "sigs.k8s.io/controller-runtime"
31+
)
32+
33+
func TestARSAreCreated(t *testing.T) {
34+
ctx := context.Background()
35+
ctrlruntime.SetLogger(logr.Discard())
36+
37+
// setup a test environment in kcp
38+
fooKubconfig := utils.CreateHomeWorkspace(t, ctx, "foo", "my-api")
39+
40+
// start a service cluster
41+
envtestKubeconfig, _, _ := utils.RunEnvtest(t)
42+
43+
t.Run("my subtest", func(t *testing.T) {
44+
utils.RunAgent(
45+
ctx,
46+
t,
47+
"bob",
48+
fooKubconfig,
49+
envtestKubeconfig,
50+
"my-api",
51+
)
52+
53+
time.Sleep(5 * time.Second)
54+
})
55+
56+
}

0 commit comments

Comments
 (0)