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

Adding a script to update etcd objects as per the latest API Version #7819

Merged
merged 1 commit into from
May 16, 2015

Conversation

nikhiljindal
Copy link
Contributor

Fixes #6583

Its a simple script that reads all objects and then writes them back as is to ensure that they are written using the latest API version.

cc @bgrant0607 @smarterclayton @lavalamp

# Read and then write it back as is.
filename="/tmp/${resource}-${instance}.json"
${KUBECTL} get ${resource} ${instance} -o json > $filename
${KUBECTL} update -f $filename
Copy link
Member

Choose a reason for hiding this comment

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

do an update loop-- repeat the get/update if the update fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.
Added a loop of 5 retries.

filename="/tmp/${resource}-${instance}.json"
${KUBECTL} get ${resource} ${instance} -o json > $filename
${KUBECTL} update -f $filename
done
Copy link
Member

Choose a reason for hiding this comment

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

Remove the tmp files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

"pods"
"persistentvolumes"
"persistentvolumeclaims"
"rc"
Copy link
Member

Choose a reason for hiding this comment

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

replicationcontrollers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@nikhiljindal
Copy link
Contributor Author

Thanks for all the comments.
Have updated the code accordingly.
Please have another look.

# TODO: Get this list of resources from server once
# https://github.com/GoogleCloudPlatform/kubernetes/issues/2057 is fixed.
declare -a resources=(
# "endpoints"
Copy link
Member

Choose a reason for hiding this comment

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

Are these commented out intentionally?

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 sorry. Fixed

@nikhiljindal
Copy link
Contributor Author

Updated the code as per comments.

@lavalamp
Copy link
Member

lavalamp commented May 7, 2015

I'm worried about testing-- can we copy/modify test-cmd.sh to make some v1beta1 objects, then restart apiserver, then run this script, then verify that the objects all got converted?

@nikhiljindal
Copy link
Contributor Author

We need the following to add tests:

  • Ability to change the storage version.
  • Ability to change the latest version.
  • Ability to stop supporting v1beta1 api.

Will work on those as separate PRs and then come back and add a test here.

@nikhiljindal nikhiljindal force-pushed the etcdTranslation branch 2 times, most recently from 8487d51 to 9481bcd Compare May 14, 2015 07:36
@nikhiljindal
Copy link
Contributor Author

Have added hack/test-update-etcd-objects.sh to test the update script. It:

  1. Starts a server that supports both the old and new api versions, with the old version being used for storage and creates a pod.
  2. It then restarts the server to support both the old and new api versions, but this time, with the new version being used for storage. It then runs the update script against this server.
  3. It then restarts the server to support only the new version. It then verifies that the server is still able to read the pod.
    Verified that the test fails if step 2 is skipped.

Have made a few other changes to make the test work:

  1. Have added a --runtime_config="api/all=false" flag to kube-apiserver, to disable all api versions. It is useful to enable just one specific api, for example by setting --runtime_config="api/all=false,api/v1beta3=true"
  2. Have added an api/registered package to parse KUBE_API_VERSIONS env var and keep track of the api versions that should be registered. This is required since we want to know the list of versions to register before the APIs are registered. But latest requires the APIs to be registered before its init() is called. Hence, we cant figure out the list of versions to register in latest's init() as we are doing currently.
    Another way to fix this was to make latest's init explicitly call each of the APIs to register themselves, but that seemed like a bigger change not fit for this PR. I can do that in next PR if required.

@nikhiljindal nikhiljindal force-pushed the etcdTranslation branch 2 times, most recently from 36d5cee to 3bd8819 Compare May 14, 2015 20:20
@@ -30,7 +30,6 @@ function cleanup()
[[ -n ${APISERVER_PID-} ]] && kill ${APISERVER_PID} 1>&2 2>/dev/null
[[ -n ${CTLRMGR_PID-} ]] && kill ${CTLRMGR_PID} 1>&2 2>/dev/null
[[ -n ${KUBELET_PID-} ]] && kill ${KUBELET_PID} 1>&2 2>/dev/null
[[ -n ${PROXY_PID-} ]] && kill ${PROXY_PID} 1>&2 2>/dev/null
Copy link
Member

Choose a reason for hiding this comment

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

why this removal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesnt seem to be used anywhere in this script.

UPDATE_ETCD_OBJECTS_SCRIPT="${KUBE_ROOT}/hack/update-etcd-objects.sh"

function startApiServer() {
kube::log::status "Starting kube-apiserver with KUBE_API_VERSIONS: ${KUBE_API_VERSIONS} and runtime_config: ${RUNTIME_CONFIG}"
Copy link
Member

Choose a reason for hiding this comment

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

indentation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

limitations under the License.
*/

// Package to keep track of API Versions that have been registered in api.Scheme.
Copy link
Member

Choose a reason for hiding this comment

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

"should be registered"? This package doesn't actually do the registering, it just records intentions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@nikhiljindal
Copy link
Contributor Author

Updated the code as per comments.
Please have another look.

disableV1beta3 = true
// "api/all=false" allows users to selectively enable specific api versions.
disableAllAPIs := false
allAPIFlagValue, ok := s.RuntimeConfig["api/all"]
Copy link
Member

Choose a reason for hiding this comment

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

I had to go look this thing up. Is it documented anywhere? I would greatly prefer not having magic keys like "api/all" or "api/legacy"; I'd prefer an opt-out or opt-in list, and clarification (in the command line flag help message!) that it determines which api versions are served (as opposed to the other env var which determines which are understood).

I guess you didn't add api/legacy, so let's not touch that one. But can we avoid adding api/all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lavalamp
Copy link
Member

Looking pretty good, I basically just have one last complaint.

@lavalamp
Copy link
Member

LGTM

@lavalamp lavalamp added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 15, 2015
@nikhiljindal
Copy link
Contributor Author

Shippable is green!

lavalamp added a commit that referenced this pull request May 16, 2015
Adding a script to update etcd objects as per the latest API Version
@lavalamp lavalamp merged commit cf33705 into kubernetes:master May 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm "Looks good to me", indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v1beta1->v1beta3 storage translation tool
5 participants