Skip to content

Commit 4771cbb

Browse files
authored
Move endpoint and local_port to networking API config (#1151)
1 parent e3d755e commit 4771cbb

File tree

15 files changed

+90
-91
lines changed

15 files changed

+90
-91
lines changed

cli/cmd/get.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ func getAPI(env cliconfig.Environment, apiName string) (string, error) {
319319

320320
apiEndpoint := apiRes.BaseURL
321321
if env.Provider == types.AWSProviderType {
322-
apiEndpoint = urls.Join(apiRes.BaseURL, *api.Endpoint)
322+
apiEndpoint = urls.Join(apiRes.BaseURL, *api.Networking.Endpoint)
323323
if api.Networking.APIGateway == userconfig.NoneAPIGatewayType {
324324
apiEndpoint = strings.Replace(apiEndpoint, "https://", "http://", 1)
325325
}

cli/cmd/predict.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ var _predictCmd = &cobra.Command{
7070
if err != nil {
7171
exit.Error(err)
7272
}
73-
apiEndpoint = urls.Join(apiRes.BaseURL, *apiRes.API.Endpoint)
73+
apiEndpoint = urls.Join(apiRes.BaseURL, *apiRes.API.Networking.Endpoint)
7474

7575
} else {
7676
apiRes, err = local.GetAPI(apiName)

cli/local/docker_spec.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ func getAPIEnv(api *spec.API, awsClient *aws.Client) []string {
111111

112112
func deployPythonContainer(api *spec.API, awsClient *aws.Client) error {
113113
portBinding := nat.PortBinding{}
114-
if api.LocalPort != nil {
115-
portBinding.HostPort = s.Int(*api.LocalPort)
114+
if api.Networking.LocalPort != nil {
115+
portBinding.HostPort = s.Int(*api.Networking.LocalPort)
116116
}
117117

118118
runtime := ""
@@ -180,8 +180,8 @@ func deployPythonContainer(api *spec.API, awsClient *aws.Client) error {
180180

181181
func deployONNXContainer(api *spec.API, awsClient *aws.Client) error {
182182
portBinding := nat.PortBinding{}
183-
if api.LocalPort != nil {
184-
portBinding.HostPort = s.Int(*api.LocalPort)
183+
if api.Networking.LocalPort != nil {
184+
portBinding.HostPort = s.Int(*api.Networking.LocalPort)
185185
}
186186

187187
runtime := ""
@@ -330,8 +330,8 @@ func deployTensorFlowContainers(api *spec.API, awsClient *aws.Client) error {
330330
tfContainerHost := containerInfo.NetworkSettings.Networks["bridge"].IPAddress
331331

332332
portBinding := nat.PortBinding{}
333-
if api.LocalPort != nil {
334-
portBinding.HostPort = fmt.Sprintf("%d", *api.LocalPort)
333+
if api.Networking.LocalPort != nil {
334+
portBinding.HostPort = fmt.Sprintf("%d", *api.Networking.LocalPort)
335335
}
336336
apiHostConfig := &container.HostConfig{
337337
PortBindings: nat.PortMap{

cli/local/validations.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -199,57 +199,57 @@ func ValidateLocalAPIs(apis []userconfig.API, projectFiles ProjectFiles, awsClie
199199
for i := range apis {
200200
api := &apis[i]
201201

202-
updatingAPIToPortMap[api.Name] = api.LocalPort
203-
if api.LocalPort != nil {
204-
if collidingAPIName, ok := portToUpdatingAPIMap[*api.LocalPort]; ok {
205-
return errors.Wrap(ErrorDuplicateLocalPort(collidingAPIName), api.Identify(), userconfig.LocalPortKey, s.Int(*api.LocalPort))
202+
updatingAPIToPortMap[api.Name] = api.Networking.LocalPort
203+
if api.Networking.LocalPort != nil {
204+
if collidingAPIName, ok := portToUpdatingAPIMap[*api.Networking.LocalPort]; ok {
205+
return errors.Wrap(ErrorDuplicateLocalPort(collidingAPIName), api.Identify(), userconfig.LocalPortKey, s.Int(*api.Networking.LocalPort))
206206
}
207-
usedPorts = append(usedPorts, *api.LocalPort)
208-
portToUpdatingAPIMap[*api.LocalPort] = api.Name
207+
usedPorts = append(usedPorts, *api.Networking.LocalPort)
208+
portToUpdatingAPIMap[*api.Networking.LocalPort] = api.Name
209209
}
210210
}
211211

212212
for i := range apis {
213213
api := &apis[i]
214-
if api.LocalPort != nil {
214+
if api.Networking.LocalPort != nil {
215215
// same port as previous deployment of this API
216-
if *api.LocalPort == runningAPIsToPortMap[api.Name] {
216+
if *api.Networking.LocalPort == runningAPIsToPortMap[api.Name] {
217217
continue
218218
}
219219

220220
// port is being used by another API
221-
if apiName, ok := portToRunningAPIsMap[*api.LocalPort]; ok {
222-
return errors.Wrap(ErrorDuplicateLocalPort(apiName), api.Identify(), userconfig.LocalPortKey, s.Int(*api.LocalPort))
221+
if apiName, ok := portToRunningAPIsMap[*api.Networking.LocalPort]; ok {
222+
return errors.Wrap(ErrorDuplicateLocalPort(apiName), api.Identify(), userconfig.LocalPortKey, s.Int(*api.Networking.LocalPort))
223223
}
224-
isPortAvailable, err := checkPortAvailability(*api.LocalPort)
224+
isPortAvailable, err := checkPortAvailability(*api.Networking.LocalPort)
225225
if err != nil {
226226
return err
227227
}
228228

229229
if !isPortAvailable {
230-
return errors.Wrap(ErrorPortAlreadyInUse(*api.LocalPort), api.Identify(), userconfig.LocalPortKey)
230+
return errors.Wrap(ErrorPortAlreadyInUse(*api.Networking.LocalPort), api.Identify(), userconfig.LocalPortKey)
231231
}
232232
} else {
233233
// get previous api deployment port
234234
if port, ok := runningAPIsToPortMap[api.Name]; ok {
235235

236236
// check that the previous api deployment port has not been claimed in new deployment
237237
if _, ok := portToUpdatingAPIMap[port]; !ok {
238-
api.LocalPort = pointer.Int(port)
238+
api.Networking.LocalPort = pointer.Int(port)
239239
}
240240
}
241241
}
242242
}
243243

244244
for i := range apis {
245245
api := &apis[i]
246-
if api.LocalPort == nil {
246+
if api.Networking.LocalPort == nil {
247247
availablePort, err := findTheNextAvailablePort(usedPorts)
248248
if err != nil {
249249
errors.Wrap(err, api.Identify())
250250
}
251251

252-
api.LocalPort = pointer.Int(availablePort)
252+
api.Networking.LocalPort = pointer.Int(availablePort)
253253
}
254254
}
255255

docs/deployments/api-configuration.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ Reference the section below which corresponds to your Predictor type: [Python](#
1010

1111
```yaml
1212
- name: <string> # API name (required)
13-
endpoint: <string> # the endpoint for the API (aws only) (default: <api_name>)
14-
local_port: <int> # specify the port for API (local only) (default: 8888)
1513
predictor:
1614
type: python
1715
path: <string> # path to a python file with a PythonPredictor class definition, relative to the Cortex root (required)
1816
config: <string: value> # arbitrary dictionary passed to the constructor of the Predictor (optional)
1917
python_path: <string> # path to the root of your Python folder that will be appended to PYTHONPATH (default: folder containing cortex.yaml)
2018
image: <string> # docker image to use for the Predictor (default: cortexlabs/python-predictor-cpu or cortexlabs/python-predictor-gpu based on compute)
2119
env: <string: string> # dictionary of environment variables
22-
monitoring: # (aws only)
23-
model_type: <string> # must be "classification" or "regression", so responses can be interpreted correctly (i.e. categorical vs continuous) (required)
24-
key: <string> # the JSON key in the response payload of the value to monitor (required if the response payload is a JSON object)
20+
networking:
21+
endpoint: <string> # the endpoint for the API (aws only) (default: <api_name>)
22+
local_port: <int> # specify the port for API (local only) (default: 8888)
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)
2524
compute:
2625
cpu: <string | int | float> # CPU request per replica, e.g. 200m or 1 (200m is equivalent to 0.2) (default: 200m)
2726
gpu: <int> # GPU request per replica (default: 0)
2827
inf: <int> # Inferentia ASIC request per replica (default: 0)
2928
mem: <string> # memory request per replica, e.g. 200Mi or 1Gi (default: Null)
30-
networking:
31-
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)
29+
monitoring: # (aws only)
30+
model_type: <string> # must be "classification" or "regression", so responses can be interpreted correctly (i.e. categorical vs continuous) (required)
31+
key: <string> # the JSON key in the response payload of the value to monitor (required if the response payload is a JSON object)
3232
autoscaling: # (aws only)
3333
min_replicas: <int> # minimum number of replicas (default: 1)
3434
max_replicas: <int> # maximum number of replicas (default: 100)
@@ -55,8 +55,6 @@ See additional documentation for [autoscaling](autoscaling.md), [compute](comput
5555
5656
```yaml
5757
- name: <string> # API name (required)
58-
endpoint: <string> # the endpoint for the API (aws only) (default: <api_name>)
59-
local_port: <int> # specify the port for API (local only) (default: 8888)
6058
predictor:
6159
type: tensorflow
6260
path: <string> # path to a python file with a TensorFlowPredictor class definition, relative to the Cortex root (required)
@@ -72,16 +70,18 @@ See additional documentation for [autoscaling](autoscaling.md), [compute](comput
7270
image: <string> # docker image to use for the Predictor (default: cortexlabs/tensorflow-predictor)
7371
tensorflow_serving_image: <string> # docker image to use for the TensorFlow Serving container (default: cortexlabs/tensorflow-serving-gpu or cortexlabs/tensorflow-serving-cpu based on compute)
7472
env: <string: string> # dictionary of environment variables
75-
monitoring: # (aws only)
76-
model_type: <string> # must be "classification" or "regression", so responses can be interpreted correctly (i.e. categorical vs continuous) (required)
77-
key: <string> # the JSON key in the response payload of the value to monitor (required if the response payload is a JSON object)
73+
networking:
74+
endpoint: <string> # the endpoint for the API (aws only) (default: <api_name>)
75+
local_port: <int> # specify the port for API (local only) (default: 8888)
76+
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)
7877
compute:
7978
cpu: <string | int | float> # CPU request per replica, e.g. 200m or 1 (200m is equivalent to 0.2) (default: 200m)
8079
gpu: <int> # GPU request per replica (default: 0)
8180
inf: <int> # Inferentia ASIC request per replica (default: 0)
8281
mem: <string> # memory request per replica, e.g. 200Mi or 1Gi (default: Null)
83-
networking:
84-
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)
82+
monitoring: # (aws only)
83+
model_type: <string> # must be "classification" or "regression", so responses can be interpreted correctly (i.e. categorical vs continuous) (required)
84+
key: <string> # the JSON key in the response payload of the value to monitor (required if the response payload is a JSON object)
8585
autoscaling: # (aws only)
8686
min_replicas: <int> # minimum number of replicas (default: 1)
8787
max_replicas: <int> # maximum number of replicas (default: 100)
@@ -108,8 +108,6 @@ See additional documentation for [autoscaling](autoscaling.md), [compute](comput
108108
109109
```yaml
110110
- name: <string> # API name (required)
111-
endpoint: <string> # the endpoint for the API (aws only) (default: <api_name>)
112-
local_port: <int> # specify the port for API (local only) (default: 8888)
113111
predictor:
114112
type: onnx
115113
path: <string> # path to a python file with an ONNXPredictor class definition, relative to the Cortex root (required)
@@ -123,15 +121,17 @@ See additional documentation for [autoscaling](autoscaling.md), [compute](comput
123121
python_path: <string> # path to the root of your Python folder that will be appended to PYTHONPATH (default: folder containing cortex.yaml)
124122
image: <string> # docker image to use for the Predictor (default: cortexlabs/onnx-predictor-gpu or cortexlabs/onnx-predictor-cpu based on compute)
125123
env: <string: string> # dictionary of environment variables
126-
monitoring: # (aws only)
127-
model_type: <string> # must be "classification" or "regression", so responses can be interpreted correctly (i.e. categorical vs continuous) (required)
128-
key: <string> # the JSON key in the response payload of the value to monitor (required if the response payload is a JSON object)
124+
networking:
125+
endpoint: <string> # the endpoint for the API (aws only) (default: <api_name>)
126+
local_port: <int> # specify the port for API (local only) (default: 8888)
127+
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)
129128
compute:
130129
cpu: <string | int | float> # CPU request per replica, e.g. 200m or 1 (200m is equivalent to 0.2) (default: 200m)
131130
gpu: <int> # GPU request per replica (default: 0)
132131
mem: <string> # memory request per replica, e.g. 200Mi or 1Gi (default: Null)
133-
networking:
134-
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)
132+
monitoring: # (aws only)
133+
model_type: <string> # must be "classification" or "regression", so responses can be interpreted correctly (i.e. categorical vs continuous) (required)
134+
key: <string> # the JSON key in the response payload of the value to monitor (required if the response payload is a JSON object)
135135
autoscaling: # (aws only)
136136
min_replicas: <int> # minimum number of replicas (default: 1)
137137
max_replicas: <int> # maximum number of replicas (default: 100)

pkg/operator/operator/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func UpdateAPI(apiConfig *userconfig.API, projectID string, force bool) (*spec.A
5858
go deleteK8sResources(api.Name)
5959
return nil, "", err
6060
}
61-
err = addAPIToAPIGateway(*api.Endpoint, api.Networking.APIGateway)
61+
err = addAPIToAPIGateway(*api.Networking.Endpoint, api.Networking.APIGateway)
6262
if err != nil {
6363
go deleteK8sResources(api.Name)
6464
return nil, "", err

pkg/operator/operator/gateway.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,5 @@ func updateAPIGatewayK8s(prevVirtualService *istioclientnetworking.VirtualServic
158158
return err
159159
}
160160

161-
return updateAPIGateway(prevEndpoint, prevAPIGatewayType, *newAPI.Endpoint, newAPI.Networking.APIGateway)
161+
return updateAPIGateway(prevEndpoint, prevAPIGatewayType, *newAPI.Networking.Endpoint, newAPI.Networking.APIGateway)
162162
}

pkg/operator/operator/k8s_specs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ func virtualServiceSpec(api *spec.API) *istioclientnetworking.VirtualService {
562562
Gateways: []string{"apis-gateway"},
563563
ServiceName: k8sName(api.Name),
564564
ServicePort: _defaultPortInt32,
565-
Path: *api.Endpoint,
565+
Path: *api.Networking.Endpoint,
566566
Rewrite: pointer.String("predict"),
567567
Annotations: api.ToK8sAnnotations(),
568568
Labels: map[string]string{

pkg/operator/operator/validations.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func ValidateClusterAPIs(apis []userconfig.API, projectFiles spec.ProjectFiles)
8383
return err
8484
}
8585

86-
if !didPrintWarning && api.LocalPort != nil {
86+
if !didPrintWarning && api.Networking.LocalPort != nil {
8787
fmt.Println(fmt.Sprintf("warning: %s will be ignored because it is not supported in an environment using aws provider\n", userconfig.LocalPortKey))
8888
didPrintWarning = true
8989
}
@@ -158,7 +158,7 @@ func validateEndpointCollisions(api *userconfig.API, virtualServices []istioclie
158158

159159
endpoints := k8s.ExtractVirtualServiceEndpoints(&virtualService)
160160
for endpoint := range endpoints {
161-
if s.EnsureSuffix(endpoint, "/") == s.EnsureSuffix(*api.Endpoint, "/") && virtualService.GetLabels()["apiName"] != api.Name {
161+
if s.EnsureSuffix(endpoint, "/") == s.EnsureSuffix(*api.Networking.Endpoint, "/") && virtualService.GetLabels()["apiName"] != api.Name {
162162
return errors.Wrap(spec.ErrorDuplicateEndpoint(virtualService.GetLabels()["apiName"]), api.Identify(), userconfig.EndpointKey, endpoint)
163163
}
164164
}
@@ -171,7 +171,7 @@ func findDuplicateEndpoints(apis []userconfig.API) []userconfig.API {
171171
endpoints := make(map[string][]userconfig.API)
172172

173173
for _, api := range apis {
174-
endpoints[*api.Endpoint] = append(endpoints[*api.Endpoint], api)
174+
endpoints[*api.Networking.Endpoint] = append(endpoints[*api.Networking.Endpoint], api)
175175
}
176176

177177
for endpoint := range endpoints {

pkg/types/spec/api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ type LocalModelCache struct {
5050
func GetAPISpec(apiConfig *userconfig.API, projectID string, deploymentID string) *API {
5151
var buf bytes.Buffer
5252
buf.WriteString(apiConfig.Name)
53-
if apiConfig.Endpoint != nil {
54-
buf.WriteString(*apiConfig.Endpoint)
53+
if apiConfig.Networking.Endpoint != nil {
54+
buf.WriteString(*apiConfig.Networking.Endpoint)
5555
}
56-
if apiConfig.LocalPort != nil {
57-
buf.WriteString(s.Obj(*apiConfig.LocalPort))
56+
if apiConfig.Networking.LocalPort != nil {
57+
buf.WriteString(s.Obj(*apiConfig.Networking.LocalPort))
5858
}
5959
buf.WriteString(s.Obj(apiConfig.Predictor))
6060
buf.WriteString(s.Obj(apiConfig.Monitoring))

0 commit comments

Comments
 (0)