{"action":"created","comment":{"url":"https://api.github.com/repos/openshift/origin/pulls/comments/41622840","id":41622840,"diff_hunk":"@@ -0,0 +1,176 @@\n+package cmd\n+\n+import (\n+\t\"fmt\"\n+\t\"io\"\n+\t\"sort\"\n+\t\"strings\"\n+\n+\t\"github.com/spf13/cobra\"\n+\n+\tkclient \"k8s.io/kubernetes/pkg/client/unversioned\"\n+\t\"k8s.io/kubernetes/pkg/fields\"\n+\tkcmd \"k8s.io/kubernetes/pkg/kubectl/cmd\"\n+\tcmdutil \"k8s.io/kubernetes/pkg/kubectl/cmd/util\"\n+\t\"k8s.io/kubernetes/pkg/labels\"\n+\n+\tbuildapi \"github.com/openshift/origin/pkg/build/api\"\n+\t\"github.com/openshift/origin/pkg/client\"\n+\t\"github.com/openshift/origin/pkg/cmd/util/clientcmd\"\n+)\n+\n+const (\n+\tlogsLong = `\n+Print the logs for a container in a pod\n+\n+If the pod has only one container, the container name is optional.`\n+\n+\tlogsExample = `  # Returns snapshot of ruby-container logs from pod 123456-7890.\n+  $ %[1]s logs 123456-7890 -c ruby-container\n+\n+  # Starts streaming of ruby-container logs from pod 123456-7890.\n+  $ %[1]s logs -f 123456-7890 -c ruby-container`\n+)\n+\n+type OpenShiftLogsOptions struct {\n+\tKubeClient   *kclient.Client\n+\tOriginClient *client.Client\n+\n+\tNamespace      string\n+\tResourceString string\n+\tContainerName  string\n+\tFollow         bool\n+\tInteractive    bool\n+\tPrevious       bool\n+\tOut            io.Writer\n+}\n+\n+// NewCmdLogs creates a new pod log command\n+func NewCmdLogs(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {\n+\to := &OpenShiftLogsOptions{\n+\t\tOut:         out,\n+\t\tInteractive: true,\n+\t}\n+\n+\tcmd := &cobra.Command{\n+\t\tUse:     \"logs [-f] RESOURCE\",\n+\t\tShort:   \"Print the logs for a container in a pod.\",\n+\t\tLong:    logsLong,\n+\t\tExample: fmt.Sprintf(logsExample, fullName),\n+\t\tRun: func(cmd *cobra.Command, args []string) {\n+\t\t\tcmdutil.CheckErr(o.Complete(f, out, cmd, args))\n+\n+\t\t\tcmdutil.CheckErr(o.Validate(cmd))\n+\n+\t\t\tcmdutil.CheckErr(o.RunLog())\n+\t\t},\n+\t\tAliases: []string{\"log\"},\n+\t}\n+\tcmd.Flags().BoolVarP(&o.Follow, \"follow\", \"f\", o.Follow, \"Specify if the logs should be streamed.\")\n+\tcmd.Flags().BoolVar(&o.Interactive, \"interactive\", o.Interactive, \"If true, prompt the user for input when required. Default true.\")\n+\tcmd.Flags().BoolVarP(&o.Previous, \"previous\", \"p\", o.Previous, \"If true, print the logs for the previous instance of the container in a pod if it exists.\")\n+\tcmd.Flags().StringVarP(&o.ContainerName, \"container\", \"c\", o.ContainerName, \"Container name\")\n+\treturn cmd\n+}\n+\n+func (o *OpenShiftLogsOptions) Complete(f *clientcmd.Factory, out io.Writer, cmd *cobra.Command, args []string) error {\n+\tswitch len(args) {\n+\tcase 0:\n+\t\treturn cmdutil.UsageError(cmd, \"RESOURCE is required for log\")\n+\n+\tcase 1:\n+\t\to.ResourceString = args[0]\n+\tcase 2:\n+\t\to.ResourceString = args[0]\n+\t\to.ContainerName = args[1]\n+\n+\tdefault:\n+\t\treturn cmdutil.UsageError(cmd, \"log RESOURCE [CONTAINER]\")\n+\t}\n+\n+\tvar err error\n+\to.Namespace, _, err = f.DefaultNamespace()\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\to.OriginClient, o.KubeClient, err = f.Clients()\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\treturn nil\n+}\n+\n+func (o *OpenShiftLogsOptions) Validate(cmd *cobra.Command) error {","path":"pkg/cmd/cli/cmd/logs.go","position":104,"original_position":104,"commit_id":"567b61ac4aa0bd31725efa55d78ccc1e9670a610","original_commit_id":"567b61ac4aa0bd31725efa55d78ccc1e9670a610","user":{"login":"deads2k","id":8225098,"avatar_url":"https://avatars.githubusercontent.com/u/8225098?v=3","gravatar_id":"","url":"https://api.github.com/users/deads2k","html_url":"https://github.com/deads2k","followers_url":"https://api.github.com/users/deads2k/followers","following_url":"https://api.github.com/users/deads2k/following{/other_user}","gists_url":"https://api.github.com/users/deads2k/gists{/gist_id}","starred_url":"https://api.github.com/users/deads2k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deads2k/subscriptions","organizations_url":"https://api.github.com/users/deads2k/orgs","repos_url":"https://api.github.com/users/deads2k/repos","events_url":"https://api.github.com/users/deads2k/events{/privacy}","received_events_url":"https://api.github.com/users/deads2k/received_events","type":"User","site_admin":false},"body":"> Don't we want to validate anything?\r\n\r\nAdded check for the resource string","created_at":"2015-10-09T12:03:09Z","updated_at":"2015-10-09T12:03:09Z","html_url":"https://github.com/openshift/origin/pull/4997#discussion_r41622840","pull_request_url":"https://api.github.com/repos/openshift/origin/pulls/4997","_links":{"self":{"href":"https://api.github.com/repos/openshift/origin/pulls/comments/41622840"},"html":{"href":"https://github.com/openshift/origin/pull/4997#discussion_r41622840"},"pull_request":{"href":"https://api.github.com/repos/openshift/origin/pulls/4997"}}},"pull_request":{"url":"https://api.github.com/repos/openshift/origin/pulls/4997","id":47056918,"html_url":"https://github.com/openshift/origin/pull/4997","diff_url":"https://github.com/openshift/origin/pull/4997.diff","patch_url":"https://github.com/openshift/origin/pull/4997.patch","issue_url":"https://api.github.com/repos/openshift/origin/issues/4997","number":4997,"state":"open","locked":false,"title":"Make logs work for builds","user":{"login":"deads2k","id":8225098,"avatar_url":"https://avatars.githubusercontent.com/u/8225098?v=3","gravatar_id":"","url":"https://api.github.com/users/deads2k","html_url":"https://github.com/deads2k","followers_url":"https://api.github.com/users/deads2k/followers","following_url":"https://api.github.com/users/deads2k/following{/other_user}","gists_url":"https://api.github.com/users/deads2k/gists{/gist_id}","starred_url":"https://api.github.com/users/deads2k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deads2k/subscriptions","organizations_url":"https://api.github.com/users/deads2k/orgs","repos_url":"https://api.github.com/users/deads2k/repos","events_url":"https://api.github.com/users/deads2k/events{/privacy}","received_events_url":"https://api.github.com/users/deads2k/received_events","type":"User","site_admin":false},"body":"This adds support to `oc logs` to handle buildconfigs and builds.  For a buildconfig, it locates the most recent build for the buildconfig and displays its logs.  I could see an argument for including `--nowait` on `oc logs`, but for now I've hardcoded the default.\r\n\r\nFixes https://github.com/openshift/origin/issues/2659\r\n\r\n@bparees @csrwng @smarterclayton @kargakis Complaints in principle?","created_at":"2015-10-07T17:28:24Z","updated_at":"2015-10-09T12:03:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"31ecb31814346b86ed49c7ef2c3439d2c73d84e5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/openshift/origin/pulls/4997/commits","review_comments_url":"https://api.github.com/repos/openshift/origin/pulls/4997/comments","review_comment_url":"https://api.github.com/repos/openshift/origin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openshift/origin/issues/4997/comments","statuses_url":"https://api.github.com/repos/openshift/origin/statuses/567b61ac4aa0bd31725efa55d78ccc1e9670a610","head":{"label":"deads2k:make-logs-work-for-builds","ref":"make-logs-work-for-builds","sha":"567b61ac4aa0bd31725efa55d78ccc1e9670a610","user":{"login":"deads2k","id":8225098,"avatar_url":"https://avatars.githubusercontent.com/u/8225098?v=3","gravatar_id":"","url":"https://api.github.com/users/deads2k","html_url":"https://github.com/deads2k","followers_url":"https://api.github.com/users/deads2k/followers","following_url":"https://api.github.com/users/deads2k/following{/other_user}","gists_url":"https://api.github.com/users/deads2k/gists{/gist_id}","starred_url":"https://api.github.com/users/deads2k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deads2k/subscriptions","organizations_url":"https://api.github.com/users/deads2k/orgs","repos_url":"https://api.github.com/users/deads2k/repos","events_url":"https://api.github.com/users/deads2k/events{/privacy}","received_events_url":"https://api.github.com/users/deads2k/received_events","type":"User","site_admin":false},"repo":{"id":24424126,"name":"origin","full_name":"deads2k/origin","owner":{"login":"deads2k","id":8225098,"avatar_url":"https://avatars.githubusercontent.com/u/8225098?v=3","gravatar_id":"","url":"https://api.github.com/users/deads2k","html_url":"https://github.com/deads2k","followers_url":"https://api.github.com/users/deads2k/followers","following_url":"https://api.github.com/users/deads2k/following{/other_user}","gists_url":"https://api.github.com/users/deads2k/gists{/gist_id}","starred_url":"https://api.github.com/users/deads2k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deads2k/subscriptions","organizations_url":"https://api.github.com/users/deads2k/orgs","repos_url":"https://api.github.com/users/deads2k/repos","events_url":"https://api.github.com/users/deads2k/events{/privacy}","received_events_url":"https://api.github.com/users/deads2k/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/deads2k/origin","description":"OpenShift 3 - build, deploy, and manage your applications with Docker and Kubernetes","fork":true,"url":"https://api.github.com/repos/deads2k/origin","forks_url":"https://api.github.com/repos/deads2k/origin/forks","keys_url":"https://api.github.com/repos/deads2k/origin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/deads2k/origin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/deads2k/origin/teams","hooks_url":"https://api.github.com/repos/deads2k/origin/hooks","issue_events_url":"https://api.github.com/repos/deads2k/origin/issues/events{/number}","events_url":"https://api.github.com/repos/deads2k/origin/events","assignees_url":"https://api.github.com/repos/deads2k/origin/assignees{/user}","branches_url":"https://api.github.com/repos/deads2k/origin/branches{/branch}","tags_url":"https://api.github.com/repos/deads2k/origin/tags","blobs_url":"https://api.github.com/repos/deads2k/origin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/deads2k/origin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/deads2k/origin/git/refs{/sha}","trees_url":"https://api.github.com/repos/deads2k/origin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/deads2k/origin/statuses/{sha}","languages_url":"https://api.github.com/repos/deads2k/origin/languages","stargazers_url":"https://api.github.com/repos/deads2k/origin/stargazers","contributors_url":"https://api.github.com/repos/deads2k/origin/contributors","subscribers_url":"https://api.github.com/repos/deads2k/origin/subscribers","subscription_url":"https://api.github.com/repos/deads2k/origin/subscription","commits_url":"https://api.github.com/repos/deads2k/origin/commits{/sha}","git_commits_url":"https://api.github.com/repos/deads2k/origin/git/commits{/sha}","comments_url":"https://api.github.com/repos/deads2k/origin/comments{/number}","issue_comment_url":"https://api.github.com/repos/deads2k/origin/issues/comments{/number}","contents_url":"https://api.github.com/repos/deads2k/origin/contents/{+path}","compare_url":"https://api.github.com/repos/deads2k/origin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/deads2k/origin/merges","archive_url":"https://api.github.com/repos/deads2k/origin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/deads2k/origin/downloads","issues_url":"https://api.github.com/repos/deads2k/origin/issues{/number}","pulls_url":"https://api.github.com/repos/deads2k/origin/pulls{/number}","milestones_url":"https://api.github.com/repos/deads2k/origin/milestones{/number}","notifications_url":"https://api.github.com/repos/deads2k/origin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/deads2k/origin/labels{/name}","releases_url":"https://api.github.com/repos/deads2k/origin/releases{/id}","created_at":"2014-09-24T17:02:12Z","updated_at":"2015-05-08T15:45:28Z","pushed_at":"2015-10-09T11:49:46Z","git_url":"git://github.com/deads2k/origin.git","ssh_url":"git@github.com:deads2k/origin.git","clone_url":"https://github.com/deads2k/origin.git","svn_url":"https://github.com/deads2k/origin","homepage":"https://openshift.github.io","size":148554,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"openshift:master","ref":"master","sha":"daf351a13a993768a9933f074d0ad69a100f1831","user":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"repo":{"id":22442668,"name":"origin","full_name":"openshift/origin","owner":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openshift/origin","description":"OpenShift 3 - build, deploy, and manage your applications with Docker and Kubernetes","fork":false,"url":"https://api.github.com/repos/openshift/origin","forks_url":"https://api.github.com/repos/openshift/origin/forks","keys_url":"https://api.github.com/repos/openshift/origin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openshift/origin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openshift/origin/teams","hooks_url":"https://api.github.com/repos/openshift/origin/hooks","issue_events_url":"https://api.github.com/repos/openshift/origin/issues/events{/number}","events_url":"https://api.github.com/repos/openshift/origin/events","assignees_url":"https://api.github.com/repos/openshift/origin/assignees{/user}","branches_url":"https://api.github.com/repos/openshift/origin/branches{/branch}","tags_url":"https://api.github.com/repos/openshift/origin/tags","blobs_url":"https://api.github.com/repos/openshift/origin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openshift/origin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openshift/origin/git/refs{/sha}","trees_url":"https://api.github.com/repos/openshift/origin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openshift/origin/statuses/{sha}","languages_url":"https://api.github.com/repos/openshift/origin/languages","stargazers_url":"https://api.github.com/repos/openshift/origin/stargazers","contributors_url":"https://api.github.com/repos/openshift/origin/contributors","subscribers_url":"https://api.github.com/repos/openshift/origin/subscribers","subscription_url":"https://api.github.com/repos/openshift/origin/subscription","commits_url":"https://api.github.com/repos/openshift/origin/commits{/sha}","git_commits_url":"https://api.github.com/repos/openshift/origin/git/commits{/sha}","comments_url":"https://api.github.com/repos/openshift/origin/comments{/number}","issue_comment_url":"https://api.github.com/repos/openshift/origin/issues/comments{/number}","contents_url":"https://api.github.com/repos/openshift/origin/contents/{+path}","compare_url":"https://api.github.com/repos/openshift/origin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openshift/origin/merges","archive_url":"https://api.github.com/repos/openshift/origin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openshift/origin/downloads","issues_url":"https://api.github.com/repos/openshift/origin/issues{/number}","pulls_url":"https://api.github.com/repos/openshift/origin/pulls{/number}","milestones_url":"https://api.github.com/repos/openshift/origin/milestones{/number}","notifications_url":"https://api.github.com/repos/openshift/origin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openshift/origin/labels{/name}","releases_url":"https://api.github.com/repos/openshift/origin/releases{/id}","created_at":"2014-07-30T20:04:05Z","updated_at":"2015-10-08T12:54:37Z","pushed_at":"2015-10-09T11:39:58Z","git_url":"git://github.com/openshift/origin.git","ssh_url":"git@github.com:openshift/origin.git","clone_url":"https://github.com/openshift/origin.git","svn_url":"https://github.com/openshift/origin","homepage":"http://www.openshift.org","size":237518,"stargazers_count":725,"watchers_count":725,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":443,"mirror_url":null,"open_issues_count":573,"forks":443,"open_issues":573,"watchers":725,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openshift/origin/pulls/4997"},"html":{"href":"https://github.com/openshift/origin/pull/4997"},"issue":{"href":"https://api.github.com/repos/openshift/origin/issues/4997"},"comments":{"href":"https://api.github.com/repos/openshift/origin/issues/4997/comments"},"review_comments":{"href":"https://api.github.com/repos/openshift/origin/pulls/4997/comments"},"review_comment":{"href":"https://api.github.com/repos/openshift/origin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openshift/origin/pulls/4997/commits"},"statuses":{"href":"https://api.github.com/repos/openshift/origin/statuses/567b61ac4aa0bd31725efa55d78ccc1e9670a610"}}}}