{"action":"created","comment":{"url":"https://api.github.com/repos/heptio/ark/pulls/comments/212130067","pull_request_review_id":148697595,"id":212130067,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxMjEzMDA2Nw==","diff_hunk":"@@ -462,43 +468,92 @@ func mostRecentCompletedBackup(backups []*api.Backup) *api.Backup {\n \treturn nil\n }\n \n-func (c *restoreController) fetchBackup(objectStore cloudprovider.ObjectStore, name string) (*api.Backup, error) {\n-\tbackup, err := c.backupLister.Backups(c.namespace).Get(name)\n-\tif err == nil {\n-\t\treturn backup, nil\n+// fetchBackupInfo checks the backup lister for a backup that matches the given name. If it doesn't\n+// find it, it tries to retrieve it from one of the backup storage locations.\n+func (c *restoreController) fetchBackupInfo(backupName string, pluginManager plugin.Manager) (backupInfo, error) {\n+\tvar info backupInfo\n+\tvar err error\n+\tinfo.backup, err = c.backupLister.Backups(c.namespace).Get(backupName)\n+\tif err != nil {\n+\t\tif !apierrors.IsNotFound(err) {\n+\t\t\treturn backupInfo{}, errors.WithStack(err)\n+\t\t}\n+\n+\t\tlogContext := c.logger.WithField(\"backupName\", backupName)\n+\t\tlogContext.Debug(\"Backup not found in backupLister, checking each backup location directly, starting with default...\")\n+\t\treturn c.fetchFromBackupStorage(backupName, pluginManager)\n \t}\n \n-\tif !apierrors.IsNotFound(err) {\n-\t\treturn nil, errors.WithStack(err)\n+\tlocation, err := c.backupLocationLister.BackupStorageLocations(c.namespace).Get(info.backup.Spec.StorageLocation)\n+\tif err != nil {\n+\t\treturn backupInfo{}, errors.WithStack(err)\n \t}\n \n-\tlogContext := c.logger.WithField(\"backupName\", name)\n+\tinfo.objectStore, err = getObjectStoreForLocation(location, pluginManager)\n+\tif err != nil {\n+\t\treturn backupInfo{}, errors.Wrap(err, \"error initializing object store\")\n+\t}\n+\tinfo.bucketName = location.Spec.ObjectStorage.Bucket\n+\n+\treturn info, nil\n+}\n \n-\tlogContext.Debug(\"Backup not found in backupLister, checking object storage directly\")\n-\tbackup, err = c.getBackup(objectStore, c.bucket, name)\n+// fetchFromBackupStorage checks each backup storage location, starting with the default,\n+// looking for a backup that matches the given backup name.\n+func (c *restoreController) fetchFromBackupStorage(backupName string, pluginManager plugin.Manager) (backupInfo, error) {\n+\tlocations, err := c.backupLocationLister.BackupStorageLocations(c.namespace).List(labels.Everything())\n \tif err != nil {\n-\t\treturn nil, err\n+\t\treturn backupInfo{}, err\n+\t}\n+\n+\tidx := 1\n+\torderedLocations := make([]*api.BackupStorageLocation, len(locations))\n+\tfor i := 0; i < len(locations); i++ {\n+\t\tif locations[i].Name == c.defaultBackupLocation {\n+\t\t\torderedLocations[0] = locations[i]\n+\t\t} else {\n+\t\t\torderedLocations[idx] = locations[i]\n+\t\t\tidx++\n+\t\t}\n \t}\n \n-\t// ResourceVersion needs to be cleared in order to create the object in the API\n-\tbackup.ResourceVersion = \"\"\n-\t// Clear out the namespace too, just in case\n-\tbackup.Namespace = \"\"\n+\tlogContext := c.logger.WithField(\"backupName\", backupName)\n+\tvar info backupInfo\n+\tfor _, location := range orderedLocations {\n+\t\tinfo.objectStore, err = getObjectStoreForLocation(location, pluginManager)\n+\t\tif err != nil {\n+\t\t\tlogContext.WithError(errors.WithStack(err)).Error(\"Unable to get an object store in the location \", location.Name)\n+\t\t\tcontinue\n+\t\t}\n \n-\tcreated, createErr := c.backupClient.Backups(c.namespace).Create(backup)\n-\tif createErr != nil {\n-\t\tlogContext.WithError(errors.WithStack(createErr)).Error(\"Unable to create API object for Backup\")\n-\t} else {\n-\t\tbackup = created\n+\t\tinfo.backup, err = c.getBackup(info.objectStore, location.Spec.ObjectStorage.Bucket, backupName)\n+\t\tif err != nil {\n+\t\t\tlogContext.WithError(errors.WithStack(err)).Error(\"Unable to find a backup in the location \", location.Name)\n+\t\t\tcontinue\n+\t\t}\n+\n+\t\t// ResourceVersion needs to be cleared in order to create the object in the API\n+\t\tinfo.backup.ResourceVersion = \"\"\n+\t\t// Clear out the namespace, in case the backup was made in a different cluster, with a different namespace\n+\t\tinfo.backup.Namespace = \"\"\n+\n+\t\tinfo.backup, err = c.backupClient.Backups(c.namespace).Create(info.backup)\n+\t\tif err != nil {\n+\t\t\tlogContext.WithError(errors.WithStack(err)).Error(\"Unable to create API object for Backup\")","path":"pkg/controller/restore_controller.go","position":356,"original_position":356,"commit_id":"6944e0c14056b4ed84f51d31b6e53b10b8bdd493","original_commit_id":"6944e0c14056b4ed84f51d31b6e53b10b8bdd493","user":{"login":"carlisia","id":16508,"node_id":"MDQ6VXNlcjE2NTA4","avatar_url":"https://avatars0.githubusercontent.com/u/16508?v=4","gravatar_id":"","url":"https://api.github.com/users/carlisia","html_url":"https://github.com/carlisia","followers_url":"https://api.github.com/users/carlisia/followers","following_url":"https://api.github.com/users/carlisia/following{/other_user}","gists_url":"https://api.github.com/users/carlisia/gists{/gist_id}","starred_url":"https://api.github.com/users/carlisia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carlisia/subscriptions","organizations_url":"https://api.github.com/users/carlisia/orgs","repos_url":"https://api.github.com/users/carlisia/repos","events_url":"https://api.github.com/users/carlisia/events{/privacy}","received_events_url":"https://api.github.com/users/carlisia/received_events","type":"User","site_admin":false},"body":"Ok I see. I didn't make my reasoning at all clear. Here it is: I thought a valid backup to use was one that was found + created. So this is not the case? If we create it or not doesn't matter?","created_at":"2018-08-22T22:26:21Z","updated_at":"2018-08-22T22:33:29Z","html_url":"https://github.com/heptio/ark/pull/766#discussion_r212130067","pull_request_url":"https://api.github.com/repos/heptio/ark/pulls/766","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/heptio/ark/pulls/comments/212130067"},"html":{"href":"https://github.com/heptio/ark/pull/766#discussion_r212130067"},"pull_request":{"href":"https://api.github.com/repos/heptio/ark/pulls/766"}},"in_reply_to_id":212115506},"pull_request":{"url":"https://api.github.com/repos/heptio/ark/pulls/766","id":208302382,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA4MzAyMzgy","html_url":"https://github.com/heptio/ark/pull/766","diff_url":"https://github.com/heptio/ark/pull/766.diff","patch_url":"https://github.com/heptio/ark/pull/766.patch","issue_url":"https://api.github.com/repos/heptio/ark/issues/766","number":766,"state":"open","locked":false,"title":"[WIP] Use backup storage location during restore","user":{"login":"carlisia","id":16508,"node_id":"MDQ6VXNlcjE2NTA4","avatar_url":"https://avatars0.githubusercontent.com/u/16508?v=4","gravatar_id":"","url":"https://api.github.com/users/carlisia","html_url":"https://github.com/carlisia","followers_url":"https://api.github.com/users/carlisia/followers","following_url":"https://api.github.com/users/carlisia/following{/other_user}","gists_url":"https://api.github.com/users/carlisia/gists{/gist_id}","starred_url":"https://api.github.com/users/carlisia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carlisia/subscriptions","organizations_url":"https://api.github.com/users/carlisia/orgs","repos_url":"https://api.github.com/users/carlisia/repos","events_url":"https://api.github.com/users/carlisia/events{/privacy}","received_events_url":"https://api.github.com/users/carlisia/received_events","type":"User","site_admin":false},"body":"Closes #740\r\n\r\nSigned-off-by: Carlisia <carlisia@grokkingtech.io>","created_at":"2018-08-14T14:31:43Z","updated_at":"2018-08-22T22:33:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d3ad06a18aa64d7b6905dce1793c9fa6aca83adc","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/heptio/ark/pulls/766/commits","review_comments_url":"https://api.github.com/repos/heptio/ark/pulls/766/comments","review_comment_url":"https://api.github.com/repos/heptio/ark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/heptio/ark/issues/766/comments","statuses_url":"https://api.github.com/repos/heptio/ark/statuses/6944e0c14056b4ed84f51d31b6e53b10b8bdd493","head":{"label":"carlisia:c-740-restore","ref":"c-740-restore","sha":"6944e0c14056b4ed84f51d31b6e53b10b8bdd493","user":{"login":"carlisia","id":16508,"node_id":"MDQ6VXNlcjE2NTA4","avatar_url":"https://avatars0.githubusercontent.com/u/16508?v=4","gravatar_id":"","url":"https://api.github.com/users/carlisia","html_url":"https://github.com/carlisia","followers_url":"https://api.github.com/users/carlisia/followers","following_url":"https://api.github.com/users/carlisia/following{/other_user}","gists_url":"https://api.github.com/users/carlisia/gists{/gist_id}","starred_url":"https://api.github.com/users/carlisia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carlisia/subscriptions","organizations_url":"https://api.github.com/users/carlisia/orgs","repos_url":"https://api.github.com/users/carlisia/repos","events_url":"https://api.github.com/users/carlisia/events{/privacy}","received_events_url":"https://api.github.com/users/carlisia/received_events","type":"User","site_admin":false},"repo":{"id":139633950,"node_id":"MDEwOlJlcG9zaXRvcnkxMzk2MzM5NTA=","name":"ark","full_name":"carlisia/ark","owner":{"login":"carlisia","id":16508,"node_id":"MDQ6VXNlcjE2NTA4","avatar_url":"https://avatars0.githubusercontent.com/u/16508?v=4","gravatar_id":"","url":"https://api.github.com/users/carlisia","html_url":"https://github.com/carlisia","followers_url":"https://api.github.com/users/carlisia/followers","following_url":"https://api.github.com/users/carlisia/following{/other_user}","gists_url":"https://api.github.com/users/carlisia/gists{/gist_id}","starred_url":"https://api.github.com/users/carlisia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carlisia/subscriptions","organizations_url":"https://api.github.com/users/carlisia/orgs","repos_url":"https://api.github.com/users/carlisia/repos","events_url":"https://api.github.com/users/carlisia/events{/privacy}","received_events_url":"https://api.github.com/users/carlisia/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/carlisia/ark","description":"Heptio Ark is a utility for managing disaster recovery, specifically for your Kubernetes cluster resources and persistent volumes. Brought to you by Heptio.","fork":true,"url":"https://api.github.com/repos/carlisia/ark","forks_url":"https://api.github.com/repos/carlisia/ark/forks","keys_url":"https://api.github.com/repos/carlisia/ark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/carlisia/ark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/carlisia/ark/teams","hooks_url":"https://api.github.com/repos/carlisia/ark/hooks","issue_events_url":"https://api.github.com/repos/carlisia/ark/issues/events{/number}","events_url":"https://api.github.com/repos/carlisia/ark/events","assignees_url":"https://api.github.com/repos/carlisia/ark/assignees{/user}","branches_url":"https://api.github.com/repos/carlisia/ark/branches{/branch}","tags_url":"https://api.github.com/repos/carlisia/ark/tags","blobs_url":"https://api.github.com/repos/carlisia/ark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/carlisia/ark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/carlisia/ark/git/refs{/sha}","trees_url":"https://api.github.com/repos/carlisia/ark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/carlisia/ark/statuses/{sha}","languages_url":"https://api.github.com/repos/carlisia/ark/languages","stargazers_url":"https://api.github.com/repos/carlisia/ark/stargazers","contributors_url":"https://api.github.com/repos/carlisia/ark/contributors","subscribers_url":"https://api.github.com/repos/carlisia/ark/subscribers","subscription_url":"https://api.github.com/repos/carlisia/ark/subscription","commits_url":"https://api.github.com/repos/carlisia/ark/commits{/sha}","git_commits_url":"https://api.github.com/repos/carlisia/ark/git/commits{/sha}","comments_url":"https://api.github.com/repos/carlisia/ark/comments{/number}","issue_comment_url":"https://api.github.com/repos/carlisia/ark/issues/comments{/number}","contents_url":"https://api.github.com/repos/carlisia/ark/contents/{+path}","compare_url":"https://api.github.com/repos/carlisia/ark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/carlisia/ark/merges","archive_url":"https://api.github.com/repos/carlisia/ark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/carlisia/ark/downloads","issues_url":"https://api.github.com/repos/carlisia/ark/issues{/number}","pulls_url":"https://api.github.com/repos/carlisia/ark/pulls{/number}","milestones_url":"https://api.github.com/repos/carlisia/ark/milestones{/number}","notifications_url":"https://api.github.com/repos/carlisia/ark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/carlisia/ark/labels{/name}","releases_url":"https://api.github.com/repos/carlisia/ark/releases{/id}","deployments_url":"https://api.github.com/repos/carlisia/ark/deployments","created_at":"2018-07-03T20:26:51Z","updated_at":"2018-07-03T20:26:54Z","pushed_at":"2018-08-22T20:55:29Z","git_url":"git://github.com/carlisia/ark.git","ssh_url":"git@github.com:carlisia/ark.git","clone_url":"https://github.com/carlisia/ark.git","svn_url":"https://github.com/carlisia/ark","homepage":"https://www.heptio.com","size":10492,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"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":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"heptio:backup-locations","ref":"backup-locations","sha":"c069017b26927d693218ab16bc7db0f29c53072c","user":{"login":"heptio","id":22035492,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIyMDM1NDky","avatar_url":"https://avatars0.githubusercontent.com/u/22035492?v=4","gravatar_id":"","url":"https://api.github.com/users/heptio","html_url":"https://github.com/heptio","followers_url":"https://api.github.com/users/heptio/followers","following_url":"https://api.github.com/users/heptio/following{/other_user}","gists_url":"https://api.github.com/users/heptio/gists{/gist_id}","starred_url":"https://api.github.com/users/heptio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heptio/subscriptions","organizations_url":"https://api.github.com/users/heptio/orgs","repos_url":"https://api.github.com/users/heptio/repos","events_url":"https://api.github.com/users/heptio/events{/privacy}","received_events_url":"https://api.github.com/users/heptio/received_events","type":"Organization","site_admin":false},"repo":{"id":99143276,"node_id":"MDEwOlJlcG9zaXRvcnk5OTE0MzI3Ng==","name":"ark","full_name":"heptio/ark","owner":{"login":"heptio","id":22035492,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIyMDM1NDky","avatar_url":"https://avatars0.githubusercontent.com/u/22035492?v=4","gravatar_id":"","url":"https://api.github.com/users/heptio","html_url":"https://github.com/heptio","followers_url":"https://api.github.com/users/heptio/followers","following_url":"https://api.github.com/users/heptio/following{/other_user}","gists_url":"https://api.github.com/users/heptio/gists{/gist_id}","starred_url":"https://api.github.com/users/heptio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heptio/subscriptions","organizations_url":"https://api.github.com/users/heptio/orgs","repos_url":"https://api.github.com/users/heptio/repos","events_url":"https://api.github.com/users/heptio/events{/privacy}","received_events_url":"https://api.github.com/users/heptio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/heptio/ark","description":"Heptio Ark is a utility for managing disaster recovery, specifically for your Kubernetes cluster resources and persistent volumes. Brought to you by Heptio.","fork":false,"url":"https://api.github.com/repos/heptio/ark","forks_url":"https://api.github.com/repos/heptio/ark/forks","keys_url":"https://api.github.com/repos/heptio/ark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/heptio/ark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/heptio/ark/teams","hooks_url":"https://api.github.com/repos/heptio/ark/hooks","issue_events_url":"https://api.github.com/repos/heptio/ark/issues/events{/number}","events_url":"https://api.github.com/repos/heptio/ark/events","assignees_url":"https://api.github.com/repos/heptio/ark/assignees{/user}","branches_url":"https://api.github.com/repos/heptio/ark/branches{/branch}","tags_url":"https://api.github.com/repos/heptio/ark/tags","blobs_url":"https://api.github.com/repos/heptio/ark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/heptio/ark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/heptio/ark/git/refs{/sha}","trees_url":"https://api.github.com/repos/heptio/ark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/heptio/ark/statuses/{sha}","languages_url":"https://api.github.com/repos/heptio/ark/languages","stargazers_url":"https://api.github.com/repos/heptio/ark/stargazers","contributors_url":"https://api.github.com/repos/heptio/ark/contributors","subscribers_url":"https://api.github.com/repos/heptio/ark/subscribers","subscription_url":"https://api.github.com/repos/heptio/ark/subscription","commits_url":"https://api.github.com/repos/heptio/ark/commits{/sha}","git_commits_url":"https://api.github.com/repos/heptio/ark/git/commits{/sha}","comments_url":"https://api.github.com/repos/heptio/ark/comments{/number}","issue_comment_url":"https://api.github.com/repos/heptio/ark/issues/comments{/number}","contents_url":"https://api.github.com/repos/heptio/ark/contents/{+path}","compare_url":"https://api.github.com/repos/heptio/ark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/heptio/ark/merges","archive_url":"https://api.github.com/repos/heptio/ark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/heptio/ark/downloads","issues_url":"https://api.github.com/repos/heptio/ark/issues{/number}","pulls_url":"https://api.github.com/repos/heptio/ark/pulls{/number}","milestones_url":"https://api.github.com/repos/heptio/ark/milestones{/number}","notifications_url":"https://api.github.com/repos/heptio/ark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/heptio/ark/labels{/name}","releases_url":"https://api.github.com/repos/heptio/ark/releases{/id}","deployments_url":"https://api.github.com/repos/heptio/ark/deployments","created_at":"2017-08-02T17:22:11Z","updated_at":"2018-08-22T21:37:59Z","pushed_at":"2018-08-22T20:55:30Z","git_url":"git://github.com/heptio/ark.git","ssh_url":"git@github.com:heptio/ark.git","clone_url":"https://github.com/heptio/ark.git","svn_url":"https://github.com/heptio/ark","homepage":"https://www.heptio.com","size":10513,"stargazers_count":1430,"watchers_count":1430,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":182,"mirror_url":null,"archived":false,"open_issues_count":166,"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":182,"open_issues":166,"watchers":1430,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/heptio/ark/pulls/766"},"html":{"href":"https://github.com/heptio/ark/pull/766"},"issue":{"href":"https://api.github.com/repos/heptio/ark/issues/766"},"comments":{"href":"https://api.github.com/repos/heptio/ark/issues/766/comments"},"review_comments":{"href":"https://api.github.com/repos/heptio/ark/pulls/766/comments"},"review_comment":{"href":"https://api.github.com/repos/heptio/ark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/heptio/ark/pulls/766/commits"},"statuses":{"href":"https://api.github.com/repos/heptio/ark/statuses/6944e0c14056b4ed84f51d31b6e53b10b8bdd493"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"carlisia"}}