MCPcopy Index your code
hub / github.com/cortexlabs/cortex / RefreshAPI

Function RefreshAPI

pkg/operator/resources/asyncapi/api.go:155–203  ·  view source on GitHub ↗
(apiName string, force bool)

Source from the content-addressed store, hash-verified

153}
154
155func RefreshAPI(apiName string, force bool) (string, error) {
156 prevK8sResources, err := getK8sResources(apiName)
157 if err != nil {
158 return "", err
159 } else if prevK8sResources.apiVirtualService == nil || prevK8sResources.apiDeployment == nil {
160 return "", errors.ErrorUnexpected("unable to find deployment", apiName)
161 }
162
163 isUpdating, err := isAPIUpdating(prevK8sResources.apiDeployment)
164 if err != nil {
165 return "", err
166 }
167
168 if isUpdating && !force {
169 return "", ErrorAPIUpdating(apiName)
170 }
171
172 apiID, err := k8s.GetLabel(prevK8sResources.apiVirtualService, "apiID")
173 if err != nil {
174 return "", err
175 }
176
177 api, err := operator.DownloadAPISpec(apiName, apiID)
178 if err != nil {
179 return "", err
180 }
181
182 initialDeploymentTime, err := k8s.ParseInt64Label(prevK8sResources.apiVirtualService, "initialDeploymentTime")
183 if err != nil {
184 return "", err
185 }
186
187 api = spec.GetAPISpec(api.API, initialDeploymentTime, generateDeploymentID(), config.ClusterConfig.ClusterUID)
188
189 if err := config.AWS.UploadJSONToS3(api, config.ClusterConfig.Bucket, api.Key); err != nil {
190 return "", errors.Wrap(err, "upload api spec")
191 }
192
193 queueURL, err := getQueueURL(api.Name, initialDeploymentTime)
194 if err != nil {
195 return "", err
196 }
197
198 if err = applyK8sResources(*api, prevK8sResources, queueURL); err != nil {
199 return "", err
200 }
201
202 return fmt.Sprintf("updating %s", api.Resource.UserString()), nil
203}
204
205func DeleteAPI(apiName string, keepCache bool) error {
206 err := parallel.RunFirstErr(

Callers 1

RefreshAPIFunction · 0.92

Calls 14

ErrorUnexpectedFunction · 0.92
GetLabelFunction · 0.92
DownloadAPISpecFunction · 0.92
ParseInt64LabelFunction · 0.92
GetAPISpecFunction · 0.92
WrapFunction · 0.92
getQueueURLFunction · 0.85
UploadJSONToS3Method · 0.80
getK8sResourcesFunction · 0.70
isAPIUpdatingFunction · 0.70
ErrorAPIUpdatingFunction · 0.70
generateDeploymentIDFunction · 0.70

Tested by

no test coverage detected