Kubernetes-client: Allow user to add custom header for k8s requests?

Created on 27 Dec 2019  ·  6Comments  ·  Source: fabric8io/kubernetes-client

Hey,
I encountered the following problem:

When I init a client instance, I want to add custom headers for k8s request(such as userpin,cluster-id etc...), , but Config object is only allow to specify "masterUrl" , how i can add clustom header?

Only by add interceptor ? for example:

        Config config = new ConfigBuilder().withMasterUrl(host).build();
        KubernetesClient client = new DefaultKubernetesClient(config);
        ((DefaultKubernetesClient) client).getHttpClient().networkInterceptors().add(chain -> {
            Request agent = chain.request().newBuilder().addHeader("user-pin","xxx")
                    .addHeader("cluster-id","xxxx").build();
            return chain.proceed(agent);
        });

Is it possible to set the customer header for requests sent to ones Kubernetes cluster in this API?

such as:

Config config = new ConfigBuilder().withMasterUrl(northHost).withHeaders("name", "value").build();

@jimmidyson @iocanel @rohanKanojia

Thanks !

Most helpful comment

I don't think that we do. Still it would be trivial to implement.

Would you like to create a pull request for that?

Yes , I would like to try it. @iocanel

All 6 comments

I'm not sure we provide this functionality at the moment. Could you please elaborate what use case are you trying to solve by providing custom headers?

I don't think that we do. Still it would be trivial to implement.

Would you like to create a pull request for that?

I'm not sure we provide this functionality at the moment. Could you please elaborate what use case are you trying to solve by providing custom headers?

In this case:

I provide a proxy that is allow user to schedule his cluster, but i want to authenticate the current user that is owner of this K8S cluster.

I ask the user to put the cluster name and user name in the header, then, proxy completes authentication and forwarding.

Thanks! @rohanKanojia

I don't think that we do. Still it would be trivial to implement.

Would you like to create a pull request for that?

Yes , I would like to try it. @iocanel

@wangyushuai : awesome, looking forward to your contribution :smiley:

Hi @rohanKanojia,

I want to know now if there is a way to add a custom headers , except for modifying the source code myself.

I found that the interceptor is not allowed to be modified after the client is initialized;

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chirlo picture chirlo  ·  18Comments

jkremser picture jkremser  ·  22Comments

rohanKanojia picture rohanKanojia  ·  14Comments

zoujinhe picture zoujinhe  ·  21Comments

WywTed picture WywTed  ·  22Comments