istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/test/framework/components/echo/common/deployment/external.go (about)

     1  // Copyright Istio Authors
     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 deployment
    16  
    17  import (
    18  	"path"
    19  
    20  	"istio.io/api/annotation"
    21  	"istio.io/istio/pkg/test/echo/common"
    22  	"istio.io/istio/pkg/test/env"
    23  	"istio.io/istio/pkg/test/framework/components/echo"
    24  	"istio.io/istio/pkg/test/framework/components/echo/common/ports"
    25  	"istio.io/istio/pkg/test/framework/components/echo/deployment"
    26  	"istio.io/istio/pkg/test/framework/components/echo/match"
    27  	"istio.io/istio/pkg/test/framework/components/namespace"
    28  	"istio.io/istio/pkg/test/framework/resource"
    29  	"istio.io/istio/pkg/test/util/file"
    30  )
    31  
    32  const (
    33  	ExternalSvc      = "external"
    34  	ExternalHostname = "fake.external.com"
    35  )
    36  
    37  type External struct {
    38  	// Namespace where external echo app will be deployed
    39  	Namespace namespace.Instance
    40  
    41  	// All external echo instances with no sidecar injected
    42  	All echo.Instances
    43  }
    44  
    45  func (e External) Build(t resource.Context, b deployment.Builder) deployment.Builder {
    46  	config := echo.Config{
    47  		Service:           ExternalSvc,
    48  		Namespace:         e.Namespace,
    49  		DefaultHostHeader: ExternalHostname,
    50  		Ports:             ports.All(),
    51  		// Set up TLS certs on the server. This will make the server listen with these credentials.
    52  		TLSSettings: &common.TLSSettings{
    53  			// Echo has these test certs baked into the docker image
    54  			RootCert:   file.MustAsString(path.Join(env.IstioSrc, "tests/testdata/certs/dns/root-cert.pem")),
    55  			ClientCert: file.MustAsString(path.Join(env.IstioSrc, "tests/testdata/certs/dns/cert-chain.pem")),
    56  			Key:        file.MustAsString(path.Join(env.IstioSrc, "tests/testdata/certs/dns/key.pem")),
    57  			// Override hostname to match the SAN in the cert we are using
    58  			// TODO(nmittler): We should probably make this the same as ExternalHostname
    59  			Hostname: "server.default.svc",
    60  		},
    61  		Subsets: []echo.SubsetConfig{
    62  			{
    63  				Version:     "v1",
    64  				Annotations: map[string]string{annotation.SidecarInject.Name: "false"},
    65  			},
    66  		},
    67  	}
    68  	if t.Settings().EnableDualStack {
    69  		config.IPFamilies = "IPv6, IPv4"
    70  		config.IPFamilyPolicy = "RequireDualStack"
    71  	}
    72  	return b.WithConfig(config)
    73  }
    74  
    75  func (e *External) LoadValues(echos echo.Instances) {
    76  	e.All = match.ServiceName(echo.NamespacedName{Name: ExternalSvc, Namespace: e.Namespace}).GetMatches(echos)
    77  }