Skip to content

Commit

Permalink
br: modify to use one kubeconfig for multiple data planes (#5186)
Browse files Browse the repository at this point in the history
  • Loading branch information
WangLe1321 authored Jul 28, 2023
1 parent 6e56ce9 commit a0ef530
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ spec:
{{- if .Values.brFederationManager.kubeClientBurst }}
- -kube-client-burst={{ .Values.brFederationManager.kubeClientBurst }}
{{- end }}
{{- if .Values.brFederationManager.federationKubeconfigSecretKey }}
- -federation-kubeconfig-path=/etc/br-federation/federation-kubeconfig/{{ .Values.brFederationManager.federationKubeconfigSecretKey }}
{{- end }}
env:
- name: NAMESPACE
valueFrom:
Expand Down
5 changes: 4 additions & 1 deletion charts/br-federation/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ brFederationManager:
serviceAccount: br-federation-manager

# Secret name of the kubeconfig for the federation Kubernetes clusters
# The data item key is the cluster name, and the data item value is the base64 encoded kubeconfig
federationKubeconfigSecret: br-federation-kubeconfig
# which data item is the kubeconfig file, and the data item value is the base64 encoded kubeconfig
# if you have multiple kubernetes clusters, you should merge them in one kubeconfig
# we use the context name in the kubeconfig as the k8sClusterName in volume backup/restore CR
federationKubeconfigSecretKey: kubeconfig

logLevel: 2
replicas: 1
Expand Down
15 changes: 6 additions & 9 deletions cmd/br-federation-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
_ "net/http/pprof"
"os"
"os/signal"
"path/filepath"
"reflect"
"syscall"

Expand Down Expand Up @@ -219,18 +218,16 @@ func main() {
}

func initFederationKubeClients(cliCfg *controller.BrFedCLIConfig) (map[string]fedversioned.Interface, error) {
files, err := os.ReadDir(cliCfg.FederationKubeConfigPath)
kubeConfig, err := clientcmd.LoadFromFile(cliCfg.FederationKubeConfigPath)
if err != nil {
return nil, err
}

clients := make(map[string]fedversioned.Interface)
for _, f := range files {
if f.IsDir() || f.Name() == "..data" {
continue
}

cfg, err := clientcmd.BuildConfigFromFlags("", filepath.Join(cliCfg.FederationKubeConfigPath, f.Name()))
for contextName := range kubeConfig.Contexts {
cfg, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: cliCfg.FederationKubeConfigPath},
&clientcmd.ConfigOverrides{CurrentContext: contextName}).ClientConfig()
if err != nil {
return nil, err // return error if any kube client init failed
}
Expand All @@ -243,7 +240,7 @@ func initFederationKubeClients(cliCfg *controller.BrFedCLIConfig) (map[string]fe
if err != nil {
return nil, err
}
clients[f.Name()] = cli
clients[contextName] = cli
}

return clients, nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/br_fed_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

const (
defaultFederationKubeConfigPath = "/etc/br-federation/federation-kubeconfig"
defaultFederationKubeConfigPath = "/etc/br-federation/federation-kubeconfig/kubeconfig"
)

// BrFedCLIConfig is used to save the configuration of br-federation-manager read from command line.
Expand All @@ -41,7 +41,7 @@ type BrFedCLIConfig struct {
KubeClientQPS float64
KubeClientBurst int

// FederationKubeConfigPath is the path to the directory containing the federation kubeconfig files
// FederationKubeConfigPath is the path to the kubeconfig file of data planes
FederationKubeConfigPath string
}

Expand Down Expand Up @@ -73,5 +73,5 @@ func (c *BrFedCLIConfig) AddFlag(_ *flag.FlagSet) {
flag.Float64Var(&c.KubeClientQPS, "kube-client-qps", c.KubeClientQPS, "The maximum QPS to the kubenetes API server from client")
flag.IntVar(&c.KubeClientBurst, "kube-client-burst", c.KubeClientBurst, "The maximum burst for throttle to the kubenetes API server from client")

flag.StringVar(&c.FederationKubeConfigPath, "federation-kubeconfig-path", c.FederationKubeConfigPath, "The path to the directory containing the federation kubeconfig files")
flag.StringVar(&c.FederationKubeConfigPath, "federation-kubeconfig-path", c.FederationKubeConfigPath, "The path to the kubeconfig file of data planes")
}

0 comments on commit a0ef530

Please sign in to comment.