Skip to content

Commit

Permalink
Add instances to application
Browse files Browse the repository at this point in the history
  • Loading branch information
thokra-nav committed Oct 17, 2024
1 parent eadcee8 commit 5b30935
Show file tree
Hide file tree
Showing 11 changed files with 1,805 additions and 133 deletions.
19 changes: 19 additions & 0 deletions integration_tests/k8s_resources/simple/dev/slug-1/another.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,22 @@ spec:
name: app-name
port:
number: 80

---
apiVersion: v1
kind: Pod
metadata:
name: another-app-23422-2sdf
labels:
app: another-app
creationTimestamp: "2022-07-06T09:45:18Z"
spec:
containers:
- name: another-app
image: navikt/app-name:latest
resources:
limits:
memory: "128Mi"
cpu: "500m"
ports:
- containerPort: 80
27 changes: 27 additions & 0 deletions integration_tests/k8s_resources/simple/dev/slug-1/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,30 @@ spec:
name: my-app
port:
number: 80

---
apiVersion: v1
kind: Pod
metadata:
name: app-name-23422-2sdf
labels:
app: app-name
creationTimestamp: "2022-07-06T09:45:18Z"
spec:
containers:
- name: app-name
image: navikt/app-name:latest
resources:
limits:
memory: "128Mi"
cpu: "500m"
ports:
- containerPort: 80
status:
containerStatuses:
- name: app-name
ready: true
restartCount: 0
state:
running:
startedAt: "2022-07-06T09:45:18Z"
77 changes: 77 additions & 0 deletions integration_tests/team_applications.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,80 @@ Test.gql("Team with no applications", function(t)
}
}
end)

Test.gql("Team with multiple applications and instances", function(t)
t.query [[
query {
team(slug: "slug-1") {
applications {
nodes {
name
instances {
nodes {
name
id
restarts
created
status {
state
message
}
}
}
}
pageInfo {
totalCount
}
}
}
}
]]

t.check {
data = {
team = {
applications = {
nodes = {
{
name = "another-app",
instances = {
nodes = {
{
created = "2022-07-06T11:45:18+02:00",
id = "INS_3reJsVY19Sss8MvJH7ghHt6WcbXHW4AqMH7QPYi5yvJr6qZLw936mCi2ZcD9eM",
name = "another-app-23422-2sdf",
restarts = 0,
status = {
message = "Unknown",
state = "UNKNOWN"
},
}
}
},
},
{
name = "app-name",
instances = {
nodes = {
{
created = "2022-07-06T11:45:18+02:00",
id = "INS_2JN3xdYkjgBWnSYwiqQiRZV44TR5uGVaoEkRVTyLhY53YfVFGju1k9",
name = "app-name-23422-2sdf",
restarts = 0,
status = {
message = "Running",
state = "RUNNING"
},
}
}
},
}
},
pageInfo = {
totalCount = 2
}
}
}
}
}
end)
21 changes: 21 additions & 0 deletions internal/v1/graphv1/applications.resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ func (r *applicationResolver) Manifest(ctx context.Context, obj *application.App
return application.Manifest(ctx, obj.TeamSlug, obj.EnvironmentName, obj.Name)
}

func (r *applicationResolver) Instances(ctx context.Context, obj *application.Application, first *int, after *pagination.Cursor, last *int, before *pagination.Cursor) (*pagination.Connection[*application.Instance], error) {
page, err := pagination.ParsePage(first, after, last, before)
if err != nil {
return nil, err
}
return application.ListInstances(ctx, obj.TeamSlug, obj.EnvironmentName, obj.Name, page)
}

func (r *deleteApplicationPayloadResolver) Team(ctx context.Context, obj *application.DeleteApplicationPayload) (*team.Team, error) {
if obj.TeamSlug == nil {
return nil, nil
Expand Down Expand Up @@ -133,3 +141,16 @@ type (
ingressResolver struct{ *Resolver }
restartApplicationPayloadResolver struct{ *Resolver }
)

// !!! WARNING !!!
// The code below was going to be deleted when updating resolvers. It has been copied here so you have
// one last chance to move it out of harms way if you want. There are two reasons this happens:
// - When renaming or deleting a resolver the old code will be put in here. You can safely delete
// it when you're done.
// - You have helper methods in this file. Move them out to keep these resolver files clean.
/*
func (r *instanceResolver) Status(ctx context.Context, obj *application.Instance) (*application.InstanceStatus, error) {
panic(fmt.Errorf("not implemented: Status - status"))
}
func (r *Resolver) Instance() gengqlv1.InstanceResolver { return &instanceResolver{r} }
*/
Loading

0 comments on commit 5b30935

Please sign in to comment.