-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test that deploys the example manifest to a kind cluster and checks if any of the configured labels are attachted to the k8s node.
- Loading branch information
1 parent
7da4131
commit cac32ce
Showing
9 changed files
with
132 additions
and
25 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: test | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- run: docker build -t "nudle:e2e" . | ||
- run: go test . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/efficientgo/core/backoff" | ||
"github.com/efficientgo/e2e" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
const imageName = "nudl:e2e" | ||
|
||
func kubectl(e *e2e.KindEnvironment, args ...string) *exec.Cmd { | ||
return exec.Command("kubectl", append([]string{"--kubeconfig", fmt.Sprintf("%s/kubeconfig", e.SharedDir())}, args...)...) | ||
} | ||
|
||
func kubectlRun(t *testing.T, e *e2e.KindEnvironment, args ...string) { | ||
cmd := kubectl(e, args...) | ||
w := &bytes.Buffer{} | ||
cmd.Stderr = w | ||
cmd.Stdout = w | ||
|
||
require.NoError(t, cmd.Run(), w.String()) | ||
} | ||
|
||
func TestMain(t *testing.T) { | ||
e, err := e2e.NewKindEnvironment() | ||
require.NoError(t, err) | ||
t.Cleanup(e.Close) | ||
|
||
runnableBuilder := e.Runnable(strings.ToLower(t.Name())) | ||
runnable := runnableBuilder.Init(e2e.StartOptions{ | ||
Image: imageName, | ||
}) | ||
_ = runnable.Start() // lazy hack to get image loaded into the cluster | ||
|
||
kubectlRun(t, e, "apply", "-f", "example.yaml") | ||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
t.Cleanup(cancel) | ||
bo := backoff.New(ctx, backoff.Config{}) | ||
for { | ||
var err error | ||
if bo.Wait(); bo.Ongoing() { | ||
cmd := kubectl(e, "wait", "pod", "--for", "condition=Ready", "--selector", "app.kubernetes.io/name=nudl") | ||
if err = cmd.Run(); err == nil { | ||
break | ||
} | ||
} else { | ||
require.NoError(t, err, "timeout waiting for daemonset") | ||
break | ||
} | ||
} | ||
|
||
{ | ||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
t.Cleanup(cancel) | ||
bo := backoff.New(ctx, backoff.Config{}) | ||
found := false | ||
for { | ||
if bo.Wait(); bo.Ongoing() { | ||
cmd := exec.Command("kubectl", "--kubeconfig", fmt.Sprintf("%s/kubeconfig", e.SharedDir()), "get", "nodes", fmt.Sprintf("%s-control-plane", e.Name()), "-o", "jsonpath={.metadata.labels}") | ||
w := &bytes.Buffer{} | ||
cmd.Stderr = w | ||
cmd.Stdout = w | ||
require.NoError(t, cmd.Run(), w.String()) | ||
labels := map[string]string{} | ||
t.Logf("buffer %s\n", w.String()) | ||
|
||
require.NoError(t, json.NewDecoder(w).Decode(&labels), w.String()) | ||
|
||
for key, value := range labels { | ||
if strings.HasPrefix(key, "nudl.squat.ai") { | ||
found = true | ||
t.Logf("found label %s=%s\n", key, value) | ||
break | ||
} | ||
} | ||
} else { | ||
break | ||
} | ||
} | ||
assert.True(t, found, "no label found") | ||
require.NoError(t, err, "timeout waiting for daemonset") | ||
} | ||
} |