Skip to content

Commit

Permalink
Merge pull request #1633 from kubescape/fixk8sclient
Browse files Browse the repository at this point in the history
get KubernetesClient only if k8s is not nil
  • Loading branch information
dwertent committed Mar 13, 2024
2 parents f64617c + 55e570a commit 5217ad2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/core/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
apisv1 "github.com/kubescape/opa-utils/httpserver/apis/v1"
"go.opentelemetry.io/otel"
"golang.org/x/exp/slices"
"k8s.io/client-go/kubernetes"

"github.com/kubescape/opa-utils/resources"
)
Expand All @@ -42,11 +43,13 @@ func getInterfaces(ctx context.Context, scanInfo *cautils.ScanInfo) componentInt

// ================== setup k8s interface object ======================================
var k8s *k8sinterface.KubernetesApi
var k8sClient kubernetes.Interface
if scanInfo.GetScanningContext() == cautils.ContextCluster {
k8s = getKubernetesApi()
if k8s == nil {
logger.L().Ctx(ctx).Fatal("failed connecting to Kubernetes cluster")
}
k8sClient = k8s.KubernetesClient
}

// ================== setup tenant object ======================================
Expand All @@ -65,7 +68,7 @@ func getInterfaces(ctx context.Context, scanInfo *cautils.ScanInfo) componentInt
// ================== version testing ======================================

v := versioncheck.NewIVersionCheckHandler(ctx)
v.CheckLatestVersion(ctx, versioncheck.NewVersionCheckRequest(scanInfo.AccountID, versioncheck.BuildNumber, policyIdentifierIdentities(scanInfo.PolicyIdentifier), "", string(scanInfo.GetScanningContext()), k8s.KubernetesClient))
v.CheckLatestVersion(ctx, versioncheck.NewVersionCheckRequest(scanInfo.AccountID, versioncheck.BuildNumber, policyIdentifierIdentities(scanInfo.PolicyIdentifier), "", string(scanInfo.GetScanningContext()), k8sClient))

// ================== setup host scanner object ======================================
ctxHostScanner, spanHostScanner := otel.Tracer("").Start(ctx, "setup host scanner")
Expand Down

0 comments on commit 5217ad2

Please sign in to comment.