Skip to content

Commit

Permalink
gh actions: catkubeletconfmap: add and use wait
Browse files Browse the repository at this point in the history
add and use wait loop to avoid false negatives in CI

Signed-off-by: Francesco Romani <[email protected]>
  • Loading branch information
ffromani committed Sep 24, 2024
1 parent 603e915 commit ccbc373
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
- name: E2E Tests
run: |
export KUBECONFIG=${HOME}/.kube/config
bin/catkubeletconfmap --namespace ${E2E_NAMESPACE_NAME} --prefix 'E2E_' >> $GITHUB_ENV
bin/catkubeletconfmap --wait 2m --namespace ${E2E_NAMESPACE_NAME} --prefix 'E2E_' >> $GITHUB_ENV
make test-e2e
- name: Export E2E Tests logs
Expand Down
46 changes: 35 additions & 11 deletions tools/catkubeletconfmap/catkubeletconfmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ import (
"flag"
"fmt"
"log"
"time"

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
k8swait "k8s.io/apimachinery/pkg/util/wait"

"sigs.k8s.io/controller-runtime/pkg/client"

Expand All @@ -32,26 +35,47 @@ import (
)

func main() {
var prefix string
var cmNamespace string
var cmName string
flag.StringVar(&cmNamespace, "namespace", "numaresources", "namespace to look the configmap into")
flag.StringVar(&cmName, "name", "numaresourcesoperator-worker", "name of the configmap to look for")
flag.StringVar(&prefix, "prefix", "", "prefix for the output")
prefix := ""
cmNamespace := "numaresources"
cmName := "numaresourcesoperator-worker"
waitTimeout := 0 * time.Second // no wait
waitInterval := 2 * time.Second // if we wait at all, this is the intervall between polls
waitImmediate := true // guarantee to call at least once, necessary with default timout

flag.StringVar(&cmNamespace, "namespace", cmNamespace, "namespace to look the configmap into")
flag.StringVar(&cmName, "name", cmName, "name of the configmap to look for")
flag.StringVar(&prefix, "prefix", prefix, "prefix for the output")
flag.DurationVar(&waitTimeout, "wait", waitTimeout, "retry till this time limit")
flag.Parse()

cli, err := clientutil.New()
if err != nil {
log.Fatalf("error creating a client: %v", err)
}

log.Printf("trying to fetch %s/%s...", cmNamespace, cmName)

ctx := context.Background()
key := client.ObjectKey{
Namespace: cmNamespace,
Name: cmName,
}
cm := corev1.ConfigMap{}
err = cli.Get(ctx, key, &cm)

err = k8swait.PollUntilContextTimeout(ctx, waitInterval, waitTimeout, waitImmediate, func(fctx context.Context) (bool, error) {
key := client.ObjectKey{
Namespace: cmNamespace,
Name: cmName,
}
ferr := cli.Get(fctx, key, &cm)
if ferr != nil {
if apierrors.IsNotFound(ferr) {
log.Printf("failed to get %s/%s - not found, retrying...", cmNamespace, cmName)
return false, nil
}
log.Printf("failed to get %s/%s: %v, aborting", cmNamespace, cmName, ferr)
return false, ferr
}
log.Printf("got %s/%s!", cmNamespace, cmName)
return true, nil
})

if err != nil {
log.Fatalf("error getting the ConfigMap %s/%s: %v", cmNamespace, cmName, err)
}
Expand Down

0 comments on commit ccbc373

Please sign in to comment.