Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

br: modify to use one kubeconfig for multiple data planes #5186

Merged
merged 5 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
WangLe1321 marked this conversation as resolved.
Show resolved Hide resolved

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")
}
Loading