forked from istio/istio
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests for DNS AUTO ALLOCATION
Signed-off-by: Yann Liu <yannliu@redhat.com>
- Loading branch information
Showing
3 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//go:build integ | ||
// +build integ | ||
|
||
// Copyright Istio Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package dnsautoallocation | ||
|
||
import ( | ||
"testing" | ||
|
||
"istio.io/istio/pkg/test/framework" | ||
"istio.io/istio/pkg/test/framework/components/echo/common/deployment" | ||
"istio.io/istio/pkg/test/framework/components/istio" | ||
"istio.io/istio/pkg/test/framework/label" | ||
"istio.io/istio/pkg/test/framework/resource" | ||
) | ||
|
||
var ( | ||
i istio.Instance | ||
|
||
// Below are various preconfigured echo deployments. Whenever possible, tests should utilize these | ||
// to avoid excessive creation/tear down of deployments. In general, a test should only deploy echo if | ||
// its doing something unique to that specific test. | ||
apps = deployment.SingleNamespaceView{} | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
// nolint: staticcheck | ||
framework. | ||
NewSuite(m). | ||
// Requires custom CP installations. Consider merging into pilot/revisions | ||
Label(label.CustomSetup). | ||
Setup(istio.Setup(&i, func(_ resource.Context, cfg *istio.Config) { | ||
cfg.ControlPlaneValues = ` | ||
meshConfig: | ||
defaultConfig: | ||
proxyMetadata: | ||
ISTIO_META_DNS_CAPTURE: "true" | ||
ISTIO_META_DNS_AUTO_ALLOCATE: "true" | ||
` | ||
})). | ||
Setup(deployment.SetupSingleNamespace(&apps, deployment.Config{})). | ||
Run() | ||
} |
130 changes: 130 additions & 0 deletions
130
tests/integration/pilot/dnsautoallocation/mesh_external_service_entry_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
//go:build integ | ||
// +build integ | ||
|
||
// Copyright Istio Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package dnsautoallocation | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"testing" | ||
"time" | ||
|
||
"istio.io/istio/pkg/config/protocol" | ||
"istio.io/istio/pkg/test/framework" | ||
"istio.io/istio/pkg/test/framework/components/echo" | ||
"istio.io/istio/pkg/test/framework/components/echo/common/ports" | ||
"istio.io/istio/pkg/test/util/retry" | ||
) | ||
|
||
type testRequestSpec struct { | ||
protocol protocol.Instance | ||
portName string | ||
portNumber int | ||
} | ||
|
||
var requestsSpec = []testRequestSpec{ | ||
{ | ||
portNumber: 80, | ||
portName: ports.HTTP, | ||
protocol: protocol.HTTP, | ||
}, | ||
{ | ||
portNumber: 443, | ||
portName: ports.HTTPS, | ||
protocol: protocol.HTTPS, | ||
}, | ||
} | ||
|
||
const serviceEntryFile = "testdata/service-entry-tmpl.yaml" | ||
const externalHost = "istio.io" | ||
|
||
func TestMeshExternalServiceEntry(t *testing.T) { | ||
// nolint: staticcheck | ||
framework. | ||
NewTest(t). | ||
Features("traffic.dnscautoallocation"). | ||
Run(func(ctx framework.TestContext) { | ||
meshNs := apps.A.NamespaceName() | ||
client := apps.A[0] | ||
server := apps.External.All[0] | ||
// externalHost := server.ClusterLocalFQDN() | ||
|
||
testRequest(ctx, "without-applying-any-service-entry", client, server) | ||
|
||
httpSe := ctx.ConfigIstio().EvalFile(meshNs, map[string]interface{}{ | ||
"externalHost": externalHost, | ||
"portNumber": 80, | ||
"portName": ports.HTTP, | ||
"portProtocol": protocol.HTTP, | ||
}, serviceEntryFile) | ||
|
||
httpSe.ApplyOrFail(ctx) | ||
|
||
// testRequest(ctx, "after-applying-only-http-service-entry", client, server) | ||
|
||
httpsSe := ctx.ConfigIstio().EvalFile(meshNs, map[string]interface{}{ | ||
"externalHost": externalHost, | ||
"portNumber": 443, | ||
"portName": ports.HTTPS, | ||
"portProtocol": protocol.HTTPS, | ||
}, serviceEntryFile) | ||
|
||
httpsSe.ApplyOrFail(ctx) | ||
|
||
testRequest(ctx, "after-applying-both-https-and-http-service-entry", client, server) | ||
}) | ||
} | ||
|
||
func testRequest(ctx framework.TestContext, status string, client, server echo.Instance) { | ||
for _, spec := range requestsSpec { | ||
testName := fmt.Sprintf("%s-request-%s", spec.portName, status) | ||
|
||
ctx.NewSubTest(testName).Run(func(ctx framework.TestContext) { | ||
retry.UntilSuccessOrFail(ctx, func() error { | ||
|
||
if err := testConnectivity(client, server, spec.protocol, spec.portName, spec.portNumber, testName); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, retry.Timeout(10*time.Second)) | ||
}) | ||
} | ||
} | ||
|
||
func testConnectivity(from, to echo.Instance, p protocol.Instance, portName string, portNumber int, testName string) error { | ||
res, err := from.Call(echo.CallOptions{ | ||
Address: externalHost, | ||
Port: echo.Port{ | ||
ServicePort: portNumber, | ||
Name: portName, | ||
Protocol: p, | ||
}, | ||
}) | ||
|
||
if err != nil { | ||
return fmt.Errorf("failed to request to external service: %s", err) | ||
} | ||
|
||
code, err := strconv.Atoi(res.Responses[0].Code) | ||
|
||
if err == nil && code >= 500 { | ||
return fmt.Errorf("expected to get server status code, got: %s", res.Responses[0].Code) | ||
} | ||
|
||
return nil | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/integration/pilot/dnsautoallocation/testdata/service-entry-tmpl.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: networking.istio.io/v1alpha3 | ||
kind: ServiceEntry | ||
metadata: | ||
name: {{ .portName }}-external-se | ||
spec: | ||
hosts: | ||
- {{ .externalHost }} | ||
location: MESH_EXTERNAL | ||
ports: | ||
- number: {{ .portNumber }} | ||
name: {{ .portName }} | ||
protocol: {{ .portProtocol }} | ||
resolution: DNS |