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

Fix the etcd version check and have it return the version string. #4991

Merged
merged 1 commit into from
Mar 4, 2015

Conversation

fabioy
Copy link
Contributor

@fabioy fabioy commented Mar 3, 2015

Also make the "CheckEtcd" call package public.

return fmt.Errorf("unknown server: %s", string(body))

var dat map[string]interface{}
if err := json.Unmarshal(body, &dat); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Are we now requiring etcd version >= 2.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No explicit version check yet, but this code will enable it. The previous version was just broken. It seems at some point etcd started returning a simple JSON version object for the version request.

Copy link
Member

Choose a reason for hiding this comment

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

This unmarshall will return an error with etcd v0.4.6 where /version still returns etcd 0.4.6 so this is essentially a > 0.4.6 minimum version check. Is that a concern? The transition may have happened at etcd v2.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't be a concern with the current usage of this code (see NewEtcdClientStartServerIfNecessary below). But, could be an issue if other start relying on this code for a true version check.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good.

}
return nil
return dat["releaseVersion"].(string), dat["internalVersion"].(string), err
Copy link
Member

Choose a reason for hiding this comment

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

You should protect these type assertions; a function to check if etcd is OK shouldn't be able to crash on bad input.

@@ -418,20 +418,24 @@ func (h *EtcdHelper) AtomicUpdate(key string, ptrToType runtime.Object, ignoreNo
}
}

func checkEtcd(host string) error {
// Performs a version check against the provided Etcd server, returning a triplet
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment should start with the name of the function, e.g. "CheckEtcd performs ..."

@fabioy fabioy force-pushed the etcdcheck-fix branch 2 times, most recently from 04ec9d4 to d6bf1c8 Compare March 3, 2015 21:36
}
return nil
if dat["releaseVersion"] != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the code to be resilient to missing attributes.

Copy link
Member

Choose a reason for hiding this comment

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

this is still not safe.

if obj := dat["internalVersion"]; obj != nil {
  if s, ok := obj.(string); ok {
    // do stuff with s
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the context of this code, the original version should be safe (I think, since it's unmarshalling a json). But to be extra safe, made the changes.

Copy link
Member

Choose a reason for hiding this comment

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

You could have ended up with an int, or a map[string]interface{} on unexpected input.

@lavalamp
Copy link
Member

lavalamp commented Mar 4, 2015

LGTM

lavalamp added a commit that referenced this pull request Mar 4, 2015
Fix the etcd version check and have it return the version string.
@lavalamp lavalamp merged commit 4e7bcca into kubernetes:master Mar 4, 2015
@fabioy fabioy deleted the etcdcheck-fix branch March 5, 2015 01:29
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.

5 participants