(apiName string, force bool)
| 153 | } |
| 154 | |
| 155 | func 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 | |
| 205 | func DeleteAPI(apiName string, keepCache bool) error { |
| 206 | err := parallel.RunFirstErr( |
no test coverage detected