Closed ederign closed 5 months ago
FYI: I'm currently working on this. (I don't have 'assign' privileges yet).
Inside cluster:
> kubectl port-forward service/my-service-nb 8080:80
Forwarding from 127.0.0.1:8080 -> 4001
Forwarding from [::1]:8080 -> 4001
Handling connection for 8080
Handling connection for 8080
Outside cluster, you can either use .kube config OR export KUBECONFIG=pathtokubeconfig.yaml
Also, I've moved the Kubernetes client to app startup. Seems like the Kubernetes client is designed to handle long-lived connections and can manage its own timeouts and retries.
However, on future, we can improve it with proper configuration of timeouts and other settings
And also see if we should deal with refresh the client due to changes in the cluster configuration or credentials. But I believe we can approach both things in future.
@thesuperzapper one thing that I would like to discuss today!
I'm guessing this is how it works here
The sources at https://github.com/kubernetes-sigs/prow/tree/main/pkg/plugins seem to be the only docs for the supported comands?
/priority p1 /assign @ederign
@jiridanek: The label(s) priority/p1
cannot be applied, because the repository doesn't have them.
/help
uh, sorry, I thought that /help
will maybe display some help text for these commands ;P
/remove-help
I think we might be able to just use the (WRONG: see https://github.com/kubeflow/notebooks/issues/12#issuecomment-2148569483)BuildConfigFromFlags
constructor directly with the KUBECONFIG
env-var, like this:
kubeconfig := os.Getenv("KUBECONFIG")
config, err = clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
return nil, fmt.Errorf("failed to load kubeconfig: %w", err)
}
Because the upstream docs say that BuildConfigFromFlags()
will fallback to the default home location:
BuildConfigFromFlags is a helper function that builds configs from a master url or a kubeconfig filepath. These are passed in as command line flags for cluster components. Warnings should reflect this usage. If neither masterUrl or kubeconfigPath are passed in we fallback to inClusterConfig. If inClusterConfig fails, we fallback to the default config.
So the flow would be:
@ederign sorry, I was mistaken in https://github.com/kubeflow/notebooks/issues/12#issuecomment-2141051590.
The correct usage of the clientcmd
package (see here) seems to be something like this:
func getRestConfig() (*restclient.Config, error) {
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
configOverrides := &clientcmd.ConfigOverrides{}
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides)
return kubeConfig.ClientConfig()
}
func newClientSet() (*kubernetes.Clientset, error) {
restConfig, err := getRestConfig()
if err != nil {
return nil, err
}
return kubernetes.NewForConfig(restConfig)
}
This combination of NewDefaultClientConfigLoadingRules
and NewNonInteractiveDeferredLoadingClientConfig
cause the following order of precedence:
:
if there are multiple files specified in it).$HOME/.kube/config
for the system.I have tested this locally with and without KUBECONFIG being set, and on a Pod (in a Notebook) to test the "in cluster" configs.
@thesuperzapper Yeah, thank you for the guidance; in the previous suggestion, I got an exception when the KUBECONFIG was not set. I tested it in all scenarios and can confirm that it works as expected.
Checks
Motivation
The goal of this issue is to develop:
Implementation
Are you willing & able to help?