Skip to content

Commit

Permalink
Upstream client support for eno reconciler (#33)
Browse files Browse the repository at this point in the history
Eno reconciler accepts an optional path to an upstream client through
the "remote-kubeconfig" flag.
  • Loading branch information
AYM1607 authored Jan 18, 2024
1 parent 61a9366 commit f59e05b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
16 changes: 15 additions & 1 deletion cmd/eno-reconciler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"

"github.com/Azure/eno/internal/controllers/reconciliation"
"github.com/Azure/eno/internal/k8s"
"github.com/Azure/eno/internal/manager"
"github.com/Azure/eno/internal/reconstitution"
)
Expand All @@ -32,6 +33,8 @@ func run() error {
writeBatchInterval time.Duration
discoveryMaxRPS float32
debugLogging bool
remoteKubeconfigFile string
remoteQPS float64

mgrOpts = &manager.Options{
Rest: ctrl.GetConfigOrDie(),
Expand All @@ -40,6 +43,8 @@ func run() error {
flag.BoolVar(&rediscoverWhenNotFound, "rediscover-when-not-found", true, "Invalidate discovery cache when any type is not found in the openapi spec. Set this to false on <= k8s 1.14")
flag.DurationVar(&writeBatchInterval, "write-batch-interval", time.Second*5, "The max throughput of composition status updates")
flag.BoolVar(&debugLogging, "debug", true, "Enable debug logging")
flag.StringVar(&remoteKubeconfigFile, "remote-kubeconfig", "", "Path to the kubeconfig of the apiserver where the resources will be reconciled. The config from the environment is used if this is not provided")
flag.Float64Var(&remoteQPS, "remote-qps", 0, "Max requests per second to the remote apiserver")
mgrOpts.Bind(flag.CommandLine)
flag.Parse()

Expand All @@ -63,7 +68,16 @@ func run() error {
return fmt.Errorf("constructing reconstitution manager: %w", err)
}

err = reconciliation.New(recmgr, mgr.GetConfig(), discoveryMaxRPS, rediscoverWhenNotFound)
remoteConfig := mgr.GetConfig()
if remoteKubeconfigFile != "" {
if remoteConfig, err = k8s.GetRESTConfig(remoteKubeconfigFile); err != nil {
return err
}
if remoteQPS != 0 {
remoteConfig.QPS = float32(remoteQPS)
}
}
err = reconciliation.New(recmgr, remoteConfig, discoveryMaxRPS, rediscoverWhenNotFound)
if err != nil {
return fmt.Errorf("constructing reconciliation controller: %w", err)
}
Expand Down
22 changes: 22 additions & 0 deletions internal/k8s/kubeconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package k8s

import (
"fmt"
"os"

"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)

// GetRESTConfig is a convenience method to avoid manually opening a file.
func GetRESTConfig(filename string) (*rest.Config, error) {
b, err := os.ReadFile(filename)
if err != nil {
return nil, fmt.Errorf("could not get read Kubeconfig file: %w", err)
}
cfg, err := clientcmd.RESTConfigFromKubeConfig(b)
if err != nil {
return nil, fmt.Errorf("could not get get Kubeconfig from file: %w", err)
}
return cfg, nil
}

0 comments on commit f59e05b

Please sign in to comment.