Skip to content

Commit

Permalink
Merge pull request #2570 from r2k1/optimization
Browse files Browse the repository at this point in the history
Switch from JSON to protobuf for kube-api requests
  • Loading branch information
AjayTripathy committed Feb 27, 2024
2 parents eeed658 + 4ff7196 commit 7e71053
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/kubeconfig/loader.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package kubeconfig

import (
"fmt"

"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/client-go/rest"
Expand All @@ -17,7 +19,16 @@ func LoadKubeconfig(path string) (*rest.Config, error) {
loadingRules.ExplicitPath = path
}
loader := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, &clientcmd.ConfigOverrides{})
return loader.ClientConfig()
config, err := loader.ClientConfig()
if err != nil {
return nil, fmt.Errorf("loading kubeconfig: %w", err)
}
config.UserAgent = "opencost"
// use protobuf for faster serialization instead of default json
// https://kubernetes.io/docs/reference/using-api/api-concepts/#alternate-representations-of-resources
config.AcceptContentTypes = "application/vnd.kubernetes.protobuf,application/json"
config.ContentType = "application/vnd.kubernetes.protobuf"
return config, nil
}

// LoadKubeClient accepts a path to a kubeconfig to load and returns the clientset
Expand Down

0 comments on commit 7e71053

Please sign in to comment.