{"action":"created","comment":{"url":"https://api.github.com/repos/openshift/origin/pulls/comments/31893805","id":31893805,"diff_hunk":"@@ -0,0 +1,167 @@\n+package cmd\n+\n+import (\n+\t\"fmt\"\n+\t\"io\"\n+\t\"os\"\n+\n+\t\"github.com/spf13/cobra\"\n+\n+\tkapi \"github.com/GoogleCloudPlatform/kubernetes/pkg/api\"\n+\t\"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl\"\n+\tcmdutil \"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util\"\n+\t\"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/resource\"\n+\t\"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime\"\n+\t\"github.com/GoogleCloudPlatform/kubernetes/pkg/util\"\n+\tutilerrors \"github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors\"\n+\n+\t\"github.com/openshift/origin/pkg/cmd/util/clientcmd\"\n+\ttemplateapi \"github.com/openshift/origin/pkg/template/api\"\n+)\n+\n+const (\n+\texportLong = `Export resources so they can be used elsewhere\n+\n+The export command makes it easy to take existing objects and convert them to configuration files\n+for backups or for creating elsewhere in the cluster. Fields that cannot be specified on create\n+will be set to empty, and any field which is assigned on creation (like a service's clusterIP, or\n+a deployment config's latestVersion). The status part of objects is also cleared.\n+\n+Some fields like clusterIP may be useful when exporting an application from one cluster to apply\n+to another - assuming another service on the destination cluster does not already use that IP.\n+The --exact flag will instruct export to not clear fields that might be useful. You may also use\n+--raw to get the exact values for an object - useful for converting a file on disk between API\n+versions.\n+\n+Another use case for export is to create reusable templates for applications. Pass --as-template\n+to generate the API structure for a template to which you can add parameters and object labels.`\n+\n+\texportExample = `  // export the services and deployment configurations labeled name=test\n+  %[1]s export svc,dc -l name=test\n+\n+  // export all services to a template\n+  %[1]s export service --all --as-template\n+\n+  // convert a file on disk to the latest API version\n+  %[1]s export -f a_v1beta3_service.json --output-version=v1 --exact`\n+)\n+\n+func NewCmdExport(fullName string, f *clientcmd.Factory, in io.Reader, out io.Writer) *cobra.Command {\n+\texporter := &defaultExporter{}\n+\tvar filenames util.StringList\n+\tcmd := &cobra.Command{\n+\t\tUse:     \"export RESOURCE/NAME ... [options]\",\n+\t\tShort:   \"Export resources so they can be used elsewhere\",\n+\t\tLong:    exportLong,\n+\t\tExample: fmt.Sprintf(exportExample, fullName),\n+\t\tRun: func(cmd *cobra.Command, args []string) {\n+\t\t\terr := RunExport(f, exporter, in, out, cmd, args, filenames)\n+\t\t\tif err == errExit {\n+\t\t\t\tos.Exit(1)\n+\t\t\t}\n+\t\t\tcmdutil.CheckErr(err)\n+\t\t},\n+\t}\n+\tcmd.Flags().Bool(\"as-template\", false, \"Output a Template object instead of a List or single object.\")\n+\tcmd.Flags().Bool(\"exact\", false, \"Preserve fields that may be cluster specific, such as service portalIPs or generated names\")\n+\tcmd.Flags().Bool(\"raw\", false, \"If true, do not alter the resources in any way after they are loaded.\")\n+\tcmd.Flags().StringP(\"selector\", \"l\", \"\", \"Selector (label query) to filter on\")\n+\tcmd.Flags().Bool(\"all\", false, \"select all resources in the namespace of the specified resource types\")\n+\tcmd.Flags().VarP(&filenames, \"filename\", \"f\", \"Filename, directory, or URL to file to use to edit the resource.\")\n+\tcmdutil.AddPrinterFlags(cmd)\n+\treturn cmd\n+}\n+\n+func RunExport(f *clientcmd.Factory, exporter Exporter, in io.Reader, out io.Writer, cmd *cobra.Command, args []string, filenames util.StringList) error {\n+\tselector := cmdutil.GetFlagString(cmd, \"selector\")\n+\tall := cmdutil.GetFlagBool(cmd, \"all\")\n+\texact := cmdutil.GetFlagBool(cmd, \"exact\")\n+\tasTemplate := cmdutil.GetFlagBool(cmd, \"as-template\")\n+\traw := cmdutil.GetFlagBool(cmd, \"raw\")\n+\tif exact && raw {\n+\t\treturn cmdutil.UsageError(cmd, \"--exact and --raw may not both be specified\")\n+\t}\n+\n+\tclientConfig, err := f.ClientConfig()\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\toutputVersion := cmdutil.OutputVersion(cmd, clientConfig.Version)\n+\n+\tcmdNamespace, err := f.DefaultNamespace()\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\tmapper, typer := f.Object()\n+\tb := resource.NewBuilder(mapper, typer, f.ClientMapperForCommand()).\n+\t\tNamespaceParam(cmdNamespace).DefaultNamespace().\n+\t\tFilenameParam(filenames...).\n+\t\tSelectorParam(selector).\n+\t\tResourceTypeOrNameArgs(all, args...).\n+\t\tFlatten()\n+\n+\tone := false\n+\tinfos, err := b.Do().IntoSingular(&one).Infos()\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\tif len(infos) == 0 {\n+\t\treturn fmt.Errorf(\"no resources found - nothing to export\")\n+\t}\n+\n+\tif !raw {\n+\t\tnewInfos := []*resource.Info{}\n+\t\terrs := []error{}\n+\t\tfor _, info := range infos {\n+\t\t\tif err := exporter.Export(info.Object, exact); err != nil {\n+\t\t\t\tif err == ErrExportOmit {\n+\t\t\t\t\tcontinue\n+\t\t\t\t}\n+\t\t\t\terrs = append(errs, err)\n+\t\t\t}\n+\t\t\tnewInfos = append(newInfos, info)\n+\t\t}\n+\t\tif len(errs) > 0 {\n+\t\t\treturn utilerrors.NewAggregate(errs)\n+\t\t}\n+\t\tinfos = newInfos\n+\t}\n+\n+\tvar result runtime.Object\n+\tif asTemplate {\n+\t\tobjects, err := resource.AsVersionedObjects(infos, outputVersion)\n+\t\tif err != nil {\n+\t\t\treturn err\n+\t\t}\n+\t\ttemplate := &templateapi.Template{\n+\t\t\tObjects: objects,\n+\t\t}\n+\t\tresult, err = kapi.Scheme.ConvertToVersion(template, outputVersion)\n+\t\tif err != nil {\n+\t\t\treturn err\n+\t\t}\n+\t} else {\n+\t\tobject, err := resource.AsVersionedObject(infos, !one, outputVersion)\n+\t\tif err != nil {\n+\t\t\treturn err\n+\t\t}\n+\t\tresult = object\n+\t}\n+\n+\t// use YAML as the default format\n+\toutputFormat := cmdutil.GetFlagString(cmd, \"output\")\n+\ttemplateFile := cmdutil.GetFlagString(cmd, \"template\")\n+\tif len(outputFormat) == 0 && len(templateFile) != 0 {\n+\t\toutputFormat = \"template\"\n+\t}\n+\tif len(outputFormat) == 0 {\n+\t\toutputFormat = \"yaml\"","path":"pkg/cmd/cli/cmd/export.go","position":160,"original_position":160,"commit_id":"f521a0ceb385c53822c448dd123a043ec5669afd","original_commit_id":"f521a0ceb385c53822c448dd123a043ec5669afd","user":{"login":"kargakis","id":3900799,"avatar_url":"https://avatars.githubusercontent.com/u/3900799?v=3","gravatar_id":"","url":"https://api.github.com/users/kargakis","html_url":"https://github.com/kargakis","followers_url":"https://api.github.com/users/kargakis/followers","following_url":"https://api.github.com/users/kargakis/following{/other_user}","gists_url":"https://api.github.com/users/kargakis/gists{/gist_id}","starred_url":"https://api.github.com/users/kargakis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kargakis/subscriptions","organizations_url":"https://api.github.com/users/kargakis/orgs","repos_url":"https://api.github.com/users/kargakis/repos","events_url":"https://api.github.com/users/kargakis/events{/privacy}","received_events_url":"https://api.github.com/users/kargakis/received_events","type":"User","site_admin":false},"body":"We should mention this somewhere in the help message. \r\n\r\n```\r\n$ oc export -f a_v1beta3_service.json --output-version=v1 --exact\r\n```\r\nIt's not clear here that the user will get back YAML...\r\n\r\n","created_at":"2015-06-08T08:13:59Z","updated_at":"2015-06-08T08:13:59Z","html_url":"https://github.com/openshift/origin/pull/2910#discussion_r31893805","pull_request_url":"https://api.github.com/repos/openshift/origin/pulls/2910","_links":{"self":{"href":"https://api.github.com/repos/openshift/origin/pulls/comments/31893805"},"html":{"href":"https://github.com/openshift/origin/pull/2910#discussion_r31893805"},"pull_request":{"href":"https://api.github.com/repos/openshift/origin/pulls/2910"}}},"pull_request":{"url":"https://api.github.com/repos/openshift/origin/pulls/2910","id":37111529,"html_url":"https://github.com/openshift/origin/pull/2910","diff_url":"https://github.com/openshift/origin/pull/2910.diff","patch_url":"https://github.com/openshift/origin/pull/2910.patch","issue_url":"https://api.github.com/repos/openshift/origin/issues/2910","number":2910,"state":"open","locked":false,"title":"Export command","user":{"login":"smarterclayton","id":1163175,"avatar_url":"https://avatars.githubusercontent.com/u/1163175?v=3","gravatar_id":"","url":"https://api.github.com/users/smarterclayton","html_url":"https://github.com/smarterclayton","followers_url":"https://api.github.com/users/smarterclayton/followers","following_url":"https://api.github.com/users/smarterclayton/following{/other_user}","gists_url":"https://api.github.com/users/smarterclayton/gists{/gist_id}","starred_url":"https://api.github.com/users/smarterclayton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smarterclayton/subscriptions","organizations_url":"https://api.github.com/users/smarterclayton/orgs","repos_url":"https://api.github.com/users/smarterclayton/repos","events_url":"https://api.github.com/users/smarterclayton/events{/privacy}","received_events_url":"https://api.github.com/users/smarterclayton/received_events","type":"User","site_admin":false},"body":"Part of #2628","created_at":"2015-06-07T19:07:40Z","updated_at":"2015-06-08T08:13:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b2cb4b127663e463b92695da3945dd6015abb979","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/openshift/origin/pulls/2910/commits","review_comments_url":"https://api.github.com/repos/openshift/origin/pulls/2910/comments","review_comment_url":"https://api.github.com/repos/openshift/origin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openshift/origin/issues/2910/comments","statuses_url":"https://api.github.com/repos/openshift/origin/statuses/f521a0ceb385c53822c448dd123a043ec5669afd","head":{"label":"smarterclayton:export","ref":"export","sha":"f521a0ceb385c53822c448dd123a043ec5669afd","user":{"login":"smarterclayton","id":1163175,"avatar_url":"https://avatars.githubusercontent.com/u/1163175?v=3","gravatar_id":"","url":"https://api.github.com/users/smarterclayton","html_url":"https://github.com/smarterclayton","followers_url":"https://api.github.com/users/smarterclayton/followers","following_url":"https://api.github.com/users/smarterclayton/following{/other_user}","gists_url":"https://api.github.com/users/smarterclayton/gists{/gist_id}","starred_url":"https://api.github.com/users/smarterclayton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smarterclayton/subscriptions","organizations_url":"https://api.github.com/users/smarterclayton/orgs","repos_url":"https://api.github.com/users/smarterclayton/repos","events_url":"https://api.github.com/users/smarterclayton/events{/privacy}","received_events_url":"https://api.github.com/users/smarterclayton/received_events","type":"User","site_admin":false},"repo":{"id":22921364,"name":"origin","full_name":"smarterclayton/origin","owner":{"login":"smarterclayton","id":1163175,"avatar_url":"https://avatars.githubusercontent.com/u/1163175?v=3","gravatar_id":"","url":"https://api.github.com/users/smarterclayton","html_url":"https://github.com/smarterclayton","followers_url":"https://api.github.com/users/smarterclayton/followers","following_url":"https://api.github.com/users/smarterclayton/following{/other_user}","gists_url":"https://api.github.com/users/smarterclayton/gists{/gist_id}","starred_url":"https://api.github.com/users/smarterclayton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smarterclayton/subscriptions","organizations_url":"https://api.github.com/users/smarterclayton/orgs","repos_url":"https://api.github.com/users/smarterclayton/repos","events_url":"https://api.github.com/users/smarterclayton/events{/privacy}","received_events_url":"https://api.github.com/users/smarterclayton/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/smarterclayton/origin","description":"OpenShift 3 - build, deploy, and manage your applications with Docker and Kubernetes","fork":true,"url":"https://api.github.com/repos/smarterclayton/origin","forks_url":"https://api.github.com/repos/smarterclayton/origin/forks","keys_url":"https://api.github.com/repos/smarterclayton/origin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/smarterclayton/origin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/smarterclayton/origin/teams","hooks_url":"https://api.github.com/repos/smarterclayton/origin/hooks","issue_events_url":"https://api.github.com/repos/smarterclayton/origin/issues/events{/number}","events_url":"https://api.github.com/repos/smarterclayton/origin/events","assignees_url":"https://api.github.com/repos/smarterclayton/origin/assignees{/user}","branches_url":"https://api.github.com/repos/smarterclayton/origin/branches{/branch}","tags_url":"https://api.github.com/repos/smarterclayton/origin/tags","blobs_url":"https://api.github.com/repos/smarterclayton/origin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/smarterclayton/origin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/smarterclayton/origin/git/refs{/sha}","trees_url":"https://api.github.com/repos/smarterclayton/origin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/smarterclayton/origin/statuses/{sha}","languages_url":"https://api.github.com/repos/smarterclayton/origin/languages","stargazers_url":"https://api.github.com/repos/smarterclayton/origin/stargazers","contributors_url":"https://api.github.com/repos/smarterclayton/origin/contributors","subscribers_url":"https://api.github.com/repos/smarterclayton/origin/subscribers","subscription_url":"https://api.github.com/repos/smarterclayton/origin/subscription","commits_url":"https://api.github.com/repos/smarterclayton/origin/commits{/sha}","git_commits_url":"https://api.github.com/repos/smarterclayton/origin/git/commits{/sha}","comments_url":"https://api.github.com/repos/smarterclayton/origin/comments{/number}","issue_comment_url":"https://api.github.com/repos/smarterclayton/origin/issues/comments{/number}","contents_url":"https://api.github.com/repos/smarterclayton/origin/contents/{+path}","compare_url":"https://api.github.com/repos/smarterclayton/origin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/smarterclayton/origin/merges","archive_url":"https://api.github.com/repos/smarterclayton/origin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/smarterclayton/origin/downloads","issues_url":"https://api.github.com/repos/smarterclayton/origin/issues{/number}","pulls_url":"https://api.github.com/repos/smarterclayton/origin/pulls{/number}","milestones_url":"https://api.github.com/repos/smarterclayton/origin/milestones{/number}","notifications_url":"https://api.github.com/repos/smarterclayton/origin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/smarterclayton/origin/labels{/name}","releases_url":"https://api.github.com/repos/smarterclayton/origin/releases{/id}","created_at":"2014-08-13T15:49:23Z","updated_at":"2015-05-17T00:07:22Z","pushed_at":"2015-06-08T04:08:03Z","git_url":"git://github.com/smarterclayton/origin.git","ssh_url":"git@github.com:smarterclayton/origin.git","clone_url":"https://github.com/smarterclayton/origin.git","svn_url":"https://github.com/smarterclayton/origin","homepage":"https://openshift.github.io","size":113801,"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":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"openshift:master","ref":"master","sha":"451889311c1da6d806f8ebb05fefff4d8a3781e7","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-06-06T19:50:38Z","pushed_at":"2015-06-08T05:11:46Z","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":177527,"stargazers_count":465,"watchers_count":465,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":233,"mirror_url":null,"open_issues_count":288,"forks":233,"open_issues":288,"watchers":465,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openshift/origin/pulls/2910"},"html":{"href":"https://github.com/openshift/origin/pull/2910"},"issue":{"href":"https://api.github.com/repos/openshift/origin/issues/2910"},"comments":{"href":"https://api.github.com/repos/openshift/origin/issues/2910/comments"},"review_comments":{"href":"https://api.github.com/repos/openshift/origin/pulls/2910/comments"},"review_comment":{"href":"https://api.github.com/repos/openshift/origin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openshift/origin/pulls/2910/commits"},"statuses":{"href":"https://api.github.com/repos/openshift/origin/statuses/f521a0ceb385c53822c448dd123a043ec5669afd"}}}}