mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-05 04:55:22 +00:00
The Velero deployment did not have a way of exposing the namespace it was installed in to the API client. This is a problem for plugins that need to query for resources in that namespaces, such as the restic restore process that needs to find PodVolume(Backup|Restore)s. While the Velero client is consulted for a configured namespace, this cannot be set in the server pod since there is no valid home directory in which to place it. This change provides the namespace to the deployment via the downward API, and updates the API client factory to use the VELERO_NAMESPACE before looking at the config file, so that any plugins using the client will look at the appropriate namespace. Fixes #1743 Signed-off-by: Nolan Brubaker <brubakern@vmware.com>
48 lines
1.7 KiB
Go
48 lines
1.7 KiB
Go
/*
|
|
Copyright 2019 the Velero contributors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package install
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
corev1 "k8s.io/api/core/v1"
|
|
)
|
|
|
|
func TestDeployment(t *testing.T) {
|
|
deploy := Deployment("velero")
|
|
|
|
assert.Equal(t, "velero", deploy.ObjectMeta.Namespace)
|
|
|
|
deploy = Deployment("velero", WithRestoreOnly())
|
|
assert.Equal(t, "--restore-only", deploy.Spec.Template.Spec.Containers[0].Args[1])
|
|
|
|
deploy = Deployment("velero", WithEnvFromSecretKey("my-var", "my-secret", "my-key"))
|
|
envSecret := deploy.Spec.Template.Spec.Containers[0].Env[2]
|
|
assert.Equal(t, "my-var", envSecret.Name)
|
|
assert.Equal(t, "my-secret", envSecret.ValueFrom.SecretKeyRef.LocalObjectReference.Name)
|
|
assert.Equal(t, "my-key", envSecret.ValueFrom.SecretKeyRef.Key)
|
|
|
|
deploy = Deployment("velero", WithImage("gcr.io/heptio-images/velero:v0.11"))
|
|
assert.Equal(t, "gcr.io/heptio-images/velero:v0.11", deploy.Spec.Template.Spec.Containers[0].Image)
|
|
assert.Equal(t, corev1.PullIfNotPresent, deploy.Spec.Template.Spec.Containers[0].ImagePullPolicy)
|
|
|
|
deploy = Deployment("velero", WithSecret(true))
|
|
assert.Equal(t, 5, len(deploy.Spec.Template.Spec.Containers[0].Env))
|
|
assert.Equal(t, 3, len(deploy.Spec.Template.Spec.Volumes))
|
|
}
|