Code Monkey home page Code Monkey logo

Comments (5)

huxiaoliang avatar huxiaoliang commented on August 10, 2024

@luxas @DirectXMan12 hi, is this issue make sense? I will create a PR to fix it, what do you think?

from prometheus-adapter.

DirectXMan12 avatar DirectXMan12 commented on August 10, 2024

The issue makes sense. I think we should have something like a kubeconfig (maybe just use the kubeconfig code?), so that we can support other auth mechanisms too, like tokens (because in OpenShift, we deploy with kind-of Kube-native proxy that can use SA tokens, for instance)

from prometheus-adapter.

huxiaoliang avatar huxiaoliang commented on August 10, 2024

@DirectXMan12 kubeconfig supports below authN refer to here for details (same like curl as well) :

case 1: ssl/tls based
-certificate-authority
--client-certificate
--client-key
--insecure-skip-tls-verify

case 2 : simple based
--username
--password

case 3: based
--token

my patch only cover case 1 now, did you mean we should support all above and leverage kubeconfig codes and implementation?

from prometheus-adapter.

DirectXMan12 avatar DirectXMan12 commented on August 10, 2024

Yeah, I'm saying it might not be a bad idea to just have a separate argument for prom-kubeconfig, use-prom-auth. By default, if use-prom-auth is set to true, prom-kubeconfig it just uses InClusterConfig, so if you have your Prometheus set up behind an auth proxy that auths against Kubernetes, everything should just work.

from prometheus-adapter.

huxiaoliang avatar huxiaoliang commented on August 10, 2024

@DirectXMan12 I am ok for your postal, append some code snippet for you check in advance. (will make it more modularization later)

	var prometheusClientConfig *rest.Config
	if o.PrometheusUseAuth && len(o.PrometheusKubeConfig) > 0 {
		loadingRules := &clientcmd.ClientConfigLoadingRules{ExplicitPath: o.RemoteKubeConfigFile}
		configOverrides := &clientcmd.ConfigOverrides{ClusterInfo: api.Cluster{Server: baseURL.String()}}
		loader := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides)
		prometheusClientConfig, err = loader.ClientConfig()
	} else {
		prometheusClientConfig, err = rest.InClusterConfig()
		prometheusClientConfig.Host = baseURL.String()
	}
	transport, err := rest.TransportFor(prometheusClientConfig)
	if err != nil {
		return fmt.Errorf("failed to create Prometheus client transport %v", err)
	}

	var httpClient *http.Client
	if transport != http.DefaultTransport {
		httpClient = &http.Client{Transport: transport}
		if prometheusClientConfig.Timeout > 0 {
			httpClient.Timeout = prometheusClientConfig.Timeout
		}
	}
	genericPromClient := prom.NewGenericAPIClient(httpClient, baseURL)
  1. if user doesn't specified prom-kubeconfig, use InClusterConfig conf to access to prometheus, but need to overwrite api server address to prometheus url in conf

  2. if user specified prom-kubeconfig, load it and create client by k8s/client-go
    for example, access to an enabled ssl/tls prometheus

apiVersion: v1
clusters:
- cluster:
    insecure-skip-tls-verify: true
    server: https://monitoring-prometheus:9090
  name: mycluster.icp
contexts: []
current-context: ""
kind: Config
preferences: {}
users:
- name: test
  user:
    client-certificate: /tmp/client.crt
    client-key: /tmp/client.key

any comments is welcome, thanks.

from prometheus-adapter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.