mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-25 20:29:56 +00:00
Allow setting content-type in binaries
This commit is contained in:
@@ -45,6 +45,7 @@ type HollowNodeConfig struct {
|
||||
Morph string
|
||||
NodeName string
|
||||
ServerPort int
|
||||
ContentType string
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -60,17 +61,19 @@ func (c *HollowNodeConfig) addFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&c.NodeName, "name", "fake-node", "Name of this Hollow Node.")
|
||||
fs.IntVar(&c.ServerPort, "api-server-port", 443, "Port on which API server is listening.")
|
||||
fs.StringVar(&c.Morph, "morph", "", fmt.Sprintf("Specifies into which Hollow component this binary should morph. Allowed values: %v", knownMorphs.List()))
|
||||
fs.StringVar(&c.ContentType, "kube-api-content-type", "application/json", "ContentType of requests sent to apiserver. Passing application/vnd.kubernetes.protobuf is an experimental feature now.")
|
||||
}
|
||||
|
||||
func createClientFromFile(path string) (*client.Client, error) {
|
||||
c, err := clientcmd.LoadFromFile(path)
|
||||
func (c *HollowNodeConfig) createClientFromFile() (*client.Client, error) {
|
||||
clientConfig, err := clientcmd.LoadFromFile(c.KubeconfigPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error while loading kubeconfig from file %v: %v", path, err)
|
||||
return nil, fmt.Errorf("error while loading kubeconfig from file %v: %v", c.KubeconfigPath, err)
|
||||
}
|
||||
config, err := clientcmd.NewDefaultClientConfig(*c, &clientcmd.ConfigOverrides{}).ClientConfig()
|
||||
config, err := clientcmd.NewDefaultClientConfig(*clientConfig, &clientcmd.ConfigOverrides{}).ClientConfig()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error while creating kubeconfig: %v", err)
|
||||
}
|
||||
config.ContentType = c.ContentType
|
||||
client, err := client.New(config)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error while creating client: %v", err)
|
||||
@@ -90,7 +93,7 @@ func main() {
|
||||
}
|
||||
|
||||
// create a client to communicate with API server.
|
||||
cl, err := createClientFromFile(config.KubeconfigPath)
|
||||
cl, err := config.createClientFromFile()
|
||||
clientset := clientset.FromUnversionedClient(cl)
|
||||
if err != nil {
|
||||
glog.Fatal("Failed to create a Client. Exiting.")
|
||||
|
Reference in New Issue
Block a user