From: Martina Ferrari <tina@debian.org>
Date: Sat, 20 Jun 2020 15:49:53 -0300
Subject: Disable Kubernetes service discovery

Forwarded: not-needed
Last-Updated: Sat Mar 12 18:35:22 2022 +0000

Disable Kubernetes SD, until dependencies are more reasonable.
---
 cmd/prometheus/main.go                             |   8 -
 cmd/promtool/main.go                               |   5 -
 config/config_test.go                              | 173 +--------------------
 config/testdata/conf.good.yml                      |  26 ----
 config/testdata/roundtrip.good.yml                 |  18 ---
 discovery/install/install.go                       |   1 -
 discovery/kubernetes/client_metrics.go             |   3 +
 discovery/kubernetes/endpoints.go                  |   3 +
 discovery/kubernetes/endpoints_test.go             |   3 +
 discovery/kubernetes/endpointslice.go              |   3 +
 discovery/kubernetes/endpointslice_adaptor.go      |   3 +
 discovery/kubernetes/endpointslice_adaptor_test.go |   3 +
 discovery/kubernetes/endpointslice_test.go         |   3 +
 discovery/kubernetes/ingress.go                    |   3 +
 discovery/kubernetes/ingress_adaptor.go            |   3 +
 discovery/kubernetes/ingress_test.go               |   3 +
 discovery/kubernetes/kubernetes.go                 |   3 +
 discovery/kubernetes/kubernetes_test.go            |   3 +
 discovery/kubernetes/node.go                       |   3 +
 discovery/kubernetes/node_test.go                  |   3 +
 discovery/kubernetes/pod.go                        |   3 +
 discovery/kubernetes/pod_test.go                   |   3 +
 discovery/kubernetes/service.go                    |   3 +
 discovery/kubernetes/service_test.go               |   3 +
 plugins/plugins.go                                 |   3 -
 25 files changed, 55 insertions(+), 233 deletions(-)

diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go
index e05ac79..4173f73 100644
--- a/cmd/prometheus/main.go
+++ b/cmd/prometheus/main.go
@@ -49,8 +49,6 @@ import (
 	toolkit_web "github.com/prometheus/exporter-toolkit/web"
 	"go.uber.org/atomic"
 	"go.uber.org/automaxprocs/maxprocs"
-	"k8s.io/klog"
-	klogv2 "k8s.io/klog/v2"
 
 	"github.com/prometheus/prometheus/config"
 	"github.com/prometheus/prometheus/discovery"
@@ -562,12 +560,6 @@ func main() {
 	noStepSubqueryInterval := &safePromQLNoStepSubqueryInterval{}
 	noStepSubqueryInterval.Set(config.DefaultGlobalConfig.EvaluationInterval)
 
-	// Above level 6, the k8s client would log bearer tokens in clear-text.
-	klog.ClampLevel(6)
-	klog.SetLogger(log.With(logger, "component", "k8s_client_runtime"))
-	klogv2.ClampLevel(6)
-	klogv2.SetLogger(log.With(logger, "component", "k8s_client_runtime"))
-
 	modeAppName := "Prometheus Server"
 	mode := "server"
 	if agentMode {
diff --git a/cmd/promtool/main.go b/cmd/promtool/main.go
index de002a0..14ca203 100644
--- a/cmd/promtool/main.go
+++ b/cmd/promtool/main.go
@@ -51,7 +51,6 @@ import (
 	"github.com/prometheus/prometheus/config"
 	"github.com/prometheus/prometheus/discovery"
 	"github.com/prometheus/prometheus/discovery/file"
-	"github.com/prometheus/prometheus/discovery/kubernetes"
 	"github.com/prometheus/prometheus/discovery/targetgroup"
 	"github.com/prometheus/prometheus/model/labels"
 	"github.com/prometheus/prometheus/model/rulefmt"
@@ -545,10 +544,6 @@ func checkConfig(agentMode bool, filename string, checkSyntaxOnly bool) ([]strin
 
 		for _, c := range scfg.ServiceDiscoveryConfigs {
 			switch c := c.(type) {
-			case *kubernetes.SDConfig:
-				if err := checkTLSConfig(c.HTTPClientConfig.TLSConfig, checkSyntaxOnly); err != nil {
-					return nil, err
-				}
 			case *file.SDConfig:
 				if checkSyntaxOnly {
 					break
diff --git a/config/config_test.go b/config/config_test.go
index d3288cc..7132cb6 100644
--- a/config/config_test.go
+++ b/config/config_test.go
@@ -41,7 +41,6 @@ import (
 	"github.com/prometheus/prometheus/discovery/hetzner"
 	"github.com/prometheus/prometheus/discovery/http"
 	"github.com/prometheus/prometheus/discovery/ionos"
-	"github.com/prometheus/prometheus/discovery/kubernetes"
 	"github.com/prometheus/prometheus/discovery/linode"
 	"github.com/prometheus/prometheus/discovery/marathon"
 	"github.com/prometheus/prometheus/discovery/moby"
@@ -459,80 +458,6 @@ var expectedConf = &Config{
 				EnableHTTP2:     true,
 			},
 		},
-		{
-			JobName: "service-kubernetes",
-
-			HonorTimestamps:       true,
-			ScrapeInterval:        model.Duration(15 * time.Second),
-			ScrapeTimeout:         DefaultGlobalConfig.ScrapeTimeout,
-			BodySizeLimit:         globBodySizeLimit,
-			SampleLimit:           globSampleLimit,
-			TargetLimit:           globTargetLimit,
-			LabelLimit:            globLabelLimit,
-			LabelNameLengthLimit:  globLabelNameLengthLimit,
-			LabelValueLengthLimit: globLabelValueLengthLimit,
-
-			MetricsPath:      DefaultScrapeConfig.MetricsPath,
-			Scheme:           DefaultScrapeConfig.Scheme,
-			HTTPClientConfig: config.DefaultHTTPClientConfig,
-
-			ServiceDiscoveryConfigs: discovery.Configs{
-				&kubernetes.SDConfig{
-					APIServer: kubernetesSDHostURL(),
-					Role:      kubernetes.RoleEndpoint,
-					HTTPClientConfig: config.HTTPClientConfig{
-						BasicAuth: &config.BasicAuth{
-							Username: "myusername",
-							Password: "mysecret",
-						},
-						TLSConfig: config.TLSConfig{
-							CertFile: filepath.FromSlash("testdata/valid_cert_file"),
-							KeyFile:  filepath.FromSlash("testdata/valid_key_file"),
-						},
-						FollowRedirects: true,
-						EnableHTTP2:     true,
-					},
-					NamespaceDiscovery: kubernetes.NamespaceDiscovery{},
-				},
-			},
-		},
-		{
-			JobName: "service-kubernetes-namespaces",
-
-			HonorTimestamps:       true,
-			ScrapeInterval:        model.Duration(15 * time.Second),
-			ScrapeTimeout:         DefaultGlobalConfig.ScrapeTimeout,
-			BodySizeLimit:         globBodySizeLimit,
-			SampleLimit:           globSampleLimit,
-			TargetLimit:           globTargetLimit,
-			LabelLimit:            globLabelLimit,
-			LabelNameLengthLimit:  globLabelNameLengthLimit,
-			LabelValueLengthLimit: globLabelValueLengthLimit,
-
-			MetricsPath: DefaultScrapeConfig.MetricsPath,
-			Scheme:      DefaultScrapeConfig.Scheme,
-			HTTPClientConfig: config.HTTPClientConfig{
-				BasicAuth: &config.BasicAuth{
-					Username:     "myusername",
-					PasswordFile: filepath.FromSlash("testdata/valid_password_file"),
-				},
-				FollowRedirects: true,
-				EnableHTTP2:     true,
-			},
-
-			ServiceDiscoveryConfigs: discovery.Configs{
-				&kubernetes.SDConfig{
-					APIServer: kubernetesSDHostURL(),
-					Role:      kubernetes.RoleEndpoint,
-					NamespaceDiscovery: kubernetes.NamespaceDiscovery{
-						Names: []string{
-							"default",
-						},
-					},
-					HTTPClientConfig: config.DefaultHTTPClientConfig,
-				},
-			},
-		},
 		{
 			JobName: "service-kuma",
 
@@ -1430,7 +1355,7 @@ func TestElideSecrets(t *testing.T) {
 	yamlConfig := string(config)
 
 	matches := secretRe.FindAllStringIndex(yamlConfig, -1)
-	require.Equal(t, 22, len(matches), "wrong number of secret matches found")
+	require.Equal(t, 21, len(matches), "wrong number of secret matches found")
 	require.NotContains(t, yamlConfig, "mysecret",
 		"yaml marshal reveals authentication credentials.")
 }
@@ -1442,29 +1367,6 @@ func TestLoadConfigRuleFilesAbsolutePath(t *testing.T) {
 	require.Equal(t, ruleFilesExpectedConf, c)
 }
 
-func TestKubernetesEmptyAPIServer(t *testing.T) {
-	_, err := LoadFile("testdata/kubernetes_empty_apiserver.good.yml", false, false, log.NewNopLogger())
-	require.NoError(t, err)
-}
-
-func TestKubernetesWithKubeConfig(t *testing.T) {
-	_, err := LoadFile("testdata/kubernetes_kubeconfig_without_apiserver.good.yml", false, false, log.NewNopLogger())
-	require.NoError(t, err)
-}
-
-func TestKubernetesSelectors(t *testing.T) {
-	_, err := LoadFile("testdata/kubernetes_selectors_endpoints.good.yml", false, false, log.NewNopLogger())
-	require.NoError(t, err)
-	_, err = LoadFile("testdata/kubernetes_selectors_node.good.yml", false, false, log.NewNopLogger())
-	require.NoError(t, err)
-	_, err = LoadFile("testdata/kubernetes_selectors_ingress.good.yml", false, false, log.NewNopLogger())
-	require.NoError(t, err)
-	_, err = LoadFile("testdata/kubernetes_selectors_pod.good.yml", false, false, log.NewNopLogger())
-	require.NoError(t, err)
-	_, err = LoadFile("testdata/kubernetes_selectors_service.good.yml", false, false, log.NewNopLogger())
-	require.NoError(t, err)
-}
-
 var expectedErrors = []struct {
 	filename string
 	errMsg   string
@@ -1601,74 +1503,6 @@ var expectedErrors = []struct {
 		filename: "bearertoken_basicauth.bad.yml",
 		errMsg:   "at most one of basic_auth, oauth2, bearer_token & bearer_token_file must be configured",
 	},
-	{
-		filename: "kubernetes_http_config_without_api_server.bad.yml",
-		errMsg:   "to use custom HTTP client configuration please provide the 'api_server' URL explicitly",
-	},
-	{
-		filename: "kubernetes_kubeconfig_with_own_namespace.bad.yml",
-		errMsg:   "cannot use 'kubeconfig_file' and 'namespaces.own_namespace' simultaneously",
-	},
-	{
-		filename: "kubernetes_api_server_with_own_namespace.bad.yml",
-		errMsg:   "cannot use 'api_server' and 'namespaces.own_namespace' simultaneously",
-	},
-	{
-		filename: "kubernetes_kubeconfig_with_apiserver.bad.yml",
-		errMsg:   "cannot use 'kubeconfig_file' and 'api_server' simultaneously",
-	},
-	{
-		filename: "kubernetes_kubeconfig_with_http_config.bad.yml",
-		errMsg:   "cannot use a custom HTTP client configuration together with 'kubeconfig_file'",
-	},
-	{
-		filename: "kubernetes_bearertoken.bad.yml",
-		errMsg:   "at most one of bearer_token & bearer_token_file must be configured",
-	},
-	{
-		filename: "kubernetes_role.bad.yml",
-		errMsg:   "role",
-	},
-	{
-		filename: "kubernetes_selectors_endpoints.bad.yml",
-		errMsg:   "endpoints role supports only pod, service, endpoints selectors",
-	},
-	{
-		filename: "kubernetes_selectors_ingress.bad.yml",
-		errMsg:   "ingress role supports only ingress selectors",
-	},
-	{
-		filename: "kubernetes_selectors_node.bad.yml",
-		errMsg:   "node role supports only node selectors",
-	},
-	{
-		filename: "kubernetes_selectors_pod.bad.yml",
-		errMsg:   "pod role supports only pod selectors",
-	},
-	{
-		filename: "kubernetes_selectors_service.bad.yml",
-		errMsg:   "service role supports only service selectors",
-	},
-	{
-		filename: "kubernetes_namespace_discovery.bad.yml",
-		errMsg:   "field foo not found in type kubernetes.plain",
-	},
-	{
-		filename: "kubernetes_selectors_duplicated_role.bad.yml",
-		errMsg:   "duplicated selector role: pod",
-	},
-	{
-		filename: "kubernetes_selectors_incorrect_selector.bad.yml",
-		errMsg:   "invalid selector: 'metadata.status-Running'; can't understand 'metadata.status-Running'",
-	},
-	{
-		filename: "kubernetes_bearertoken_basicauth.bad.yml",
-		errMsg:   "at most one of basic_auth, oauth2, bearer_token & bearer_token_file must be configured",
-	},
-	{
-		filename: "kubernetes_authorization_basicauth.bad.yml",
-		errMsg:   "at most one of basic_auth, oauth2 & authorization must be configured",
-	},
 	{
 		filename: "marathon_no_servers.bad.yml",
 		errMsg:   "marathon_sd: must contain at least one Marathon server",
@@ -2136,8 +1970,3 @@ func TestGetScrapeConfigs(t *testing.T) {
 		})
 	}
 }
-
-func kubernetesSDHostURL() config.URL {
-	tURL, _ := url.Parse("https://localhost:1234")
-	return config.URL{URL: tURL}
-}
diff --git a/config/testdata/conf.good.yml b/config/testdata/conf.good.yml
index 19cfe1e..b32021f 100644
--- a/config/testdata/conf.good.yml
+++ b/config/testdata/conf.good.yml
@@ -191,32 +191,6 @@ scrape_configs:
     authorization:
       credentials: mysecret
 
-  - job_name: service-kubernetes
-
-    kubernetes_sd_configs:
-      - role: endpoints
-        api_server: "https://localhost:1234"
-        tls_config:
-          cert_file: valid_cert_file
-          key_file: valid_key_file
-
-        basic_auth:
-          username: "myusername"
-          password: "mysecret"
-
-  - job_name: service-kubernetes-namespaces
-
-    kubernetes_sd_configs:
-      - role: endpoints
-        api_server: "https://localhost:1234"
-        namespaces:
-          names:
-            - default
-
-    basic_auth:
-      username: "myusername"
-      password_file: valid_password_file
-
   - job_name: service-kuma
 
     kuma_sd_configs:
diff --git a/config/testdata/roundtrip.good.yml b/config/testdata/roundtrip.good.yml
index f2634d2..de7fd67 100644
--- a/config/testdata/roundtrip.good.yml
+++ b/config/testdata/roundtrip.good.yml
@@ -88,24 +88,6 @@ scrape_configs:
       - files:
           - single/file.yml
 
-    kubernetes_sd_configs:
-      - role: endpoints
-        api_server: https://localhost:1234
-        tls_config:
-          cert_file: valid_cert_file
-          key_file: valid_key_file
-        basic_auth:
-          username: username
-          password: <secret>
-      - role: endpoints
-        api_server: https://localhost:1234
-        namespaces:
-          names:
-            - default
-        basic_auth:
-          username: username
-          password_file: valid_password_file
-
     kuma_sd_configs:
       - server: http://kuma-control-plane.kuma-system.svc:5676
 
diff --git a/discovery/install/install.go b/discovery/install/install.go
index f090076..467984d 100644
--- a/discovery/install/install.go
+++ b/discovery/install/install.go
@@ -27,7 +27,6 @@ import (
 	_ "github.com/prometheus/prometheus/discovery/hetzner"      // register hetzner
 	_ "github.com/prometheus/prometheus/discovery/http"         // register http
 	_ "github.com/prometheus/prometheus/discovery/ionos"        // register ionos
-	_ "github.com/prometheus/prometheus/discovery/kubernetes"   // register kubernetes
 	_ "github.com/prometheus/prometheus/discovery/linode"       // register linode
 	_ "github.com/prometheus/prometheus/discovery/marathon"     // register marathon
 	_ "github.com/prometheus/prometheus/discovery/moby"         // register moby
diff --git a/discovery/kubernetes/client_metrics.go b/discovery/kubernetes/client_metrics.go
index b316f7d..c6eefb7 100644
--- a/discovery/kubernetes/client_metrics.go
+++ b/discovery/kubernetes/client_metrics.go
@@ -11,6 +11,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+//go:build ignore
+// +build ignore
+
 package kubernetes
 
 import (
diff --git a/discovery/kubernetes/endpoints.go b/discovery/kubernetes/endpoints.go
index 2413dab..d34e0a0 100644
--- a/discovery/kubernetes/endpoints.go
+++ b/discovery/kubernetes/endpoints.go
@@ -11,6 +11,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+//go:build ignore
+// +build ignore
+
 // nolint:revive // Many legitimately empty blocks in this file.
 package kubernetes
 
diff --git a/discovery/kubernetes/endpoints_test.go b/discovery/kubernetes/endpoints_test.go
index 5aa58bd..d6591aa 100644
--- a/discovery/kubernetes/endpoints_test.go
+++ b/discovery/kubernetes/endpoints_test.go
@@ -11,6 +11,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+//go:build ignore
+// +build ignore
+
 package kubernetes
 
 import (
diff --git a/discovery/kubernetes/endpointslice.go b/discovery/kubernetes/endpointslice.go
index c7df642..a620306 100644
--- a/discovery/kubernetes/endpointslice.go
+++ b/discovery/kubernetes/endpointslice.go
@@ -11,6 +11,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+//go:build ignore
+// +build ignore
+
 package kubernetes
 
 import (
diff --git a/discovery/kubernetes/endpointslice_adaptor.go b/discovery/kubernetes/endpointslice_adaptor.go
index 5a21f1b..2a84448 100644
--- a/discovery/kubernetes/endpointslice_adaptor.go
+++ b/discovery/kubernetes/endpointslice_adaptor.go
@@ -11,6 +11,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+//go:build ignore
+// +build ignore
+
 package kubernetes
 
 import (
diff --git a/discovery/kubernetes/endpointslice_adaptor_test.go b/discovery/kubernetes/endpointslice_adaptor_test.go
index e564910..756c5a5 100644
--- a/discovery/kubernetes/endpointslice_adaptor_test.go
+++ b/discovery/kubernetes/endpointslice_adaptor_test.go
@@ -11,6 +11,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+//go:build ignore
+// +build ignore
+
 package kubernetes
 
 import (
diff --git a/discovery/kubernetes/endpointslice_test.go b/discovery/kubernetes/endpointslice_test.go
index 8104e3d..597a331 100644
--- a/discovery/kubernetes/endpointslice_test.go
+++ b/discovery/kubernetes/endpointslice_test.go
@@ -11,6 +11,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+//go:build ignore
+// +build ignore
+
 package kubernetes
 
 import (
diff --git a/discovery/kubernetes/ingress.go b/discovery/kubernetes/ingress.go
index ad47c34..d19e5c0 100644
--- a/discovery/kubernetes/ingress.go
+++ b/discovery/kubernetes/ingress.go
@@ -11,6 +11,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+//go:build ignore
+// +build ignore
+
 package kubernetes
 
 import (
diff --git a/discovery/kubernetes/ingress_adaptor.go b/discovery/kubernetes/ingress_adaptor.go
index 113a067..1b73747 100644
--- a/discovery/kubernetes/ingress_adaptor.go
+++ b/discovery/kubernetes/ingress_adaptor.go
@@ -11,6 +11,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+//go:build ignore
+// +build ignore
+
 package kubernetes
 
 import (
diff --git a/discovery/kubernetes/ingress_test.go b/discovery/kubernetes/ingress_test.go
index 8e6654c..d2f375b 100644
--- a/discovery/kubernetes/ingress_test.go
+++ b/discovery/kubernetes/ingress_test.go
@@ -11,6 +11,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+//go:build ignore
+// +build ignore
+
 package kubernetes
 
 import (
diff --git a/discovery/kubernetes/kubernetes.go b/discovery/kubernetes/kubernetes.go
index e87a1c9..5042981 100644
--- a/discovery/kubernetes/kubernetes.go
+++ b/discovery/kubernetes/kubernetes.go
@@ -11,6 +11,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+//go:build ignore
+// +build ignore
+
 package kubernetes
 
 import (
diff --git a/discovery/kubernetes/kubernetes_test.go b/discovery/kubernetes/kubernetes_test.go
index d0ed4c6..5028322 100644
--- a/discovery/kubernetes/kubernetes_test.go
+++ b/discovery/kubernetes/kubernetes_test.go
@@ -11,6 +11,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+//go:build ignore
+// +build ignore
+
 package kubernetes
 
 import (
diff --git a/discovery/kubernetes/node.go b/discovery/kubernetes/node.go
index d0a6d27..6e87740 100644
--- a/discovery/kubernetes/node.go
+++ b/discovery/kubernetes/node.go
@@ -11,6 +11,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+//go:build ignore
+// +build ignore
+
 package kubernetes
 
 import (
diff --git a/discovery/kubernetes/node_test.go b/discovery/kubernetes/node_test.go
index bbf7a6b..7d89020 100644
--- a/discovery/kubernetes/node_test.go
+++ b/discovery/kubernetes/node_test.go
@@ -11,6 +11,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+//go:build ignore
+// +build ignore
+
 package kubernetes
 
 import (
diff --git a/discovery/kubernetes/pod.go b/discovery/kubernetes/pod.go
index 732cf52..6e74502 100644
--- a/discovery/kubernetes/pod.go
+++ b/discovery/kubernetes/pod.go
@@ -11,6 +11,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+//go:build ignore
+// +build ignore
+
 package kubernetes
 
 import (
diff --git a/discovery/kubernetes/pod_test.go b/discovery/kubernetes/pod_test.go
index 286a1a2..4115d31 100644
--- a/discovery/kubernetes/pod_test.go
+++ b/discovery/kubernetes/pod_test.go
@@ -11,6 +11,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+//go:build ignore
+// +build ignore
+
 package kubernetes
 
 import (
diff --git a/discovery/kubernetes/service.go b/discovery/kubernetes/service.go
index 40e1767..afa63b3 100644
--- a/discovery/kubernetes/service.go
+++ b/discovery/kubernetes/service.go
@@ -11,6 +11,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+//go:build ignore
+// +build ignore
+
 package kubernetes
 
 import (
diff --git a/discovery/kubernetes/service_test.go b/discovery/kubernetes/service_test.go
index dde3aae..f4723c9 100644
--- a/discovery/kubernetes/service_test.go
+++ b/discovery/kubernetes/service_test.go
@@ -11,6 +11,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+//go:build ignore
+// +build ignore
+
 package kubernetes
 
 import (
diff --git a/plugins/plugins.go b/plugins/plugins.go
index e6994e2..f135e1d 100644
--- a/plugins/plugins.go
+++ b/plugins/plugins.go
@@ -43,9 +43,6 @@ import (
 	// Register ionos plugin.
 	_ "github.com/prometheus/prometheus/discovery/ionos"
 
-	// Register kubernetes plugin.
-	_ "github.com/prometheus/prometheus/discovery/kubernetes"
-
 	// Register linode plugin.
 	_ "github.com/prometheus/prometheus/discovery/linode"
 
