Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 share k8s discovery cache within a provider instance #2063

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions providers/k8s/connection/api/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Connection struct {
currentClusterName string
}

func NewConnection(id uint32, asset *inventory.Asset) (shared.Connection, error) {
func NewConnection(id uint32, asset *inventory.Asset, discoveryCache *resources.DiscoveryCache) (shared.Connection, error) {
// check if the user .kube/config file exists
// NOTE: BuildConfigFromFlags falls back to cluster loading when .kube/config string is empty
// therefore we want to only change the kubeconfig string when the file really exists
Expand Down Expand Up @@ -72,7 +72,7 @@ func NewConnection(id uint32, asset *inventory.Asset) (shared.Connection, error)
config.Burst = 1000

// initialize api
d, err := resources.NewDiscoveryCache().Get(config)
d, err := discoveryCache.Get(config)
if err != nil {
return nil, err
}
Expand Down
5 changes: 4 additions & 1 deletion providers/k8s/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"go.mondoo.com/cnquery/providers/k8s/connection/api"
"go.mondoo.com/cnquery/providers/k8s/connection/manifest"
"go.mondoo.com/cnquery/providers/k8s/connection/shared"
connectionResources "go.mondoo.com/cnquery/providers/k8s/connection/shared/resources"
"go.mondoo.com/cnquery/providers/k8s/resources"
)

Expand All @@ -24,12 +25,14 @@ const ConnectionType = "k8s"
type Service struct {
runtimes map[uint32]*plugin.Runtime
lastConnectionID uint32
discoveryCache *connectionResources.DiscoveryCache
}

func Init() *Service {
return &Service{
runtimes: map[uint32]*plugin.Runtime{},
lastConnectionID: 0,
discoveryCache: connectionResources.NewDiscoveryCache(),
}
}

Expand Down Expand Up @@ -165,7 +168,7 @@ func (s *Service) connect(req *plugin.ConnectReq, callback plugin.ProviderCallba
}
} else {
s.lastConnectionID++
conn, err = api.NewConnection(s.lastConnectionID, asset)
conn, err = api.NewConnection(s.lastConnectionID, asset, s.discoveryCache)
if err != nil {
return nil, err
}
Expand Down
Loading