mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-09-24 23:08:43 -04:00
Wait for kube api during init (#440)
* kubernetes: wait for KubeAPI to be reachable
This commit is contained in:
parent
b89fae8062
commit
9ad377284d
9 changed files with 190 additions and 10 deletions
60
bootstrapper/internal/kubernetes/kubeWaiter/waiter_test.go
Normal file
60
bootstrapper/internal/kubernetes/kubeWaiter/waiter_test.go
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
Copyright (c) Edgeless Systems GmbH
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package kubewaiter
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/goleak"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
goleak.VerifyTestMain(m)
|
||||
}
|
||||
|
||||
func TestCloudKubeAPIWaiter(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
kubeClient KubernetesClient
|
||||
wantErr bool
|
||||
}{
|
||||
"success": {
|
||||
kubeClient: &stubKubernetesClient{},
|
||||
},
|
||||
"error": {
|
||||
kubeClient: &stubKubernetesClient{listAllNamespacesErr: errors.New("error")},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
waiter := &CloudKubeAPIWaiter{}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 0)
|
||||
defer cancel()
|
||||
err := waiter.Wait(ctx, tc.kubeClient)
|
||||
if tc.wantErr {
|
||||
require.Error(err)
|
||||
} else {
|
||||
require.NoError(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type stubKubernetesClient struct {
|
||||
listAllNamespacesErr error
|
||||
}
|
||||
|
||||
func (c *stubKubernetesClient) ListAllNamespaces(ctx context.Context) (*corev1.NamespaceList, error) {
|
||||
return nil, c.listAllNamespacesErr
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue