Skip to content

Commit 09cb875

Browse files
committed
Simplify UpdateAPI()
1 parent 15f1a82 commit 09cb875

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

pkg/operator/operator/api.go

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ func UpdateAPI(
5454

5555
api := getAPISpec(apiConfig, projectID, deploymentID)
5656

57-
var msg string
58-
5957
if prevDeployment == nil {
6058
err = config.AWS.UploadMsgpackToS3(api, *config.Cluster.Bucket, api.Key)
6159
if err != nil {
@@ -65,9 +63,10 @@ func UpdateAPI(
6563
go deleteK8sResources(api.Name)
6664
return nil, "", err
6765
}
68-
msg = fmt.Sprintf("creating %s api", api.Name)
66+
return api, fmt.Sprintf("creating %s api", api.Name), nil
67+
}
6968

70-
} else if !areDeploymentsEqual(prevDeployment, deploymentSpec(api, prevDeployment)) {
69+
if !areDeploymentsEqual(prevDeployment, deploymentSpec(api, prevDeployment)) {
7170
isUpdating, err := isAPIUpdating(prevDeployment)
7271
if err != nil {
7372
return nil, "", err
@@ -82,21 +81,18 @@ func UpdateAPI(
8281
if err = applyK8sResources(api, prevDeployment, prevService, prevVirtualService); err != nil {
8382
return nil, "", err
8483
}
85-
msg = fmt.Sprintf("updating %s api", api.Name)
86-
87-
} else { // deployment didn't change
88-
isUpdating, err := isAPIUpdating(prevDeployment)
89-
if err != nil {
90-
return nil, "", err
91-
}
92-
if isUpdating {
93-
msg = fmt.Sprintf("%s api is already updating", api.Name)
94-
} else {
95-
msg = fmt.Sprintf("%s api is up to date", api.Name)
96-
}
84+
return api, fmt.Sprintf("updating %s api", api.Name), nil
9785
}
9886

99-
return api, msg, nil
87+
// deployment didn't change
88+
isUpdating, err := isAPIUpdating(prevDeployment)
89+
if err != nil {
90+
return nil, "", err
91+
}
92+
if isUpdating {
93+
return api, fmt.Sprintf("%s api is already updating", api.Name), nil
94+
}
95+
return api, fmt.Sprintf("%s api is up to date", api.Name), nil
10096
}
10197

10298
func RefreshAPI(apiName string, force bool) (string, error) {

0 commit comments

Comments
 (0)