@@ -15,6 +15,7 @@ package helpers
1515
1616import (
1717 "encoding/json"
18+
1819 networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
1920 "github.com/onsi/gomega"
2021 corev1 "k8s.io/api/core/v1"
@@ -76,14 +77,22 @@ func (tc *TestHelper) SimulateDeploymentReplicaReady(name types.NamespacedName)
7677// map[string][]string{manilaName.Namespace + "/internalapi": {"10.0.0.1"}},
7778// )
7879func (tc * TestHelper ) SimulateDeploymentReadyWithPods (name types.NamespacedName , networkIPs map [string ][]string ) {
79- ss := tc .GetDeployment (name )
80- for i := 0 ; i < int (* ss .Spec .Replicas ); i ++ {
80+ depl := tc .GetDeployment (name )
81+ for i := 0 ; i < int (* depl .Spec .Replicas ); i ++ {
8182 pod := & corev1.Pod {
82- ObjectMeta : ss .Spec .Template .ObjectMeta ,
83- Spec : ss .Spec .Template .Spec ,
83+ ObjectMeta : depl .Spec .Template .ObjectMeta ,
84+ Spec : depl .Spec .Template .Spec ,
8485 }
8586 pod .ObjectMeta .Namespace = name .Namespace
8687 pod .ObjectMeta .GenerateName = name .Name
88+ // NOTE(gibi): If there is a mount that refers to a volume created via
89+ // persistent volume claim then that mount won't have a corresponding
90+ // volume created in EnvTest as we are not simulating the k8s volume
91+ // claim logic here at the moment. Therefore the Pod create would fail
92+ // with a missing volume. So to avoid that we remove every mount and
93+ // volume from the pod we create here.
94+ pod .Spec .Volumes = []corev1.Volume {}
95+ pod .Spec .Containers [0 ].VolumeMounts = []corev1.VolumeMount {}
8796
8897 var netStatus []networkv1.NetworkStatus
8998 for network , IPs := range networkIPs {
@@ -103,10 +112,10 @@ func (tc *TestHelper) SimulateDeploymentReadyWithPods(name types.NamespacedName,
103112 }
104113
105114 gomega .Eventually (func (g gomega.Gomega ) {
106- ss := tc .GetDeployment (name )
107- ss .Status .Replicas = 1
108- ss .Status .ReadyReplicas = 1
109- g .Expect (tc .K8sClient .Status ().Update (tc .Ctx , ss )).To (gomega .Succeed ())
115+ depl := tc .GetDeployment (name )
116+ depl .Status .Replicas = 1
117+ depl .Status .ReadyReplicas = 1
118+ g .Expect (tc .K8sClient .Status ().Update (tc .Ctx , depl )).To (gomega .Succeed ())
110119
111120 }, tc .Timeout , tc .Interval ).Should (gomega .Succeed ())
112121
0 commit comments