Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store/source: Show associated agents in source api model #107

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 22 additions & 23 deletions api/v1alpha1/agent/spec.gen.go

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

12 changes: 0 additions & 12 deletions api/v1alpha1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,6 @@ components:
id:
type: string
format: uuid
name:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe in future, we can gather vcenter name or something and display it, so it's recognized somehow in UI?

type: string
status:
type: string
enum: [not-connected, waiting-for-credentials, error, gathering-initial-inventory, up-to-date]
statusInfo:
type: string
inventory:
$ref: '#/components/schemas/Inventory'
createdAt:
Expand All @@ -294,17 +287,12 @@ components:
updatedAt:
type: string
format: date-time
sshKey:
type: string
agents:
type: array
items:
$ref: '#/components/schemas/SourceAgentItem'
required:
- id
- name
- status
- statusInfo
- createdAt
- updatedAt

Expand Down
62 changes: 31 additions & 31 deletions api/v1alpha1/spec.gen.go

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

26 changes: 5 additions & 21 deletions api/v1alpha1/types.gen.go

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

4 changes: 2 additions & 2 deletions internal/cli/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ func printTable(response interface{}, kind string, id *uuid.UUID) error {
}

func printSourcesTable(w *tabwriter.Writer, sources ...api.Source) {
fmt.Fprintln(w, "ID\tNAME\tSTATUS")
fmt.Fprintln(w, "ID")
for _, s := range sources {
fmt.Fprintf(w, "%s\t%s\t%s\n", s.Id, s.Name, s.Status)
fmt.Fprintf(w, "%s\n", s.Id)
}
}
2 changes: 1 addition & 1 deletion internal/store/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *SourceStore) InitialMigration(ctx context.Context) error {

func (s *SourceStore) List(ctx context.Context) (api.SourceList, error) {
var sources model.SourceList
result := s.getDB(ctx).Model(&sources).Order("id").Find(&sources)
result := s.getDB(ctx).Model(&sources).Order("id").Preload("Agents").Find(&sources)
if result.Error != nil {
return nil, result.Error
}
Expand Down
19 changes: 19 additions & 0 deletions internal/store/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,32 @@ var _ = Describe("source store", Ordered, func() {
Expect(sources).To(HaveLen(2))
})

It("successfully list all the sources -- with agents", func() {
sourceID := uuid.NewString()
agentID := uuid.NewString()
tx := gormdb.Exec(fmt.Sprintf(insertAgentStm, agentID, "not-connected", "status-info-1", "cred_url-1"))
Expect(tx.Error).To(BeNil())
tx = gormdb.Exec(fmt.Sprintf(insertSourceStm, sourceID))
Expect(tx.Error).To(BeNil())
tx = gormdb.Exec(fmt.Sprintf("UPDATE agents set source_id = '%s';", sourceID))
Expect(tx.Error).To(BeNil())

sources, err := s.Source().List(context.TODO())
Expect(err).To(BeNil())
Expect(sources).To(HaveLen(1))
agents := *sources[0].Agents
Expect(agents).To(HaveLen(1))
Expect(agents[0].Id.String()).To(Equal(agentID))
})

It("list all sources -- no sources", func() {
sources, err := s.Source().List(context.TODO())
Expect(err).To(BeNil())
Expect(sources).To(HaveLen(0))
})

AfterEach(func() {
gormdb.Exec("DELETE from agents;")
gormdb.Exec("DELETE from sources;")
})
})
Expand Down
Loading