Skip to content

Fix some errors be ignored #2290

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 1 commit into from
Apr 17, 2023
Merged

Conversation

drivebyer
Copy link
Contributor

@drivebyer drivebyer commented Apr 17, 2023

In Create() function, some errors not been check. It will cause cluster status to unexpected.

For example:

if c.Endpoints[role] != nil {
return fmt.Errorf("%s endpoint already exists in the cluster", role)
}

@FxKu
Copy link
Member

FxKu commented Apr 17, 2023

I don't get what this code change improves? Can you explain in a bit more detail? I've had a quick look at the Create() code and it looked fine to me.

@drivebyer
Copy link
Contributor Author

I don't get what this code change improves? Can you explain in a bit more detail? I've had a quick look at the Create() code and it looked fine to me.

Such as following code in Create():

if c.Services[role] != nil {
return fmt.Errorf("service already exists in the cluster")
}

If c.Services[role] != nil. There error will not be assigned to err variable. So it will go to first branch in following defer:

defer func() {
if err == nil {
c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusRunning) //TODO: are you sure it's running?
} else {
c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusAddFailed)
}
}()

Actually, we should go to second branch.

Here is example code:
https://go.dev/play/p/BEi5R6GATfG

@FxKu
Copy link
Member

FxKu commented Apr 17, 2023

Ah, there's a defer block. Now I got it. Thanks!

@FxKu
Copy link
Member

FxKu commented Apr 17, 2023

👍

@FxKu FxKu added this to the 1.9.1 milestone Apr 17, 2023
@jopadi
Copy link
Member

jopadi commented Apr 17, 2023

👍

@FxKu FxKu merged commit 1e64ae7 into zalando:master Apr 17, 2023
@drivebyer drivebyer deleted the fix_cluster_status branch April 18, 2023 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants