{"action":"created","comment":{"url":"https://api.github.com/repos/coreos/etcd-operator/pulls/comments/94196881","pull_request_review_id":14727916,"id":94196881,"diff_hunk":"@@ -82,63 +83,90 @@ type Cluster struct {\n \tbackupDir string\n }\n \n-func New(c Config, e *spec.EtcdCluster, stopC <-chan struct{}, wg *sync.WaitGroup) (*Cluster, error) {\n-\treturn new(c, e, stopC, wg, true)\n-}\n-\n-func Restore(c Config, e *spec.EtcdCluster, stopC <-chan struct{}, wg *sync.WaitGroup) (*Cluster, error) {\n-\treturn new(c, e, stopC, wg, false)\n-}\n-\n-func new(config Config, e *spec.EtcdCluster, stopC <-chan struct{}, wg *sync.WaitGroup, isNewCluster bool) (*Cluster, error) {\n-\terr := e.Spec.Validate()\n-\tif err != nil {\n-\t\treturn nil, fmt.Errorf(\"invalid cluster spec: %v\", err)\n-\t}\n-\n+func New(config Config, e *spec.EtcdCluster, stopC <-chan struct{}, wg *sync.WaitGroup) *Cluster {\n \tlg := logrus.WithField(\"pkg\", \"cluster\").WithField(\"cluster-name\", e.Name)\n-\tvar bm *backupManager\n-\n-\tif b := e.Spec.Backup; b != nil && b.MaxBackups > 0 {\n-\t\tbm, err = newBackupManager(config, e, lg, isNewCluster)\n-\t\tif err != nil {\n-\t\t\treturn nil, err\n-\t\t}\n-\t}\n \tc := &Cluster{\n \t\tlogger:  lg,\n \t\tconfig:  config,\n \t\tcluster: e,\n \t\teventCh: make(chan *clusterEvent, 100),\n \t\tstopCh:  make(chan struct{}),\n \t\tstatus:  &spec.ClusterStatus{},\n-\t\tbm:      bm,\n \t}\n \n-\tif isNewCluster {\n-\t\tif c.bm != nil {\n-\t\t\tif err := c.bm.setup(); err != nil {\n-\t\t\t\treturn nil, err\n+\terr := c.setup()\n+\tif err != nil {\n+\t\tc.logger.Errorf(\"fail to setup: %v\", err)\n+\t\tif c.status.Phase != spec.ClusterPhaseFailed {\n+\t\t\tc.status.SetReason(err.Error())\n+\t\t\tc.status.SetPhase(spec.ClusterPhaseFailed)\n+\t\t\tif err := c.updateStatus(); err != nil {\n+\t\t\t\tc.logger.Errorf(\"failed to update cluster phase (%v): %v\", spec.ClusterPhaseFailed, err)\n \t\t\t}\n \t\t}\n+\t\treturn nil\n+\t}\n \n-\t\tif c.cluster.Spec.Restore == nil {\n-\t\t\t// Note: For restore case, we don't need to create seed member,\n-\t\t\t// and will go through reconcile loop and disaster recovery.\n-\t\t\tif err := c.prepareSeedMember(); err != nil {\n-\t\t\t\treturn nil, err\n-\t\t\t}\n+\twg.Add(1)\n+\tgo c.run(stopC, wg)\n+\treturn c\n+}\n+\n+func (c *Cluster) setup() error {\n+\terr := c.cluster.Spec.Validate()\n+\tif err != nil {\n+\t\treturn fmt.Errorf(\"invalid cluster spec: %v\", err)\n+\t}\n+\n+\tvar shouldCreateCluster bool\n+\tswitch c.status.Phase {\n+\tcase \"\":\n+\t\tshouldCreateCluster = true\n+\tcase spec.ClusterPhaseCreating:\n+\t\treturn errors.New(\"cluster creation was attempted before but failed\")\n+\tcase spec.ClusterPhaseRunning:\n+\t\tshouldCreateCluster = false\n+\tcase spec.ClusterPhaseFailed:\n+\t\treturn errors.New(\"cluster already failed\")\n+\t}\n+\n+\tif b := c.cluster.Spec.Backup; b != nil && b.MaxBackups > 0 {\n+\t\tc.bm, err = newBackupManager(c.config, c.cluster, c.logger)\n+\t\tif err != nil {\n+\t\t\treturn err\n \t\t}\n+\t}\n \n-\t\tif err := c.createClientServiceLB(); err != nil {\n-\t\t\treturn nil, fmt.Errorf(\"fail to create client service LB: %v\", err)\n+\tif !shouldCreateCluster {","path":"pkg/cluster/cluster.go","position":101,"original_position":101,"commit_id":"37beb5cff25b6549a7ab8b092e36ca0d26d33970","original_commit_id":"37beb5cff25b6549a7ab8b092e36ca0d26d33970","user":{"login":"xiang90","id":4479947,"avatar_url":"https://avatars.githubusercontent.com/u/4479947?v=3","gravatar_id":"","url":"https://api.github.com/users/xiang90","html_url":"https://github.com/xiang90","followers_url":"https://api.github.com/users/xiang90/followers","following_url":"https://api.github.com/users/xiang90/following{/other_user}","gists_url":"https://api.github.com/users/xiang90/gists{/gist_id}","starred_url":"https://api.github.com/users/xiang90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiang90/subscriptions","organizations_url":"https://api.github.com/users/xiang90/orgs","repos_url":"https://api.github.com/users/xiang90/repos","events_url":"https://api.github.com/users/xiang90/events{/privacy}","received_events_url":"https://api.github.com/users/xiang90/received_events","type":"User","site_admin":false},"body":"if shouldCreateCluster {\r\n    return c.create()\r\n}\r\n\r\nreturn nil","created_at":"2016-12-30T01:39:09Z","updated_at":"2016-12-30T01:39:09Z","html_url":"https://github.com/coreos/etcd-operator/pull/553#discussion_r94196881","pull_request_url":"https://api.github.com/repos/coreos/etcd-operator/pulls/553","_links":{"self":{"href":"https://api.github.com/repos/coreos/etcd-operator/pulls/comments/94196881"},"html":{"href":"https://github.com/coreos/etcd-operator/pull/553#discussion_r94196881"},"pull_request":{"href":"https://api.github.com/repos/coreos/etcd-operator/pulls/553"}}},"pull_request":{"url":"https://api.github.com/repos/coreos/etcd-operator/pulls/553","id":99690430,"html_url":"https://github.com/coreos/etcd-operator/pull/553","diff_url":"https://github.com/coreos/etcd-operator/pull/553.diff","patch_url":"https://github.com/coreos/etcd-operator/pull/553.patch","issue_url":"https://api.github.com/repos/coreos/etcd-operator/issues/553","number":553,"state":"open","locked":false,"title":"cluster: use status phase to detect new cluster","user":{"login":"hongchaodeng","id":920884,"avatar_url":"https://avatars.githubusercontent.com/u/920884?v=3","gravatar_id":"","url":"https://api.github.com/users/hongchaodeng","html_url":"https://github.com/hongchaodeng","followers_url":"https://api.github.com/users/hongchaodeng/followers","following_url":"https://api.github.com/users/hongchaodeng/following{/other_user}","gists_url":"https://api.github.com/users/hongchaodeng/gists{/gist_id}","starred_url":"https://api.github.com/users/hongchaodeng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hongchaodeng/subscriptions","organizations_url":"https://api.github.com/users/hongchaodeng/orgs","repos_url":"https://api.github.com/users/hongchaodeng/repos","events_url":"https://api.github.com/users/hongchaodeng/events{/privacy}","received_events_url":"https://api.github.com/users/hongchaodeng/received_events","type":"User","site_admin":false},"body":"Previously, controller list TPR could potentially restore a cluster\r\nthat was created fresh.\r\n\r\nPreviously, we also didn’t do failed status reporting on failure to new\r\nand didn’t set running status immediately.\r\n\r\nhttps://github.com/coreos/etcd-operator/pull/553#issuecomment-269705792","created_at":"2016-12-29T19:31:23Z","updated_at":"2016-12-30T01:39:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4195b27a5d9b20a4f85b68bf8de9bffaa467c208","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/coreos/etcd-operator/pulls/553/commits","review_comments_url":"https://api.github.com/repos/coreos/etcd-operator/pulls/553/comments","review_comment_url":"https://api.github.com/repos/coreos/etcd-operator/pulls/comments{/number}","comments_url":"https://api.github.com/repos/coreos/etcd-operator/issues/553/comments","statuses_url":"https://api.github.com/repos/coreos/etcd-operator/statuses/37beb5cff25b6549a7ab8b092e36ca0d26d33970","head":{"label":"hongchaodeng:r","ref":"r","sha":"37beb5cff25b6549a7ab8b092e36ca0d26d33970","user":{"login":"hongchaodeng","id":920884,"avatar_url":"https://avatars.githubusercontent.com/u/920884?v=3","gravatar_id":"","url":"https://api.github.com/users/hongchaodeng","html_url":"https://github.com/hongchaodeng","followers_url":"https://api.github.com/users/hongchaodeng/followers","following_url":"https://api.github.com/users/hongchaodeng/following{/other_user}","gists_url":"https://api.github.com/users/hongchaodeng/gists{/gist_id}","starred_url":"https://api.github.com/users/hongchaodeng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hongchaodeng/subscriptions","organizations_url":"https://api.github.com/users/hongchaodeng/orgs","repos_url":"https://api.github.com/users/hongchaodeng/repos","events_url":"https://api.github.com/users/hongchaodeng/events{/privacy}","received_events_url":"https://api.github.com/users/hongchaodeng/received_events","type":"User","site_admin":false},"repo":{"id":72786503,"name":"etcd-operator","full_name":"hongchaodeng/etcd-operator","owner":{"login":"hongchaodeng","id":920884,"avatar_url":"https://avatars.githubusercontent.com/u/920884?v=3","gravatar_id":"","url":"https://api.github.com/users/hongchaodeng","html_url":"https://github.com/hongchaodeng","followers_url":"https://api.github.com/users/hongchaodeng/followers","following_url":"https://api.github.com/users/hongchaodeng/following{/other_user}","gists_url":"https://api.github.com/users/hongchaodeng/gists{/gist_id}","starred_url":"https://api.github.com/users/hongchaodeng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hongchaodeng/subscriptions","organizations_url":"https://api.github.com/users/hongchaodeng/orgs","repos_url":"https://api.github.com/users/hongchaodeng/repos","events_url":"https://api.github.com/users/hongchaodeng/events{/privacy}","received_events_url":"https://api.github.com/users/hongchaodeng/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/hongchaodeng/etcd-operator","description":"etcd Operator creates/configures/manages etcd clusters atop Kubernetes","fork":true,"url":"https://api.github.com/repos/hongchaodeng/etcd-operator","forks_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/forks","keys_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/teams","hooks_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/hooks","issue_events_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/issues/events{/number}","events_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/events","assignees_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/assignees{/user}","branches_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/branches{/branch}","tags_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/tags","blobs_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/git/refs{/sha}","trees_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/statuses/{sha}","languages_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/languages","stargazers_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/stargazers","contributors_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/contributors","subscribers_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/subscribers","subscription_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/subscription","commits_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/commits{/sha}","git_commits_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/git/commits{/sha}","comments_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/comments{/number}","issue_comment_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/issues/comments{/number}","contents_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/contents/{+path}","compare_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/merges","archive_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/downloads","issues_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/issues{/number}","pulls_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/pulls{/number}","milestones_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/milestones{/number}","notifications_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/labels{/name}","releases_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/releases{/id}","deployments_url":"https://api.github.com/repos/hongchaodeng/etcd-operator/deployments","created_at":"2016-11-03T21:01:55Z","updated_at":"2016-11-03T21:01:56Z","pushed_at":"2016-12-30T01:33:58Z","git_url":"git://github.com/hongchaodeng/etcd-operator.git","ssh_url":"git@github.com:hongchaodeng/etcd-operator.git","clone_url":"https://github.com/hongchaodeng/etcd-operator.git","svn_url":"https://github.com/hongchaodeng/etcd-operator","homepage":"https://coreos.com/blog/introducing-the-etcd-operator.html","size":1169,"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":"coreos:master","ref":"master","sha":"7e45d01f88349f257e1781369967f922f22bae2f","user":{"login":"coreos","id":3730757,"avatar_url":"https://avatars.githubusercontent.com/u/3730757?v=3","gravatar_id":"","url":"https://api.github.com/users/coreos","html_url":"https://github.com/coreos","followers_url":"https://api.github.com/users/coreos/followers","following_url":"https://api.github.com/users/coreos/following{/other_user}","gists_url":"https://api.github.com/users/coreos/gists{/gist_id}","starred_url":"https://api.github.com/users/coreos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coreos/subscriptions","organizations_url":"https://api.github.com/users/coreos/orgs","repos_url":"https://api.github.com/users/coreos/repos","events_url":"https://api.github.com/users/coreos/events{/privacy}","received_events_url":"https://api.github.com/users/coreos/received_events","type":"Organization","site_admin":false},"repo":{"id":64974719,"name":"etcd-operator","full_name":"coreos/etcd-operator","owner":{"login":"coreos","id":3730757,"avatar_url":"https://avatars.githubusercontent.com/u/3730757?v=3","gravatar_id":"","url":"https://api.github.com/users/coreos","html_url":"https://github.com/coreos","followers_url":"https://api.github.com/users/coreos/followers","following_url":"https://api.github.com/users/coreos/following{/other_user}","gists_url":"https://api.github.com/users/coreos/gists{/gist_id}","starred_url":"https://api.github.com/users/coreos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coreos/subscriptions","organizations_url":"https://api.github.com/users/coreos/orgs","repos_url":"https://api.github.com/users/coreos/repos","events_url":"https://api.github.com/users/coreos/events{/privacy}","received_events_url":"https://api.github.com/users/coreos/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coreos/etcd-operator","description":"etcd Operator creates/configures/manages etcd clusters atop Kubernetes","fork":false,"url":"https://api.github.com/repos/coreos/etcd-operator","forks_url":"https://api.github.com/repos/coreos/etcd-operator/forks","keys_url":"https://api.github.com/repos/coreos/etcd-operator/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coreos/etcd-operator/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coreos/etcd-operator/teams","hooks_url":"https://api.github.com/repos/coreos/etcd-operator/hooks","issue_events_url":"https://api.github.com/repos/coreos/etcd-operator/issues/events{/number}","events_url":"https://api.github.com/repos/coreos/etcd-operator/events","assignees_url":"https://api.github.com/repos/coreos/etcd-operator/assignees{/user}","branches_url":"https://api.github.com/repos/coreos/etcd-operator/branches{/branch}","tags_url":"https://api.github.com/repos/coreos/etcd-operator/tags","blobs_url":"https://api.github.com/repos/coreos/etcd-operator/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coreos/etcd-operator/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coreos/etcd-operator/git/refs{/sha}","trees_url":"https://api.github.com/repos/coreos/etcd-operator/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coreos/etcd-operator/statuses/{sha}","languages_url":"https://api.github.com/repos/coreos/etcd-operator/languages","stargazers_url":"https://api.github.com/repos/coreos/etcd-operator/stargazers","contributors_url":"https://api.github.com/repos/coreos/etcd-operator/contributors","subscribers_url":"https://api.github.com/repos/coreos/etcd-operator/subscribers","subscription_url":"https://api.github.com/repos/coreos/etcd-operator/subscription","commits_url":"https://api.github.com/repos/coreos/etcd-operator/commits{/sha}","git_commits_url":"https://api.github.com/repos/coreos/etcd-operator/git/commits{/sha}","comments_url":"https://api.github.com/repos/coreos/etcd-operator/comments{/number}","issue_comment_url":"https://api.github.com/repos/coreos/etcd-operator/issues/comments{/number}","contents_url":"https://api.github.com/repos/coreos/etcd-operator/contents/{+path}","compare_url":"https://api.github.com/repos/coreos/etcd-operator/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coreos/etcd-operator/merges","archive_url":"https://api.github.com/repos/coreos/etcd-operator/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coreos/etcd-operator/downloads","issues_url":"https://api.github.com/repos/coreos/etcd-operator/issues{/number}","pulls_url":"https://api.github.com/repos/coreos/etcd-operator/pulls{/number}","milestones_url":"https://api.github.com/repos/coreos/etcd-operator/milestones{/number}","notifications_url":"https://api.github.com/repos/coreos/etcd-operator/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coreos/etcd-operator/labels{/name}","releases_url":"https://api.github.com/repos/coreos/etcd-operator/releases{/id}","deployments_url":"https://api.github.com/repos/coreos/etcd-operator/deployments","created_at":"2016-08-04T23:54:58Z","updated_at":"2016-12-30T01:30:10Z","pushed_at":"2016-12-30T01:33:59Z","git_url":"git://github.com/coreos/etcd-operator.git","ssh_url":"git@github.com:coreos/etcd-operator.git","clone_url":"https://github.com/coreos/etcd-operator.git","svn_url":"https://github.com/coreos/etcd-operator","homepage":"https://coreos.com/blog/introducing-the-etcd-operator.html","size":1174,"stargazers_count":155,"watchers_count":155,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":20,"mirror_url":null,"open_issues_count":27,"forks":20,"open_issues":27,"watchers":155,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/coreos/etcd-operator/pulls/553"},"html":{"href":"https://github.com/coreos/etcd-operator/pull/553"},"issue":{"href":"https://api.github.com/repos/coreos/etcd-operator/issues/553"},"comments":{"href":"https://api.github.com/repos/coreos/etcd-operator/issues/553/comments"},"review_comments":{"href":"https://api.github.com/repos/coreos/etcd-operator/pulls/553/comments"},"review_comment":{"href":"https://api.github.com/repos/coreos/etcd-operator/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/coreos/etcd-operator/pulls/553/commits"},"statuses":{"href":"https://api.github.com/repos/coreos/etcd-operator/statuses/37beb5cff25b6549a7ab8b092e36ca0d26d33970"}}}}
{"actor":{"display_login":"xiang90"}}