Skip to content

Commit 910671c

Browse files
authored
e2e: add asynchronous suspend upload and detach checks (#3264)
Expand the demo e2e suite to cover asynchronous suspend background upload, background detach, and CreateTag promotion. Lower atelet's snapshot detach delay in kind so the suite can wait for background detach. Checks that wait for a background upload or detach skip on installs with longer delays, and fail in CI. AI use: AI-assisted, I reviewed and tested it. - [ ] Tests pass - [ ] Docs updated Signed-off-by: msau42 <[email protected]>
1 parent 62efb70 commit 910671c

5 files changed

Lines changed: 587 additions & 190 deletions

File tree

‎cmd/ate-setup/internal/steps/overlay_test.go‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ func TestRenderFakeDataPlane(t *testing.T) {
789789

790790
// Under --e2e-tuning every path that applies atelet appends the e2e tuning
791791
// flags without dropping the overlay's own args, and a non-e2e kind render
792-
// keeps atelet on its default snapshot upload delay.
792+
// keeps atelet on its default snapshot delays.
793793
func TestRenderE2ETuning(t *testing.T) {
794794
root := repoRoot(t)
795795
const ateletDS = "atelet"
@@ -805,41 +805,41 @@ func TestRenderE2ETuning(t *testing.T) {
805805
cfg: config.Config{Router: config.RouterEnvoy},
806806
path: func(e *Env) string { return e.Cfg.Path(SystemOverlay(e.Cfg)) },
807807
wantAtelet: true,
808-
wantArgs: []string{"--grpc-server-cred-bundle=/run/podidentity.podcert.ate.dev/credential-bundle.pem", "--snapshot-upload-delay=2s"},
808+
wantArgs: []string{"--grpc-server-cred-bundle=/run/podidentity.podcert.ate.dev/credential-bundle.pem", "--snapshot-upload-delay=2s", "--snapshot-detach-delay=30s"},
809809
},
810810
{
811811
name: "kind bundle",
812812
cfg: config.Config{Router: config.RouterEnvoy, Kind: true},
813813
path: func(e *Env) string { return e.Cfg.Path(SystemOverlay(e.Cfg)) },
814814
wantAtelet: true,
815-
wantArgs: []string{"--localhost-registry-replacement=kind-registry:5000", "--log-level=debug", "--snapshot-upload-delay=2s"},
815+
wantArgs: []string{"--localhost-registry-replacement=kind-registry:5000", "--log-level=debug", "--snapshot-upload-delay=2s", "--snapshot-detach-delay=30s"},
816816
},
817817
{
818818
name: "agentgateway bundle",
819819
cfg: config.Config{Router: config.RouterAgentgateway},
820820
path: func(e *Env) string { return e.Cfg.Path(SystemOverlay(e.Cfg)) },
821821
wantAtelet: true,
822-
wantArgs: []string{"--grpc-server-cred-bundle=/run/podidentity.podcert.ate.dev/credential-bundle.pem", "--snapshot-upload-delay=2s"},
822+
wantArgs: []string{"--grpc-server-cred-bundle=/run/podidentity.podcert.ate.dev/credential-bundle.pem", "--snapshot-upload-delay=2s", "--snapshot-detach-delay=30s"},
823823
},
824824
{
825825
name: "kind agentgateway bundle",
826826
cfg: config.Config{Router: config.RouterAgentgateway, Kind: true},
827827
path: func(e *Env) string { return e.Cfg.Path(SystemOverlay(e.Cfg)) },
828828
wantAtelet: true,
829-
wantArgs: []string{"--localhost-registry-replacement=kind-registry:5000", "--log-level=debug", "--snapshot-upload-delay=2s"},
829+
wantArgs: []string{"--localhost-registry-replacement=kind-registry:5000", "--log-level=debug", "--snapshot-upload-delay=2s", "--snapshot-detach-delay=30s"},
830830
},
831831
{
832832
name: "atelet file",
833833
path: func(e *Env) string { return e.Cfg.Manifest("atelet.yaml") },
834834
wantAtelet: true,
835-
wantArgs: []string{"--grpc-server-cred-bundle=/run/podidentity.podcert.ate.dev/credential-bundle.pem", "--snapshot-upload-delay=2s"},
835+
wantArgs: []string{"--grpc-server-cred-bundle=/run/podidentity.podcert.ate.dev/credential-bundle.pem", "--snapshot-upload-delay=2s", "--snapshot-detach-delay=30s"},
836836
},
837837
{
838838
name: "kind atelet overlay",
839839
cfg: config.Config{Kind: true},
840840
path: func(e *Env) string { return e.ateletManifestPath() },
841841
wantAtelet: true,
842-
wantArgs: []string{"--localhost-registry-replacement=kind-registry:5000", "--log-level=debug", "--snapshot-upload-delay=2s"},
842+
wantArgs: []string{"--localhost-registry-replacement=kind-registry:5000", "--log-level=debug", "--snapshot-upload-delay=2s", "--snapshot-detach-delay=30s"},
843843
},
844844
{
845845
name: "api server file without atelet",
@@ -873,7 +873,7 @@ func TestRenderE2ETuning(t *testing.T) {
873873
})
874874
}
875875

876-
t.Run("kind without e2e-tuning omits snapshot-upload-delay", func(t *testing.T) {
876+
t.Run("kind without e2e-tuning omits snapshot delays", func(t *testing.T) {
877877
e := &Env{Cfg: &config.Config{Root: root, Kind: true}}
878878
rendered, err := e.render(e.ateletManifestPath())
879879
if err != nil {
@@ -885,7 +885,7 @@ func TestRenderE2ETuning(t *testing.T) {
885885
t.Errorf("kind atelet args = %v, missing --log-level=debug", args)
886886
}
887887
for _, arg := range args {
888-
if strings.HasPrefix(arg, "--snapshot-upload-delay") {
888+
if strings.HasPrefix(arg, "--snapshot-upload-delay") || strings.HasPrefix(arg, "--snapshot-detach-delay") {
889889
t.Errorf("kind atelet without --e2e-tuning carries %q in args %v", arg, args)
890890
}
891891
}

‎internal/e2e/snapshotdelays.go‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright 2026 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package e2e
16+
17+
import (
18+
"context"
19+
"fmt"
20+
"os"
21+
"slices"
22+
"testing"
23+
"time"
24+
25+
"github.com/spf13/pflag"
26+
corev1 "k8s.io/api/core/v1"
27+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28+
)
29+
30+
// RequireShortSnapshotDelays skips t unless atelet runs with
31+
// --snapshot-upload-delay and --snapshot-detach-delay of at most maxDelay, so t
32+
// can wait for atelet to upload or detach a suspended actor's snapshot in the
33+
// background. In CI it fails instead.
34+
func RequireShortSnapshotDelays(t testing.TB, ctx context.Context, maxDelay time.Duration) {
35+
t.Helper()
36+
ds, err := GetClients().K8s.AppsV1().DaemonSets(SystemNamespace()).Get(ctx, ResourceName("atelet"), metav1.GetOptions{})
37+
if err != nil {
38+
t.Fatalf("getting the atelet DaemonSet: %v", err)
39+
}
40+
containers := ds.Spec.Template.Spec.Containers
41+
i := slices.IndexFunc(containers, func(c corev1.Container) bool { return c.Name == "atelet" })
42+
if i < 0 {
43+
t.Fatalf("DaemonSet %s/%s has no atelet container", ds.Namespace, ds.Name)
44+
}
45+
skip, fail := shortSnapshotDelaysDecision(containers[i].Args, maxDelay, shortSnapshotDelaysRequired())
46+
if fail != "" {
47+
t.Fatal(fail)
48+
}
49+
if skip != "" {
50+
t.Skip(skip)
51+
}
52+
}
53+
54+
// shortSnapshotDelaysRequired reports whether RequireShortSnapshotDelays fails
55+
// rather than skips. CI runs with --e2e-tuning, which sets both delays short,
56+
// so a skip there would pass having checked nothing.
57+
func shortSnapshotDelaysRequired() bool {
58+
return os.Getenv("CI") == "true"
59+
}
60+
61+
// shortSnapshotDelaysDecision is RequireShortSnapshotDelays's rule for args,
62+
// atelet's arguments, apart from testing.TB and the cluster so it is tested
63+
// without them.
64+
func shortSnapshotDelaysDecision(args []string, maxDelay time.Duration, required bool) (skip, fail string) {
65+
fs := pflag.NewFlagSet("atelet", pflag.ContinueOnError)
66+
fs.ParseErrorsAllowlist.UnknownFlags = true
67+
upload := fs.Duration("snapshot-upload-delay", 0, "")
68+
detach := fs.Duration("snapshot-detach-delay", 0, "")
69+
if err := fs.Parse(args); err != nil {
70+
return "", fmt.Sprintf("parsing atelet's arguments: %v", err)
71+
}
72+
// An unset flag leaves atelet's default delay, which is minutes long.
73+
describe := func(name string, d time.Duration) string {
74+
if !fs.Changed(name) {
75+
return "unset"
76+
}
77+
return d.String()
78+
}
79+
if fs.Changed("snapshot-upload-delay") && *upload <= maxDelay && fs.Changed("snapshot-detach-delay") && *detach <= maxDelay {
80+
return "", ""
81+
}
82+
msg := fmt.Sprintf("this check waits for atelet to upload or detach a snapshot in the background, so it needs atelet's --snapshot-upload-delay and --snapshot-detach-delay at most %v, as manifests/ate-install/components/e2e sets them; they are %s and %s",
83+
maxDelay, describe("snapshot-upload-delay", *upload), describe("snapshot-detach-delay", *detach))
84+
if required {
85+
return "", msg + " (required because CI=true)"
86+
}
87+
return msg, ""
88+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2026 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package e2e
16+
17+
import (
18+
"testing"
19+
"time"
20+
)
21+
22+
func TestShortSnapshotDelaysDecision(t *testing.T) {
23+
kind := []string{"--log-level=debug", "--snapshot-upload-delay=2s", "--snapshot-detach-delay=30s"}
24+
defaults := []string{"--log-level=debug"}
25+
tests := []struct {
26+
name string
27+
args []string
28+
required bool
29+
wantSkip bool
30+
wantFail bool
31+
}{
32+
{name: "short delays run", args: kind},
33+
{name: "short delays run in CI", args: kind, required: true},
34+
{name: "default delays skip", args: defaults, wantSkip: true},
35+
{name: "default delays fail in CI", args: defaults, required: true, wantFail: true},
36+
{name: "a long delay skips", args: []string{"--snapshot-upload-delay=2s", "--snapshot-detach-delay=30m"}, wantSkip: true},
37+
{name: "an unparsable delay fails", args: []string{"--snapshot-detach-delay=soon"}, wantFail: true},
38+
}
39+
for _, tt := range tests {
40+
t.Run(tt.name, func(t *testing.T) {
41+
skip, fail := shortSnapshotDelaysDecision(tt.args, 30*time.Second, tt.required)
42+
if (skip != "") != tt.wantSkip || (fail != "") != tt.wantFail {
43+
t.Errorf("shortSnapshotDelaysDecision(%q, required=%t) = skip %q, fail %q; want skip %t, fail %t",
44+
tt.args, tt.required, skip, fail, tt.wantSkip, tt.wantFail)
45+
}
46+
})
47+
}
48+
}

0 commit comments

Comments
 (0)