istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/test/framework/components/echo/staticvm/workload.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 staticvm
    16  
    17  import (
    18  	"fmt"
    19  	"net"
    20  	"strings"
    21  
    22  	"github.com/hashicorp/go-multierror"
    23  
    24  	"istio.io/istio/pkg/test"
    25  	echoClient "istio.io/istio/pkg/test/echo"
    26  	"istio.io/istio/pkg/test/echo/common"
    27  	"istio.io/istio/pkg/test/framework/components/cluster"
    28  	"istio.io/istio/pkg/test/framework/components/echo"
    29  )
    30  
    31  var _ echo.Workload = &workload{}
    32  
    33  type workload struct {
    34  	*echoClient.Client
    35  	cluster   cluster.Cluster
    36  	address   string
    37  	addresses []string
    38  }
    39  
    40  func newWorkloads(address []string, grpcPort int, tls *common.TLSSettings, c cluster.Cluster) (echo.Workloads, error) {
    41  	var errs error
    42  	var out echo.Workloads
    43  	for _, ip := range address {
    44  		w, err := newWorkload(ip, grpcPort, tls, c)
    45  		if err != nil {
    46  			errs = multierror.Append(errs, err)
    47  		}
    48  		out = append(out, w)
    49  	}
    50  	if errs != nil {
    51  		return nil, errs
    52  	}
    53  	return out, nil
    54  }
    55  
    56  func newWorkload(addresses string, grpcPort int, tls *common.TLSSettings, cl cluster.Cluster) (*workload, error) {
    57  	var (
    58  		external string
    59  		internal string
    60  	)
    61  	parts := strings.Split(addresses, ":")
    62  	external = parts[0]
    63  	if len(parts) > 1 {
    64  		internal = parts[1]
    65  	}
    66  
    67  	c, err := echoClient.New(net.JoinHostPort(external, fmt.Sprint(grpcPort)), tls)
    68  	if err != nil {
    69  		return nil, err
    70  	}
    71  	return &workload{
    72  		Client:  c,
    73  		cluster: cl,
    74  		address: internal,
    75  	}, nil
    76  }
    77  
    78  func (w *workload) PodName() string {
    79  	return ""
    80  }
    81  
    82  func (w *workload) Address() string {
    83  	return w.address
    84  }
    85  
    86  func (w *workload) Addresses() []string {
    87  	return w.addresses
    88  }
    89  
    90  func (w *workload) Cluster() cluster.Cluster {
    91  	return w.cluster
    92  }
    93  
    94  func (w *workload) Sidecar() echo.Sidecar {
    95  	panic("implement me")
    96  }
    97  
    98  func (w *workload) Logs() (string, error) {
    99  	panic("implement me")
   100  }
   101  
   102  func (w *workload) LogsOrFail(_ test.Failer) string {
   103  	panic("implement me")
   104  }