Skip to content
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
1 change: 1 addition & 0 deletions .configs/gqlgen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ autobind:
- "github.com/nais/api/internal/workload/netpol"
- "github.com/nais/api/internal/workload/podlog"
- "github.com/nais/api/internal/workload/config"
- "github.com/nais/api/internal/workload/instancegroup"
- "github.com/nais/api/internal/workload/secret"

# Don't generate Get<FieldName> functions for fields included in the GraphQL interfaces
Expand Down
335 changes: 335 additions & 0 deletions integration_tests/instance_groups.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,335 @@
Helper.readK8sResources("k8s_resources/instance_groups")

local user = User.new("username", "user@example.com", "ext-id")
Team.new("myteam", "some purpose", "#channel")

Test.gql("Application with instance groups", function(t)
t.addHeader("x-user-email", user:email())

t.query [[
query {
team(slug: "myteam") {
applications {
nodes {
name
instanceGroups {
name
id
revision
image {
name
tag
}
readyInstances
desiredInstances
created
}
}
}
}
}
]]

-- Only the current ReplicaSet (revision 2) should be included because
-- the old one (revision 1) has 0 desired and 0 ready replicas.
t.check {
data = {
team = {
applications = {
nodes = {
{
name = "myapp",
instanceGroups = {
{
name = "myapp-abc123",
id = NotNull(),
revision = 2,
image = {
name = "ghcr.io/navikt/myapp",
tag = "v1.2.3",
},
readyInstances = 2,
desiredInstances = 2,
created = "2024-01-15T10:00:00Z",
},
},
},
},
},
},
},
}
end)

Test.gql("Instance group with instances", function(t)
t.addHeader("x-user-email", user:email())

t.query [[
query {
team(slug: "myteam") {
applications {
nodes {
name
instanceGroups {
name
instances {
name
id
restarts
created
status {
state
message
ready
lastExitReason
lastExitCode
}
}
}
}
}
}
}
]]

t.check {
data = {
team = {
applications = {
nodes = {
{
name = "myapp",
instanceGroups = {
{
name = "myapp-abc123",
instances = {
{
name = "myapp-abc123-pod1",
id = NotNull(),
restarts = 0,
created = "2024-01-15T10:01:00Z",
status = {
state = "RUNNING",
message = "Running and ready.",
ready = true,
lastExitReason = Null,
lastExitCode = Null,
},
},
{
name = "myapp-abc123-pod2",
id = NotNull(),
restarts = 2,
created = "2024-01-15T10:02:00Z",
status = {
state = "RUNNING",
message = "Running and ready.",
ready = true,
lastExitReason = Null,
lastExitCode = Null,
},
},
},
},
},
},
},
},
},
},
}
end)

Test.gql("Instance group with environment variables", function(t)
t.addHeader("x-user-email", user:email())

t.query [[
query {
team(slug: "myteam") {
applications {
nodes {
name
instanceGroups {
name
environmentVariables {
name
value
source {
kind
name
}
}
}
}
}
}
}
]]

t.check {
data = {
team = {
applications = {
nodes = {
{
name = "myapp",
instanceGroups = {
{
name = "myapp-abc123",
environmentVariables = {
-- Direct env var
{
name = "APP_ENV",
value = "production",
source = {
kind = "SPEC",
name = "myapp",
},
},
-- ConfigMap key ref (value resolved from ConfigMap)
{
name = "DB_HOST",
value = "postgres.myteam.svc.cluster.local",
source = {
kind = "CONFIG_MAP",
name = "myapp-config",
},
},
-- Secret key ref (value is null, requires elevation)
{
name = "API_KEY",
value = Null,
source = {
kind = "SECRET",
name = "myapp-secret",
},
},
-- envFrom ConfigMap (individual keys resolved)
{
name = "FEATURE_FLAG_A",
value = "true",
source = {
kind = "CONFIG_MAP",
name = "myapp-envs",
},
},
{
name = "FEATURE_FLAG_B",
value = "false",
source = {
kind = "CONFIG_MAP",
name = "myapp-envs",
},
},
},
},
},
},
},
},
},
},
}
end)

Test.gql("Instance group with mounted files", function(t)
t.addHeader("x-user-email", user:email())

t.query [[
query {
team(slug: "myteam") {
applications {
nodes {
name
instanceGroups {
name
mountedFiles {
path
content
isBinary
error
source {
kind
name
}
}
}
}
}
}
}
]]

t.check {
data = {
team = {
applications = {
nodes = {
{
name = "myapp",
instanceGroups = {
{
name = "myapp-abc123",
mountedFiles = {
-- ConfigMap files (individual keys expanded, content included)
{
path = "/etc/config/db_host",
content = "postgres.myteam.svc.cluster.local",
isBinary = false,
error = Null,
source = {
kind = "CONFIG_MAP",
name = "myapp-config",
},
},
{
path = "/etc/config/db_port",
content = "5432",
isBinary = false,
error = Null,
source = {
kind = "CONFIG_MAP",
name = "myapp-config",
},
},
{
path = "/etc/config/log_level",
content = "info",
isBinary = false,
error = Null,
source = {
kind = "CONFIG_MAP",
name = "myapp-config",
},
},
-- Secret files (individual keys expanded, content is null)
{
path = "/etc/secret/api_key",
content = Null,
isBinary = false,
error = Null,
source = {
kind = "SECRET",
name = "myapp-secret",
},
},
{
path = "/etc/secret/db_password",
content = Null,
isBinary = false,
error = Null,
source = {
kind = "SECRET",
name = "myapp-secret",
},
},
},
},
},
},
},
},
},
},
}
end)
Loading
Loading