Skip to content

Commit 0c28734

Browse files
adityathebemoshloop
authored andcommitted
fix: kubernetes file scraper kubeconfig default
1 parent aa1ea9f commit 0c28734

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

scrapers/kubernetes/kubernetes_file.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ import (
55
"path"
66
"strings"
77

8-
perrors "github.com/pkg/errors"
9-
10-
"github.com/flanksource/config-db/api"
11-
v1 "github.com/flanksource/config-db/api/v1"
12-
"github.com/flanksource/config-db/utils/kube"
138
"github.com/flanksource/duty/connection"
14-
9+
perrors "github.com/pkg/errors"
1510
appsv1 "k8s.io/api/apps/v1"
1611
k8sv1 "k8s.io/api/core/v1"
1712
"k8s.io/apimachinery/pkg/api/errors"
1813
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1914
"k8s.io/client-go/kubernetes"
15+
16+
"github.com/flanksource/config-db/api"
17+
v1 "github.com/flanksource/config-db/api/v1"
18+
"github.com/flanksource/config-db/utils/kube"
2019
)
2120

2221
type KubernetesFileScraper struct {
@@ -127,14 +126,12 @@ func (kubernetes KubernetesFileScraper) Scrape(ctx api.ScrapeContext) v1.ScrapeR
127126
results := v1.ScrapeResults{}
128127

129128
for _, config := range ctx.ScrapeConfig().Spec.KubernetesFile {
130-
129+
kc := connection.KubernetesConnection{}
131130
if config.Kubeconfig != nil {
132-
c := ctx.WithKubernetes(connection.KubernetesConnection{
133-
KubeconfigConnection: connection.KubeconfigConnection{
134-
Kubeconfig: config.Kubeconfig,
135-
},
136-
})
137-
ctx.Context = c
131+
kc.Kubeconfig = config.Kubeconfig
132+
ctx.Context = ctx.WithKubernetes(kc)
133+
} else if ctx.KubernetesConnection() == nil {
134+
ctx.Context = ctx.WithKubernetes(kc)
138135
}
139136

140137
if config.Selector.Kind == "" {

0 commit comments

Comments
 (0)