Skip to content

Commit

Permalink
Fix unit-tests (ci) errors
Browse files Browse the repository at this point in the history
  • Loading branch information
levikobi committed Jul 21, 2023
1 parent c376e66 commit 3ffb31f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

By("bootstrapping test environment")

testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
ErrorIfCRDPathMissing: false,
Expand Down
22 changes: 12 additions & 10 deletions internal/dataplane/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,12 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/kubernetes"
ctrl "sigs.k8s.io/controller-runtime"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/log"

"github.com/kong/blixt/pkg/vars"
)

var (
config = ctrl.GetConfigOrDie()
clientset, _ = kubernetes.NewForConfig(config)
)

// clientInfo encapsulates the gathered information about a BackendsClient
// along with the gRPC client connection.
type clientInfo struct {
Expand All @@ -39,7 +34,8 @@ type observer interface {
// BackendsClientManager is managing the connections and interactions with
// the available BackendsClient servers.
type BackendsClientManager struct {
log logr.Logger
log logr.Logger
clientset *kubernetes.Clientset

mu sync.RWMutex
clients map[string]clientInfo
Expand All @@ -48,13 +44,19 @@ type BackendsClientManager struct {
}

// NewBackendsClientManager returns an initialized instance of BackendsClientManager.
func NewBackendsClientManager() *BackendsClientManager {
func NewBackendsClientManager(config *rest.Config) (*BackendsClientManager, error) {
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
return nil, err
}

return &BackendsClientManager{
log: log.FromContext(context.Background()),
clientset: clientset,
mu: sync.RWMutex{},
clients: map[string]clientInfo{},
observers: []observer{},
}
}, nil
}

// RegisterObservers adds new observer(s) to the observers list of BackendsClientManager.
Expand Down Expand Up @@ -104,7 +106,7 @@ func (c *BackendsClientManager) ManageDataPlanePods(ctx context.Context) error {
vars.DefaultDataPlaneAppLabel, vars.DefaultDataPlaneComponentLabel),
}

watcher, err := clientset.CoreV1().Pods(vars.DefaultNamespace).Watch(ctx, listOptions)
watcher, err := c.clientset.CoreV1().Pods(vars.DefaultNamespace).Watch(ctx, listOptions)
if err != nil {
return err
}
Expand Down
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
cfg := ctrl.GetConfigOrDie()
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
Expand All @@ -76,7 +77,10 @@ func main() {
os.Exit(1)
}

clientsManager := client.NewBackendsClientManager()
clientsManager, err := client.NewBackendsClientManager(cfg)
if err != nil {
setupLog.Error(err, "unable to create backends client manager")
}

if err = (&controllers.GatewayReconciler{
Client: mgr.GetClient(),
Expand Down

0 comments on commit 3ffb31f

Please sign in to comment.