Skip to content

Commit

Permalink
chore: add tests for parent lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra committed Jan 8, 2024
1 parent 8518ed6 commit 5ce8ef1
Show file tree
Hide file tree
Showing 12 changed files with 262 additions and 69 deletions.
33 changes: 14 additions & 19 deletions api/v1/component_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package v1

import (
"fmt"
"strings"

"github.com/flanksource/duty/types"
"github.com/google/uuid"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -18,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 @@ -61,16 +60,6 @@ type ComponentSpec struct {
// +kubebuilder:validation:Type=object
type ComponentSpecObject ComponentSpec

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

func (p ParentLookup) CacheKey(topologyID uuid.UUID) string {
return strings.Join([]string{topologyID.String(), p.Name, p.Namespace, p.Type}, "/")
}

func (c ComponentSpec) String() string {
if c.Name != "" {
return c.Name
Expand Down Expand Up @@ -99,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
Loading

0 comments on commit 5ce8ef1

Please sign in to comment.