{"action":"created","comment":{"url":"https://api.github.com/repos/rancher/rke/pulls/comments/232106850","pull_request_review_id":173230316,"id":232106850,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzMjEwNjg1MA==","diff_hunk":"@@ -249,3 +134,106 @@ func GetK8sVersion(localConfigPath string, k8sWrapTransport k8s.WrapTransport) (\n \t}\n \treturn fmt.Sprintf(\"%#v\", *serverVersion), nil\n }\n+\n+func RebuildState(ctx context.Context, rkeConfig *v3.RancherKubernetesEngineConfig, oldState *RKEFullState, configPath, configDir string) (*RKEFullState, error) {\n+\tnewState := &RKEFullState{\n+\t\tDesiredState: RKEState{\n+\t\t\tRancherKubernetesEngineConfig: rkeConfig.DeepCopy(),\n+\t\t},\n+\t}\n+\n+\t// Rebuilding the certificates of the desired state\n+\tif oldState.DesiredState.CertificatesBundle == nil {\n+\t\t// Get the certificate Bundle\n+\t\tcertBundle, err := pki.GenerateRKECerts(ctx, *rkeConfig, \"\", \"\")\n+\t\tif err != nil {\n+\t\t\treturn nil, fmt.Errorf(\"Failed to generate certificate bundle: %v\", err)\n+\t\t}\n+\t\tnewState.DesiredState.CertificatesBundle = certBundle\n+\t} else {\n+\t\t// Regenerating etcd certificates for any new etcd nodes\n+\t\tpkiCertBundle := oldState.DesiredState.CertificatesBundle\n+\t\tif err := pki.GenerateEtcdCertificates(ctx, pkiCertBundle, *rkeConfig, \"\", \"\"); err != nil {\n+\t\t\treturn nil, err\n+\t\t}\n+\t\t// Regenerating kubeapi certificates for any new kubeapi nodes\n+\t\tif err := pki.GenerateKubeAPICertificate(ctx, pkiCertBundle, *rkeConfig, \"\", \"\"); err != nil {\n+\t\t\treturn nil, err\n+\t\t}\n+\t\t// Regenerating kubeadmin certificates/config\n+\t\tif err := pki.GenerateKubeAdminCertificate(ctx, pkiCertBundle, *rkeConfig, configPath, configDir); err != nil {\n+\t\t\treturn nil, err\n+\t\t}\n+\t\tnewState.DesiredState.CertificatesBundle = pkiCertBundle\n+\t}\n+\tnewState.CurrentState = oldState.CurrentState\n+\treturn newState, nil\n+}\n+\n+func (s *RKEFullState) WriteStateFile(ctx context.Context, statePath string) error {\n+\tstateFile, err := json.MarshalIndent(s, \"\", \"  \")\n+\tif err != nil {\n+\t\treturn fmt.Errorf(\"Failed to Marshal state object: %v\", err)\n+\t}\n+\tlogrus.Debugf(\"Writing state file: %s\", stateFile)\n+\tif err := ioutil.WriteFile(statePath, stateFile, 0640); err != nil {\n+\t\treturn fmt.Errorf(\"Failed to write state file: %v\", err)\n+\t}\n+\tlog.Infof(ctx, \"Successfully Deployed state file at [%s]\", statePath)\n+\treturn nil\n+}\n+\n+func GetStateFilePath(configPath, configDir string) string {\n+\tif configPath == \"\" {\n+\t\tconfigPath = pki.ClusterConfig\n+\t}\n+\tbaseDir := filepath.Dir(configPath)\n+\tif len(configDir) > 0 {\n+\t\tbaseDir = filepath.Dir(configDir)\n+\t}\n+\tfileName := filepath.Base(configPath)\n+\tbaseDir += \"/\"\n+\tfullPath := fmt.Sprintf(\"%s%s\", baseDir, fileName)\n+\ttrimmedName := strings.TrimSuffix(fullPath, filepath.Ext(fullPath))\n+\treturn trimmedName + stateFileExt\n+}\n+\n+func ReadStateFile(ctx context.Context, statePath string) (*RKEFullState, error) {\n+\trkeFullState := &RKEFullState{}\n+\tfp, err := filepath.Abs(statePath)\n+\tif err != nil {\n+\t\treturn rkeFullState, fmt.Errorf(\"failed to lookup current directory name: %v\", err)\n+\t}\n+\tfile, err := os.Open(fp)\n+\tif err != nil {\n+\t\treturn rkeFullState, fmt.Errorf(\"Can not find RKE state file: %v\", err)\n+\t}\n+\tdefer file.Close()\n+\tbuf, err := ioutil.ReadAll(file)\n+\tif err != nil {\n+\t\treturn rkeFullState, fmt.Errorf(\"failed to read state file: %v\", err)\n+\t}\n+\tif err := json.Unmarshal(buf, rkeFullState); err != nil {\n+\t\treturn rkeFullState, fmt.Errorf(\"failed to unmarshal the state file: %v\", err)\n+\t}\n+\trkeFullState.DesiredState.CertificatesBundle = pki.TransformPEMToObject(rkeFullState.DesiredState.CertificatesBundle)\n+\trkeFullState.CurrentState.CertificatesBundle = pki.TransformPEMToObject(rkeFullState.CurrentState.CertificatesBundle)\n+\treturn rkeFullState, nil\n+}\n+\n+func RemoveStateFile(ctx context.Context, statePath string) {\n+\tlog.Infof(ctx, \"Removing state file: %s\", statePath)\n+\tif err := os.Remove(statePath); err != nil {\n+\t\tlogrus.Warningf(\"Failed to remove state file: %v\", err)","path":"cluster/state.go","position":358,"original_position":358,"commit_id":"a4cbbbbdeb9e8b8e61b3bff2c8e9a5a488c95a1d","original_commit_id":"a4cbbbbdeb9e8b8e61b3bff2c8e9a5a488c95a1d","user":{"login":"galal-hussein","id":3309968,"node_id":"MDQ6VXNlcjMzMDk5Njg=","avatar_url":"https://avatars1.githubusercontent.com/u/3309968?v=4","gravatar_id":"","url":"https://api.github.com/users/galal-hussein","html_url":"https://github.com/galal-hussein","followers_url":"https://api.github.com/users/galal-hussein/followers","following_url":"https://api.github.com/users/galal-hussein/following{/other_user}","gists_url":"https://api.github.com/users/galal-hussein/gists{/gist_id}","starred_url":"https://api.github.com/users/galal-hussein/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/galal-hussein/subscriptions","organizations_url":"https://api.github.com/users/galal-hussein/orgs","repos_url":"https://api.github.com/users/galal-hussein/repos","events_url":"https://api.github.com/users/galal-hussein/events{/privacy}","received_events_url":"https://api.github.com/users/galal-hussein/received_events","type":"User","site_admin":false},"body":"the same case applies to the kube config file\r\n","created_at":"2018-11-09T00:16:03Z","updated_at":"2018-11-09T00:16:03Z","html_url":"https://github.com/rancher/rke/pull/1009#discussion_r232106850","pull_request_url":"https://api.github.com/repos/rancher/rke/pulls/1009","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/rancher/rke/pulls/comments/232106850"},"html":{"href":"https://github.com/rancher/rke/pull/1009#discussion_r232106850"},"pull_request":{"href":"https://api.github.com/repos/rancher/rke/pulls/1009"}},"in_reply_to_id":232101420},"pull_request":{"url":"https://api.github.com/repos/rancher/rke/pulls/1009","id":229209436,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI5MjA5NDM2","html_url":"https://github.com/rancher/rke/pull/1009","diff_url":"https://github.com/rancher/rke/pull/1009.diff","patch_url":"https://github.com/rancher/rke/pull/1009.patch","issue_url":"https://api.github.com/repos/rancher/rke/issues/1009","number":1009,"state":"open","locked":false,"title":"Refactoring State Management","user":{"login":"galal-hussein","id":3309968,"node_id":"MDQ6VXNlcjMzMDk5Njg=","avatar_url":"https://avatars1.githubusercontent.com/u/3309968?v=4","gravatar_id":"","url":"https://api.github.com/users/galal-hussein","html_url":"https://github.com/galal-hussein","followers_url":"https://api.github.com/users/galal-hussein/followers","following_url":"https://api.github.com/users/galal-hussein/following{/other_user}","gists_url":"https://api.github.com/users/galal-hussein/gists{/gist_id}","starred_url":"https://api.github.com/users/galal-hussein/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/galal-hussein/subscriptions","organizations_url":"https://api.github.com/users/galal-hussein/orgs","repos_url":"https://api.github.com/users/galal-hussein/repos","events_url":"https://api.github.com/users/galal-hussein/events{/privacy}","received_events_url":"https://api.github.com/users/galal-hussein/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-11-08T00:04:52Z","updated_at":"2018-11-09T00:16:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"38bfc960bc74451fb905622a3d9439667c1bdfd4","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/rancher/rke/pulls/1009/commits","review_comments_url":"https://api.github.com/repos/rancher/rke/pulls/1009/comments","review_comment_url":"https://api.github.com/repos/rancher/rke/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rancher/rke/issues/1009/comments","statuses_url":"https://api.github.com/repos/rancher/rke/statuses/a4cbbbbdeb9e8b8e61b3bff2c8e9a5a488c95a1d","head":{"label":"galal-hussein:squashed_refactoring_state","ref":"squashed_refactoring_state","sha":"a4cbbbbdeb9e8b8e61b3bff2c8e9a5a488c95a1d","user":{"login":"galal-hussein","id":3309968,"node_id":"MDQ6VXNlcjMzMDk5Njg=","avatar_url":"https://avatars1.githubusercontent.com/u/3309968?v=4","gravatar_id":"","url":"https://api.github.com/users/galal-hussein","html_url":"https://github.com/galal-hussein","followers_url":"https://api.github.com/users/galal-hussein/followers","following_url":"https://api.github.com/users/galal-hussein/following{/other_user}","gists_url":"https://api.github.com/users/galal-hussein/gists{/gist_id}","starred_url":"https://api.github.com/users/galal-hussein/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/galal-hussein/subscriptions","organizations_url":"https://api.github.com/users/galal-hussein/orgs","repos_url":"https://api.github.com/users/galal-hussein/repos","events_url":"https://api.github.com/users/galal-hussein/events{/privacy}","received_events_url":"https://api.github.com/users/galal-hussein/received_events","type":"User","site_admin":false},"repo":{"id":108339863,"node_id":"MDEwOlJlcG9zaXRvcnkxMDgzMzk4NjM=","name":"rke","full_name":"galal-hussein/rke","private":false,"owner":{"login":"galal-hussein","id":3309968,"node_id":"MDQ6VXNlcjMzMDk5Njg=","avatar_url":"https://avatars1.githubusercontent.com/u/3309968?v=4","gravatar_id":"","url":"https://api.github.com/users/galal-hussein","html_url":"https://github.com/galal-hussein","followers_url":"https://api.github.com/users/galal-hussein/followers","following_url":"https://api.github.com/users/galal-hussein/following{/other_user}","gists_url":"https://api.github.com/users/galal-hussein/gists{/gist_id}","starred_url":"https://api.github.com/users/galal-hussein/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/galal-hussein/subscriptions","organizations_url":"https://api.github.com/users/galal-hussein/orgs","repos_url":"https://api.github.com/users/galal-hussein/repos","events_url":"https://api.github.com/users/galal-hussein/events{/privacy}","received_events_url":"https://api.github.com/users/galal-hussein/received_events","type":"User","site_admin":false},"html_url":"https://github.com/galal-hussein/rke","description":null,"fork":true,"url":"https://api.github.com/repos/galal-hussein/rke","forks_url":"https://api.github.com/repos/galal-hussein/rke/forks","keys_url":"https://api.github.com/repos/galal-hussein/rke/keys{/key_id}","collaborators_url":"https://api.github.com/repos/galal-hussein/rke/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/galal-hussein/rke/teams","hooks_url":"https://api.github.com/repos/galal-hussein/rke/hooks","issue_events_url":"https://api.github.com/repos/galal-hussein/rke/issues/events{/number}","events_url":"https://api.github.com/repos/galal-hussein/rke/events","assignees_url":"https://api.github.com/repos/galal-hussein/rke/assignees{/user}","branches_url":"https://api.github.com/repos/galal-hussein/rke/branches{/branch}","tags_url":"https://api.github.com/repos/galal-hussein/rke/tags","blobs_url":"https://api.github.com/repos/galal-hussein/rke/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/galal-hussein/rke/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/galal-hussein/rke/git/refs{/sha}","trees_url":"https://api.github.com/repos/galal-hussein/rke/git/trees{/sha}","statuses_url":"https://api.github.com/repos/galal-hussein/rke/statuses/{sha}","languages_url":"https://api.github.com/repos/galal-hussein/rke/languages","stargazers_url":"https://api.github.com/repos/galal-hussein/rke/stargazers","contributors_url":"https://api.github.com/repos/galal-hussein/rke/contributors","subscribers_url":"https://api.github.com/repos/galal-hussein/rke/subscribers","subscription_url":"https://api.github.com/repos/galal-hussein/rke/subscription","commits_url":"https://api.github.com/repos/galal-hussein/rke/commits{/sha}","git_commits_url":"https://api.github.com/repos/galal-hussein/rke/git/commits{/sha}","comments_url":"https://api.github.com/repos/galal-hussein/rke/comments{/number}","issue_comment_url":"https://api.github.com/repos/galal-hussein/rke/issues/comments{/number}","contents_url":"https://api.github.com/repos/galal-hussein/rke/contents/{+path}","compare_url":"https://api.github.com/repos/galal-hussein/rke/compare/{base}...{head}","merges_url":"https://api.github.com/repos/galal-hussein/rke/merges","archive_url":"https://api.github.com/repos/galal-hussein/rke/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/galal-hussein/rke/downloads","issues_url":"https://api.github.com/repos/galal-hussein/rke/issues{/number}","pulls_url":"https://api.github.com/repos/galal-hussein/rke/pulls{/number}","milestones_url":"https://api.github.com/repos/galal-hussein/rke/milestones{/number}","notifications_url":"https://api.github.com/repos/galal-hussein/rke/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/galal-hussein/rke/labels{/name}","releases_url":"https://api.github.com/repos/galal-hussein/rke/releases{/id}","deployments_url":"https://api.github.com/repos/galal-hussein/rke/deployments","created_at":"2017-10-26T00:06:12Z","updated_at":"2017-11-08T00:09:32Z","pushed_at":"2018-11-08T20:43:58Z","git_url":"git://github.com/galal-hussein/rke.git","ssh_url":"git@github.com:galal-hussein/rke.git","clone_url":"https://github.com/galal-hussein/rke.git","svn_url":"https://github.com/galal-hussein/rke","homepage":null,"size":16903,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rancher:master","ref":"master","sha":"fd99385ab1ddc0a4f44c4c6cb4605f948b7ba2dc","user":{"login":"rancher","id":9343010,"node_id":"MDEyOk9yZ2FuaXphdGlvbjkzNDMwMTA=","avatar_url":"https://avatars3.githubusercontent.com/u/9343010?v=4","gravatar_id":"","url":"https://api.github.com/users/rancher","html_url":"https://github.com/rancher","followers_url":"https://api.github.com/users/rancher/followers","following_url":"https://api.github.com/users/rancher/following{/other_user}","gists_url":"https://api.github.com/users/rancher/gists{/gist_id}","starred_url":"https://api.github.com/users/rancher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rancher/subscriptions","organizations_url":"https://api.github.com/users/rancher/orgs","repos_url":"https://api.github.com/users/rancher/repos","events_url":"https://api.github.com/users/rancher/events{/privacy}","received_events_url":"https://api.github.com/users/rancher/received_events","type":"Organization","site_admin":false},"repo":{"id":108337180,"node_id":"MDEwOlJlcG9zaXRvcnkxMDgzMzcxODA=","name":"rke","full_name":"rancher/rke","private":false,"owner":{"login":"rancher","id":9343010,"node_id":"MDEyOk9yZ2FuaXphdGlvbjkzNDMwMTA=","avatar_url":"https://avatars3.githubusercontent.com/u/9343010?v=4","gravatar_id":"","url":"https://api.github.com/users/rancher","html_url":"https://github.com/rancher","followers_url":"https://api.github.com/users/rancher/followers","following_url":"https://api.github.com/users/rancher/following{/other_user}","gists_url":"https://api.github.com/users/rancher/gists{/gist_id}","starred_url":"https://api.github.com/users/rancher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rancher/subscriptions","organizations_url":"https://api.github.com/users/rancher/orgs","repos_url":"https://api.github.com/users/rancher/repos","events_url":"https://api.github.com/users/rancher/events{/privacy}","received_events_url":"https://api.github.com/users/rancher/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/rancher/rke","description":"Rancher Kubernetes Engine, an extremely simple, lightning fast Kubernetes installer that works everywhere.","fork":false,"url":"https://api.github.com/repos/rancher/rke","forks_url":"https://api.github.com/repos/rancher/rke/forks","keys_url":"https://api.github.com/repos/rancher/rke/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rancher/rke/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rancher/rke/teams","hooks_url":"https://api.github.com/repos/rancher/rke/hooks","issue_events_url":"https://api.github.com/repos/rancher/rke/issues/events{/number}","events_url":"https://api.github.com/repos/rancher/rke/events","assignees_url":"https://api.github.com/repos/rancher/rke/assignees{/user}","branches_url":"https://api.github.com/repos/rancher/rke/branches{/branch}","tags_url":"https://api.github.com/repos/rancher/rke/tags","blobs_url":"https://api.github.com/repos/rancher/rke/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rancher/rke/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rancher/rke/git/refs{/sha}","trees_url":"https://api.github.com/repos/rancher/rke/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rancher/rke/statuses/{sha}","languages_url":"https://api.github.com/repos/rancher/rke/languages","stargazers_url":"https://api.github.com/repos/rancher/rke/stargazers","contributors_url":"https://api.github.com/repos/rancher/rke/contributors","subscribers_url":"https://api.github.com/repos/rancher/rke/subscribers","subscription_url":"https://api.github.com/repos/rancher/rke/subscription","commits_url":"https://api.github.com/repos/rancher/rke/commits{/sha}","git_commits_url":"https://api.github.com/repos/rancher/rke/git/commits{/sha}","comments_url":"https://api.github.com/repos/rancher/rke/comments{/number}","issue_comment_url":"https://api.github.com/repos/rancher/rke/issues/comments{/number}","contents_url":"https://api.github.com/repos/rancher/rke/contents/{+path}","compare_url":"https://api.github.com/repos/rancher/rke/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rancher/rke/merges","archive_url":"https://api.github.com/repos/rancher/rke/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rancher/rke/downloads","issues_url":"https://api.github.com/repos/rancher/rke/issues{/number}","pulls_url":"https://api.github.com/repos/rancher/rke/pulls{/number}","milestones_url":"https://api.github.com/repos/rancher/rke/milestones{/number}","notifications_url":"https://api.github.com/repos/rancher/rke/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rancher/rke/labels{/name}","releases_url":"https://api.github.com/repos/rancher/rke/releases{/id}","deployments_url":"https://api.github.com/repos/rancher/rke/deployments","created_at":"2017-10-25T23:25:53Z","updated_at":"2018-11-08T21:14:20Z","pushed_at":"2018-11-08T21:17:55Z","git_url":"git://github.com/rancher/rke.git","ssh_url":"git@github.com:rancher/rke.git","clone_url":"https://github.com/rancher/rke.git","svn_url":"https://github.com/rancher/rke","homepage":"","size":16802,"stargazers_count":876,"watchers_count":876,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":184,"mirror_url":null,"archived":false,"open_issues_count":128,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":184,"open_issues":128,"watchers":876,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rancher/rke/pulls/1009"},"html":{"href":"https://github.com/rancher/rke/pull/1009"},"issue":{"href":"https://api.github.com/repos/rancher/rke/issues/1009"},"comments":{"href":"https://api.github.com/repos/rancher/rke/issues/1009/comments"},"review_comments":{"href":"https://api.github.com/repos/rancher/rke/pulls/1009/comments"},"review_comment":{"href":"https://api.github.com/repos/rancher/rke/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rancher/rke/pulls/1009/commits"},"statuses":{"href":"https://api.github.com/repos/rancher/rke/statuses/a4cbbbbdeb9e8b8e61b3bff2c8e9a5a488c95a1d"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"galal-hussein"}}