Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Limit list k8s objects queries to current namespace for backup and restore #1106

Merged
merged 1 commit into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion controllers/checlusterrestore/backup_data_restorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ func cleanPreviousInstallation(rctx *RestoreContext, dataDir string) (bool, erro
skipBackupObjectsRequirement, _ := labels.NewRequirement(deploy.KubernetesPartOfLabelKey, selection.NotEquals, []string{checlusterbackup.BackupCheEclipseOrg})

cheResourcesLabelSelector := labels.NewSelector().Add(*cheInstanceRequirement).Add(*cheNameRequirement).Add(*skipBackupObjectsRequirement)
cheResourcesListOptions := &client.ListOptions{LabelSelector: cheResourcesLabelSelector}
cheResourcesListOptions := &client.ListOptions{
LabelSelector: cheResourcesLabelSelector,
Namespace: rctx.namespace,
}
cheResourcesMatchingLabelsSelector := client.MatchingLabelsSelector{Selector: cheResourcesLabelSelector}

// Delete all Che related deployments, but keep operator (excluded by name) and internal backup server (excluded by label)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ func (r *ReconcileCheClusterRestore) doReconcile(restoreCR *chev1.CheClusterRest
if backupServerConfigName == "" {
// Try to find backup server configuration in the same namespace
cheBackupServersConfigurationList := &chev1.CheBackupServerConfigurationList{}
if err := r.client.List(context.TODO(), cheBackupServersConfigurationList); err != nil {
listOptions := &client.ListOptions{Namespace: restoreCR.GetNamespace()}
if err := r.client.List(context.TODO(), cheBackupServersConfigurationList, listOptions); err != nil {
return false, err
}
if len(cheBackupServersConfigurationList.Items) != 1 {
Expand Down
7 changes: 4 additions & 3 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,9 +568,10 @@ func ReloadCheCluster(client client.Client, cheCluster *orgv1.CheCluster) error
cheCluster)
}

func FindCheCRinNamespace(client client.Client, namespace string) (*orgv1.CheCluster, int, error) {
func FindCheCRinNamespace(cl client.Client, namespace string) (*orgv1.CheCluster, int, error) {
cheClusters := &orgv1.CheClusterList{}
if err := client.List(context.TODO(), cheClusters); err != nil {
listOptions := &client.ListOptions{Namespace: namespace}
if err := cl.List(context.TODO(), cheClusters, listOptions); err != nil {
return nil, -1, err
}

Expand All @@ -580,7 +581,7 @@ func FindCheCRinNamespace(client client.Client, namespace string) (*orgv1.CheClu

cheCR := &orgv1.CheCluster{}
namespacedName := types.NamespacedName{Namespace: namespace, Name: cheClusters.Items[0].GetName()}
err := client.Get(context.TODO(), namespacedName, cheCR)
err := cl.Get(context.TODO(), namespacedName, cheCR)
if err != nil {
return nil, -1, err
}
Expand Down