/
flags.go
264 lines (220 loc) · 13.8 KB
/
flags.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
// 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 resource
import (
"flag"
"fmt"
"os"
"strings"
"istio.io/istio/pkg/log"
"istio.io/istio/pkg/test/env"
"istio.io/istio/pkg/test/framework/config"
"istio.io/istio/pkg/test/framework/label"
)
var settingsFromCommandLine = DefaultSettings()
// SettingsFromCommandLine returns settings obtained from command-line flags. config.Parse must be called before
// calling this function.
func SettingsFromCommandLine(testID string) (*Settings, error) {
if !config.Parsed() {
panic("config.Parse must be called before this function")
}
s := settingsFromCommandLine.Clone()
s.TestID = testID
f, err := label.ParseSelector(s.SelectorString)
if err != nil {
return nil, err
}
s.Selector = f
s.SkipMatcher, err = NewMatcher(s.SkipString)
if err != nil {
return nil, err
}
// NOTE: not using echo.VM, etc. here to avoid circular dependency.
if s.SkipVM {
s.SkipWorkloadClasses = append(s.SkipWorkloadClasses, "vm")
}
if s.SkipTProxy {
s.SkipWorkloadClasses = append(s.SkipWorkloadClasses, "tproxy")
}
// Allow passing a single CSV flag as well
normalized := make(ArrayFlags, 0)
for _, sk := range s.SkipWorkloadClasses {
normalized = append(normalized, strings.Split(sk, ",")...)
}
s.SkipWorkloadClasses = normalized
if s.Image.Hub == "" {
s.Image.Hub = env.HUB.ValueOrDefault("gcr.io/istio-testing")
}
if s.Image.Tag == "" {
s.Image.Tag = env.TAG.ValueOrDefault("latest")
}
if s.Image.Variant == "" {
s.Image.Variant = env.VARIANT.ValueOrDefault("")
}
if s.Image.PullPolicy == "" {
s.Image.PullPolicy = env.PULL_POLICY.ValueOrDefault("Always")
}
if s.EchoImage == "" {
s.EchoImage = env.ECHO_IMAGE.ValueOrDefault("")
}
if s.CustomGRPCEchoImage == "" {
s.CustomGRPCEchoImage = env.GRPC_ECHO_IMAGE.ValueOrDefault("")
}
if s.HelmRepo == "" {
s.HelmRepo = "https://istio-release.storage.googleapis.com/charts"
}
if err = validate(s); err != nil {
return nil, err
}
return s, nil
}
// validate checks that user has not passed invalid flag combinations to test framework.
func validate(s *Settings) error {
if s.FailOnDeprecation && s.NoCleanup {
return fmt.Errorf("checking for deprecation occurs at cleanup level, thus flags -istio.test.nocleanup and" +
" -istio.test.deprecation_failure must not be used at the same time")
}
if s.Revision != "" {
if s.Revisions != nil {
return fmt.Errorf("cannot use --istio.test.revision and --istio.test.revisions at the same time," +
" --istio.test.revisions will take precedence and --istio.test.revision will be ignored")
}
// use Revision as the sole revision in RevVerMap
s.Revisions = RevVerMap{
s.Revision: "",
}
} else if s.Revisions != nil {
// TODO(Monkeyanator) remove once existing jobs are migrated to use compatibility flag.
s.Compatibility = true
}
if s.Revisions == nil && s.Compatibility {
return fmt.Errorf("cannot use --istio.test.compatibility without setting --istio.test.revisions")
}
if s.Image.Hub == "" || s.Image.Tag == "" {
return fmt.Errorf("values for Hub & Tag are not detected. Please supply them through command-line or via environment")
}
return nil
}
// init registers the command-line flags that we can exposed for "go test".
func init() {
log.EnableKlogWithGoFlag()
flag.StringVar(&settingsFromCommandLine.BaseDir, "istio.test.work_dir", os.TempDir(),
"Local working directory for creating logs/temp files. If left empty, os.TempDir() is used.")
var env string
flag.StringVar(&env, "istio.test.env", "", "Deprecated. This flag does nothing")
flag.BoolVar(&settingsFromCommandLine.NoCleanup, "istio.test.nocleanup", settingsFromCommandLine.NoCleanup,
"Do not cleanup resources after test completion")
flag.BoolVar(&settingsFromCommandLine.CIMode, "istio.test.ci", settingsFromCommandLine.CIMode,
"Enable CI Mode. Additional logging and state dumping will be enabled.")
flag.StringVar(&settingsFromCommandLine.SelectorString, "istio.test.select", settingsFromCommandLine.SelectorString,
"Comma separated list of labels for selecting tests to run (e.g. 'foo,+bar-baz').")
flag.Var(&settingsFromCommandLine.SkipString, "istio.test.skip",
"Skip tests matching the regular expression. This follows the semantics of -test.run.")
flag.Var(&settingsFromCommandLine.SkipWorkloadClasses, "istio.test.skipWorkloads",
"Skips deploying and using workloads of the given comma-separated classes (e.g. vm, proxyless, etc.)")
flag.Var(&settingsFromCommandLine.OnlyWorkloadClasses, "istio.test.onlyWorkloads",
"Skips deploying and using workloads not included in the given comma-separated classes (e.g. vm, proxyless, etc.)")
flag.IntVar(&settingsFromCommandLine.Retries, "istio.test.retries", settingsFromCommandLine.Retries,
"Number of times to retry tests")
flag.BoolVar(&settingsFromCommandLine.StableNamespaces, "istio.test.stableNamespaces", settingsFromCommandLine.StableNamespaces,
"If set, will use consistent namespace rather than randomly generated. Useful with nocleanup to develop tests.")
flag.BoolVar(&settingsFromCommandLine.FailOnDeprecation, "istio.test.deprecation_failure", settingsFromCommandLine.FailOnDeprecation,
"Make tests fail if any usage of deprecated stuff (e.g. Envoy flags) is detected.")
flag.StringVar(&settingsFromCommandLine.Revision, "istio.test.revision", settingsFromCommandLine.Revision,
"If set to XXX, overwrite the default namespace label (istio-injection=enabled) with istio.io/rev=XXX.")
flag.BoolVar(&settingsFromCommandLine.SkipVM, "istio.test.skipVM", settingsFromCommandLine.SkipVM,
"Skip VM related parts in all tests.")
flag.BoolVar(&settingsFromCommandLine.SkipTProxy, "istio.test.skipTProxy", settingsFromCommandLine.SkipTProxy,
"Skip TProxy related parts in all tests.")
flag.BoolVar(&settingsFromCommandLine.Ambient, "istio.test.ambient", settingsFromCommandLine.Ambient,
"Indicate the use of ambient mesh.")
flag.BoolVar(&settingsFromCommandLine.PeerMetadataDiscovery, "istio.test.peer_metadata_discovery", settingsFromCommandLine.PeerMetadataDiscovery,
"Force the use of peer metadata discovery fallback for metadata exchange")
flag.BoolVar(&settingsFromCommandLine.AmbientEverywhere, "istio.test.ambient.everywhere", settingsFromCommandLine.AmbientEverywhere,
"Make Waypoint proxies the default instead of sidecar proxies for all echo apps. Must be used with istio.test.ambient")
flag.BoolVar(&settingsFromCommandLine.Compatibility, "istio.test.compatibility", settingsFromCommandLine.Compatibility,
"Transparently deploy echo instances pointing to each revision set in `Revisions`")
flag.Var(&settingsFromCommandLine.Revisions, "istio.test.revisions", "Istio CP revisions available to the test framework and their corresponding versions.")
flag.StringVar(&settingsFromCommandLine.Image.Hub, "istio.test.hub", settingsFromCommandLine.Image.Hub,
"Container registry hub to use")
flag.StringVar(&settingsFromCommandLine.Image.Tag, "istio.test.tag", settingsFromCommandLine.Image.Tag,
"Common Container tag to use when deploying container images")
flag.StringVar(&settingsFromCommandLine.Image.Variant, "istio.test.variant", settingsFromCommandLine.Image.Variant,
"Common Container variant to use when deploying container images")
flag.StringVar(&settingsFromCommandLine.Image.PullPolicy, "istio.test.pullpolicy", settingsFromCommandLine.Image.PullPolicy,
"Common image pull policy to use when deploying container images")
flag.StringVar(&settingsFromCommandLine.Image.PullSecret, "istio.test.imagePullSecret", settingsFromCommandLine.Image.PullSecret,
"Path to a file containing a DockerConfig secret use for test apps. This will be pushed to all created namespaces."+
"Secret should already exist when used with istio.test.stableNamespaces.")
flag.Uint64Var(&settingsFromCommandLine.MaxDumps, "istio.test.maxDumps", settingsFromCommandLine.MaxDumps,
"Maximum number of full test dumps that are allowed to occur within a test suite.")
flag.BoolVar(&settingsFromCommandLine.EnableDualStack, "istio.test.enableDualStack", settingsFromCommandLine.EnableDualStack,
"Deploy Istio with Dual Stack enabled.")
flag.StringVar(&settingsFromCommandLine.HelmRepo, "istio.test.helmRepo", settingsFromCommandLine.HelmRepo, "Helm repo to use to pull the charts.")
flag.BoolVar(&settingsFromCommandLine.GatewayConformanceStandardOnly, "istio.test.gatewayConformanceStandardOnly",
settingsFromCommandLine.GatewayConformanceStandardOnly,
"If set, only the standard gateway conformance tests will be run; tests relying on experimental resources will be skipped.")
initGatewayConformanceTimeouts()
}
func initGatewayConformanceTimeouts() {
flag.DurationVar(&settingsFromCommandLine.GatewayConformanceTimeoutConfig.CreateTimeout, "istio.test.gatewayConformance.createTimeout",
0, "Gateway conformance test timeout for waiting for creating a k8s resource.")
flag.DurationVar(&settingsFromCommandLine.GatewayConformanceTimeoutConfig.DeleteTimeout, "istio.test.gatewayConformance.deleteTimeout",
0, "Gateway conformance test timeout for getting a k8s resource.")
flag.DurationVar(&settingsFromCommandLine.GatewayConformanceTimeoutConfig.GetTimeout, "istio.test.gatewayConformance.geTimeout",
0, "Gateway conformance test timeout for getting a k8s resource.")
flag.DurationVar(&settingsFromCommandLine.GatewayConformanceTimeoutConfig.GatewayMustHaveAddress,
"istio.test.gatewayConformance.gatewayMustHaveAddressTimeout", 0,
"Gateway conformance test timeout for waiting for a Gateway to have an address.")
flag.DurationVar(&settingsFromCommandLine.GatewayConformanceTimeoutConfig.GatewayMustHaveCondition,
"istio.test.gatewayConformance.gatewayMustHaveConditionTimeout", 0,
"Gateway conformance test timeout for waiting for a Gateway to have a certain condition.")
flag.DurationVar(&settingsFromCommandLine.GatewayConformanceTimeoutConfig.GatewayStatusMustHaveListeners,
"istio.test.gatewayConformance.gatewayStatusMustHaveListenersTimeout", 0,
"Gateway conformance test timeout for waiting for a Gateway's status to have listeners.")
flag.DurationVar(&settingsFromCommandLine.GatewayConformanceTimeoutConfig.GatewayListenersMustHaveConditions,
"istio.test.gatewayConformance.gatewayListenersMustHaveConditionTimeout", 0,
"Gateway conformance test timeout for waiting for a Gateway's listeners to have certain conditions.")
flag.DurationVar(&settingsFromCommandLine.GatewayConformanceTimeoutConfig.GWCMustBeAccepted,
"istio.test.gatewayConformance.gatewayClassMustBeAcceptedTimeout",
0, "Gateway conformance test timeout for waiting for a GatewayClass to be accepted.")
flag.DurationVar(&settingsFromCommandLine.GatewayConformanceTimeoutConfig.HTTPRouteMustNotHaveParents,
"istio.test.gatewayConformance.httpRouteMustNotHaveParentsTimeout", 0,
"Gateway conformance test timeout for waiting for an HTTPRoute to either have no parents or a single parent that is not accepted.")
flag.DurationVar(&settingsFromCommandLine.GatewayConformanceTimeoutConfig.HTTPRouteMustHaveCondition,
"istio.test.gatewayConformance.httpRouteMustHaveConditionTimeout",
0, "Gateway conformance test timeout for waiting for an HTTPRoute to have a certain condition.")
flag.DurationVar(&settingsFromCommandLine.GatewayConformanceTimeoutConfig.TLSRouteMustHaveCondition,
"istio.test.gatewayConformance.tlsRouteMustHaveConditionTimeout", 0,
"Gateway conformance test timeout for waiting for an TLSRoute to have a certain condition.")
flag.DurationVar(&settingsFromCommandLine.GatewayConformanceTimeoutConfig.RouteMustHaveParents, "istio.test.gatewayConformance.routeMustHaveParentsTimeout",
0, "Gateway conformance test timeout for the the maximum time for an xRoute to have parents in status that match the expected parents.")
flag.DurationVar(&settingsFromCommandLine.GatewayConformanceTimeoutConfig.ManifestFetchTimeout, "istio.test.gatewayConformance.manifestFetchTimeout",
0, "Gateway conformance test timeout for the maximum time for getting content from a https:// URL.")
flag.DurationVar(&settingsFromCommandLine.GatewayConformanceTimeoutConfig.MaxTimeToConsistency, "istio.test.gatewayConformance.maxTimeToConsistency",
0, "Gateway conformance test setting for the maximum time for requiredConsecutiveSuccesses (default 3) requests to succeed in a row before failing the test.")
flag.DurationVar(&settingsFromCommandLine.GatewayConformanceTimeoutConfig.NamespacesMustBeReady,
"istio.test.gatewayConformance.namespacesMustBeReadyTimeout", 0,
"Gateway conformance test timeout for waiting for namespaces to be ready.")
flag.DurationVar(&settingsFromCommandLine.GatewayConformanceTimeoutConfig.RequestTimeout, "istio.test.gatewayConformance.requestTimeout",
0, "Gateway conformance test timeout for an HTTP request.")
flag.DurationVar(&settingsFromCommandLine.GatewayConformanceTimeoutConfig.LatestObservedGenerationSet,
"istio.test.gatewayConformance.latestObservedGenerationSetTimeout", 0,
"Gateway conformance test timeout for waiting for a latest observed generation to be set.")
flag.DurationVar(&settingsFromCommandLine.GatewayConformanceTimeoutConfig.DefaultTestTimeout, "istio.test.gatewayConformance.defaultTestTimeout",
0, "Default gateway conformance test case timeout.")
flag.IntVar(&settingsFromCommandLine.GatewayConformanceTimeoutConfig.RequiredConsecutiveSuccesses,
"istio.test.gatewayConformance.requiredConsecutiveSuccesses", 0,
"Gateway conformance test setting for the required number of consecutive successes before failing the test.")
}