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

feat: added dependency support to k8s #1487

Merged
merged 3 commits into from
Aug 19, 2024

Conversation

AvineshTripathi
Copy link
Collaborator

@AvineshTripathi AvineshTripathi commented Aug 7, 2024

Because we currently fetch all the objects separately and without any connection, some relationships are difficult to generate and would result in redundancy. In other cases, we also need both resources to be present in order to validate the relations.

To avoid this, we should have something like a stitching module that would asynchronously join the node based on a predefined condition. Open to discussion

Solution proposed:
Based on current architecture, the relationship field is sent by the resource itself. However, sometimes comparison between two resources are required to find a relationship. The solution we are using for this PR (which may change if any better approach to this problem comes) is that if a resource requires another resource to find the relationship, it will do so by making an api call and fetching all the resources of that particular service where the relationship is to be found. However, the result is cached and stored in memory for some time, so if another resource requires this resource list can use it.

@Azanul
Copy link
Collaborator

Azanul commented Aug 8, 2024

We can create a routine which will start when all the resources(k8s) from the wait group are completed

Copy link
Collaborator

@Azanul Azanul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Why are we only using cache for services?
  2. address lint issue
  3. Let's maintain a clear document to keep track of what changes we're making and how it'll reflect on the dependency graph

internal/config/load.go Outdated Show resolved Hide resolved
internal/config/load.go Outdated Show resolved Hide resolved
@@ -37,7 +37,7 @@ func FetchResources(ctx context.Context, client providers.ProviderClient, db *bu
log.Printf("[%s][K8s] %s", client.Name, err)
} else {
for _, resource := range resources {
_, err = db.NewInsert().Model(&resource).On("CONFLICT (resource_id) DO UPDATE").Set("cost = EXCLUDED.cost").Exec(context.Background())
_, err = db.NewInsert().Model(&resource).On("CONFLICT (resource_id) DO UPDATE").Set("cost = EXCLUDED.cost, relations=EXCLUDED.relations").Exec(context.Background())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explain

Copy link
Collaborator Author

@AvineshTripathi AvineshTripathi Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the resource or the relation was deleted, in the next cycle it will not be updated if this is not added

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cost = EXCLUDED.cost means that if a conflict occurs, the cost column of the existing row will be updated with the value from the new row being inserted. Same goes for relations

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats correct and we want to ensure this field gets updated

@AvineshTripathi
Copy link
Collaborator Author

AvineshTripathi commented Aug 16, 2024

  1. Why are we only using cache for services?

Since we have to get list of all the services to find the relation between pod and services, a new call to the service list has to be done. However we already have a service fetcher and since services might be used for other relations, i felt it would be better if we cache it for some time to avoid multiple calls.

This I feel can be used across the project to find relations where presence of other resource is mandatory.

  1. address lint issue

Will do

  1. Let's maintain a clear document to keep track of what changes we're making and how it'll reflect on the dependency graph

where should we document

@Azanul
Copy link
Collaborator

Azanul commented Aug 16, 2024

Since we have to get list of all the services to find the relation between pod and services, a new call to the service list has to be done. However we already have a service fetcher and since services might be used for other relations, i felt it would be better if we cache it for some time to avoid multiple calls.

Is the case different for nodes, pods, etc.?

where should we document

Let's create a documentation page for dependency graph that'll help users to navigate the graph easily. Like a user guide

@AvineshTripathi
Copy link
Collaborator Author

Since we have to get list of all the services to find the relation between pod and services, a new call to the service list has to be done. However we already have a service fetcher and since services might be used for other relations, i felt it would be better if we cache it for some time to avoid multiple calls.

Is the case different for nodes, pods, etc.?

Didnt get you here

@Azanul
Copy link
Collaborator

Azanul commented Aug 16, 2024

Since we have to get list of all the services to find the relation between pod and services, a new call to the service list has to be done. However we already have a service fetcher and since services might be used for other relations, i felt it would be better if we cache it for some time to avoid multiple calls.

Is the case different for nodes, pods, etc.?

Didnt get you here

What's stopping us from caching nodes and pods too?

@AvineshTripathi
Copy link
Collaborator Author

In case of nodes and pod we do get fields to get the relation in there as comparison is not required while in case of service its not the case. Let me know if that answers your question

@Azanul
Copy link
Collaborator

Azanul commented Aug 16, 2024

In case of nodes and pod we do get fields to get the relation in there as comparison is not required while in case of service its not the case. Let me know if that answers your question

It does, thanks

@Azanul Azanul merged commit d382587 into tailwarden:develop Aug 19, 2024
3 checks passed
@AvineshTripathi AvineshTripathi deleted the k8s-dep-graph branch August 31, 2024 15:07
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

Successfully merging this pull request may close these issues.

2 participants