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

[Policy Assistant] Avoid unnecessary api calls to get all the pods in the namespace. #236

Open
gabrielggg opened this issue Jun 18, 2024 · 3 comments

Comments

@gabrielggg
Copy link
Contributor

gabrielggg commented Jun 18, 2024

When calling functions that use the translate func (for example DeploymentsToTrafficPeers func), we are getting all the pods on the namespace one time per each deployment on that specific namespace , so that is not correct. Ideally, we'd get all pods in the namespace only once.

Example code snippet from DeploymentsToTrafficPeers func to take as reference (source file: https://github.com/kubernetes-sigs/network-policy-api/blob/main/cmd/policy-assistant/pkg/matcher/traffic.go):

for _, deployment := range kubeDeployments {
			tmpInternalPeer := InternalPeer{
				Workload: namespace.Name + "/deployment/" + deployment.Name,
			}
			tmpPeer := TrafficPeer{
				Internal: &tmpInternalPeer,
			}
			tmpPeerTranslated := tmpPeer.Translate() //here we are calling the translate func inside a loop and 
                        //the translate func is making the same api call to the api server multiple times
			if tmpPeerTranslated.Internal.Workload != "" {
				deploymentPeers = append(deploymentPeers, tmpPeerTranslated)
			}

		}

And inside the translate func we are doing this call:

 utils.DoOrDie(err)
 ns, err := kubeClient.GetNamespace(workloadMetadata[0])
 utils.DoOrDie(err)
 kubePods, err := kube.GetPodsInNamespaces(kubeClient, []string{workloadMetadata[0]})

Originally posted by @huntergregory in #227 (comment)

@gabrielggg gabrielggg changed the title Extra calls to API Server in some scenarios. Ideally, we'd get all pods in the namespace only once. [Policy Assistant] Avoid multiple calls to API Server for getting all pods in the namespace. Jun 18, 2024
@gabrielggg gabrielggg changed the title [Policy Assistant] Avoid multiple calls to API Server for getting all pods in the namespace. [Policy Assistant] Avoid multiple calls to API Server to get all the pods in the namespace. Jun 18, 2024
@gabrielggg
Copy link
Contributor Author

/assign

@gabrielggg gabrielggg removed their assignment Aug 4, 2024
@gabrielggg gabrielggg changed the title [Policy Assistant] Avoid multiple calls to API Server to get all the pods in the namespace. [Policy Assistant] Avoid multiple calls to the API Server to get all the pods in the namespace. Aug 4, 2024
@gabrielggg gabrielggg changed the title [Policy Assistant] Avoid multiple calls to the API Server to get all the pods in the namespace. [Policy Assistant] Avoid unnecessary api calls to get all the pods in the namespace. Aug 4, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 2, 2024
@gabrielggg
Copy link
Contributor Author

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants