Skip to content
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

Checks to ensure Cluster name unique and required #13798

Merged
merged 2 commits into from Jun 1, 2018

Conversation

prachidamle
Copy link
Member

@prachidamle prachidamle changed the title Checks to ensure Cluster name unique and required WIP: Checks to ensure Cluster name unique and required May 31, 2018
@prachidamle
Copy link
Member Author

@alena1108 review pls.

@prachidamle prachidamle changed the title WIP: Checks to ensure Cluster name unique and required Checks to ensure Cluster name unique and required May 31, 2018

name, ok := data["name"].(string)
if !ok {
return nil, errors.New("Cluster name is required")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prachidamle do we need this extra check? Given that required attribute is already specified as norman annotation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alena1108 yeah we need this check since the API request data is sent in a map and not as the Cluster object, so need to check the field to avoid panics while casting to string

return nil, errors.New("Cluster name is required")
}

r.mu.Lock()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code should be invoked on the update as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the update method

r.mu.Lock()
defer r.mu.Unlock()

var clusters []managementv3.Cluster

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should perhaps extract the code into common method. From line 39 to line 51


func (r *Store) Create(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}) (map[string]interface{}, error) {

name, ok := data["name"].(string)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should extract lines 31-34 into common method

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

clusterName = ""
}

updatedName, ok := data["name"].(string)
Copy link

@alena1108 alena1108 May 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we always expect the name in the update request? does UI send it all the time? if so, may be it's something we can check at the very top of the method, to save on querying the existing cluster if the name is missing. Also it can be extracted to its own method, so the call can replace line 31-34 in create

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah name is always sent in the data[] for the UPdate call, infact all properties are present in the data[]. So to know if name is getting updated, we would have to compare with the existing name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will swap the order of checking cluster name and pulling existing object. But just checking if clusterName is missing need not be a common method.

clusterName = ""
}

updatedName, ok := data["name"].(string)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should use convert library, otherwise there are chances of nil pointer. I believe it's convert.toString()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will check the library!

@alena1108
Copy link

alena1108 commented Jun 1, 2018

LGTM. @prachidamle could you remove this file from the vendor commit; usually binaries should not be included: vendor/github.com/rancher/kontainer-engine/.DS_Store I tried to update vendor to the types fdb95a1ac6c93f633224f165eae9d1ba86977a93, this file doesn't get generated. Once this file is gone, the PR can be merged.

@alena1108 alena1108 merged commit b038c93 into rancher:master Jun 1, 2018
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.

None yet

2 participants