@@ -11,6 +11,7 @@ import (
1111 "github.com/loft-sh/devspace/e2e/kube"
1212 "github.com/onsi/gomega"
1313 "github.com/pkg/errors"
14+ corev1 "k8s.io/api/core/v1"
1415 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1516 "k8s.io/apimachinery/pkg/util/wait"
1617)
@@ -169,6 +170,52 @@ func ExpectRemoteContainerFileContents(labelSelector, container string, namespac
169170 ExpectNoErrorWithOffset (1 , err )
170171}
171172
173+ func ExpectRemoteFileContentsOnAllPods (labelSelector , containerName , namespace , filePath , contents string , wantCount int ) {
174+ kubeClient , err := kube .NewKubeHelper ()
175+ ExpectNoErrorWithOffset (1 , err )
176+
177+ want := strings .TrimSpace (contents )
178+ err = wait .PollUntilContextTimeout (context .TODO (), time .Second , time .Minute * 3 , true , func (ctx context.Context ) (done bool , err error ) {
179+ pods , err := kubeClient .RawClient ().CoreV1 ().Pods (namespace ).List (ctx , metav1.ListOptions {LabelSelector : labelSelector })
180+ if err != nil {
181+ return false , nil
182+ }
183+ readyPods := make ([]corev1.Pod , 0 , len (pods .Items ))
184+ for _ , p := range pods .Items {
185+ if p .Status .Phase != corev1 .PodRunning {
186+ continue
187+ }
188+ if ! podContainerReady (& p , containerName ) {
189+ continue
190+ }
191+ readyPods = append (readyPods , p )
192+ }
193+ if len (readyPods ) < wantCount {
194+ return false , nil
195+ }
196+ for i := range readyPods {
197+ out , err := kubeClient .ExecInPod (ctx , & readyPods [i ], containerName , []string {"cat" , filePath })
198+ if err != nil {
199+ return false , nil
200+ }
201+ if strings .TrimSpace (out ) != want {
202+ return false , nil
203+ }
204+ }
205+ return true , nil
206+ })
207+ ExpectNoErrorWithOffset (1 , err )
208+ }
209+
210+ func podContainerReady (pod * corev1.Pod , containerName string ) bool {
211+ for _ , cs := range pod .Status .ContainerStatuses {
212+ if cs .Name == containerName {
213+ return cs .Ready
214+ }
215+ }
216+ return false
217+ }
218+
172219func ExpectLocalFileContentsImmediately (filePath string , contents string ) {
173220 out , err := os .ReadFile (filePath )
174221 ExpectNoError (err )
0 commit comments