Skip to content

Commit

Permalink
chore: make externalID part of component spec
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra committed May 2, 2024
1 parent 1eef979 commit f7247d2
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 23 deletions.
19 changes: 10 additions & 9 deletions api/v1/component_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ type Component struct {
}

type ComponentSpec struct {
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"`
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"`
ExternalID string `json:"externalID,omitempty"`
Id *Template `json:"id,omitempty"` //nolint
Order int `json:"order,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
// If set to true, do not display in UI
Hidden bool `json:"hidden,omitempty"`
// The type of component, e.g. service, API, website, library, database, etc.
Expand Down Expand Up @@ -95,7 +96,7 @@ type ParentLookup struct {
Name string `json:"name,omitempty"`
Namespace string `json:"namespace,omitempty"`
Type string `json:"type,omitempty"`
ExternalID string `json:"external_id,omitempty"`
ExternalID string `json:"externalID,omitempty"`
}

type ComponentStatus struct {
Expand Down
8 changes: 6 additions & 2 deletions config/deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7161,6 +7161,8 @@ spec:
type: array
type: object
type: array
externalID:
type: string
forEach:
description: |-
Only applies when using lookup, when specified the components and properties
Expand Down Expand Up @@ -7223,7 +7225,7 @@ spec:
parentLookup:
description: Reference to populate parent_id
properties:
external_id:
externalID:
type: string
name:
type: string
Expand Down Expand Up @@ -7611,6 +7613,8 @@ spec:
type: array
type: object
type: array
externalID:
type: string
forEach:
description: |-
Only applies when using lookup, when specified the components and properties
Expand Down Expand Up @@ -7673,7 +7677,7 @@ spec:
parentLookup:
description: Reference to populate parent_id
properties:
external_id:
externalID:
type: string
name:
type: string
Expand Down
8 changes: 6 additions & 2 deletions config/deploy/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7429,6 +7429,8 @@ spec:
type: array
type: object
type: array
externalID:
type: string
forEach:
description: |-
Only applies when using lookup, when specified the components and properties
Expand Down Expand Up @@ -7491,7 +7493,7 @@ spec:
parentLookup:
description: Reference to populate parent_id
properties:
external_id:
externalID:
type: string
name:
type: string
Expand Down Expand Up @@ -7879,6 +7881,8 @@ spec:
type: array
type: object
type: array
externalID:
type: string
forEach:
description: |-
Only applies when using lookup, when specified the components and properties
Expand Down Expand Up @@ -7941,7 +7945,7 @@ spec:
parentLookup:
description: Reference to populate parent_id
properties:
external_id:
externalID:
type: string
name:
type: string
Expand Down
8 changes: 7 additions & 1 deletion config/schemas/component.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,9 @@
"owner": {
"type": "string"
},
"externalID": {
"type": "string"
},
"id": {
"$ref": "#/$defs/Template"
},
Expand Down Expand Up @@ -939,6 +942,9 @@
"owner": {
"type": "string"
},
"externalID": {
"type": "string"
},
"id": {
"$ref": "#/$defs/Template"
},
Expand Down Expand Up @@ -3458,7 +3464,7 @@
"type": {
"type": "string"
},
"external_id": {
"externalID": {
"type": "string"
}
},
Expand Down
8 changes: 7 additions & 1 deletion config/schemas/topology.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,9 @@
"owner": {
"type": "string"
},
"externalID": {
"type": "string"
},
"id": {
"$ref": "#/$defs/Template"
},
Expand Down Expand Up @@ -918,6 +921,9 @@
"owner": {
"type": "string"
},
"externalID": {
"type": "string"
},
"id": {
"$ref": "#/$defs/Template"
},
Expand Down Expand Up @@ -3428,7 +3434,7 @@
"type": {
"type": "string"
},
"external_id": {
"externalID": {
"type": "string"
}
},
Expand Down
4 changes: 2 additions & 2 deletions fixtures/topology/component-with-parent-lookup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ spec:
- name: Child-2B
- name: Child-2C
parentLookup:
external_id: parent-3-external-id
externalID: parent-3-external-id

- name: Parent-3
type: Type3
namespace: parent3-namespace
external_id: parent-3-external-id
externalID: parent-3-external-id
1 change: 1 addition & 0 deletions pkg/system_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ func NewComponent(c v1.ComponentSpec) *Component {
Namespace: c.Namespace,
Owner: c.Owner,
Type: c.Type,
ExternalId: c.ExternalID,
Order: c.Order,
Hidden: c.Hidden,
Lifecycle: c.Lifecycle,
Expand Down
8 changes: 4 additions & 4 deletions pkg/topology/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,10 @@ func populateParentRefMap(c *pkg.Component, parentRefMap map[string]*pkg.Compone
}
}

func lookupParent(parentRefMap map[string]*pkg.Component, genKey, externalID string) (*pkg.Component, bool) {
func lookupParent(parentRefMap map[string]*pkg.Component, genKey, parentExternalID string) (*pkg.Component, bool) {
// Check External ID first
if externalID != "" {
c, ok := parentRefMap[externalID]
if parentExternalID != "" {
c, ok := parentRefMap[parentExternalID]
return c, ok
}

Expand All @@ -401,7 +401,7 @@ func changeComponentParents(c *pkg.Component, parentRefMap map[string]*pkg.Compo
}

key := genParentKey(child.ParentLookup.Name, child.ParentLookup.Type, child.ParentLookup.Namespace)
if parentComp, exists := lookupParent(parentRefMap, key, child.ExternalId); exists {
if parentComp, exists := lookupParent(parentRefMap, key, child.ParentLookup.ExternalID); exists {
// Set nil to prevent processing again
child.ParentLookup = nil
parentComp.Components = append(parentComp.Components, child)
Expand Down
4 changes: 2 additions & 2 deletions pkg/topology/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ var _ = ginkgo.Describe("Topology run", ginkgo.Ordered, func() {
Expect(parent2.Components[1].Name).To(Equal("Child-2B"))
Expect(parent2.Components[2].Name).To(Equal("Child-1C"))

Expect(parent3.Components[0].Name).To(Equal("Child-2C"))
Expect(parent3.Components[1].Name).To(Equal("Child-1D"))
Expect(parent3.Components[0].Name).To(Equal("Child-1D"))
Expect(parent3.Components[1].Name).To(Equal("Child-2C"))
})

})
Expand Down

0 comments on commit f7247d2

Please sign in to comment.