Skip to content

Commit

Permalink
remove redundant bookinfo ambient tests and add waypoint template cha…
Browse files Browse the repository at this point in the history
…nge test o baseline tests (#50472)

* remove redundant bookinfo ambient tests and add waypoint template change test o baseline tests

Signed-off-by: Keerthan Ekbote <keerthan.ekbote@solo.io>

* Extend coverage a bit

* lint

---------

Signed-off-by: Keerthan Ekbote <keerthan.ekbote@solo.io>
Co-authored-by: Keerthan Ekbote <keerthan.ekbote@solo.io>
  • Loading branch information
howardjohn and saiskee committed Apr 18, 2024
1 parent 12b77bc commit 5789705
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 384 deletions.
181 changes: 181 additions & 0 deletions tests/integration/ambient/baseline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"istio.io/api/networking/v1alpha3"
"istio.io/istio/pkg/config/constants"
"istio.io/istio/pkg/http/headers"
"istio.io/istio/pkg/kube/inject"
"istio.io/istio/pkg/ptr"
echot "istio.io/istio/pkg/test/echo"
"istio.io/istio/pkg/test/echo/common/scheme"
"istio.io/istio/pkg/test/env"
"istio.io/istio/pkg/test/framework"
"istio.io/istio/pkg/test/framework/components/ambient"
"istio.io/istio/pkg/test/framework/components/echo"
Expand All @@ -47,16 +50,25 @@ import (
"istio.io/istio/pkg/test/framework/components/echo/match"
"istio.io/istio/pkg/test/framework/components/istio"
"istio.io/istio/pkg/test/framework/components/istio/ingress"
"istio.io/istio/pkg/test/framework/components/istioctl"
"istio.io/istio/pkg/test/framework/components/namespace"
"istio.io/istio/pkg/test/framework/components/prometheus"
"istio.io/istio/pkg/test/framework/resource/config/apply"
"istio.io/istio/pkg/test/framework/resource/config/cleanup"
kubetest "istio.io/istio/pkg/test/kube"
"istio.io/istio/pkg/test/util/assert"
"istio.io/istio/pkg/test/util/file"
"istio.io/istio/pkg/test/util/retry"
"istio.io/istio/pkg/util/sets"
"istio.io/istio/tests/common/jwt"
"istio.io/istio/tests/integration/security/util/reachability"
util "istio.io/istio/tests/integration/telemetry"
)

const (
templateFile = "manifests/charts/istio-control/istio-discovery/files/waypoint.yaml"
)

func IsL7() echo.Checker {
return check.Each(func(r echot.Response) error {
// TODO: response headers?
Expand Down Expand Up @@ -297,6 +309,175 @@ func TestServerSideLB(t *testing.T) {
})
}

func TestWaypointChanges(t *testing.T) {
framework.NewTest(t).Run(func(t framework.TestContext) {
getGracePeriod := func(want int64) bool {
pods, err := kubetest.NewPodFetch(t.AllClusters()[0], apps.Namespace.Name(), constants.GatewayNameLabel+"=waypoint")()
assert.NoError(t, err)
for _, p := range pods {
grace := p.Spec.TerminationGracePeriodSeconds
if grace != nil && *grace == want {
return true
}
}
return false
}
// check that waypoint deployment is unmodified
retry.UntilOrFail(t, func() bool {
return getGracePeriod(2)
})
// change the waypoint template
istio.GetOrFail(t, t).UpdateInjectionConfig(t, func(cfg *inject.Config) error {
mainTemplate := file.MustAsString(filepath.Join(env.IstioSrc, templateFile))
cfg.RawTemplates["waypoint"] = strings.ReplaceAll(mainTemplate, "terminationGracePeriodSeconds: 2", "terminationGracePeriodSeconds: 3")
return nil
}, cleanup.Always)

retry.UntilOrFail(t, func() bool {
return getGracePeriod(3)
})
})
}

func TestOtherRevisionIgnored(t *testing.T) {
framework.NewTest(t).Run(func(t framework.TestContext) {
// This is a negative test, ensuring gateways with tags other
// than my tags do not get controlled by me.
nsConfig, err := namespace.New(t, namespace.Config{
Prefix: "badgateway",
Inject: false,
Labels: map[string]string{
constants.DataplaneMode: "ambient",
},
})
if err != nil {
t.Fatal(err)
}
istioctl.NewOrFail(t, t, istioctl.Config{}).InvokeOrFail(t, []string{
"x",
"waypoint",
"apply",
"--namespace",
nsConfig.Name(),
"--revision",
"foo",
})
waypointError := retry.UntilSuccess(func() error {
fetch := kubetest.NewPodFetch(t.AllClusters()[0], nsConfig.Name(), constants.GatewayNameLabel+"="+"sa")
if _, err := kubetest.CheckPodsAreReady(fetch); err != nil {
return fmt.Errorf("gateway is not ready: %v", err)
}
return nil
}, retry.Timeout(15*time.Second), retry.BackoffDelay(time.Millisecond*100))
if waypointError == nil {
t.Fatal("Waypoint for non-existent tag foo created deployment!")
}
})
}

func TestRemoveAddWaypoint(t *testing.T) {
framework.NewTest(t).Run(func(t framework.TestContext) {
istioctl.NewOrFail(t, t, istioctl.Config{}).InvokeOrFail(t, []string{
"x",
"waypoint",
"apply",
"--namespace",
apps.Namespace.Name(),
"--name", "captured-waypoint",
"--wait",
})
t.Cleanup(func() {
istioctl.NewOrFail(t, t, istioctl.Config{}).InvokeOrFail(t, []string{
"x",
"waypoint",
"delete",
"--namespace",
apps.Namespace.Name(),
"captured-waypoint",
})
})

t.NewSubTest("before").Run(func(t framework.TestContext) {
dst := apps.Captured
for _, src := range apps.All {
if src.Config().IsUncaptured() {
continue
}
t.NewSubTestf("from %v", src.Config().Service).Run(func(t framework.TestContext) {
c := IsL4()
if src.Config().HasSidecar() {
c = IsL7()
}
opt := echo.CallOptions{
To: dst,
Port: echo.Port{Name: "http"},
Scheme: scheme.HTTP,
Count: 10,
Check: check.And(check.OK(), c),
}
src.CallOrFail(t, opt)
})
}
})

SetWaypoint(t, Captured, "captured-waypoint")

// Now should always be L7
t.NewSubTest("after").Run(func(t framework.TestContext) {
dst := apps.Captured
for _, src := range apps.All {
if src.Config().IsUncaptured() {
continue
}
t.NewSubTestf("from %v", src.Config().Service).Run(func(t framework.TestContext) {
opt := echo.CallOptions{
To: dst,
Port: echo.Port{Name: "http"},
Scheme: scheme.HTTP,
Count: 10,
Check: check.And(check.OK(), IsL7()),
}
src.CallOrFail(t, opt)
})
}
})
})
}

func TestBogusUseWaypoint(t *testing.T) {
framework.NewTest(t).Run(func(t framework.TestContext) {
check := func(t framework.TestContext) {
dst := apps.Captured
for _, src := range apps.All {
if src.Config().IsUncaptured() {
continue
}
t.NewSubTestf("from %v", src.Config().Service).Run(func(t framework.TestContext) {
c := IsL4()
if src.Config().HasSidecar() {
c = IsL7()
}
opt := echo.CallOptions{
To: dst,
Port: echo.Port{Name: "http"},
Scheme: scheme.HTTP,
Count: 10,
Check: check.And(check.OK(), c),
}
src.CallOrFail(t, opt)
})
}
}
t.NewSubTest("before").Run(check)

SetWaypoint(t, Captured, "bogus-waypoint")
t.NewSubTest("with waypoint").Run(check)

SetWaypoint(t, Captured, "")
t.NewSubTest("waypoint removed").Run(check)
})
}

func TestServerRouting(t *testing.T) {
runTest(t, func(t framework.TestContext, src echo.Instance, dst echo.Instance, opt echo.CallOptions) {
// Need waypoint proxy and HTTP
Expand Down

0 comments on commit 5789705

Please sign in to comment.