Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: data injection flake #2361

Merged
merged 13 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pkg/cluster/injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func (c *Cluster) getImagesAndNodesForInjection(timeoutDuration time.Duration) (

// After delay, try running
default:
pods, err := c.GetPods(corev1.NamespaceAll)
pods, err := c.GetPods(corev1.NamespaceAll, nil)
if err != nil {
return nil, fmt.Errorf("unable to get the list of pods in the cluster")
}
Expand Down
12 changes: 7 additions & 5 deletions src/pkg/k8s/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@ func (k *K8s) CreatePod(pod *corev1.Pod) (*corev1.Pod, error) {

// GetAllPods returns a list of pods from the cluster for all namespaces.
func (k *K8s) GetAllPods() (*corev1.PodList, error) {
return k.GetPods(corev1.NamespaceAll)
return k.GetPods(corev1.NamespaceAll, nil)
}

// GetPods returns a list of pods from the cluster by namespace.
func (k *K8s) GetPods(namespace string) (*corev1.PodList, error) {
metaOptions := metav1.ListOptions{}
return k.Clientset.CoreV1().Pods(namespace).List(context.TODO(), metaOptions)
// GetPods returns a list of pods from the cluster by namespace and listOpts.
func (k *K8s) GetPods(namespace string, listOpts *metav1.ListOptions) (*corev1.PodList, error) {
if listOpts == nil {
listOpts = &metav1.ListOptions{}
}
return k.Clientset.CoreV1().Pods(namespace).List(context.TODO(), *listOpts)
}

// WaitForPodsAndContainers attempts to find pods matching the given selector and optional inclusion filter
Expand Down
20 changes: 17 additions & 3 deletions src/test/e2e/23_data_injection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/defenseunicorns/zarf/src/pkg/cluster"
"github.com/defenseunicorns/zarf/src/pkg/utils/exec"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestDataInjection(t *testing.T) {
Expand All @@ -31,15 +32,28 @@ func TestDataInjection(t *testing.T) {
runDataInjection(t, path)
}

c, err := cluster.NewCluster()
require.NoError(t, err)

// Find a running kiwix pod
pods, err := c.GetPods("kiwix", &metav1.ListOptions{
FieldSelector: "status.phase=Running",
LabelSelector: "app=kiwix-serve",
})
require.NoError(t, err)
var runningKiwixPod string
for _, pod := range pods.Items {
runningKiwixPod = pod.Name
break
}

// Verify the file and injection marker were created
stdOut, stdErr, err := e2e.Kubectl("--namespace=kiwix", "logs", "--tail=5", "--selector=app=kiwix-serve", "-c=kiwix-serve")
stdOut, stdErr, err := e2e.Kubectl("--namespace=kiwix", "logs", runningKiwixPod, "--tail=5", "-c=kiwix-serve")
Noxsios marked this conversation as resolved.
Show resolved Hide resolved
require.NoError(t, err, stdOut, stdErr)
require.Contains(t, stdOut, "devops.stackexchange.com_en_all_2023-05.zim")
require.Contains(t, stdOut, ".zarf-injection-")

// need target to equal svc that we are trying to connect to call checkForZarfConnectLabel
c, err := cluster.NewCluster()
require.NoError(t, err)
tunnel, err := c.Connect("kiwix")
require.NoError(t, err)
defer tunnel.Close()
Expand Down