mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-03 11:45:20 +00:00
@@ -24,10 +24,23 @@ import (
|
||||
)
|
||||
|
||||
func TestDaemonSet(t *testing.T) {
|
||||
userID := int64(0)
|
||||
boolFalse := false
|
||||
boolTrue := true
|
||||
|
||||
ds := DaemonSet("velero")
|
||||
|
||||
assert.Equal(t, "node-agent", ds.Spec.Template.Spec.Containers[0].Name)
|
||||
assert.Equal(t, "velero", ds.ObjectMeta.Namespace)
|
||||
assert.Equal(t, "node-agent", ds.Spec.Template.ObjectMeta.Labels["name"])
|
||||
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)
|
||||
|
||||
ds = DaemonSet("velero", WithPrivilegedNodeAgent(true))
|
||||
assert.Equal(t, corev1.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)
|
||||
@@ -47,4 +60,14 @@ func TestDaemonSet(t *testing.T) {
|
||||
|
||||
ds = DaemonSet("velero", WithServiceAccountName("test-sa"))
|
||||
assert.Equal(t, "test-sa", ds.Spec.Template.Spec.ServiceAccountName)
|
||||
|
||||
ds = DaemonSet("velero", WithForWindows())
|
||||
assert.Equal(t, "node-agent-windows", ds.Spec.Template.Spec.Containers[0].Name)
|
||||
assert.Equal(t, "velero", ds.ObjectMeta.Namespace)
|
||||
assert.Equal(t, "node-agent-windows", ds.Spec.Template.ObjectMeta.Labels["name"])
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ func WithItemBlockWorkerCount(itemBlockWorkerCount int) podTemplateOption {
|
||||
}
|
||||
}
|
||||
|
||||
func WithForWinows() podTemplateOption {
|
||||
func WithForWindows() podTemplateOption {
|
||||
return func(c *podTemplateConfig) {
|
||||
c.forWindows = true
|
||||
}
|
||||
|
||||
@@ -206,9 +206,19 @@ func DeploymentIsReady(factory client.DynamicFactory, namespace string) (bool, e
|
||||
return isReady, err
|
||||
}
|
||||
|
||||
// DaemonSetIsReady will poll the Kubernetes API server to ensure the node-agent daemonset is ready, i.e. that
|
||||
// NodeAgentIsReady will poll the Kubernetes API server to ensure the node-agent daemonset is ready, i.e. that
|
||||
// pods are scheduled and available on all of the desired nodes.
|
||||
func DaemonSetIsReady(factory client.DynamicFactory, namespace string) (bool, error) {
|
||||
func NodeAgentIsReady(factory client.DynamicFactory, namespace string) (bool, error) {
|
||||
return daemonSetIsReady(factory, namespace, "node-agent")
|
||||
}
|
||||
|
||||
// NodeAgentWindowsIsReady will poll the Kubernetes API server to ensure the node-agent-windows daemonset is ready, i.e. that
|
||||
// pods are scheduled and available on all of the desired nodes.
|
||||
func NodeAgentWindowsIsReady(factory client.DynamicFactory, namespace string) (bool, error) {
|
||||
return daemonSetIsReady(factory, namespace, "node-agent-windows")
|
||||
}
|
||||
|
||||
func daemonSetIsReady(factory client.DynamicFactory, namespace string, name string) (bool, error) {
|
||||
gvk := schema.FromAPIVersionAndKind(appsv1.SchemeGroupVersion.String(), "DaemonSet")
|
||||
apiResource := metav1.APIResource{
|
||||
Name: "daemonsets",
|
||||
@@ -225,7 +235,7 @@ func DaemonSetIsReady(factory client.DynamicFactory, namespace string) (bool, er
|
||||
var readyObservations int32
|
||||
|
||||
err = wait.PollUntilContextTimeout(context.Background(), time.Second, time.Minute, true, func(ctx context.Context) (bool, error) {
|
||||
unstructuredDaemonSet, err := c.Get("node-agent", metav1.GetOptions{})
|
||||
unstructuredDaemonSet, err := c.Get(name, metav1.GetOptions{})
|
||||
if apierrors.IsNotFound(err) {
|
||||
return false, nil
|
||||
} else if err != nil {
|
||||
|
||||
@@ -127,7 +127,7 @@ func TestDeploymentIsReady(t *testing.T) {
|
||||
assert.True(t, ready)
|
||||
}
|
||||
|
||||
func TestDaemonSetIsReady(t *testing.T) {
|
||||
func TestNodeAgentIsReady(t *testing.T) {
|
||||
daemonset := &appsv1.DaemonSet{
|
||||
Status: appsv1.DaemonSetStatus{
|
||||
NumberAvailable: 1,
|
||||
@@ -143,7 +143,28 @@ func TestDaemonSetIsReady(t *testing.T) {
|
||||
factory := &test.FakeDynamicFactory{}
|
||||
factory.On("ClientForGroupVersionResource", mock.Anything, mock.Anything, mock.Anything).Return(dc, nil)
|
||||
|
||||
ready, err := DaemonSetIsReady(factory, "velero")
|
||||
ready, err := NodeAgentIsReady(factory, "velero")
|
||||
require.NoError(t, err)
|
||||
assert.True(t, ready)
|
||||
}
|
||||
|
||||
func TestNodeAgentWindowsIsReady(t *testing.T) {
|
||||
daemonset := &appsv1.DaemonSet{
|
||||
Status: appsv1.DaemonSetStatus{
|
||||
NumberAvailable: 0,
|
||||
DesiredNumberScheduled: 0,
|
||||
},
|
||||
}
|
||||
obj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(daemonset)
|
||||
require.NoError(t, err)
|
||||
|
||||
dc := &test.FakeDynamicClient{}
|
||||
dc.On("Get", mock.Anything, mock.Anything).Return(&unstructured.Unstructured{Object: obj}, nil)
|
||||
|
||||
factory := &test.FakeDynamicFactory{}
|
||||
factory.On("ClientForGroupVersionResource", mock.Anything, mock.Anything, mock.Anything).Return(dc, nil)
|
||||
|
||||
ready, err := NodeAgentWindowsIsReady(factory, "velero")
|
||||
require.NoError(t, err)
|
||||
assert.True(t, ready)
|
||||
}
|
||||
|
||||
@@ -419,7 +419,7 @@ func AllResources(o *VeleroOptions) *unstructured.UnstructuredList {
|
||||
fmt.Printf("error appending DaemonSet %s: %s\n", ds.GetName(), err.Error())
|
||||
}
|
||||
|
||||
dsOpts = append(dsOpts, WithForWinows())
|
||||
dsOpts = append(dsOpts, WithForWindows())
|
||||
|
||||
dsWin := DaemonSet(o.Namespace, dsOpts...)
|
||||
if err := appendUnstructured(resources, dsWin); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user