-
Notifications
You must be signed in to change notification settings - Fork 2
/
errors.go
394 lines (308 loc) · 18.9 KB
/
errors.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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
package radixvalidators
import (
"errors"
"fmt"
"strings"
radixv1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
)
// MissingPrivateImageHubUsernameError Error when username for private image hubs is not defined
func MissingPrivateImageHubUsernameError(server string) error {
return fmt.Errorf("username is required for private image hub %s", server)
}
// MissingPrivateImageHubEmailError Error when email for private image hubs is not defined
func MissingPrivateImageHubEmailError(server string) error {
return fmt.Errorf("email is required for private image hub %s", server)
}
// EnvForDNSAppAliasNotDefinedError Error when env not defined
func EnvForDNSAppAliasNotDefinedError(env string) error {
return fmt.Errorf("env %s referred to by dnsAppAlias is not defined", env)
}
// ComponentForDNSAppAliasNotDefinedError Error when env not defined
func ComponentForDNSAppAliasNotDefinedError(component string) error {
return fmt.Errorf("component %s referred to by dnsAppAlias is not defined", component)
}
// ExternalAliasCannotBeEmptyError Structure cannot be left empty
func ExternalAliasCannotBeEmptyError() error {
return errors.New("external alias cannot be empty")
}
// EnvForDNSExternalAliasNotDefinedError Error when env not defined
func EnvForDNSExternalAliasNotDefinedError(env string) error {
return fmt.Errorf("env %s referred to by dnsExternalAlias is not defined", env)
}
// ComponentForDNSExternalAliasNotDefinedError Error when env not defined
func ComponentForDNSExternalAliasNotDefinedError(component string) error {
return fmt.Errorf("component %s referred to by dnsExternalAlias is not defined", component)
}
// ComponentForDNSExternalAliasIsNotMarkedAsPublicError Component is not marked as public
func ComponentForDNSExternalAliasIsNotMarkedAsPublicError(component string) error {
return fmt.Errorf("component %s referred to by dnsExternalAlias is not marked as public", component)
}
// EnvironmentReferencedByComponentDoesNotExistError Environment does not exists
func EnvironmentReferencedByComponentDoesNotExistError(environment, component string) error {
return fmt.Errorf("env %s refered to by component %s is not defined", environment, component)
}
// InvalidPortNameLengthError Invalid resource length
func InvalidPortNameLengthError(value string) error {
return fmt.Errorf("%s (%s) max length is %d", "port name", value, maxPortNameLength)
}
// PortSpecificationCannotBeEmptyForComponentError Port cannot be empty for component
func PortSpecificationCannotBeEmptyForComponentError(component string) error {
return fmt.Errorf("port specification cannot be empty for %s", component)
}
// PortNameIsRequiredForPublicComponentError Port name cannot be empty
func PortNameIsRequiredForPublicComponentError(publicPortName, component string) error {
return fmt.Errorf("%s port name is required for public component %s", publicPortName, component)
}
// MonitoringPortNameIsNotFoundComponentError Monitoring port name not found on component
func MonitoringPortNameIsNotFoundComponentError(portName, component string) error {
return fmt.Errorf("%s port name referred to in MonitoringConfig not found on component %s", portName, component)
}
// MultipleMatchingPortNamesError Multiple matching port names
func MultipleMatchingPortNamesError(matchingPortName int, publicPortName, component string) error {
return fmt.Errorf("there are %d ports with name %s for component %s. Only 1 is allowed", matchingPortName, publicPortName, component)
}
// SchedulerPortCannotBeEmptyForJobError Scheduler port cannot be empty for job
func SchedulerPortCannotBeEmptyForJobError(jobName string) error {
return fmt.Errorf("scheduler port cannot be empty for %s", jobName)
}
// PayloadPathCannotBeEmptyForJobError Payload path cannot be empty for job
func PayloadPathCannotBeEmptyForJobError(jobName string) error {
return fmt.Errorf("payload path cannot be empty for %s", jobName)
}
// MemoryResourceRequirementFormatError Invalid memory resource requirement error
func MemoryResourceRequirementFormatError(value string) error {
return fmt.Errorf("format of memory resource requirement %s (value %s) is wrong. Value must be a valid Kubernetes quantity", "memory", value)
}
// CPUResourceRequirementFormatError Invalid CPU resource requirement
func CPUResourceRequirementFormatError(value string) error {
return fmt.Errorf("format of cpu resource requirement %s (value %s) is wrong. Must match regex %s", "cpu", value, cpuRegex)
}
func InvalidVerificationType(verification string) error {
return fmt.Errorf("invalid VerificationType (value %s)", verification)
}
// ResourceRequestOverLimitError Invalid resource requirement error
func ResourceRequestOverLimitError(resource string, require string, limit string) error {
return fmt.Errorf("%s resource requirement (value %s) is larger than the limit (value %s)", resource, require, limit)
}
// InvalidResourceError Invalid resource type
func InvalidResourceError(name string) error {
return fmt.Errorf("only support resource requirement type 'memory' and 'cpu' (not %s)", name)
}
// DuplicateExternalAliasError Cannot have duplicate external alias
func DuplicateExternalAliasError() error {
return errors.New("cannot have duplicate aliases for dnsExternalAlias")
}
// InvalidBranchNameError Indicates that branch name is invalid
func InvalidBranchNameError(branch string) error {
return fmt.Errorf("invalid branch name %s. See documentation for more info", branch)
}
// MaxReplicasForHPANotSetOrZeroError Indicates that minReplicas of horizontalScaling is not set or set to 0
func MaxReplicasForHPANotSetOrZeroError(component, environment string) error {
return fmt.Errorf("maxReplicas is not set or set to 0 for component %s in environment %s. See documentation for more info", component, environment)
}
// MinReplicasGreaterThanMaxReplicasError Indicates that minReplicas is greater than maxReplicas
func MinReplicasGreaterThanMaxReplicasError(component, environment string) error {
return fmt.Errorf("minReplicas is greater than maxReplicas for component %s in environment %s. See documentation for more info", component, environment)
}
func emptyVolumeMountTypeContainerNameOrTempPathError(component, environment string) error {
return fmt.Errorf("volume mount type, name, containers and temp-path of volumeMount for component %s in environment %s cannot be empty. See documentation for more info", component, environment)
}
func duplicatePathForVolumeMountType(path, volumeMountType, component, environment string) error {
return fmt.Errorf("duplicate path %s for volume mount type %s, for component %s in environment %s. See documentation for more info",
path, volumeMountType, component, environment)
}
func duplicateNameForVolumeMountType(name, volumeMountType, component, environment string) error {
return fmt.Errorf("duplicate names %s for volume mount type %s, for component %s in environment %s. See documentation for more info",
name, volumeMountType, component, environment)
}
func unknownVolumeMountTypeError(volumeMountType, component, environment string) error {
return fmt.Errorf("not recognized volume mount type %s for component %s in environment %s. See documentation for more info",
volumeMountType, component, environment)
}
//ApplicationNameNotLowercaseError Indicates that application name contains upper case letters
func ApplicationNameNotLowercaseError(appName string) error {
return fmt.Errorf("application with name %s contains uppercase letters", appName)
}
// PublicImageComponentCannotHaveSourceOrDockerfileSet Error if image is set and radix config contains src or dockerfile
func PublicImageComponentCannotHaveSourceOrDockerfileSet(componentName string) error {
return fmt.Errorf("component %s cannot have neither 'src' nor 'Dockerfile' set", componentName)
}
// ComponentWithDynamicTagRequiresTagInEnvironmentConfig Error if image is set with dynamic tag and tag is missing
func ComponentWithDynamicTagRequiresTagInEnvironmentConfig(componentName string) error {
return fmt.Errorf("component %s with %s on image requires an image tag set on environment config",
componentName, radixv1.DynamicTagNameInEnvironmentConfig)
}
// ComponentWithDynamicTagRequiresTagInEnvironmentConfigForEnvironment Error if image is set with dynamic tag and tag is missing
func ComponentWithDynamicTagRequiresTagInEnvironmentConfigForEnvironment(componentName, environment string) error {
return fmt.Errorf(
"component %s with %s on image requires an image tag set on environment config for environment %s",
componentName, radixv1.DynamicTagNameInEnvironmentConfig, environment)
}
// ComponentWithTagInEnvironmentConfigForEnvironmentRequiresDynamicTag If tag is set then the dynamic tag needs to be set on the image
func ComponentWithTagInEnvironmentConfigForEnvironmentRequiresDynamicTag(componentName, environment string) error {
return fmt.Errorf(
"component %s with image tag set on environment config for environment %s requires %s on image setting",
componentName, environment, radixv1.DynamicTagNameInEnvironmentConfig)
}
// ComponentWithDynamicTagRequiresTagInEnvironmentConfig Error if image is set with dynamic tag and tag is missing
func ComponentNameReservedSuffixError(componentName, componentType, suffix string) error {
return fmt.Errorf("%s %s using reserved suffix %s", componentType, componentName, suffix)
}
// SecretNameConflictsWithEnvironmentVariable If secret name is the same as environment variable fail validation
func SecretNameConflictsWithEnvironmentVariable(componentName, secretName string) error {
return fmt.Errorf(
"component %s has a secret with name %s which exists as an environment variable",
componentName, secretName)
}
// InvalidAppNameLengthError Invalid app length
func InvalidAppNameLengthError(value string) error {
return InvalidStringValueMaxLengthError("app name", value, 253)
}
// AppNameCannotBeEmptyError App name cannot be empty
func AppNameCannotBeEmptyError() error {
return ResourceNameCannotBeEmptyError("app name")
}
// InvalidStringValueMinLengthError Invalid string value min length
func InvalidStringValueMinLengthError(resourceName, value string, minValue int) error {
return fmt.Errorf("%s (\"%s\") min length is %d", resourceName, value, minValue)
}
// InvalidStringValueMaxLengthError Invalid string value max length
func InvalidStringValueMaxLengthError(resourceName, value string, maxValue int) error {
return fmt.Errorf("%s (\"%s\") max length is %d", resourceName, value, maxValue)
}
// ResourceNameCannotBeEmptyError Resource name cannot be left empty
func ResourceNameCannotBeEmptyError(resourceName string) error {
return fmt.Errorf("%s cannot be empty", resourceName)
}
// InvalidEmailError Invalid email
func InvalidEmailError(resourceName, email string) error {
return fmt.Errorf("field %s does not contain a valid email (value: %s)", resourceName, email)
}
// InvalidResourceNameError Invalid resource name
func InvalidResourceNameError(resourceName, value string) error {
return fmt.Errorf("%s %s can only consist of alphanumeric characters, '.' and '-'", resourceName, value)
}
//InvalidLowerCaseAlphaNumericDotDashResourceNameError Invalid lower case alpha-numeric, dot, dash resource name error
func InvalidLowerCaseAlphaNumericDotDashResourceNameError(resourceName, value string) error {
return fmt.Errorf("%s %s can only consist of lower case alphanumeric characters, '.' and '-'", resourceName, value)
}
// NoRegistrationExistsForApplicationError No registration exists
func NoRegistrationExistsForApplicationError(appName string) error {
return fmt.Errorf("no application found with name %s. Name of the application in radixconfig.yaml needs to be exactly the same as used when defining the app in the console", appName)
}
func InvalidConfigBranchName(configBranch string) error {
return fmt.Errorf("config branch name is not valid (value: %s)", configBranch)
}
// *********** OAuth2 config errors ***********
func oauthRequiredPropertyEmptyError(componentName, environmentName, propertyName string) error {
return fmt.Errorf("component %s in environment %s: required property %s in oauth2 configuration not set", componentName, environmentName, propertyName)
}
func oauthPropertyInvalidValueError(componentName, environmentName, propertyName, value string) error {
return fmt.Errorf("component %s in environment %s: invalid value %s for property %s in oauth2 configuration", componentName, environmentName, value, propertyName)
}
func oauthRequiredPropertyEmptyWithConditionError(componentName, environmentName, propertyName, whenCondition string) error {
return fmt.Errorf("component %s in environment %s: property %s in oauth2 configuration must be set when %s", componentName, environmentName, propertyName, whenCondition)
}
func oauthRequiredPropertyEmptyWithSkipDiscoveryEnabledError(componentName, environmentName, propertyName string) error {
return oauthRequiredPropertyEmptyWithConditionError(componentName, environmentName, propertyName, "oidc.skipDiscovery is true")
}
func oauthRequiredPropertyEmptyWithSessionStoreRedisError(componentName, environmentName, propertyName string) error {
return oauthRequiredPropertyEmptyWithConditionError(componentName, environmentName, propertyName, "sessionStoreType is redis")
}
func oauthCookieStoreMinimalIncorrectPropertyValueError(componentName, environmentName, propertyName, expectedValue string) error {
return fmt.Errorf("component %s in environment %s: property %s in oauth configuration must be set to %s when cookieStore.minimal is true", componentName, environmentName, propertyName, expectedValue)
}
func OAuthClientIdEmptyError(componentName, environmentName string) error {
return oauthRequiredPropertyEmptyError(componentName, environmentName, "clientId")
}
func OAuthProxyPrefixEmptyError(componentName, environmentName string) error {
return oauthRequiredPropertyEmptyError(componentName, environmentName, "proxyPrefix")
}
func OAuthProxyPrefixIsRootError(componentName, environmentName string) error {
return fmt.Errorf("component %s in environment %s: property proxyPrefix in oauth configuration cannot be set to '/' (root)", componentName, environmentName)
}
func OAuthSessionStoreTypeInvalidError(componentName, environmentName string, actualSessionStoreType radixv1.SessionStoreType) error {
return oauthPropertyInvalidValueError(componentName, environmentName, "sessionStoreType", string(actualSessionStoreType))
}
func OAuthOidcJwksUrlEmptyError(componentName, environmentName string) error {
return oauthRequiredPropertyEmptyWithSkipDiscoveryEnabledError(componentName, environmentName, "oidc.jwksUrl")
}
func OAuthLoginUrlEmptyError(componentName, environmentName string) error {
return oauthRequiredPropertyEmptyWithSkipDiscoveryEnabledError(componentName, environmentName, "oidc.loginUrl")
}
func OAuthRedeemUrlEmptyError(componentName, environmentName string) error {
return oauthRequiredPropertyEmptyWithSkipDiscoveryEnabledError(componentName, environmentName, "oidc.redeemUrl")
}
func OAuthOidcEmptyError(componentName, environmentName string) error {
return oauthRequiredPropertyEmptyError(componentName, environmentName, "oidc")
}
func OAuthOidcSkipDiscoveryEmptyError(componentName, environmentName string) error {
return oauthRequiredPropertyEmptyError(componentName, environmentName, "oidc.skipDiscovery")
}
func OAuthRedisStoreEmptyError(componentName, environmentName string) error {
return oauthRequiredPropertyEmptyWithSessionStoreRedisError(componentName, environmentName, "redisStore")
}
func OAuthRedisStoreConnectionURLEmptyError(componentName, environmentName string) error {
return oauthRequiredPropertyEmptyWithSessionStoreRedisError(componentName, environmentName, "redisStore.connectionUrl")
}
func OAuthCookieStoreMinimalIncorrectSetXAuthRequestHeadersError(componentName, environmentName string) error {
return oauthCookieStoreMinimalIncorrectPropertyValueError(componentName, environmentName, "setXAuthRequestHeaders", "false")
}
func OAuthCookieStoreMinimalIncorrectSetAuthorizationHeaderError(componentName, environmentName string) error {
return oauthCookieStoreMinimalIncorrectPropertyValueError(componentName, environmentName, "setAuthorizationHeader", "false")
}
func OAuthCookieStoreMinimalIncorrectCookieRefreshIntervalError(componentName, environmentName string) error {
return oauthCookieStoreMinimalIncorrectPropertyValueError(componentName, environmentName, "cookie.refresh", "0")
}
func OAuthCookieEmptyError(componentName, environmentName string) error {
return oauthRequiredPropertyEmptyError(componentName, environmentName, "cookie")
}
func OAuthCookieNameEmptyError(componentName, environmentName string) error {
return oauthRequiredPropertyEmptyError(componentName, environmentName, "cookie.name")
}
func OAuthCookieSameSiteInvalidError(componentName, environmentName string, actualSameSite radixv1.CookieSameSiteType) error {
return oauthPropertyInvalidValueError(componentName, environmentName, "cookie.sameSite", string(actualSameSite))
}
func OAuthCookieExpireInvalidError(componentName, environmentName, actualExpire string) error {
return oauthPropertyInvalidValueError(componentName, environmentName, "cookie.expire", actualExpire)
}
func OAuthCookieRefreshInvalidError(componentName, environmentName, actualRefresh string) error {
return oauthPropertyInvalidValueError(componentName, environmentName, "cookie.refresh", actualRefresh)
}
func OAuthCookieRefreshMustBeLessThanExpireError(componentName, environmentName string) error {
return fmt.Errorf("component %s in environment %s: property cookie.refresh in oauth configuration must be less than cookie.expire", componentName, environmentName)
}
// ********************************************
func DuplicateComponentOrJobNameError(duplicates []string) error {
return fmt.Errorf("duplicate component/job names %s not allowed", duplicates)
}
// InvalidPortNumberError Invalid port number
func InvalidPortNumberError(value int32) error {
return fmt.Errorf("submitted configuration contains port number %d. Port numbers must be greater than or equal to %d and lower than or equal to %d", value, minimumPortNumber, maximumPortNumber)
}
func duplicateSecretName(name string) error {
return fmt.Errorf("secret has a duplicate name %s", name)
}
func duplicateEnvVarName(name string) error {
return fmt.Errorf("environment variable has a duplicate name %s", name)
}
func duplicateAlias(alias string) error {
return fmt.Errorf("alias has a duplicate %s", alias)
}
func duplicateAzureKeyVaultName(name string) error {
return fmt.Errorf("azure Key vault has a duplicate name %s", name)
}
func secretRefEnvVarNameConflictsWithEnvironmentVariable(componentName, secretRefEnvVarName string) error {
return fmt.Errorf(
"component %s has a secret reference with environment variable name %s which exists as a regular environment variable or a secret",
componentName, secretRefEnvVarName)
}
func NotValidCidrError(s string) error {
return fmt.Errorf(s)
}
func NotValidIPv4CidrError(ipMask string) error {
return fmt.Errorf("%s is not a valid IPv4 mask", ipMask)
}
func InvalidEgressPortProtocolError(protocol string, validProtocols []string) error {
return fmt.Errorf("protocol %s must be one of {%s}", protocol, strings.Join(validProtocols, ", "))
}