mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-05 13:05:17 +00:00
chore: define common aliases for k8s packages (#8672)
Some checks failed
Run the E2E test on kind / build (push) Failing after 6m48s
Run the E2E test on kind / setup-test-matrix (push) Successful in 3s
Run the E2E test on kind / run-e2e-test (push) Has been skipped
Main CI / Build (push) Failing after 35s
Close stale issues and PRs / stale (push) Successful in 8s
Trivy Nightly Scan / Trivy nightly scan (velero, main) (push) Failing after 1m11s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-aws, main) (push) Failing after 47s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-gcp, main) (push) Failing after 49s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-microsoft-azure, main) (push) Failing after 43s
Some checks failed
Run the E2E test on kind / build (push) Failing after 6m48s
Run the E2E test on kind / setup-test-matrix (push) Successful in 3s
Run the E2E test on kind / run-e2e-test (push) Has been skipped
Main CI / Build (push) Failing after 35s
Close stale issues and PRs / stale (push) Successful in 8s
Trivy Nightly Scan / Trivy nightly scan (velero, main) (push) Failing after 1m11s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-aws, main) (push) Failing after 47s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-gcp, main) (push) Failing after 49s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-microsoft-azure, main) (push) Failing after 43s
* lchore: define common alias for k8s packages Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> * Update .golangci.yaml Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> * Update .golangci.yaml Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> * Update .golangci.yaml Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> --------- Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
@@ -20,14 +20,14 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
appsv1api "k8s.io/api/apps/v1"
|
||||
corev1api "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/vmware-tanzu/velero/internal/velero"
|
||||
)
|
||||
|
||||
func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1.DaemonSet {
|
||||
func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1api.DaemonSet {
|
||||
c := &podTemplateConfig{
|
||||
image: velero.DefaultVeleroImage(),
|
||||
}
|
||||
@@ -36,10 +36,10 @@ func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1.DaemonSet {
|
||||
opt(c)
|
||||
}
|
||||
|
||||
pullPolicy := corev1.PullAlways
|
||||
pullPolicy := corev1api.PullAlways
|
||||
imageParts := strings.Split(c.image, ":")
|
||||
if len(imageParts) == 2 && imageParts[1] != "latest" {
|
||||
pullPolicy = corev1.PullIfNotPresent
|
||||
pullPolicy = corev1api.PullIfNotPresent
|
||||
}
|
||||
|
||||
daemonSetArgs := []string{
|
||||
@@ -55,26 +55,26 @@ func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1.DaemonSet {
|
||||
}
|
||||
|
||||
userID := int64(0)
|
||||
mountPropagationMode := corev1.MountPropagationHostToContainer
|
||||
mountPropagationMode := corev1api.MountPropagationHostToContainer
|
||||
|
||||
dsName := "node-agent"
|
||||
if c.forWindows {
|
||||
dsName = "node-agent-windows"
|
||||
}
|
||||
|
||||
daemonSet := &appsv1.DaemonSet{
|
||||
daemonSet := &appsv1api.DaemonSet{
|
||||
ObjectMeta: objectMeta(namespace, dsName),
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "DaemonSet",
|
||||
APIVersion: appsv1.SchemeGroupVersion.String(),
|
||||
APIVersion: appsv1api.SchemeGroupVersion.String(),
|
||||
},
|
||||
Spec: appsv1.DaemonSetSpec{
|
||||
Spec: appsv1api.DaemonSetSpec{
|
||||
Selector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"name": dsName,
|
||||
},
|
||||
},
|
||||
Template: corev1.PodTemplateSpec{
|
||||
Template: corev1api.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: podLabels(c.labels, map[string]string{
|
||||
"name": dsName,
|
||||
@@ -82,36 +82,36 @@ func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1.DaemonSet {
|
||||
}),
|
||||
Annotations: c.annotations,
|
||||
},
|
||||
Spec: corev1.PodSpec{
|
||||
Spec: corev1api.PodSpec{
|
||||
ServiceAccountName: c.serviceAccountName,
|
||||
SecurityContext: &corev1.PodSecurityContext{
|
||||
SecurityContext: &corev1api.PodSecurityContext{
|
||||
RunAsUser: &userID,
|
||||
},
|
||||
Volumes: []corev1.Volume{
|
||||
Volumes: []corev1api.Volume{
|
||||
{
|
||||
Name: "host-pods",
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
HostPath: &corev1.HostPathVolumeSource{
|
||||
VolumeSource: corev1api.VolumeSource{
|
||||
HostPath: &corev1api.HostPathVolumeSource{
|
||||
Path: "/var/lib/kubelet/pods",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "host-plugins",
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
HostPath: &corev1.HostPathVolumeSource{
|
||||
VolumeSource: corev1api.VolumeSource{
|
||||
HostPath: &corev1api.HostPathVolumeSource{
|
||||
Path: "/var/lib/kubelet/plugins",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "scratch",
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
EmptyDir: new(corev1.EmptyDirVolumeSource),
|
||||
VolumeSource: corev1api.VolumeSource{
|
||||
EmptyDir: new(corev1api.EmptyDirVolumeSource),
|
||||
},
|
||||
},
|
||||
},
|
||||
Containers: []corev1.Container{
|
||||
Containers: []corev1api.Container{
|
||||
{
|
||||
Name: dsName,
|
||||
Image: c.image,
|
||||
@@ -121,10 +121,10 @@ func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1.DaemonSet {
|
||||
"/velero",
|
||||
},
|
||||
Args: daemonSetArgs,
|
||||
SecurityContext: &corev1.SecurityContext{
|
||||
SecurityContext: &corev1api.SecurityContext{
|
||||
Privileged: &c.privilegedNodeAgent,
|
||||
},
|
||||
VolumeMounts: []corev1.VolumeMount{
|
||||
VolumeMounts: []corev1api.VolumeMount{
|
||||
{
|
||||
Name: "host-pods",
|
||||
MountPath: "/host_pods",
|
||||
@@ -140,19 +140,19 @@ func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1.DaemonSet {
|
||||
MountPath: "/scratch",
|
||||
},
|
||||
},
|
||||
Env: []corev1.EnvVar{
|
||||
Env: []corev1api.EnvVar{
|
||||
{
|
||||
Name: "NODE_NAME",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
FieldRef: &corev1.ObjectFieldSelector{
|
||||
ValueFrom: &corev1api.EnvVarSource{
|
||||
FieldRef: &corev1api.ObjectFieldSelector{
|
||||
FieldPath: "spec.nodeName",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "VELERO_NAMESPACE",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
FieldRef: &corev1.ObjectFieldSelector{
|
||||
ValueFrom: &corev1api.EnvVarSource{
|
||||
FieldRef: &corev1api.ObjectFieldSelector{
|
||||
FieldPath: "metadata.namespace",
|
||||
},
|
||||
},
|
||||
@@ -173,10 +173,10 @@ func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1.DaemonSet {
|
||||
if c.withSecret {
|
||||
daemonSet.Spec.Template.Spec.Volumes = append(
|
||||
daemonSet.Spec.Template.Spec.Volumes,
|
||||
corev1.Volume{
|
||||
corev1api.Volume{
|
||||
Name: "cloud-credentials",
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
Secret: &corev1.SecretVolumeSource{
|
||||
VolumeSource: corev1api.VolumeSource{
|
||||
Secret: &corev1api.SecretVolumeSource{
|
||||
SecretName: "cloud-credentials",
|
||||
},
|
||||
},
|
||||
@@ -185,13 +185,13 @@ func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1.DaemonSet {
|
||||
|
||||
daemonSet.Spec.Template.Spec.Containers[0].VolumeMounts = append(
|
||||
daemonSet.Spec.Template.Spec.Containers[0].VolumeMounts,
|
||||
corev1.VolumeMount{
|
||||
corev1api.VolumeMount{
|
||||
Name: "cloud-credentials",
|
||||
MountPath: "/credentials",
|
||||
},
|
||||
)
|
||||
|
||||
daemonSet.Spec.Template.Spec.Containers[0].Env = append(daemonSet.Spec.Template.Spec.Containers[0].Env, []corev1.EnvVar{
|
||||
daemonSet.Spec.Template.Spec.Containers[0].Env = append(daemonSet.Spec.Template.Spec.Containers[0].Env, []corev1api.EnvVar{
|
||||
{
|
||||
Name: "GOOGLE_APPLICATION_CREDENTIALS",
|
||||
Value: "/credentials/cloud",
|
||||
@@ -217,10 +217,10 @@ func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1.DaemonSet {
|
||||
daemonSet.Spec.Template.Spec.NodeSelector = map[string]string{
|
||||
"kubernetes.io/os": "windows",
|
||||
}
|
||||
daemonSet.Spec.Template.Spec.OS = &corev1.PodOS{
|
||||
daemonSet.Spec.Template.Spec.OS = &corev1api.PodOS{
|
||||
Name: "windows",
|
||||
}
|
||||
daemonSet.Spec.Template.Spec.Tolerations = []corev1.Toleration{
|
||||
daemonSet.Spec.Template.Spec.Tolerations = []corev1api.Toleration{
|
||||
{
|
||||
Key: "os",
|
||||
Operator: "Equal",
|
||||
@@ -232,7 +232,7 @@ func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1.DaemonSet {
|
||||
daemonSet.Spec.Template.Spec.NodeSelector = map[string]string{
|
||||
"kubernetes.io/os": "linux",
|
||||
}
|
||||
daemonSet.Spec.Template.Spec.OS = &corev1.PodOS{
|
||||
daemonSet.Spec.Template.Spec.OS = &corev1api.PodOS{
|
||||
Name: "linux",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
corev1api "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
func TestDaemonSet(t *testing.T) {
|
||||
@@ -36,15 +36,15 @@ func TestDaemonSet(t *testing.T) {
|
||||
assert.Equal(t, "node-agent", ds.Spec.Template.ObjectMeta.Labels["role"])
|
||||
assert.Equal(t, "linux", ds.Spec.Template.Spec.NodeSelector["kubernetes.io/os"])
|
||||
assert.Equal(t, "linux", string(ds.Spec.Template.Spec.OS.Name))
|
||||
assert.Equal(t, corev1.PodSecurityContext{RunAsUser: &userID}, *ds.Spec.Template.Spec.SecurityContext)
|
||||
assert.Equal(t, corev1.SecurityContext{Privileged: &boolFalse}, *ds.Spec.Template.Spec.Containers[0].SecurityContext)
|
||||
assert.Equal(t, corev1api.PodSecurityContext{RunAsUser: &userID}, *ds.Spec.Template.Spec.SecurityContext)
|
||||
assert.Equal(t, corev1api.SecurityContext{Privileged: &boolFalse}, *ds.Spec.Template.Spec.Containers[0].SecurityContext)
|
||||
|
||||
ds = DaemonSet("velero", WithPrivilegedNodeAgent(true))
|
||||
assert.Equal(t, corev1.SecurityContext{Privileged: &boolTrue}, *ds.Spec.Template.Spec.Containers[0].SecurityContext)
|
||||
assert.Equal(t, corev1api.SecurityContext{Privileged: &boolTrue}, *ds.Spec.Template.Spec.Containers[0].SecurityContext)
|
||||
|
||||
ds = DaemonSet("velero", WithImage("velero/velero:v0.11"))
|
||||
assert.Equal(t, "velero/velero:v0.11", ds.Spec.Template.Spec.Containers[0].Image)
|
||||
assert.Equal(t, corev1.PullIfNotPresent, ds.Spec.Template.Spec.Containers[0].ImagePullPolicy)
|
||||
assert.Equal(t, corev1api.PullIfNotPresent, ds.Spec.Template.Spec.Containers[0].ImagePullPolicy)
|
||||
|
||||
ds = DaemonSet("velero", WithSecret(true))
|
||||
assert.Len(t, ds.Spec.Template.Spec.Containers[0].Env, 7)
|
||||
@@ -68,6 +68,6 @@ func TestDaemonSet(t *testing.T) {
|
||||
assert.Equal(t, "node-agent", ds.Spec.Template.ObjectMeta.Labels["role"])
|
||||
assert.Equal(t, "windows", ds.Spec.Template.Spec.NodeSelector["kubernetes.io/os"])
|
||||
assert.Equal(t, "windows", string(ds.Spec.Template.Spec.OS.Name))
|
||||
assert.Equal(t, (*corev1.PodSecurityContext)(nil), ds.Spec.Template.Spec.SecurityContext)
|
||||
assert.Equal(t, (*corev1.SecurityContext)(nil), ds.Spec.Template.Spec.Containers[0].SecurityContext)
|
||||
assert.Equal(t, (*corev1api.PodSecurityContext)(nil), ds.Spec.Template.Spec.SecurityContext)
|
||||
assert.Equal(t, (*corev1api.SecurityContext)(nil), ds.Spec.Template.Spec.Containers[0].SecurityContext)
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
appsv1api "k8s.io/api/apps/v1"
|
||||
corev1api "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/vmware-tanzu/velero/internal/velero"
|
||||
@@ -34,11 +34,11 @@ type podTemplateOption func(*podTemplateConfig)
|
||||
|
||||
type podTemplateConfig struct {
|
||||
image string
|
||||
envVars []corev1.EnvVar
|
||||
envVars []corev1api.EnvVar
|
||||
restoreOnly bool
|
||||
annotations map[string]string
|
||||
labels map[string]string
|
||||
resources corev1.ResourceRequirements
|
||||
resources corev1api.ResourceRequirements
|
||||
withSecret bool
|
||||
defaultRepoMaintenanceFrequency time.Duration
|
||||
garbageCollectionFrequency time.Duration
|
||||
@@ -81,11 +81,11 @@ func WithLabels(labels map[string]string) podTemplateOption {
|
||||
|
||||
func WithEnvFromSecretKey(varName, secret, key string) podTemplateOption {
|
||||
return func(c *podTemplateConfig) {
|
||||
c.envVars = append(c.envVars, corev1.EnvVar{
|
||||
c.envVars = append(c.envVars, corev1api.EnvVar{
|
||||
Name: varName,
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
SecretKeyRef: &corev1.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{
|
||||
ValueFrom: &corev1api.EnvVarSource{
|
||||
SecretKeyRef: &corev1api.SecretKeySelector{
|
||||
LocalObjectReference: corev1api.LocalObjectReference{
|
||||
Name: secret,
|
||||
},
|
||||
Key: key,
|
||||
@@ -107,7 +107,7 @@ func WithRestoreOnly(b bool) podTemplateOption {
|
||||
}
|
||||
}
|
||||
|
||||
func WithResources(resources corev1.ResourceRequirements) podTemplateOption {
|
||||
func WithResources(resources corev1api.ResourceRequirements) podTemplateOption {
|
||||
return func(c *podTemplateConfig) {
|
||||
c.resources = resources
|
||||
}
|
||||
@@ -226,7 +226,7 @@ func WithForWindows() podTemplateOption {
|
||||
}
|
||||
}
|
||||
|
||||
func Deployment(namespace string, opts ...podTemplateOption) *appsv1.Deployment {
|
||||
func Deployment(namespace string, opts ...podTemplateOption) *appsv1api.Deployment {
|
||||
// TODO: Add support for server args
|
||||
c := &podTemplateConfig{
|
||||
image: velero.DefaultVeleroImage(),
|
||||
@@ -236,10 +236,10 @@ func Deployment(namespace string, opts ...podTemplateOption) *appsv1.Deployment
|
||||
opt(c)
|
||||
}
|
||||
|
||||
pullPolicy := corev1.PullAlways
|
||||
pullPolicy := corev1api.PullAlways
|
||||
imageParts := strings.Split(c.image, ":")
|
||||
if len(imageParts) == 2 && imageParts[1] != "latest" {
|
||||
pullPolicy = corev1.PullIfNotPresent
|
||||
pullPolicy = corev1api.PullIfNotPresent
|
||||
}
|
||||
|
||||
args := []string{"server"}
|
||||
@@ -315,29 +315,29 @@ func Deployment(namespace string, opts ...podTemplateOption) *appsv1.Deployment
|
||||
args = append(args, fmt.Sprintf("--item-block-worker-count=%d", c.itemBlockWorkerCount))
|
||||
}
|
||||
|
||||
deployment := &appsv1.Deployment{
|
||||
deployment := &appsv1api.Deployment{
|
||||
ObjectMeta: objectMeta(namespace, "velero"),
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Deployment",
|
||||
APIVersion: appsv1.SchemeGroupVersion.String(),
|
||||
APIVersion: appsv1api.SchemeGroupVersion.String(),
|
||||
},
|
||||
Spec: appsv1.DeploymentSpec{
|
||||
Spec: appsv1api.DeploymentSpec{
|
||||
Selector: &metav1.LabelSelector{MatchLabels: map[string]string{"deploy": "velero"}},
|
||||
Template: corev1.PodTemplateSpec{
|
||||
Template: corev1api.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: podLabels(c.labels, map[string]string{"deploy": "velero"}),
|
||||
Annotations: podAnnotations(c.annotations),
|
||||
},
|
||||
Spec: corev1.PodSpec{
|
||||
RestartPolicy: corev1.RestartPolicyAlways,
|
||||
Spec: corev1api.PodSpec{
|
||||
RestartPolicy: corev1api.RestartPolicyAlways,
|
||||
ServiceAccountName: c.serviceAccountName,
|
||||
NodeSelector: map[string]string{
|
||||
"kubernetes.io/os": "linux",
|
||||
},
|
||||
OS: &corev1.PodOS{
|
||||
OS: &corev1api.PodOS{
|
||||
Name: "linux",
|
||||
},
|
||||
Containers: []corev1.Container{
|
||||
Containers: []corev1api.Container{
|
||||
{
|
||||
Name: "velero",
|
||||
Image: c.image,
|
||||
@@ -347,7 +347,7 @@ func Deployment(namespace string, opts ...podTemplateOption) *appsv1.Deployment
|
||||
"/velero",
|
||||
},
|
||||
Args: args,
|
||||
VolumeMounts: []corev1.VolumeMount{
|
||||
VolumeMounts: []corev1api.VolumeMount{
|
||||
{
|
||||
Name: "plugins",
|
||||
MountPath: "/plugins",
|
||||
@@ -357,15 +357,15 @@ func Deployment(namespace string, opts ...podTemplateOption) *appsv1.Deployment
|
||||
MountPath: "/scratch",
|
||||
},
|
||||
},
|
||||
Env: []corev1.EnvVar{
|
||||
Env: []corev1api.EnvVar{
|
||||
{
|
||||
Name: "VELERO_SCRATCH_DIR",
|
||||
Value: "/scratch",
|
||||
},
|
||||
{
|
||||
Name: "VELERO_NAMESPACE",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
FieldRef: &corev1.ObjectFieldSelector{
|
||||
ValueFrom: &corev1api.EnvVarSource{
|
||||
FieldRef: &corev1api.ObjectFieldSelector{
|
||||
FieldPath: "metadata.namespace",
|
||||
},
|
||||
},
|
||||
@@ -378,17 +378,17 @@ func Deployment(namespace string, opts ...podTemplateOption) *appsv1.Deployment
|
||||
Resources: c.resources,
|
||||
},
|
||||
},
|
||||
Volumes: []corev1.Volume{
|
||||
Volumes: []corev1api.Volume{
|
||||
{
|
||||
Name: "plugins",
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
EmptyDir: &corev1.EmptyDirVolumeSource{},
|
||||
VolumeSource: corev1api.VolumeSource{
|
||||
EmptyDir: &corev1api.EmptyDirVolumeSource{},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "scratch",
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
EmptyDir: new(corev1.EmptyDirVolumeSource),
|
||||
VolumeSource: corev1api.VolumeSource{
|
||||
EmptyDir: new(corev1api.EmptyDirVolumeSource),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -400,10 +400,10 @@ func Deployment(namespace string, opts ...podTemplateOption) *appsv1.Deployment
|
||||
if c.withSecret {
|
||||
deployment.Spec.Template.Spec.Volumes = append(
|
||||
deployment.Spec.Template.Spec.Volumes,
|
||||
corev1.Volume{
|
||||
corev1api.Volume{
|
||||
Name: "cloud-credentials",
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
Secret: &corev1.SecretVolumeSource{
|
||||
VolumeSource: corev1api.VolumeSource{
|
||||
Secret: &corev1api.SecretVolumeSource{
|
||||
SecretName: "cloud-credentials",
|
||||
},
|
||||
},
|
||||
@@ -412,13 +412,13 @@ func Deployment(namespace string, opts ...podTemplateOption) *appsv1.Deployment
|
||||
|
||||
deployment.Spec.Template.Spec.Containers[0].VolumeMounts = append(
|
||||
deployment.Spec.Template.Spec.Containers[0].VolumeMounts,
|
||||
corev1.VolumeMount{
|
||||
corev1api.VolumeMount{
|
||||
Name: "cloud-credentials",
|
||||
MountPath: "/credentials",
|
||||
},
|
||||
)
|
||||
|
||||
deployment.Spec.Template.Spec.Containers[0].Env = append(deployment.Spec.Template.Spec.Containers[0].Env, []corev1.EnvVar{
|
||||
deployment.Spec.Template.Spec.Containers[0].Env = append(deployment.Spec.Template.Spec.Containers[0].Env, []corev1api.EnvVar{
|
||||
{
|
||||
Name: "GOOGLE_APPLICATION_CREDENTIALS",
|
||||
Value: "/credentials/cloud",
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
corev1api "k8s.io/api/core/v1"
|
||||
|
||||
"github.com/vmware-tanzu/velero/pkg/util/kube"
|
||||
)
|
||||
@@ -42,7 +42,7 @@ func TestDeployment(t *testing.T) {
|
||||
|
||||
deploy = Deployment("velero", WithImage("velero/velero:v0.11"))
|
||||
assert.Equal(t, "velero/velero:v0.11", deploy.Spec.Template.Spec.Containers[0].Image)
|
||||
assert.Equal(t, corev1.PullIfNotPresent, deploy.Spec.Template.Spec.Containers[0].ImagePullPolicy)
|
||||
assert.Equal(t, corev1api.PullIfNotPresent, deploy.Spec.Template.Spec.Containers[0].ImagePullPolicy)
|
||||
|
||||
deploy = Deployment("velero", WithSecret(true))
|
||||
assert.Len(t, deploy.Spec.Template.Spec.Containers[0].Env, 7)
|
||||
|
||||
@@ -24,8 +24,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
appsv1api "k8s.io/api/apps/v1"
|
||||
corev1api "k8s.io/api/core/v1"
|
||||
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||
apiextv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
@@ -152,11 +152,11 @@ func crdsAreReady(kbClient kbclient.Client, crds []*unstructured.Unstructured) (
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func isAvailable(c appsv1.DeploymentCondition) bool {
|
||||
func isAvailable(c appsv1api.DeploymentCondition) bool {
|
||||
// Make sure that the deployment has been available for at least 10 seconds.
|
||||
// This is because the deployment can show as Ready momentarily before the pods fall into a CrashLoopBackOff.
|
||||
// See podutils.IsPodAvailable upstream for similar logic with pods
|
||||
if c.Type == appsv1.DeploymentAvailable && c.Status == corev1.ConditionTrue {
|
||||
if c.Type == appsv1api.DeploymentAvailable && c.Status == corev1api.ConditionTrue {
|
||||
if !c.LastTransitionTime.IsZero() && c.LastTransitionTime.Add(10*time.Second).Before(time.Now()) {
|
||||
return true
|
||||
}
|
||||
@@ -166,7 +166,7 @@ func isAvailable(c appsv1.DeploymentCondition) bool {
|
||||
|
||||
// DeploymentIsReady will poll the Kubernetes API server to see if the velero deployment is ready to service user requests.
|
||||
func DeploymentIsReady(factory client.DynamicFactory, namespace string) (bool, error) {
|
||||
gvk := schema.FromAPIVersionAndKind(appsv1.SchemeGroupVersion.String(), "Deployment")
|
||||
gvk := schema.FromAPIVersionAndKind(appsv1api.SchemeGroupVersion.String(), "Deployment")
|
||||
apiResource := metav1.APIResource{
|
||||
Name: "deployments",
|
||||
Namespaced: true,
|
||||
@@ -186,7 +186,7 @@ func DeploymentIsReady(factory client.DynamicFactory, namespace string) (bool, e
|
||||
return false, errors.Wrap(err, "error waiting for deployment to be ready")
|
||||
}
|
||||
|
||||
deploy := new(appsv1.Deployment)
|
||||
deploy := new(appsv1api.Deployment)
|
||||
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredDeployment.Object, deploy); err != nil {
|
||||
return false, errors.Wrap(err, "error converting deployment from unstructured")
|
||||
}
|
||||
@@ -219,7 +219,7 @@ func NodeAgentWindowsIsReady(factory client.DynamicFactory, namespace string) (b
|
||||
}
|
||||
|
||||
func daemonSetIsReady(factory client.DynamicFactory, namespace string, name string) (bool, error) {
|
||||
gvk := schema.FromAPIVersionAndKind(appsv1.SchemeGroupVersion.String(), "DaemonSet")
|
||||
gvk := schema.FromAPIVersionAndKind(appsv1api.SchemeGroupVersion.String(), "DaemonSet")
|
||||
apiResource := metav1.APIResource{
|
||||
Name: "daemonsets",
|
||||
Namespaced: true,
|
||||
@@ -242,7 +242,7 @@ func daemonSetIsReady(factory client.DynamicFactory, namespace string, name stri
|
||||
return false, errors.Wrap(err, "error waiting for daemonset to be ready")
|
||||
}
|
||||
|
||||
daemonSet := new(appsv1.DaemonSet)
|
||||
daemonSet := new(appsv1api.DaemonSet)
|
||||
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredDaemonSet.Object, daemonSet); err != nil {
|
||||
return false, errors.Wrap(err, "error converting daemonset from unstructured")
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
appsv1api "k8s.io/api/apps/v1"
|
||||
corev1api "k8s.io/api/core/v1"
|
||||
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||
apiextv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||
@@ -30,7 +30,7 @@ func TestInstall(t *testing.T) {
|
||||
|
||||
c := fake.NewClientBuilder().WithObjects(
|
||||
&apiextv1.CustomResourceDefinition{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "backuprepositories.velero.io",
|
||||
},
|
||||
|
||||
@@ -59,7 +59,7 @@ func TestInstall(t *testing.T) {
|
||||
func Test_crdsAreReady(t *testing.T) {
|
||||
c := fake.NewClientBuilder().WithObjects(
|
||||
&apiextv1beta1.CustomResourceDefinition{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "backuprepositories.velero.io",
|
||||
},
|
||||
|
||||
@@ -79,11 +79,11 @@ func Test_crdsAreReady(t *testing.T) {
|
||||
).Build()
|
||||
|
||||
crd := &apiextv1beta1.CustomResourceDefinition{
|
||||
TypeMeta: v1.TypeMeta{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "CustomResourceDefinition",
|
||||
APIVersion: "v1beta1",
|
||||
},
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "backuprepositories.velero.io",
|
||||
},
|
||||
}
|
||||
@@ -102,13 +102,13 @@ func Test_crdsAreReady(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeploymentIsReady(t *testing.T) {
|
||||
deployment := &appsv1.Deployment{
|
||||
Status: appsv1.DeploymentStatus{
|
||||
Conditions: []appsv1.DeploymentCondition{
|
||||
deployment := &appsv1api.Deployment{
|
||||
Status: appsv1api.DeploymentStatus{
|
||||
Conditions: []appsv1api.DeploymentCondition{
|
||||
{
|
||||
Type: appsv1.DeploymentAvailable,
|
||||
Status: corev1.ConditionTrue,
|
||||
LastTransitionTime: v1.NewTime(time.Now().Add(-15 * time.Second)),
|
||||
Type: appsv1api.DeploymentAvailable,
|
||||
Status: corev1api.ConditionTrue,
|
||||
LastTransitionTime: metav1.NewTime(time.Now().Add(-15 * time.Second)),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -128,8 +128,8 @@ func TestDeploymentIsReady(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNodeAgentIsReady(t *testing.T) {
|
||||
daemonset := &appsv1.DaemonSet{
|
||||
Status: appsv1.DaemonSetStatus{
|
||||
daemonset := &appsv1api.DaemonSet{
|
||||
Status: appsv1api.DaemonSetStatus{
|
||||
NumberAvailable: 1,
|
||||
DesiredNumberScheduled: 1,
|
||||
},
|
||||
@@ -149,8 +149,8 @@ func TestNodeAgentIsReady(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNodeAgentWindowsIsReady(t *testing.T) {
|
||||
daemonset := &appsv1.DaemonSet{
|
||||
Status: appsv1.DaemonSetStatus{
|
||||
daemonset := &appsv1api.DaemonSet{
|
||||
Status: appsv1api.DaemonSetStatus{
|
||||
NumberAvailable: 0,
|
||||
DesiredNumberScheduled: 0,
|
||||
},
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
corev1api "k8s.io/api/core/v1"
|
||||
rbacv1 "k8s.io/api/rbac/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
@@ -92,8 +92,8 @@ func podAnnotations(userAnnotations map[string]string) map[string]string {
|
||||
return base
|
||||
}
|
||||
|
||||
func containerPorts() []corev1.ContainerPort {
|
||||
return []corev1.ContainerPort{
|
||||
func containerPorts() []corev1api.ContainerPort {
|
||||
return []corev1api.ContainerPort{
|
||||
{
|
||||
Name: "metrics",
|
||||
ContainerPort: 8085,
|
||||
@@ -109,14 +109,14 @@ func objectMeta(namespace, name string) metav1.ObjectMeta {
|
||||
}
|
||||
}
|
||||
|
||||
func ServiceAccount(namespace string, annotations map[string]string) *corev1.ServiceAccount {
|
||||
func ServiceAccount(namespace string, annotations map[string]string) *corev1api.ServiceAccount {
|
||||
objMeta := objectMeta(namespace, defaultServiceAccountName)
|
||||
objMeta.Annotations = annotations
|
||||
return &corev1.ServiceAccount{
|
||||
return &corev1api.ServiceAccount{
|
||||
ObjectMeta: objMeta,
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "ServiceAccount",
|
||||
APIVersion: corev1.SchemeGroupVersion.String(),
|
||||
APIVersion: corev1api.SchemeGroupVersion.String(),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -149,12 +149,12 @@ func ClusterRoleBinding(namespace string) *rbacv1.ClusterRoleBinding {
|
||||
return crb
|
||||
}
|
||||
|
||||
func Namespace(namespace string) *corev1.Namespace {
|
||||
ns := &corev1.Namespace{
|
||||
func Namespace(namespace string) *corev1api.Namespace {
|
||||
ns := &corev1api.Namespace{
|
||||
ObjectMeta: objectMeta("", namespace),
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Namespace",
|
||||
APIVersion: corev1.SchemeGroupVersion.String(),
|
||||
APIVersion: corev1api.SchemeGroupVersion.String(),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -204,17 +204,17 @@ func VolumeSnapshotLocation(namespace, provider string, config map[string]string
|
||||
}
|
||||
}
|
||||
|
||||
func Secret(namespace string, data []byte) *corev1.Secret {
|
||||
return &corev1.Secret{
|
||||
func Secret(namespace string, data []byte) *corev1api.Secret {
|
||||
return &corev1api.Secret{
|
||||
ObjectMeta: objectMeta(namespace, "cloud-credentials"),
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Secret",
|
||||
APIVersion: corev1.SchemeGroupVersion.String(),
|
||||
APIVersion: corev1api.SchemeGroupVersion.String(),
|
||||
},
|
||||
Data: map[string][]byte{
|
||||
"cloud": data,
|
||||
},
|
||||
Type: corev1.SecretTypeOpaque,
|
||||
Type: corev1api.SecretTypeOpaque,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,8 +241,8 @@ type VeleroOptions struct {
|
||||
PodLabels map[string]string
|
||||
ServiceAccountAnnotations map[string]string
|
||||
ServiceAccountName string
|
||||
VeleroPodResources corev1.ResourceRequirements
|
||||
NodeAgentPodResources corev1.ResourceRequirements
|
||||
VeleroPodResources corev1api.ResourceRequirements
|
||||
NodeAgentPodResources corev1api.ResourceRequirements
|
||||
SecretData []byte
|
||||
RestoreOnly bool
|
||||
UseNodeAgent bool
|
||||
|
||||
Reference in New Issue
Block a user