Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions controllers/fipsetup/fipsetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -27,6 +28,7 @@ var log = logf.Log.WithName("fipsetup")
type Reconciler struct {
client.Client
v1alpha1.Config
recorder record.EventRecorder
}

func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error) {
Expand Down Expand Up @@ -180,6 +182,7 @@ func (r *Reconciler) deleteJob(ctx context.Context, job *batchv1.Job) error {

// SetupWithManager sets up the controller with the Manager.
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
r.recorder = mgr.GetEventRecorderFor("fipsetup")
preds := []predicate.Predicate{
predicate.Or(
predicate.AnnotationChangedPredicate{},
Expand Down
53 changes: 47 additions & 6 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
)

const (
defaultTimeout = 5 * time.Minute
pollInterval = 5 * time.Second
logInterval = 30 * time.Second
defaultTimeout = 5 * time.Minute
pollInterval = 5 * time.Second
logInterval = 30 * time.Second
nodeReadyTimeout = 5 * time.Minute
)

Expand Down Expand Up @@ -82,6 +82,10 @@ func TestFloatingIPAssignment(t *testing.T) {
assignCtx, assignCancel := context.WithTimeout(ctx, cfg.timeout)
nodeName := waitForAssignment(assignCtx, t, kubeClient, hcloudClient, fip.ID, cfg.labelKey, "")
assignCancel()

eventCtx, eventCancel := context.WithTimeout(ctx, cfg.timeout)
waitForEvent(eventCtx, t, kubeClient, cfg.namespace, "FloatingIPAssigned", fmt.Sprintf("%s assigned to Node", fip.IP.String()))
eventCancel()
assignments[fip.ID] = nodeName
}

Expand Down Expand Up @@ -437,9 +441,9 @@ func createFloatingIPs(ctx context.Context, t *testing.T, client *hcloud.Client,
for i := 0; i < count; i++ {
description := fmt.Sprintf("hcloud-fip-k8s e2e %d", time.Now().UnixNano())
opts := hcloud.FloatingIPCreateOpts{
Type: hcloud.FloatingIPTypeIPv4,
Description: &description,
Labels: labels,
Type: hcloud.FloatingIPTypeIPv4,
Description: &description,
Labels: labels,
}
if location != nil {
opts.HomeLocation = location
Expand Down Expand Up @@ -673,6 +677,43 @@ func logAssignmentWait(t *testing.T, start time.Time, lastLog *time.Time, msg, d
}
}

func waitForEvent(ctx context.Context, t *testing.T, kube *kubernetes.Clientset, namespace, reason, message string) {
t.Helper()
if namespace == "" {
t.Fatalf("event namespace must be set")
}
start := time.Now()
lastLog := time.Now()
logDetail := message
if logDetail == "" {
logDetail = reason
}
err := poll(ctx, func() (bool, error) {
list, err := kube.CoreV1().Events(namespace).List(ctx, metav1.ListOptions{})
if err != nil {
return false, err
}
for _, event := range list.Items {
if reason != "" && event.Reason != reason {
continue
}
if message != "" && !strings.Contains(event.Message, message) {
continue
}
if reason == "" && message == "" {
continue
}
t.Logf("found event %s/%s: reason=%s message=%s", event.Namespace, event.Name, event.Reason, event.Message)
return true, nil
}
logAssignmentWait(t, start, &lastLog, "waiting for event", logDetail)
return false, nil
})
if err != nil {
t.Fatalf("failed waiting for event reason %q message %q in namespace %s: %v", reason, message, namespace, err)
}
}

func waitForAction(ctx context.Context, t *testing.T, client *hcloud.Client, action *hcloud.Action, desc string) {
t.Helper()
if action == nil {
Expand Down
Loading