Skip to content

Commit 6484bf0

Browse files
author
lec-bit
committed
update
Signed-off-by: lec-bit <glfhzmy@126.com>
1 parent b0a5cad commit 6484bf0

File tree

9 files changed

+328
-1
lines changed

9 files changed

+328
-1
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
//go:build integ || all
2+
// +build integ all
3+
4+
/*
5+
* Copyright The Kmesh Authors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at:
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
// NOTE: THE CODE IN THIS FILE IS MAINLY REFERENCED FROM ISTIO INTEGRATION
21+
// FRAMEWORK(https://github.com/istio/istio/tree/master/tests/integration)
22+
// AND ADAPTED FOR KMESH.
23+
24+
package kmesh
25+
26+
import (
27+
"fmt"
28+
"net/http"
29+
30+
echot "istio.io/istio/pkg/test/echo"
31+
"istio.io/istio/pkg/test/echo/common/scheme"
32+
"istio.io/istio/pkg/test/framework"
33+
"istio.io/istio/pkg/test/framework/components/echo"
34+
"istio.io/istio/pkg/test/framework/components/echo/check"
35+
"istio.io/istio/pkg/util/sets"
36+
)
37+
38+
func IsL7() echo.Checker {
39+
return nil
40+
}
41+
42+
func IsL4() echo.Checker {
43+
return check.Each(func(r echot.Response) error {
44+
// TODO: response headers?
45+
_, f := r.RequestHeaders[http.CanonicalHeaderKey("X-Request-Id")]
46+
if f {
47+
return fmt.Errorf("X-Request-Id set, is L7 processing enabled unexpectedly?")
48+
}
49+
return nil
50+
})
51+
}
52+
53+
var (
54+
httpValidator = check.And(check.OK(), IsL7())
55+
tcpValidator = check.And(check.OK(), IsL4())
56+
callOptions = []echo.CallOptions{
57+
{
58+
Port: echo.Port{Name: "http"},
59+
Scheme: scheme.HTTP,
60+
Count: 10,
61+
},
62+
{
63+
Port: echo.Port{Name: "tcp"},
64+
Scheme: scheme.TCP,
65+
Count: 1,
66+
},
67+
}
68+
)
69+
70+
func supportsL7(opt echo.CallOptions, src, dst echo.Instance) bool {
71+
isL7Scheme := opt.Scheme == scheme.HTTP || opt.Scheme == scheme.GRPC || opt.Scheme == scheme.WebSocket
72+
return dst.Config().HasAnyWaypointProxy() && isL7Scheme
73+
}
74+
75+
func OriginalSourceCheck(t framework.TestContext, src echo.Instance) echo.Checker {
76+
// Check that each response saw one of the workload IPs for the src echo instance
77+
addresses := sets.New(src.WorkloadsOrFail(t).Addresses()...)
78+
return check.Each(func(response echot.Response) error {
79+
if !addresses.Contains(response.IP) {
80+
return fmt.Errorf("expected original source (%v) to be propagated, but got %v", addresses.UnsortedList(), response.IP)
81+
}
82+
return nil
83+
})
84+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
//go:build integ || all
2+
// +build integ all
3+
4+
/*
5+
* Copyright The Kmesh Authors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at:
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
package kmesh
21+
22+
import (
23+
"testing"
24+
"time"
25+
26+
"istio.io/api/label"
27+
"istio.io/istio/pkg/test/framework"
28+
"istio.io/istio/pkg/test/framework/components/echo"
29+
"istio.io/istio/pkg/test/framework/components/echo/common/ports"
30+
"istio.io/istio/pkg/test/framework/components/echo/deployment"
31+
"istio.io/istio/pkg/test/framework/components/echo/match"
32+
"istio.io/istio/pkg/test/framework/components/namespace"
33+
"istio.io/istio/pkg/test/framework/resource"
34+
)
35+
36+
var (
37+
apps = &EchoDeployments{}
38+
)
39+
40+
type EchoDeployments struct {
41+
Namespace namespace.Instance
42+
All echo.Instances
43+
44+
// The echo service which is enrolled to Kmesh without waypoint.
45+
EnrolledToKmesh echo.Instances
46+
}
47+
48+
const (
49+
ServiceName = "echo-service"
50+
ServiceName2 = "echo-service2"
51+
EnrolledToKmesh = "enrolled-to-kmesh"
52+
Timeout = 2 * time.Minute
53+
KmeshReleaseName = "kmesh"
54+
KmeshDaemonsetName = "kmesh"
55+
KmeshNamespace = "kmesh-system"
56+
DataplaneModeKmesh = "Kmesh"
57+
)
58+
59+
func TestMain(m *testing.M) {
60+
framework.
61+
NewSuite(m).
62+
Setup(func(t resource.Context) error {
63+
t.Settings().Ambient = true
64+
return nil
65+
}).
66+
Setup(func(t resource.Context) error {
67+
return SetupApps(t, apps)
68+
}).
69+
Run()
70+
}
71+
72+
func SetupApps(t resource.Context, apps *EchoDeployments) error {
73+
var err error
74+
apps.Namespace, err = namespace.New(t, namespace.Config{
75+
Prefix: "echo",
76+
Inject: false,
77+
Labels: map[string]string{
78+
label.IoIstioDataplaneMode.Name: DataplaneModeKmesh,
79+
},
80+
})
81+
if err != nil {
82+
return err
83+
}
84+
85+
builder := deployment.New(t).
86+
WithClusters(t.Clusters()...).
87+
WithConfig(echo.Config{
88+
Service: ServiceName,
89+
Namespace: apps.Namespace,
90+
Ports: ports.All(),
91+
ServiceAccount: true,
92+
Subsets: []echo.SubsetConfig{
93+
{
94+
Replicas: 1,
95+
Version: "v1",
96+
Labels: map[string]string{
97+
"app": ServiceName,
98+
"version": "v1",
99+
},
100+
},
101+
{
102+
Replicas: 1,
103+
Version: "v2",
104+
Labels: map[string]string{
105+
"app": ServiceName,
106+
"version": "v2",
107+
},
108+
},
109+
},
110+
}).
111+
WithConfig(echo.Config{
112+
Service: EnrolledToKmesh,
113+
Namespace: apps.Namespace,
114+
Ports: ports.All(),
115+
ServiceAccount: true,
116+
Subsets: []echo.SubsetConfig{
117+
{
118+
Replicas: 1,
119+
Version: "v1",
120+
},
121+
},
122+
})
123+
124+
echos, err := builder.Build()
125+
if err != nil {
126+
return err
127+
}
128+
129+
apps.All = echos
130+
131+
apps.EnrolledToKmesh = match.ServiceName(echo.NamespacedName{Name: EnrolledToKmesh, Namespace: apps.Namespace}).GetMatches(echos)
132+
return nil
133+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//go:build integ || all
2+
// +build integ all
3+
4+
/*
5+
* Copyright The Kmesh Authors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at:
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
// NOTE: THE CODE IN THIS FILE IS MAINLY REFERENCED FROM ISTIO INTEGRATION
21+
// FRAMEWORK(https://github.com/istio/istio/tree/master/tests/integration)
22+
// AND ADAPTED FOR KMESH.
23+
24+
package kmesh
25+
26+
import (
27+
"context"
28+
"fmt"
29+
"testing"
30+
"time"
31+
32+
"istio.io/istio/pkg/test/framework"
33+
"istio.io/istio/pkg/test/framework/components/echo"
34+
"istio.io/istio/pkg/test/framework/components/echo/util/traffic"
35+
kubetest "istio.io/istio/pkg/test/kube"
36+
"istio.io/istio/pkg/test/util/retry"
37+
appsv1 "k8s.io/api/apps/v1"
38+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
39+
"k8s.io/apimachinery/pkg/types"
40+
)
41+
42+
func TestKmeshRestart(t *testing.T) {
43+
framework.NewTest(t).Run(func(t framework.TestContext) {
44+
src := apps.EnrolledToKmesh[0]
45+
dst := apps.All
46+
options := echo.CallOptions{
47+
To: dst,
48+
Count: 1,
49+
// Determine whether it is managed by Kmesh by passing through Waypoint.
50+
Check: httpValidator,
51+
Port: echo.Port{
52+
Name: "http",
53+
},
54+
Retry: echo.Retry{NoRetry: true},
55+
}
56+
57+
g := traffic.NewGenerator(t, traffic.Config{
58+
Source: src,
59+
Options: options,
60+
Interval: 50 * time.Millisecond,
61+
}).Start()
62+
63+
time.Sleep(5 * time.Second)
64+
restartKmesh(t)
65+
g.Stop().CheckSuccessRate(t, 0.1)
66+
})
67+
}
68+
69+
func restartKmesh(t framework.TestContext) {
70+
patchOpts := metav1.PatchOptions{}
71+
patchData := fmt.Sprintf(`{
72+
"spec": {
73+
"template": {
74+
"metadata": {
75+
"annotations": {
76+
"kubectl.kubernetes.io/restartedAt": %q
77+
}
78+
}
79+
}
80+
}
81+
}`, time.Now().Format(time.RFC3339))
82+
ds := t.Clusters().Default().Kube().AppsV1().DaemonSets(KmeshNamespace)
83+
_, err := ds.Patch(context.Background(), KmeshDaemonsetName, types.StrategicMergePatchType, []byte(patchData), patchOpts)
84+
if err != nil {
85+
t.Fatal(err)
86+
}
87+
88+
if err := retry.UntilSuccess(func() error {
89+
d, err := ds.Get(context.Background(), KmeshDaemonsetName, metav1.GetOptions{})
90+
if err != nil {
91+
return err
92+
}
93+
if !daemonsetsetComplete(d) {
94+
return fmt.Errorf("rollout is not yet done")
95+
}
96+
return nil
97+
}, retry.Timeout(60*time.Second), retry.Delay(2*time.Second)); err != nil {
98+
t.Fatal("failed to wait for Kmesh rollout status for: %v", err)
99+
}
100+
if _, err := kubetest.CheckPodsAreReady(kubetest.NewPodFetch(t.AllClusters()[0], KmeshNamespace, "app=kmesh")); err != nil {
101+
t.Fatal(err)
102+
}
103+
}
104+
105+
func daemonsetsetComplete(ds *appsv1.DaemonSet) bool {
106+
return ds.Status.UpdatedNumberScheduled == ds.Status.DesiredNumberScheduled && ds.Status.NumberReady == ds.Status.DesiredNumberScheduled && ds.Status.ObservedGeneration >= ds.Generation
107+
}

test/e2e/run_test.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ while (( "$#" )); do
244244
IPV6=true
245245
shift
246246
;;
247+
--kernel-native)
248+
shift
249+
;;
247250
--cleanup)
248251
CLEANUP_KIND=true
249252
CLEANUP_REGISTRY=true
@@ -285,7 +288,7 @@ if [[ -z "${SKIP_SETUP:-}" ]]; then
285288
setup_kmesh
286289
fi
287290

288-
cmd="go test -v -tags=integ $ROOT_DIR/test/e2e/... -istio.test.kube.loadbalancer=false ${PARAMS[*]}"
291+
cmd="go test -v -tags=integ $ROOT_DIR/test/e2e/kernel-native/... -istio.test.kube.loadbalancer=false ${PARAMS[*]}"
289292

290293
bash -c "$cmd"
291294

0 commit comments

Comments
 (0)