From ffb2556c9e605e5c555fde594b62595cf97663c0 Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Tue, 28 Nov 2023 08:48:59 +0545 Subject: [PATCH] chore: address review comment --- api/v1/interface.go | 3 +-- ...configs.flanksource.com_scrapeconfigs.yaml | 2 ++ db/update.go | 10 ++++------ fixtures/kubernetes.yaml | 19 +++++++++++++++++++ scrapers/kubernetes/kubernetes.go | 2 +- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/api/v1/interface.go b/api/v1/interface.go index 623460005..35606697d 100644 --- a/api/v1/interface.go +++ b/api/v1/interface.go @@ -8,7 +8,6 @@ import ( "github.com/flanksource/commons/logger" "github.com/flanksource/duty/models" - "github.com/google/uuid" ) // Analyzer ... @@ -161,7 +160,7 @@ type RelationshipResult struct { // Used when the config id is not known. RelatedExternalID ExternalID // Config ID of the related config. - RelatedConfigID uuid.UUID + RelatedConfigID string Relationship string } diff --git a/chart/crds/configs.flanksource.com_scrapeconfigs.yaml b/chart/crds/configs.flanksource.com_scrapeconfigs.yaml index aa83af4f8..dbaa60e7a 100644 --- a/chart/crds/configs.flanksource.com_scrapeconfigs.yaml +++ b/chart/crds/configs.flanksource.com_scrapeconfigs.yaml @@ -923,6 +923,8 @@ spec: namespace: type: string relationships: + description: Relationships specify the fields to use to relate + Kubernetes objects. items: properties: kind: diff --git a/db/update.go b/db/update.go index b53a9e34f..9c3dc17bb 100644 --- a/db/update.go +++ b/db/update.go @@ -7,8 +7,6 @@ import ( "strings" "time" - commonUtils "github.com/flanksource/commons/utils" - "github.com/aws/smithy-go/ptr" jsonpatch "github.com/evanphx/json-patch" "github.com/flanksource/commons/logger" @@ -357,13 +355,13 @@ func relationshipResultHandler(relationships v1.RelationshipResults) error { continue } if configID == nil { - logger.Warnf("failed to find config %s", relationship.ConfigExternalID) + logger.Debugf("failed to find config %s", relationship.ConfigExternalID) continue } var relatedID *string - if relationship.RelatedConfigID != uuid.Nil { - relatedID = commonUtils.Ptr(relationship.RelatedConfigID.String()) + if relationship.RelatedConfigID != "" { + relatedID = &relationship.RelatedConfigID } else { relatedID, err = FindConfigItemID(relationship.RelatedExternalID) if err != nil { @@ -371,7 +369,7 @@ func relationshipResultHandler(relationships v1.RelationshipResults) error { continue } if relatedID == nil { - logger.Warnf("related external config item(id=%s) not found.", relationship.RelatedExternalID) + logger.Debugf("related external config item(id=%s) not found.", relationship.RelatedExternalID) continue } } diff --git a/fixtures/kubernetes.yaml b/fixtures/kubernetes.yaml index 4c3efc9d8..b65dcec93 100644 --- a/fixtures/kubernetes.yaml +++ b/fixtures/kubernetes.yaml @@ -20,6 +20,25 @@ spec: - controllerrevision - certificaterequest - orders.acme.cert-manager.io + relationships: + - kind: + expr: has(spec.claimRef) && spec.claimRef.kind + name: + expr: has(spec.claimRef) && spec.claimRef.name + namespace: + expr: has(spec.claimRef) && spec.claimRef.namespace + - kind: + value: Kustomization + name: + label: kustomize.toolkit.fluxcd.io/name + namespace: + label: kustomize.toolkit.fluxcd.io/namespace + - kind: + value: HelmRelease + name: + label: helm.toolkit.fluxcd.io/name + namespace: + label: helm.toolkit.fluxcd.io/namespace event: exclusions: - SuccessfulCreate diff --git a/scrapers/kubernetes/kubernetes.go b/scrapers/kubernetes/kubernetes.go index abc679434..42f9126f0 100644 --- a/scrapers/kubernetes/kubernetes.go +++ b/scrapers/kubernetes/kubernetes.go @@ -152,7 +152,7 @@ func (kubernetes KubernetesScraper) Scrape(ctx api.ScrapeContext) v1.ScrapeResul ExternalID: []string{string(obj.GetUID())}, ConfigType: ConfigTypePrefix + obj.GetKind(), }, - RelatedConfigID: id, + RelatedConfigID: id.String(), Relationship: kind + obj.GetKind(), } relationships = append(relationships, rel)