Skip to content

Set default api gateway value to none if disabled cluster-wide #1337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/local/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func Deploy(env cliconfig.Environment, configPath string, projectFileList []stri
}
}

apiConfigs, err := spec.ExtractAPIConfigs(configBytes, types.LocalProviderType, configFileName)
apiConfigs, err := spec.ExtractAPIConfigs(configBytes, types.LocalProviderType, configFileName, nil)
if err != nil {
return schema.DeployResponse{}, err
}
Expand Down
6 changes: 3 additions & 3 deletions docs/deployments/batch-api/api-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Reference the section below which corresponds to your Predictor type: [Python](#
env: <string: string> # dictionary of environment variables
networking:
endpoint: <string> # the endpoint for the API (default: <api_name>)
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)
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)
compute:
cpu: <string | int | float> # CPU request per worker, e.g. 200m or 1 (200m is equivalent to 0.2) (default: 200m)
gpu: <int> # GPU request per worker (default: 0)
Expand Down Expand Up @@ -55,7 +55,7 @@ See additional documentation for [compute](../compute.md), [networking](../netwo
env: <string: string> # dictionary of environment variables
networking:
endpoint: <string> # the endpoint for the API (default: <api_name>)
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)
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)
compute:
cpu: <string | int | float> # CPU request per worker, e.g. 200m or 1 (200m is equivalent to 0.2) (default: 200m)
gpu: <int> # GPU request per worker (default: 0)
Expand Down Expand Up @@ -85,7 +85,7 @@ See additional documentation for [compute](../compute.md), [networking](../netwo
env: <string: string> # dictionary of environment variables
networking:
endpoint: <string> # the endpoint for the API (default: <api_name>)
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)
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)
compute:
cpu: <string | int | float> # CPU request per worker, e.g. 200m or 1 (200m is equivalent to 0.2) (default: 200m)
gpu: <int> # GPU request per worker (default: 0)
Expand Down
6 changes: 3 additions & 3 deletions docs/deployments/realtime-api/api-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Reference the section below which corresponds to your Predictor type: [Python](#
networking:
endpoint: <string> # the endpoint for the API (aws only) (default: <api_name>)
local_port: <int> # specify the port for API (local only) (default: 8888)
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)
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)
compute:
cpu: <string | int | float> # CPU request per replica, e.g. 200m or 1 (200m is equivalent to 0.2) (default: 200m)
gpu: <int> # GPU request per replica (default: 0)
Expand Down Expand Up @@ -80,7 +80,7 @@ See additional documentation for [parallelism](parallelism.md), [autoscaling](au
networking:
endpoint: <string> # the endpoint for the API (aws only) (default: <api_name>)
local_port: <int> # specify the port for API (local only) (default: 8888)
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)
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)
compute:
cpu: <string | int | float> # CPU request per replica, e.g. 200m or 1 (200m is equivalent to 0.2) (default: 200m)
gpu: <int> # GPU request per replica (default: 0)
Expand Down Expand Up @@ -132,7 +132,7 @@ See additional documentation for [parallelism](parallelism.md), [autoscaling](au
networking:
endpoint: <string> # the endpoint for the API (aws only) (default: <api_name>)
local_port: <int> # specify the port for API (local only) (default: 8888)
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)
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)
compute:
cpu: <string | int | float> # CPU request per replica, e.g. 200m or 1 (200m is equivalent to 0.2) (default: 200m)
gpu: <int> # GPU request per replica (default: 0)
Expand Down
2 changes: 1 addition & 1 deletion docs/deployments/realtime-api/traffic-splitter.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Traffic Splitter expects the target Realtime APIs to already be running or be in
kind: TrafficSplitter # must be "TrafficSplitter", create an Traffic Splitter which routes traffic to multiple Realtime APIs
networking:
endpoint: <string> # the endpoint for the Traffic Splitter (default: <api_name>)
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)
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)
apis: # list of Realtime APIs to target
- name: <string> # name of a Realtime API that is already running or is included in the same configuration file (required)
weight: <int> # percentage of traffic to route to the Realtime API (all weights must sum to 100) (required)
Expand Down
7 changes: 1 addition & 6 deletions pkg/operator/resources/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,8 @@ func ErrorAPIsNotDeployed(notDeployedAPIs []string) error {
}

func ErrorAPIGatewayDisabled(apiGatewayType userconfig.APIGatewayType) error {
msg := fmt.Sprintf("%s is not permitted because api gateway is disabled cluster-wide", s.UserStr(apiGatewayType))
if apiGatewayType == userconfig.PublicAPIGatewayType {
msg += fmt.Sprintf(" (%s is the default value, and the valid values are %s)", s.UserStr(userconfig.PublicAPIGatewayType), s.UserStrsAnd(userconfig.APIGatewayTypeStrings()))
}

return errors.WithStack(&errors.Error{
Kind: ErrAPIGatewayDisabled,
Message: msg,
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())),
})
}
2 changes: 1 addition & 1 deletion pkg/operator/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func Deploy(projectBytes []byte, configFileName string, configBytes []byte, forc
ConfigFileName: configFileName,
}

apiConfigs, err := spec.ExtractAPIConfigs(configBytes, types.AWSProviderType, configFileName)
apiConfigs, err := spec.ExtractAPIConfigs(configBytes, types.AWSProviderType, configFileName, &config.Cluster.Config)
if err != nil {
return nil, err
}
Expand Down
37 changes: 29 additions & 8 deletions pkg/types/spec/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,25 @@ import (
libtime "github.com/cortexlabs/cortex/pkg/lib/time"
"github.com/cortexlabs/cortex/pkg/lib/urls"
"github.com/cortexlabs/cortex/pkg/types"
"github.com/cortexlabs/cortex/pkg/types/clusterconfig"
"github.com/cortexlabs/cortex/pkg/types/userconfig"
kresource "k8s.io/apimachinery/pkg/api/resource"
)

var AutoscalingTickInterval = 10 * time.Second

func apiValidation(provider types.ProviderType, resource userconfig.Resource) *cr.StructValidation {
func apiValidation(
provider types.ProviderType,
resource userconfig.Resource,
clusterConfig *clusterconfig.Config, // should be omitted if running locally
) *cr.StructValidation {

structFieldValidations := []*cr.StructFieldValidation{}
switch resource.Kind {
case userconfig.RealtimeAPIKind:
structFieldValidations = append(resourceStructValidations,
predictorValidation(),
networkingValidation(resource.Kind),
networkingValidation(resource.Kind, clusterConfig),
computeValidation(provider),
monitoringValidation(),
autoscalingValidation(provider),
Expand All @@ -62,13 +68,13 @@ func apiValidation(provider types.ProviderType, resource userconfig.Resource) *c
case userconfig.BatchAPIKind:
structFieldValidations = append(resourceStructValidations,
predictorValidation(),
networkingValidation(resource.Kind),
networkingValidation(resource.Kind, clusterConfig),
computeValidation(provider),
)
case userconfig.TrafficSplitterKind:
structFieldValidations = append(resourceStructValidations,
multiAPIsValidation(),
networkingValidation(resource.Kind),
networkingValidation(resource.Kind, clusterConfig),
)
}
return &cr.StructValidation{
Expand Down Expand Up @@ -253,7 +259,16 @@ func monitoringValidation() *cr.StructFieldValidation {
}
}

func networkingValidation(kind userconfig.Kind) *cr.StructFieldValidation {
func networkingValidation(
kind userconfig.Kind,
clusterConfig *clusterconfig.Config, // should be omitted if running locally
) *cr.StructFieldValidation {

defaultAPIGatewayType := userconfig.PublicAPIGatewayType
if clusterConfig != nil && clusterConfig.APIGatewaySetting == clusterconfig.NoneAPIGatewaySetting {
defaultAPIGatewayType = userconfig.NoneAPIGatewayType
}

structFieldValidation := []*cr.StructFieldValidation{
{
StructField: "Endpoint",
Expand All @@ -266,7 +281,7 @@ func networkingValidation(kind userconfig.Kind) *cr.StructFieldValidation {
StructField: "APIGateway",
StringValidation: &cr.StringValidation{
AllowedValues: userconfig.APIGatewayTypeStrings(),
Default: userconfig.PublicAPIGatewayType.String(),
Default: defaultAPIGatewayType.String(),
},
Parser: func(str string) (interface{}, error) {
return userconfig.APIGatewayTypeFromString(str), nil
Expand Down Expand Up @@ -570,7 +585,13 @@ var resourceStructValidation = cr.StructValidation{
StructFieldValidations: resourceStructValidations,
}

func ExtractAPIConfigs(configBytes []byte, provider types.ProviderType, configFileName string) ([]userconfig.API, error) {
func ExtractAPIConfigs(
configBytes []byte,
provider types.ProviderType,
configFileName string,
clusterConfig *clusterconfig.Config, // should be omitted if running locally
) ([]userconfig.API, error) {

var err error

configData, err := cr.ReadYAMLBytes(configBytes)
Expand Down Expand Up @@ -607,7 +628,7 @@ func ExtractAPIConfigs(configBytes []byte, provider types.ProviderType, configFi
}
}

errs = cr.Struct(&api, data, apiValidation(provider, resourceStruct))
errs = cr.Struct(&api, data, apiValidation(provider, resourceStruct, clusterConfig))
if errors.HasError(errs) {
name, _ := data[userconfig.NameKey].(string)
kindString, _ := data[userconfig.KindKey].(string)
Expand Down