-
Notifications
You must be signed in to change notification settings - Fork 591
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rely on controller-runtime for kong crds
- Loading branch information
Showing
5 changed files
with
96 additions
and
59 deletions.
There are no files selected for viewing
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,68 @@ | ||
//go:build envtest | ||
|
||
package envtest | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/url" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/kong/kubernetes-ingress-controller/v2/test/internal/helpers" | ||
"github.com/samber/lo" | ||
"github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestManagerDoesntStartUntilKubernetesAPIReachable ensures that the manager and its Runnables are not start until the | ||
// Kubernetes API server is reachable. | ||
func TestManagerDoesntStartUntilKubernetesAPIReachable(t *testing.T) { | ||
scheme := Scheme(t, WithKong) | ||
envcfg := Setup(t, scheme) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
t.Log("Setting up a proxy for Kubernetes API server so that we can interrupt it") | ||
u, err := url.Parse(envcfg.Host) | ||
require.NoError(t, err) | ||
apiServerProxy, err := helpers.NewTCPProxy(u.Host) | ||
require.NoError(t, err) | ||
go func() { | ||
err := apiServerProxy.Run(ctx) | ||
assert.NoError(t, err) | ||
}() | ||
apiServerProxy.StopHandlingConnections() | ||
|
||
t.Log("Replacing Kubernetes API server address with the proxy address") | ||
envcfg.Host = fmt.Sprintf("https://%s", apiServerProxy.Address()) | ||
|
||
loggerHook := RunManager(ctx, t, envcfg) | ||
hasLog := func(expectedLog string) bool { | ||
return lo.ContainsBy(loggerHook.AllEntries(), func(entry *logrus.Entry) bool { | ||
return strings.Contains(entry.Message, expectedLog) | ||
}) | ||
} | ||
|
||
t.Log("Ensuring manager is waiting for Kubernetes API to be ready") | ||
const expectedKubernetesAPICheckErrorLog = "Retrying Kubernetes API readiness check after error" | ||
require.Eventually(t, func() bool { return hasLog(expectedKubernetesAPICheckErrorLog) }, time.Minute, time.Millisecond) | ||
|
||
t.Log("Ensure manager hasn't been started yet and no config sync has happened") | ||
const configurationSyncedToKongLog = "successfully synced configuration to Kong" | ||
const startingManagerLog = "Starting manager" | ||
require.False(t, hasLog(configurationSyncedToKongLog)) | ||
require.False(t, hasLog(startingManagerLog)) | ||
|
||
t.Log("Starting accepting connections in Kubernetes API proxy so that manager can start") | ||
apiServerProxy.StartHandlingConnections() | ||
|
||
t.Log("Ensuring manager has been started and config sync has happened") | ||
require.Eventually(t, func() bool { | ||
return hasLog(startingManagerLog) && | ||
hasLog(configurationSyncedToKongLog) | ||
}, time.Minute, time.Millisecond) | ||
} |
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