Select the velero deployment with both label and container name (#3996)

Select the velero deployment with both label and container name

Fixes #3961

Signed-off-by: Wenkai Yin(尹文开) <yinw@vmware.com>
This commit is contained in:
Wenkai Yin(尹文开)
2021-07-29 12:01:48 -04:00
committed by GitHub
parent 5438ff79e3
commit d8141eabce
2 changed files with 10 additions and 4 deletions
+1
View File
@@ -0,0 +1 @@
Select the velero deployment with both label and container name
+9 -4
View File
@@ -28,7 +28,8 @@ import (
"github.com/vmware-tanzu/velero/pkg/install"
)
// veleroDeployment returns a Velero deployment object, selected using a label.
// veleroDeployment returns a Velero deployment object, selected with label and container name,
// refer to https://github.com/vmware-tanzu/velero/issues/3961 for more information
func veleroDeployment(ctx context.Context, kubeClient kubernetes.Interface, namespace string) (*appsv1api.Deployment, error) {
veleroLabels := labels.FormatLabels(install.Labels())
@@ -42,9 +43,13 @@ func veleroDeployment(ctx context.Context, kubeClient kubernetes.Interface, name
return nil, err
}
if len(deployList.Items) < 1 {
return nil, errors.New("Velero deployment not found")
for _, deploy := range deployList.Items {
for _, container := range deploy.Spec.Template.Spec.Containers {
if container.Name == "velero" {
return &deploy, nil
}
}
}
return &deployList.Items[0], nil
return nil, errors.New("Velero deployment not found")
}