Skip to content

Commit

Permalink
chore: address review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Nov 28, 2023
1 parent e1487f9 commit ffb2556
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
3 changes: 1 addition & 2 deletions api/v1/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/flanksource/commons/logger"
"github.com/flanksource/duty/models"
"github.com/google/uuid"
)

// Analyzer ...
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions chart/crds/configs.flanksource.com_scrapeconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,8 @@ spec:
namespace:
type: string
relationships:
description: Relationships specify the fields to use to relate
Kubernetes objects.
items:
properties:
kind:
Expand Down
10 changes: 4 additions & 6 deletions db/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -357,21 +355,21 @@ 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 {
logger.Errorf("error fetching external config item(id=%s): %v", relationship.RelatedExternalID, err)
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
}
}
Expand Down
19 changes: 19 additions & 0 deletions fixtures/kubernetes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scrapers/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ffb2556

Please sign in to comment.