-
Notifications
You must be signed in to change notification settings - Fork 0
/
workload.go
99 lines (81 loc) · 2.69 KB
/
workload.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// 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 echo
import (
"context"
"sort"
"strings"
"istio.io/istio/pkg/test"
"istio.io/istio/pkg/test/echo"
"istio.io/istio/pkg/test/echo/proto"
"istio.io/istio/pkg/test/framework/components/cluster"
)
// WorkloadContainer is container for a number of Workload objects.
type WorkloadContainer interface {
// Workloads retrieves the list of all deployed workloads for this Echo service.
// Guarantees at least one workload, if error == nil.
Workloads() (Workloads, error)
WorkloadsOrFail(t test.Failer) Workloads
MustWorkloads() Workloads
// Clusters where the workloads are deployed.
Clusters() cluster.Clusters
}
// Workload provides an interface for a single deployed echo server.
type Workload interface {
// PodName gets the original pod name for the workload.
PodName() string
// Address returns the network address of the endpoint.
Address() string
// Addresses returns the network addresses of the endpoint.
Addresses() []string
// Sidecar if one was specified.
Sidecar() Sidecar
// Cluster where this Workload resides.
Cluster() cluster.Cluster
// ForwardEcho executes specific call from this workload.
// TODO(nmittler): Instead of this, we should just make Workload implement Caller.
ForwardEcho(context.Context, *proto.ForwardEchoRequest) (echo.Responses, error)
// Logs returns the logs for the app container
Logs() (string, error)
LogsOrFail(t test.Failer) string
}
type Workloads []Workload
func (ws Workloads) Len() int {
return len(ws)
}
// Addresses returns the list of addresses for all workloads.
func (ws Workloads) Addresses() []string {
out := make([]string, 0, len(ws))
for _, w := range ws {
out = append(out, w.Addresses()...)
}
return out
}
func (ws Workloads) Clusters() cluster.Clusters {
clusters := make(map[string]cluster.Cluster)
for _, w := range ws {
if c := w.Cluster(); c != nil {
clusters[c.Name()] = c
}
}
out := make(cluster.Clusters, 0, len(clusters))
for _, c := range clusters {
out = append(out, c)
}
// Sort the clusters by name.
sort.SliceStable(out, func(i, j int) bool {
return strings.Compare(out[i].Name(), out[j].Name()) < 0
})
return out
}