Skip to content

Commit f7b254c

Browse files
authored
Set default api gateway value to none if disabled cluster-wide (#1337)
1 parent c68ce3c commit f7b254c

File tree

7 files changed

+39
-23
lines changed

7 files changed

+39
-23
lines changed

Diff for: cli/local/deploy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func Deploy(env cliconfig.Environment, configPath string, projectFileList []stri
6262
}
6363
}
6464

65-
apiConfigs, err := spec.ExtractAPIConfigs(configBytes, types.LocalProviderType, configFileName)
65+
apiConfigs, err := spec.ExtractAPIConfigs(configBytes, types.LocalProviderType, configFileName, nil)
6666
if err != nil {
6767
return schema.DeployResponse{}, err
6868
}

Diff for: docs/deployments/batch-api/api-configuration.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Reference the section below which corresponds to your Predictor type: [Python](#
2020
env: <string: string> # dictionary of environment variables
2121
networking:
2222
endpoint: <string> # the endpoint for the API (default: <api_name>)
23-
api_gateway: public | none # whether to create a public API Gateway endpoint for this API (if not, the load balancer will be accessed directly) (default: public)
23+
api_gateway: public | none # whether to create a public API Gateway endpoint for this API (if not, the API will still be accessible via the load balancer) (default: public, unless disabled cluster-wide)
2424
compute:
2525
cpu: <string | int | float> # CPU request per worker, e.g. 200m or 1 (200m is equivalent to 0.2) (default: 200m)
2626
gpu: <int> # GPU request per worker (default: 0)
@@ -55,7 +55,7 @@ See additional documentation for [compute](../compute.md), [networking](../netwo
5555
env: <string: string> # dictionary of environment variables
5656
networking:
5757
endpoint: <string> # the endpoint for the API (default: <api_name>)
58-
api_gateway: public | none # whether to create a public API Gateway endpoint for this API (if not, the load balancer will be accessed directly) (default: public)
58+
api_gateway: public | none # whether to create a public API Gateway endpoint for this API (if not, the API will still be accessible via the load balancer) (default: public, unless disabled cluster-wide)
5959
compute:
6060
cpu: <string | int | float> # CPU request per worker, e.g. 200m or 1 (200m is equivalent to 0.2) (default: 200m)
6161
gpu: <int> # GPU request per worker (default: 0)
@@ -85,7 +85,7 @@ See additional documentation for [compute](../compute.md), [networking](../netwo
8585
env: <string: string> # dictionary of environment variables
8686
networking:
8787
endpoint: <string> # the endpoint for the API (default: <api_name>)
88-
api_gateway: public | none # whether to create a public API Gateway endpoint for this API (if not, the load balancer will be accessed directly) (default: public)
88+
api_gateway: public | none # whether to create a public API Gateway endpoint for this API (if not, the API will still be accessible via the load balancer) (default: public, unless disabled cluster-wide)
8989
compute:
9090
cpu: <string | int | float> # CPU request per worker, e.g. 200m or 1 (200m is equivalent to 0.2) (default: 200m)
9191
gpu: <int> # GPU request per worker (default: 0)

Diff for: docs/deployments/realtime-api/api-configuration.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Reference the section below which corresponds to your Predictor type: [Python](#
2323
networking:
2424
endpoint: <string> # the endpoint for the API (aws only) (default: <api_name>)
2525
local_port: <int> # specify the port for API (local only) (default: 8888)
26-
api_gateway: public | none # whether to create a public API Gateway endpoint for this API (if not, the load balancer will be accessed directly) (default: public)
26+
api_gateway: public | none # whether to create a public API Gateway endpoint for this API (if not, the API will still be accessible via the load balancer) (default: public, unless disabled cluster-wide)
2727
compute:
2828
cpu: <string | int | float> # CPU request per replica, e.g. 200m or 1 (200m is equivalent to 0.2) (default: 200m)
2929
gpu: <int> # GPU request per replica (default: 0)
@@ -80,7 +80,7 @@ See additional documentation for [parallelism](parallelism.md), [autoscaling](au
8080
networking:
8181
endpoint: <string> # the endpoint for the API (aws only) (default: <api_name>)
8282
local_port: <int> # specify the port for API (local only) (default: 8888)
83-
api_gateway: public | none # whether to create a public API Gateway endpoint for this API (if not, the load balancer will be accessed directly) (default: public)
83+
api_gateway: public | none # whether to create a public API Gateway endpoint for this API (if not, the API will still be accessible via the load balancer) (default: public, unless disabled cluster-wide)
8484
compute:
8585
cpu: <string | int | float> # CPU request per replica, e.g. 200m or 1 (200m is equivalent to 0.2) (default: 200m)
8686
gpu: <int> # GPU request per replica (default: 0)
@@ -132,7 +132,7 @@ See additional documentation for [parallelism](parallelism.md), [autoscaling](au
132132
networking:
133133
endpoint: <string> # the endpoint for the API (aws only) (default: <api_name>)
134134
local_port: <int> # specify the port for API (local only) (default: 8888)
135-
api_gateway: public | none # whether to create a public API Gateway endpoint for this API (if not, the load balancer will be accessed directly) (default: public)
135+
api_gateway: public | none # whether to create a public API Gateway endpoint for this API (if not, the API will still be accessible via the load balancer) (default: public, unless disabled cluster-wide)
136136
compute:
137137
cpu: <string | int | float> # CPU request per replica, e.g. 200m or 1 (200m is equivalent to 0.2) (default: 200m)
138138
gpu: <int> # GPU request per replica (default: 0)

Diff for: docs/deployments/realtime-api/traffic-splitter.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Traffic Splitter expects the target Realtime APIs to already be running or be in
1717
kind: TrafficSplitter # must be "TrafficSplitter", create an Traffic Splitter which routes traffic to multiple Realtime APIs
1818
networking:
1919
endpoint: <string> # the endpoint for the Traffic Splitter (default: <api_name>)
20-
api_gateway: public | none # whether to create a public API Gateway endpoint for this API (if not, the load balancer will be accessed directly) (default: public)
20+
api_gateway: public | none # whether to create a public API Gateway endpoint for this API (if not, the API will still be accessible via the load balancer) (default: public, unless disabled cluster-wide)
2121
apis: # list of Realtime APIs to target
2222
- name: <string> # name of a Realtime API that is already running or is included in the same configuration file (required)
2323
weight: <int> # percentage of traffic to route to the Realtime API (all weights must sum to 100) (required)

Diff for: pkg/operator/resources/errors.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,8 @@ func ErrorAPIsNotDeployed(notDeployedAPIs []string) error {
9595
}
9696

9797
func ErrorAPIGatewayDisabled(apiGatewayType userconfig.APIGatewayType) error {
98-
msg := fmt.Sprintf("%s is not permitted because api gateway is disabled cluster-wide", s.UserStr(apiGatewayType))
99-
if apiGatewayType == userconfig.PublicAPIGatewayType {
100-
msg += fmt.Sprintf(" (%s is the default value, and the valid values are %s)", s.UserStr(userconfig.PublicAPIGatewayType), s.UserStrsAnd(userconfig.APIGatewayTypeStrings()))
101-
}
102-
10398
return errors.WithStack(&errors.Error{
10499
Kind: ErrAPIGatewayDisabled,
105-
Message: msg,
100+
Message: fmt.Sprintf("%s is not permitted because api gateway is disabled cluster-wide (valid values are %s)", s.UserStr(apiGatewayType), s.UserStrsAnd(userconfig.APIGatewayTypeStrings())),
106101
})
107102
}

Diff for: pkg/operator/resources/resources.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func Deploy(projectBytes []byte, configFileName string, configBytes []byte, forc
8686
ConfigFileName: configFileName,
8787
}
8888

89-
apiConfigs, err := spec.ExtractAPIConfigs(configBytes, types.AWSProviderType, configFileName)
89+
apiConfigs, err := spec.ExtractAPIConfigs(configBytes, types.AWSProviderType, configFileName, &config.Cluster.Config)
9090
if err != nil {
9191
return nil, err
9292
}

Diff for: pkg/types/spec/validations.go

+29-8
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,25 @@ import (
4141
libtime "github.com/cortexlabs/cortex/pkg/lib/time"
4242
"github.com/cortexlabs/cortex/pkg/lib/urls"
4343
"github.com/cortexlabs/cortex/pkg/types"
44+
"github.com/cortexlabs/cortex/pkg/types/clusterconfig"
4445
"github.com/cortexlabs/cortex/pkg/types/userconfig"
4546
kresource "k8s.io/apimachinery/pkg/api/resource"
4647
)
4748

4849
var AutoscalingTickInterval = 10 * time.Second
4950

50-
func apiValidation(provider types.ProviderType, resource userconfig.Resource) *cr.StructValidation {
51+
func apiValidation(
52+
provider types.ProviderType,
53+
resource userconfig.Resource,
54+
clusterConfig *clusterconfig.Config, // should be omitted if running locally
55+
) *cr.StructValidation {
56+
5157
structFieldValidations := []*cr.StructFieldValidation{}
5258
switch resource.Kind {
5359
case userconfig.RealtimeAPIKind:
5460
structFieldValidations = append(resourceStructValidations,
5561
predictorValidation(),
56-
networkingValidation(resource.Kind),
62+
networkingValidation(resource.Kind, clusterConfig),
5763
computeValidation(provider),
5864
monitoringValidation(),
5965
autoscalingValidation(provider),
@@ -62,13 +68,13 @@ func apiValidation(provider types.ProviderType, resource userconfig.Resource) *c
6268
case userconfig.BatchAPIKind:
6369
structFieldValidations = append(resourceStructValidations,
6470
predictorValidation(),
65-
networkingValidation(resource.Kind),
71+
networkingValidation(resource.Kind, clusterConfig),
6672
computeValidation(provider),
6773
)
6874
case userconfig.TrafficSplitterKind:
6975
structFieldValidations = append(resourceStructValidations,
7076
multiAPIsValidation(),
71-
networkingValidation(resource.Kind),
77+
networkingValidation(resource.Kind, clusterConfig),
7278
)
7379
}
7480
return &cr.StructValidation{
@@ -253,7 +259,16 @@ func monitoringValidation() *cr.StructFieldValidation {
253259
}
254260
}
255261

256-
func networkingValidation(kind userconfig.Kind) *cr.StructFieldValidation {
262+
func networkingValidation(
263+
kind userconfig.Kind,
264+
clusterConfig *clusterconfig.Config, // should be omitted if running locally
265+
) *cr.StructFieldValidation {
266+
267+
defaultAPIGatewayType := userconfig.PublicAPIGatewayType
268+
if clusterConfig != nil && clusterConfig.APIGatewaySetting == clusterconfig.NoneAPIGatewaySetting {
269+
defaultAPIGatewayType = userconfig.NoneAPIGatewayType
270+
}
271+
257272
structFieldValidation := []*cr.StructFieldValidation{
258273
{
259274
StructField: "Endpoint",
@@ -266,7 +281,7 @@ func networkingValidation(kind userconfig.Kind) *cr.StructFieldValidation {
266281
StructField: "APIGateway",
267282
StringValidation: &cr.StringValidation{
268283
AllowedValues: userconfig.APIGatewayTypeStrings(),
269-
Default: userconfig.PublicAPIGatewayType.String(),
284+
Default: defaultAPIGatewayType.String(),
270285
},
271286
Parser: func(str string) (interface{}, error) {
272287
return userconfig.APIGatewayTypeFromString(str), nil
@@ -570,7 +585,13 @@ var resourceStructValidation = cr.StructValidation{
570585
StructFieldValidations: resourceStructValidations,
571586
}
572587

573-
func ExtractAPIConfigs(configBytes []byte, provider types.ProviderType, configFileName string) ([]userconfig.API, error) {
588+
func ExtractAPIConfigs(
589+
configBytes []byte,
590+
provider types.ProviderType,
591+
configFileName string,
592+
clusterConfig *clusterconfig.Config, // should be omitted if running locally
593+
) ([]userconfig.API, error) {
594+
574595
var err error
575596

576597
configData, err := cr.ReadYAMLBytes(configBytes)
@@ -607,7 +628,7 @@ func ExtractAPIConfigs(configBytes []byte, provider types.ProviderType, configFi
607628
}
608629
}
609630

610-
errs = cr.Struct(&api, data, apiValidation(provider, resourceStruct))
631+
errs = cr.Struct(&api, data, apiValidation(provider, resourceStruct, clusterConfig))
611632
if errors.HasError(errs) {
612633
name, _ := data[userconfig.NameKey].(string)
613634
kindString, _ := data[userconfig.KindKey].(string)

0 commit comments

Comments
 (0)