Skip to content

Commit

Permalink
chore: update config traversal to handle new relationship way
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra authored and moshloop committed Mar 26, 2024
1 parent fd78b37 commit 0f75713
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion query/config_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func SyncConfigCache(ctx context.Context) error {
return fmt.Errorf("error setting config relationships in cache: %w", err)
}
for _, relID := range relIDs {
configIDRelatedTypeToRelatedIDs[configItemRelatedTypeCacheKey(cID, configIDTypeMap[relID])] = append(configIDRelatedTypeToRelatedIDs[configItemRelatedTypeCacheKey(cID, configIDTypeMap[relID])], relID)
configIDRelatedTypeToRelatedIDs[configItemRelatedTypeCacheKey(relID, configIDTypeMap[cID])] = append(configIDRelatedTypeToRelatedIDs[configItemRelatedTypeCacheKey(relID, configIDTypeMap[cID])], cID)
}
}

Expand Down
8 changes: 6 additions & 2 deletions tests/config_traversal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ var _ = ginkgo.Describe("Config traversal", ginkgo.Ordered, func() {
Expect(err).ToNot(HaveOccurred())

configRelations := []models.ConfigRelationship{
{ConfigID: configItems["deployment"].ID.String(), RelatedID: configItems["helm-release-of-deployment"].ID.String(), Relation: "HelmReleaseDeployment"},
{ConfigID: configItems["helm-release-of-deployment"].ID.String(), RelatedID: configItems["kustomize-of-helm-release"].ID.String(), Relation: "KustomizationHelmRelease"},
{ConfigID: configItems["helm-release-of-deployment"].ID.String(), RelatedID: configItems["deployment"].ID.String(), Relation: "HelmReleaseDeployment"},
{ConfigID: configItems["kustomize-of-helm-release"].ID.String(), RelatedID: configItems["helm-release-of-deployment"].ID.String(), Relation: "KustomizationHelmRelease"},
}
err = ctx.DB().Clauses(clause.OnConflict{DoNothing: true}).Save(configRelations).Error
Expect(err).ToNot(HaveOccurred())
Expand All @@ -39,6 +39,10 @@ var _ = ginkgo.Describe("Config traversal", ginkgo.Ordered, func() {
Expect(got).ToNot(BeNil())
Expect(got.ID.String()).To(Equal(configItems["helm-release-of-deployment"].ID.String()))

got = query.TraverseConfig(DefaultContext, configItems["helm-release-of-deployment"].ID.String(), "Kubernetes::Kustomization")
Expect(got).ToNot(BeNil())
Expect(got.ID.String()).To(Equal(configItems["kustomize-of-helm-release"].ID.String()))

got = query.TraverseConfig(DefaultContext, configItems["deployment"].ID.String(), "Kubernetes::HelmRelease/Kubernetes::Kustomization")
Expect(got).ToNot(BeNil())
Expect(got.ID.String()).To(Equal(configItems["kustomize-of-helm-release"].ID.String()))
Expand Down

0 comments on commit 0f75713

Please sign in to comment.