{"action":"created","comment":{"url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments/49806296","id":49806296,"diff_hunk":"@@ -0,0 +1,136 @@\n+/*\n+Copyright 2015 The Kubernetes Authors All rights reserved.\n+\n+Licensed under the Apache License, Version 2.0 (the \"License\");\n+you may not use this file except in compliance with the License.\n+You may obtain a copy of the License at\n+\n+    http://www.apache.org/licenses/LICENSE-2.0\n+\n+Unless required by applicable law or agreed to in writing, software\n+distributed under the License is distributed on an \"AS IS\" BASIS,\n+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+See the License for the specific language governing permissions and\n+limitations under the License.\n+*/\n+\n+package container\n+\n+import (\n+\t\"errors\"\n+\t\"fmt\"\n+\n+\tutilerrors \"k8s.io/kubernetes/pkg/util/errors\"\n+)\n+\n+// TODO(random-liu): We need better organize runtime errors for introspection.\n+\n+// Container Terminated and Kubelet is backing off the restart\n+var ErrCrashLoopBackOff = errors.New(\"CrashLoopBackOff\")\n+\n+var (\n+\t// Container image pull failed, kubelet is backing off image pull\n+\tErrImagePullBackOff = errors.New(\"ImagePullBackOff\")\n+\n+\t// Unable to inspect image\n+\tErrImageInspect = errors.New(\"ImageInspectError\")\n+\n+\t// General image pull error\n+\tErrImagePull = errors.New(\"ErrImagePull\")\n+\n+\t// Required Image is absent on host and PullPolicy is NeverPullImage\n+\tErrImageNeverPull = errors.New(\"ErrImageNeverPull\")\n+\n+\t// ErrContainerNotFound returned when a container in the given pod with the\n+\t// given container name was not found, amongst those managed by the kubelet.\n+\tErrContainerNotFound = errors.New(\"no matching container\")\n+\n+\t// Get http error when pulling image from registry\n+\tRegistryUnavailable = errors.New(\"RegistryUnavailable\")\n+)\n+\n+var (\n+\tErrRunContainer  = errors.New(\"RunContainerError\")\n+\tErrKillContainer = errors.New(\"KillContainerError\")\n+\tErrVerifyNonRoot = errors.New(\"VerifyNonRootError\")","path":"pkg/kubelet/container/sync_result.go","position":55,"original_position":55,"commit_id":"ef825ec651d1efe3fa47a56cfd2e1423f674c7ce","original_commit_id":"ef825ec651d1efe3fa47a56cfd2e1423f674c7ce","user":{"login":"yujuhong","id":10524058,"avatar_url":"https://avatars.githubusercontent.com/u/10524058?v=3","gravatar_id":"","url":"https://api.github.com/users/yujuhong","html_url":"https://github.com/yujuhong","followers_url":"https://api.github.com/users/yujuhong/followers","following_url":"https://api.github.com/users/yujuhong/following{/other_user}","gists_url":"https://api.github.com/users/yujuhong/gists{/gist_id}","starred_url":"https://api.github.com/users/yujuhong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yujuhong/subscriptions","organizations_url":"https://api.github.com/users/yujuhong/orgs","repos_url":"https://api.github.com/users/yujuhong/repos","events_url":"https://api.github.com/users/yujuhong/events{/privacy}","received_events_url":"https://api.github.com/users/yujuhong/received_events","type":"User","site_admin":false},"body":"Not relevant to this PR, but if we want to use these errors, maybe we should create custom a custom error type that stores the error key and the reason. Returning an error and a reason is a pain.","created_at":"2016-01-15T00:17:43Z","updated_at":"2016-01-15T00:17:43Z","html_url":"https://github.com/kubernetes/kubernetes/pull/18172#discussion_r49806296","pull_request_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/18172","_links":{"self":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments/49806296"},"html":{"href":"https://github.com/kubernetes/kubernetes/pull/18172#discussion_r49806296"},"pull_request":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/18172"}}},"pull_request":{"url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/18172","id":52598405,"html_url":"https://github.com/kubernetes/kubernetes/pull/18172","diff_url":"https://github.com/kubernetes/kubernetes/pull/18172.diff","patch_url":"https://github.com/kubernetes/kubernetes/pull/18172.patch","issue_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/18172","number":18172,"state":"open","locked":false,"title":"Generate SyncPod Result","user":{"login":"Random-Liu","id":5821883,"avatar_url":"https://avatars.githubusercontent.com/u/5821883?v=3","gravatar_id":"","url":"https://api.github.com/users/Random-Liu","html_url":"https://github.com/Random-Liu","followers_url":"https://api.github.com/users/Random-Liu/followers","following_url":"https://api.github.com/users/Random-Liu/following{/other_user}","gists_url":"https://api.github.com/users/Random-Liu/gists{/gist_id}","starred_url":"https://api.github.com/users/Random-Liu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Random-Liu/subscriptions","organizations_url":"https://api.github.com/users/Random-Liu/orgs","repos_url":"https://api.github.com/users/Random-Liu/repos","events_url":"https://api.github.com/users/Random-Liu/events{/privacy}","received_events_url":"https://api.github.com/users/Random-Liu/received_events","type":"User","site_admin":false},"body":"This PR based on #17420, only the last commit is new.\r\n\r\nIn this PR, I added `PodSyncEvent` and `ContainerSyncEvent`, and let `SyncPod()` return the expected events after the pod is changed.\r\n```go\r\n// (random-liu) This is just a temporary function, will be replace SyncPod() when we acturally add PodSyncEvent\r\nfunc (dm *DockerManager) syncPodWithSyncEvent(pod *api.Pod, _ kubecontainer.Pod, _ api.PodStatus, podStatus *kubecontainer.PodStatus, pullSecrets []api.Secret, backOff *util.Backoff) (error, PodSyncEvent) {\r\n```\r\n\r\nWhy we add expected events?\r\n* **Remove `GetAPIPodStatus()` from runtime interface, and move reason cache to Kubelet level.** In `dockertools`, when we failed to start a container, we want to note down the error reason and message, and set the `ContainerState` to `Waiting` with these reasons in `GetAPIPodStatus()`. So we added the reason cache before. However, now we plan to remove `GetAPIPodStatus()` from runtime interface, which means that we want to generate `api.PodStatus` directly from `PodStatus` at the Kubelet level. So we have to move the reason cache related logic up to Kubelet level. For this reason, `SyncPod()` should return the container failed to be restarted in this turn.\r\n* **Add event stream support.** We plan to support runtime event stream in the future, such as docker event stream. But in case of missing event, we still have to do `relist` periodically. If `SyncPod()` returns the expected events after the pod is changed, it will not be a black box for Kubelet any more. That will help Kubelet decide when to do `relist`.\r\n\r\nHowever, the problem now is how to define the \"Expected Event\". In this PR, I assume the only two things `SyncPod()` does are **\"Start Container\"** and **\"Kill Container\"**. Whatever error happens during starting or killing container such as pulling image error, network error etc. will be saved into Error and ErrorMessage fields.\r\nSo the `ContainerSyncEvent` looks like:\r\n``` go\r\ntype ContainerSyncEvent struct {\r\n  // The name of the changed container\r\n  Name string\r\n  // The expected event. Now there should be only pleg.ContainerStarted and pleg.ContainerDied\r\n  //   * pleg.ContainerStarted means that the container is tried to be started in SyncPod()\r\n  //   * pleg.ContainerDied means that the container is tried to be killed in SyncPod()\r\n  Event pleg.PodLifeCycleEventType\r\n  // The result of the action which should trigger the expected event\r\n  // The brief error reason of the action\r\n  Error error\r\n  // The detailed error message of the action\r\n  ErrorMessage string\r\n}\r\n```\r\n\r\nFor now, this definition works well for docker, but I'm not sure whether it is proper design and sufficient enough. Especially for other runtimes like **rkt** and **hyper** which work at pod level.\r\n\r\nAny thoughts? Or is this enough? @kubernetes/goog-node @yifan-gu @feiskyer \r\n\r\nAlso related to  #18302, #12826","created_at":"2015-12-03T21:54:35Z","updated_at":"2016-01-15T00:17:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5c06656c8949f144b0559781ceb28ac4a54257ea","assignee":{"login":"yujuhong","id":10524058,"avatar_url":"https://avatars.githubusercontent.com/u/10524058?v=3","gravatar_id":"","url":"https://api.github.com/users/yujuhong","html_url":"https://github.com/yujuhong","followers_url":"https://api.github.com/users/yujuhong/followers","following_url":"https://api.github.com/users/yujuhong/following{/other_user}","gists_url":"https://api.github.com/users/yujuhong/gists{/gist_id}","starred_url":"https://api.github.com/users/yujuhong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yujuhong/subscriptions","organizations_url":"https://api.github.com/users/yujuhong/orgs","repos_url":"https://api.github.com/users/yujuhong/repos","events_url":"https://api.github.com/users/yujuhong/events{/privacy}","received_events_url":"https://api.github.com/users/yujuhong/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/18172/commits","review_comments_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/18172/comments","review_comment_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/18172/comments","statuses_url":"https://api.github.com/repos/kubernetes/kubernetes/statuses/ef825ec651d1efe3fa47a56cfd2e1423f674c7ce","head":{"label":"Random-Liu:generate-sync-event","ref":"generate-sync-event","sha":"ef825ec651d1efe3fa47a56cfd2e1423f674c7ce","user":{"login":"Random-Liu","id":5821883,"avatar_url":"https://avatars.githubusercontent.com/u/5821883?v=3","gravatar_id":"","url":"https://api.github.com/users/Random-Liu","html_url":"https://github.com/Random-Liu","followers_url":"https://api.github.com/users/Random-Liu/followers","following_url":"https://api.github.com/users/Random-Liu/following{/other_user}","gists_url":"https://api.github.com/users/Random-Liu/gists{/gist_id}","starred_url":"https://api.github.com/users/Random-Liu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Random-Liu/subscriptions","organizations_url":"https://api.github.com/users/Random-Liu/orgs","repos_url":"https://api.github.com/users/Random-Liu/repos","events_url":"https://api.github.com/users/Random-Liu/events{/privacy}","received_events_url":"https://api.github.com/users/Random-Liu/received_events","type":"User","site_admin":false},"repo":{"id":44042241,"name":"kubernetes","full_name":"Random-Liu/kubernetes","owner":{"login":"Random-Liu","id":5821883,"avatar_url":"https://avatars.githubusercontent.com/u/5821883?v=3","gravatar_id":"","url":"https://api.github.com/users/Random-Liu","html_url":"https://github.com/Random-Liu","followers_url":"https://api.github.com/users/Random-Liu/followers","following_url":"https://api.github.com/users/Random-Liu/following{/other_user}","gists_url":"https://api.github.com/users/Random-Liu/gists{/gist_id}","starred_url":"https://api.github.com/users/Random-Liu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Random-Liu/subscriptions","organizations_url":"https://api.github.com/users/Random-Liu/orgs","repos_url":"https://api.github.com/users/Random-Liu/repos","events_url":"https://api.github.com/users/Random-Liu/events{/privacy}","received_events_url":"https://api.github.com/users/Random-Liu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Random-Liu/kubernetes","description":"Container Cluster Manager from Google","fork":true,"url":"https://api.github.com/repos/Random-Liu/kubernetes","forks_url":"https://api.github.com/repos/Random-Liu/kubernetes/forks","keys_url":"https://api.github.com/repos/Random-Liu/kubernetes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Random-Liu/kubernetes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Random-Liu/kubernetes/teams","hooks_url":"https://api.github.com/repos/Random-Liu/kubernetes/hooks","issue_events_url":"https://api.github.com/repos/Random-Liu/kubernetes/issues/events{/number}","events_url":"https://api.github.com/repos/Random-Liu/kubernetes/events","assignees_url":"https://api.github.com/repos/Random-Liu/kubernetes/assignees{/user}","branches_url":"https://api.github.com/repos/Random-Liu/kubernetes/branches{/branch}","tags_url":"https://api.github.com/repos/Random-Liu/kubernetes/tags","blobs_url":"https://api.github.com/repos/Random-Liu/kubernetes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Random-Liu/kubernetes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Random-Liu/kubernetes/git/refs{/sha}","trees_url":"https://api.github.com/repos/Random-Liu/kubernetes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Random-Liu/kubernetes/statuses/{sha}","languages_url":"https://api.github.com/repos/Random-Liu/kubernetes/languages","stargazers_url":"https://api.github.com/repos/Random-Liu/kubernetes/stargazers","contributors_url":"https://api.github.com/repos/Random-Liu/kubernetes/contributors","subscribers_url":"https://api.github.com/repos/Random-Liu/kubernetes/subscribers","subscription_url":"https://api.github.com/repos/Random-Liu/kubernetes/subscription","commits_url":"https://api.github.com/repos/Random-Liu/kubernetes/commits{/sha}","git_commits_url":"https://api.github.com/repos/Random-Liu/kubernetes/git/commits{/sha}","comments_url":"https://api.github.com/repos/Random-Liu/kubernetes/comments{/number}","issue_comment_url":"https://api.github.com/repos/Random-Liu/kubernetes/issues/comments{/number}","contents_url":"https://api.github.com/repos/Random-Liu/kubernetes/contents/{+path}","compare_url":"https://api.github.com/repos/Random-Liu/kubernetes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Random-Liu/kubernetes/merges","archive_url":"https://api.github.com/repos/Random-Liu/kubernetes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Random-Liu/kubernetes/downloads","issues_url":"https://api.github.com/repos/Random-Liu/kubernetes/issues{/number}","pulls_url":"https://api.github.com/repos/Random-Liu/kubernetes/pulls{/number}","milestones_url":"https://api.github.com/repos/Random-Liu/kubernetes/milestones{/number}","notifications_url":"https://api.github.com/repos/Random-Liu/kubernetes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Random-Liu/kubernetes/labels{/name}","releases_url":"https://api.github.com/repos/Random-Liu/kubernetes/releases{/id}","created_at":"2015-10-11T06:51:00Z","updated_at":"2015-10-11T06:51:16Z","pushed_at":"2016-01-14T22:31:46Z","git_url":"git://github.com/Random-Liu/kubernetes.git","ssh_url":"git@github.com:Random-Liu/kubernetes.git","clone_url":"https://github.com/Random-Liu/kubernetes.git","svn_url":"https://github.com/Random-Liu/kubernetes","homepage":"http://kubernetes.io","size":148476,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"kubernetes:master","ref":"master","sha":"c059dfdb9bf05fc3dec96243b6101cf84f2db4ef","user":{"login":"kubernetes","id":13629408,"avatar_url":"https://avatars.githubusercontent.com/u/13629408?v=3","gravatar_id":"","url":"https://api.github.com/users/kubernetes","html_url":"https://github.com/kubernetes","followers_url":"https://api.github.com/users/kubernetes/followers","following_url":"https://api.github.com/users/kubernetes/following{/other_user}","gists_url":"https://api.github.com/users/kubernetes/gists{/gist_id}","starred_url":"https://api.github.com/users/kubernetes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kubernetes/subscriptions","organizations_url":"https://api.github.com/users/kubernetes/orgs","repos_url":"https://api.github.com/users/kubernetes/repos","events_url":"https://api.github.com/users/kubernetes/events{/privacy}","received_events_url":"https://api.github.com/users/kubernetes/received_events","type":"Organization","site_admin":false},"repo":{"id":20580498,"name":"kubernetes","full_name":"kubernetes/kubernetes","owner":{"login":"kubernetes","id":13629408,"avatar_url":"https://avatars.githubusercontent.com/u/13629408?v=3","gravatar_id":"","url":"https://api.github.com/users/kubernetes","html_url":"https://github.com/kubernetes","followers_url":"https://api.github.com/users/kubernetes/followers","following_url":"https://api.github.com/users/kubernetes/following{/other_user}","gists_url":"https://api.github.com/users/kubernetes/gists{/gist_id}","starred_url":"https://api.github.com/users/kubernetes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kubernetes/subscriptions","organizations_url":"https://api.github.com/users/kubernetes/orgs","repos_url":"https://api.github.com/users/kubernetes/repos","events_url":"https://api.github.com/users/kubernetes/events{/privacy}","received_events_url":"https://api.github.com/users/kubernetes/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/kubernetes/kubernetes","description":"Container Cluster Manager from Google","fork":false,"url":"https://api.github.com/repos/kubernetes/kubernetes","forks_url":"https://api.github.com/repos/kubernetes/kubernetes/forks","keys_url":"https://api.github.com/repos/kubernetes/kubernetes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kubernetes/kubernetes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kubernetes/kubernetes/teams","hooks_url":"https://api.github.com/repos/kubernetes/kubernetes/hooks","issue_events_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/events{/number}","events_url":"https://api.github.com/repos/kubernetes/kubernetes/events","assignees_url":"https://api.github.com/repos/kubernetes/kubernetes/assignees{/user}","branches_url":"https://api.github.com/repos/kubernetes/kubernetes/branches{/branch}","tags_url":"https://api.github.com/repos/kubernetes/kubernetes/tags","blobs_url":"https://api.github.com/repos/kubernetes/kubernetes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kubernetes/kubernetes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kubernetes/kubernetes/git/refs{/sha}","trees_url":"https://api.github.com/repos/kubernetes/kubernetes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kubernetes/kubernetes/statuses/{sha}","languages_url":"https://api.github.com/repos/kubernetes/kubernetes/languages","stargazers_url":"https://api.github.com/repos/kubernetes/kubernetes/stargazers","contributors_url":"https://api.github.com/repos/kubernetes/kubernetes/contributors","subscribers_url":"https://api.github.com/repos/kubernetes/kubernetes/subscribers","subscription_url":"https://api.github.com/repos/kubernetes/kubernetes/subscription","commits_url":"https://api.github.com/repos/kubernetes/kubernetes/commits{/sha}","git_commits_url":"https://api.github.com/repos/kubernetes/kubernetes/git/commits{/sha}","comments_url":"https://api.github.com/repos/kubernetes/kubernetes/comments{/number}","issue_comment_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/comments{/number}","contents_url":"https://api.github.com/repos/kubernetes/kubernetes/contents/{+path}","compare_url":"https://api.github.com/repos/kubernetes/kubernetes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kubernetes/kubernetes/merges","archive_url":"https://api.github.com/repos/kubernetes/kubernetes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kubernetes/kubernetes/downloads","issues_url":"https://api.github.com/repos/kubernetes/kubernetes/issues{/number}","pulls_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls{/number}","milestones_url":"https://api.github.com/repos/kubernetes/kubernetes/milestones{/number}","notifications_url":"https://api.github.com/repos/kubernetes/kubernetes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kubernetes/kubernetes/labels{/name}","releases_url":"https://api.github.com/repos/kubernetes/kubernetes/releases{/id}","created_at":"2014-06-06T22:56:04Z","updated_at":"2016-01-14T23:06:09Z","pushed_at":"2016-01-15T00:16:00Z","git_url":"git://github.com/kubernetes/kubernetes.git","ssh_url":"git@github.com:kubernetes/kubernetes.git","clone_url":"https://github.com/kubernetes/kubernetes.git","svn_url":"https://github.com/kubernetes/kubernetes","homepage":"http://kubernetes.io","size":304725,"stargazers_count":12138,"watchers_count":12138,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":3410,"mirror_url":null,"open_issues_count":2779,"forks":3410,"open_issues":2779,"watchers":12138,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/18172"},"html":{"href":"https://github.com/kubernetes/kubernetes/pull/18172"},"issue":{"href":"https://api.github.com/repos/kubernetes/kubernetes/issues/18172"},"comments":{"href":"https://api.github.com/repos/kubernetes/kubernetes/issues/18172/comments"},"review_comments":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/18172/comments"},"review_comment":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/18172/commits"},"statuses":{"href":"https://api.github.com/repos/kubernetes/kubernetes/statuses/ef825ec651d1efe3fa47a56cfd2e1423f674c7ce"}}}}