Skip to content

Commit

Permalink
Merge pull request #1568 from flanksource/parent-lookup-change
Browse files Browse the repository at this point in the history
feat: add support for parent lookup
  • Loading branch information
moshloop authored Jan 8, 2024
2 parents 3f6e081 + 9bdc4c0 commit 54b45b1
Show file tree
Hide file tree
Showing 14 changed files with 280 additions and 12 deletions.
24 changes: 17 additions & 7 deletions api/v1/component_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ type Component struct {
}

type ComponentSpec struct {
Name string `json:"name,omitempty"`
Tooltip string `json:"tooltip,omitempty"`
Icon string `json:"icon,omitempty"`
Owner string `json:"owner,omitempty"`
Id *Template `json:"id,omitempty"` //nolint
Order int `json:"order,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Name string `json:"name,omitempty"`
Namespace string `json:"namespace,omitempty"`
Tooltip string `json:"tooltip,omitempty"`
Icon string `json:"icon,omitempty"`
Owner string `json:"owner,omitempty"`
Id *Template `json:"id,omitempty"` //nolint
Order int `json:"order,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
// The type of component, e.g. service, API, website, library, database, etc.
Type string `json:"type,omitempty"`
// The lifecycle state of the component e.g. production, staging, dev, etc.
Expand Down Expand Up @@ -51,6 +52,9 @@ type ComponentSpec struct {
ForEach *ForEach `json:"forEach,omitempty"`
// Logs is a list of logs selector for apm-hub.
LogSelectors types.LogSelectors `json:"logs,omitempty"`

// Reference to populate parent_id
ParentLookup *ParentLookup `json:"parentLookup,omitempty"`
}

// +kubebuilder:validation:Type=object
Expand Down Expand Up @@ -84,6 +88,12 @@ func (f *ForEach) String() string {
return fmt.Sprintf("ForEach(components=%d, properties=%d)", len(f.Components), len(f.Properties))
}

type ParentLookup struct {
Name string `json:"name,omitempty"`
Namespace string `json:"namespace,omitempty"`
Type string `json:"type,omitempty"`
}

type ComponentStatus struct {
Status types.ComponentStatus `json:"status,omitempty"`
}
Expand Down
25 changes: 25 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions config/deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6900,10 +6900,22 @@ spec:
x-kubernetes-preserve-unknown-fields: true
name:
type: string
namespace:
type: string
order:
type: integer
owner:
type: string
parentLookup:
description: Reference to populate parent_id
properties:
name:
type: string
namespace:
type: string
type:
type: string
type: object
properties:
items:
properties:
Expand Down Expand Up @@ -7208,10 +7220,22 @@ spec:
x-kubernetes-preserve-unknown-fields: true
name:
type: string
namespace:
type: string
order:
type: integer
owner:
type: string
parentLookup:
description: Reference to populate parent_id
properties:
name:
type: string
namespace:
type: string
type:
type: string
type: object
properties:
items:
properties:
Expand Down
24 changes: 24 additions & 0 deletions config/deploy/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7168,10 +7168,22 @@ spec:
x-kubernetes-preserve-unknown-fields: true
name:
type: string
namespace:
type: string
order:
type: integer
owner:
type: string
parentLookup:
description: Reference to populate parent_id
properties:
name:
type: string
namespace:
type: string
type:
type: string
type: object
properties:
items:
properties:
Expand Down Expand Up @@ -7476,10 +7488,22 @@ spec:
x-kubernetes-preserve-unknown-fields: true
name:
type: string
namespace:
type: string
order:
type: integer
owner:
type: string
parentLookup:
description: Reference to populate parent_id
properties:
name:
type: string
namespace:
type: string
type:
type: string
type: object
properties:
items:
properties:
Expand Down
27 changes: 27 additions & 0 deletions config/schemas/component.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,9 @@
"name": {
"type": "string"
},
"namespace": {
"type": "string"
},
"tooltip": {
"type": "string"
},
Expand Down Expand Up @@ -856,6 +859,9 @@
},
"logs": {
"$ref": "#/$defs/LogSelectors"
},
"parentLookup": {
"$ref": "#/$defs/ParentLookup"
}
},
"additionalProperties": false,
Expand All @@ -866,6 +872,9 @@
"name": {
"type": "string"
},
"namespace": {
"type": "string"
},
"tooltip": {
"type": "string"
},
Expand Down Expand Up @@ -933,6 +942,9 @@
},
"logs": {
"$ref": "#/$defs/LogSelectors"
},
"parentLookup": {
"$ref": "#/$defs/ParentLookup"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -3048,6 +3060,21 @@
"uid"
]
},
"ParentLookup": {
"properties": {
"name": {
"type": "string"
},
"namespace": {
"type": "string"
},
"type": {
"type": "string"
}
},
"additionalProperties": false,
"type": "object"
},
"PodCheck": {
"properties": {
"description": {
Expand Down
27 changes: 27 additions & 0 deletions config/schemas/topology.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,9 @@
"name": {
"type": "string"
},
"namespace": {
"type": "string"
},
"tooltip": {
"type": "string"
},
Expand Down Expand Up @@ -835,6 +838,9 @@
},
"logs": {
"$ref": "#/$defs/LogSelectors"
},
"parentLookup": {
"$ref": "#/$defs/ParentLookup"
}
},
"additionalProperties": false,
Expand All @@ -845,6 +851,9 @@
"name": {
"type": "string"
},
"namespace": {
"type": "string"
},
"tooltip": {
"type": "string"
},
Expand Down Expand Up @@ -912,6 +921,9 @@
},
"logs": {
"$ref": "#/$defs/LogSelectors"
},
"parentLookup": {
"$ref": "#/$defs/ParentLookup"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -3018,6 +3030,21 @@
"uid"
]
},
"ParentLookup": {
"properties": {
"name": {
"type": "string"
},
"namespace": {
"type": "string"
},
"type": {
"type": "string"
}
},
"additionalProperties": false,
"type": "object"
},
"PodCheck": {
"properties": {
"description": {
Expand Down
31 changes: 31 additions & 0 deletions fixtures/topology/component-with-parent-lookup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: canaries.flanksource.com/v1
kind: Topology
metadata:
name: test-topology-with-parent-lookup
spec:
schedule: "@every 10m"
components:
- name: Parent-1
type: Type1
components:
- name: Child-1A
- name: Child-1B
- name: Child-1C
parentLookup:
name: Parent-2
type: Type2
- name: Child-1D
parentLookup:
name: Parent-3
type: Type3
namespace: parent3-namespace

- name: Parent-2
type: Type2
components:
- name: Child-2A
- name: Child-2B

- name: Parent-3
type: Type3
namespace: parent3-namespace
5 changes: 4 additions & 1 deletion pkg/system_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ type Component struct {
ComponentChecks v1.ComponentChecks `json:"-" gorm:"componentChecks" swaggerignore:"true"`
Checks Checks `json:"checks,omitempty" gorm:"-"`
Configs dutyTypes.ConfigQueries `json:"configs,omitempty" gorm:"type:configs"`
TopologyID *uuid.UUID `json:"topology_id,omitempty"` //nolint
TopologyID uuid.UUID `json:"topology_id,omitempty"` //nolint
CreatedAt time.Time `json:"created_at,omitempty" time_format:"postgres_timestamp"`
UpdatedAt time.Time `json:"updated_at,omitempty" time_format:"postgres_timestamp"`
DeletedAt *time.Time `json:"deleted_at,omitempty" time_format:"postgres_timestamp" swaggerignore:"true"`
Expand All @@ -148,6 +148,7 @@ type Component struct {
CostTotal7d float64 `json:"cost_total_7d,omitempty" gorm:"column:cost_total_7d"`
CostTotal30d float64 `json:"cost_total_30d,omitempty" gorm:"column:cost_total_30d"`
LogSelectors dutyTypes.LogSelectors `json:"logs,omitempty" gorm:"column:log_selectors"`
ParentLookup *v1.ParentLookup `json:"parentLookup,omitempty" gorm:"-"`
}

func (component *Component) FindExisting(db *gorm.DB) (*models.Component, error) {
Expand Down Expand Up @@ -245,6 +246,7 @@ func (component Component) GetAsEnvironment() map[string]interface{} {
func NewComponent(c v1.ComponentSpec) *Component {
_c := Component{
Name: c.Name,
Namespace: c.Namespace,
Owner: c.Owner,
Type: c.Type,
Order: c.Order,
Expand All @@ -256,6 +258,7 @@ func NewComponent(c v1.ComponentSpec) *Component {
Labels: c.Labels,
Configs: c.Configs,
LogSelectors: c.LogSelectors,
ParentLookup: c.ParentLookup,
}
if c.Summary != nil {
_c.Summary = *c.Summary
Expand Down
7 changes: 6 additions & 1 deletion pkg/topology/component_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

var _ = ginkgo.Describe("Topology checks", ginkgo.Ordered, func() {
topology := pkg.Topology{Name: "Topology ComponentCheck"}
component := pkg.Component{
Name: "Component",
ComponentChecks: []v1.ComponentCheck{{
Expand All @@ -27,7 +28,11 @@ var _ = ginkgo.Describe("Topology checks", ginkgo.Ordered, func() {
}

ginkgo.BeforeAll(func() {
err := DefaultContext.DB().Create(&component).Error
err := DefaultContext.DB().Create(&topology).Error
Expect(err).To(BeNil())

component.TopologyID = topology.ID
err = DefaultContext.DB().Create(&component).Error
Expect(err).To(BeNil())

err = DefaultContext.DB().Create(&canary).Error
Expand Down
Loading

0 comments on commit 54b45b1

Please sign in to comment.