mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-29 03:05:54 +00:00
Add imagePullSecrets inheritance for VGDP pod and maintenance job. (#9102)
Signed-off-by: Xun Jiang <xun.jiang@broadcom.com>
This commit is contained in:
@@ -75,6 +75,11 @@ func GetServiceAccountFromVeleroServer(deployment *appsv1.Deployment) string {
|
||||
return deployment.Spec.Template.Spec.ServiceAccountName
|
||||
}
|
||||
|
||||
// GetImagePullSecretsFromVeleroServer get the image pull secrets from the Velero server deployment
|
||||
func GetImagePullSecretsFromVeleroServer(deployment *appsv1.Deployment) []v1.LocalObjectReference {
|
||||
return deployment.Spec.Template.Spec.ImagePullSecrets
|
||||
}
|
||||
|
||||
// getVeleroServerImage get the image of the Velero server deployment
|
||||
func GetVeleroServerImage(deployment *appsv1.Deployment) string {
|
||||
return deployment.Spec.Template.Spec.Containers[0].Image
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -582,6 +583,63 @@ func TestGetServiceAccountFromVeleroServer(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetImagePullSecretsFromVeleroServer(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
deploy *appsv1.Deployment
|
||||
want []v1.LocalObjectReference
|
||||
}{
|
||||
{
|
||||
name: "no image pull secrets",
|
||||
deploy: &appsv1.Deployment{
|
||||
Spec: appsv1.DeploymentSpec{
|
||||
Template: v1.PodTemplateSpec{
|
||||
Spec: v1.PodSpec{
|
||||
ServiceAccountName: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
want: nil,
|
||||
},
|
||||
{
|
||||
name: "image pull secrets",
|
||||
deploy: &appsv1.Deployment{
|
||||
Spec: appsv1.DeploymentSpec{
|
||||
Template: v1.PodTemplateSpec{
|
||||
Spec: v1.PodSpec{
|
||||
ImagePullSecrets: []v1.LocalObjectReference{
|
||||
{
|
||||
Name: "imagePullSecret1",
|
||||
},
|
||||
{
|
||||
Name: "imagePullSecret2",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
want: []v1.LocalObjectReference{
|
||||
{
|
||||
Name: "imagePullSecret1",
|
||||
},
|
||||
{
|
||||
Name: "imagePullSecret2",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got := GetImagePullSecretsFromVeleroServer(test.deploy)
|
||||
|
||||
require.Equal(t, test.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetVeleroServerImage(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user