Commit 194acaca authored by Alex Ives's avatar Alex Ives

Add GraphQL for Terraform States

- Add terraform state registry finder
- Add terraform state resolver
- Add terraform state registry type
- Use package_file specific feature flag for it's graphql

Relates to https://gitlab.com/gitlab-org/gitlab/issues/220956
parent 5cad762b
...@@ -5839,7 +5839,7 @@ type GeoNode { ...@@ -5839,7 +5839,7 @@ type GeoNode {
name: String name: String
""" """
Package file registries of the GeoNode. Available only when feature flag `geo_self_service_framework` is enabled Package file registries of the GeoNode. Available only when feature flag `geo_package_file_replication` is enabled
""" """
packageFileRegistries( packageFileRegistries(
""" """
...@@ -5918,6 +5918,37 @@ type GeoNode { ...@@ -5918,6 +5918,37 @@ type GeoNode {
""" """
syncObjectStorage: Boolean syncObjectStorage: Boolean
"""
Find terraform state registries on this Geo node. Available only when feature
flag `geo_terraform_state_replication` is enabled
"""
terraformStateRegistries(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String
"""
Returns the elements in the list that come before the specified cursor.
"""
before: String
"""
Returns the first _n_ elements from the list.
"""
first: Int
"""
Filters registries by their ID
"""
ids: [ID!]
"""
Returns the last _n_ elements from the list.
"""
last: Int
): TerraformStateRegistryConnection
""" """
The user-facing URL for this Geo node The user-facing URL for this Geo node
""" """
...@@ -15347,6 +15378,86 @@ type TaskCompletionStatus { ...@@ -15347,6 +15378,86 @@ type TaskCompletionStatus {
count: Int! count: Int!
} }
"""
Represents the sync and verification state of a terraform state
"""
type TerraformStateRegistry {
"""
Timestamp when the TerraformStateRegistry was created
"""
createdAt: Time
"""
ID of the TerraformStateRegistry
"""
id: ID!
"""
Error message during sync of the TerraformStateRegistry
"""
lastSyncFailure: String
"""
Timestamp of the most recent successful sync of the TerraformStateRegistry
"""
lastSyncedAt: Time
"""
Timestamp after which the TerraformStateRegistry should be resynced
"""
retryAt: Time
"""
Number of consecutive failed sync attempts of the TerraformStateRegistry
"""
retryCount: Int
"""
Sync state of the TerraformStateRegistry
"""
state: RegistryState
"""
ID of the TerraformState
"""
terraformStateId: ID!
}
"""
The connection type for TerraformStateRegistry.
"""
type TerraformStateRegistryConnection {
"""
A list of edges.
"""
edges: [TerraformStateRegistryEdge]
"""
A list of nodes.
"""
nodes: [TerraformStateRegistry]
"""
Information to aid in pagination.
"""
pageInfo: PageInfo!
}
"""
An edge in a connection.
"""
type TerraformStateRegistryEdge {
"""
A cursor for use in pagination.
"""
cursor: String!
"""
The item at the end of the edge.
"""
node: TerraformStateRegistry
}
""" """
Represents a requirement test report. Represents a requirement test report.
""" """
......
...@@ -2274,6 +2274,21 @@ Completion status of tasks ...@@ -2274,6 +2274,21 @@ Completion status of tasks
| `completedCount` | Int! | Number of completed tasks | | `completedCount` | Int! | Number of completed tasks |
| `count` | Int! | Number of total tasks | | `count` | Int! | Number of total tasks |
## TerraformStateRegistry
Represents the sync and verification state of a terraform state
| Name | Type | Description |
| --- | ---- | ---------- |
| `createdAt` | Time | Timestamp when the TerraformStateRegistry was created |
| `id` | ID! | ID of the TerraformStateRegistry |
| `lastSyncFailure` | String | Error message during sync of the TerraformStateRegistry |
| `lastSyncedAt` | Time | Timestamp of the most recent successful sync of the TerraformStateRegistry |
| `retryAt` | Time | Timestamp after which the TerraformStateRegistry should be resynced |
| `retryCount` | Int | Number of consecutive failed sync attempts of the TerraformStateRegistry |
| `state` | RegistryState | Sync state of the TerraformStateRegistry |
| `terraformStateId` | ID! | ID of the TerraformState |
## TestReport ## TestReport
Represents a requirement test report. Represents a requirement test report.
......
...@@ -566,7 +566,7 @@ the Admin Area UI, and Prometheus! ...@@ -566,7 +566,7 @@ the Admin Area UI, and Prometheus!
null: true, null: true,
resolver: ::Resolvers::Geo::WidgetRegistriesResolver, resolver: ::Resolvers::Geo::WidgetRegistriesResolver,
description: 'Find widget registries on this Geo node', description: 'Find widget registries on this Geo node',
feature_flag: :geo_self_service_framework feature_flag: :geo_widget_replication
``` ```
1. Add the new `widget_registries` field name to the `expected_fields` array in 1. Add the new `widget_registries` field name to the `expected_fields` array in
......
# frozen_string_literal: true
module Geo
class TerraformStateRegistryFinder
include FrameworkRegistryFinder
end
end
# frozen_string_literal: true
module Resolvers
module Geo
class TerraformStateRegistriesResolver < BaseResolver
include RegistriesResolver
end
end
end
...@@ -26,7 +26,12 @@ module Types ...@@ -26,7 +26,12 @@ module Types
null: true, null: true,
resolver: ::Resolvers::Geo::PackageFileRegistriesResolver, resolver: ::Resolvers::Geo::PackageFileRegistriesResolver,
description: 'Package file registries of the GeoNode', description: 'Package file registries of the GeoNode',
feature_flag: :geo_self_service_framework feature_flag: :geo_package_file_replication
field :terraform_state_registries, ::Types::Geo::TerraformStateRegistryType.connection_type,
null: true,
resolver: ::Resolvers::Geo::TerraformStateRegistriesResolver,
description: 'Find terraform state registries on this Geo node',
feature_flag: :geo_terraform_state_replication
end end
end end
end end
# frozen_string_literal: true
module Types
module Geo
# rubocop:disable Graphql/AuthorizeTypes because it is included
class TerraformStateRegistryType < BaseObject
include ::Types::Geo::RegistryType
graphql_name 'TerraformStateRegistry'
description 'Represents the sync and verification state of a terraform state'
field :terraform_state_id, GraphQL::ID_TYPE, null: false, description: 'ID of the TerraformState'
end
end
end
---
title: Add graphql endpoints for terraform state store
merge_request: 40317
author:
type: added
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Geo::TerraformStateRegistryFinder do
it_behaves_like 'a framework registry finder', :geo_terraform_state_registry
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Resolvers::Geo::TerraformStateRegistriesResolver do
it_behaves_like 'a Geo registries resolver', :geo_terraform_state_registry
end
...@@ -12,6 +12,7 @@ RSpec.describe GitlabSchema.types['GeoNode'] do ...@@ -12,6 +12,7 @@ RSpec.describe GitlabSchema.types['GeoNode'] do
container_repositories_max_capacity sync_object_storage container_repositories_max_capacity sync_object_storage
selective_sync_type selective_sync_shards selective_sync_namespaces selective_sync_type selective_sync_shards selective_sync_namespaces
minimum_reverification_interval package_file_registries minimum_reverification_interval package_file_registries
terraform_state_registries
] ]
expect(described_class).to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe GitlabSchema.types['TerraformStateRegistry'] do
it_behaves_like 'a Geo registry type'
it 'has the expected fields (other than those included in RegistryType)' do
expected_fields = %i[terraform_state_id]
expect(described_class).to have_graphql_fields(*expected_fields).at_least
end
end
...@@ -9,4 +9,11 @@ RSpec.describe 'Gets registries' do ...@@ -9,4 +9,11 @@ RSpec.describe 'Gets registries' do
registry_factory: :geo_package_file_registry, registry_factory: :geo_package_file_registry,
registry_foreign_key_field_name: 'packageFileId' registry_foreign_key_field_name: 'packageFileId'
} }
it_behaves_like 'gets registries for', {
field_name: 'terraformStateRegistries',
registry_class_name: 'TerraformStateRegistry',
registry_factory: :geo_terraform_state_registry,
registry_foreign_key_field_name: 'terraformStateId'
}
end end
...@@ -5,6 +5,7 @@ RSpec.shared_examples 'gets registries for' do |args| ...@@ -5,6 +5,7 @@ RSpec.shared_examples 'gets registries for' do |args|
let(:registry_class_name) { args[:registry_class_name] } let(:registry_class_name) { args[:registry_class_name] }
let(:registry_factory) { args[:registry_factory] } let(:registry_factory) { args[:registry_factory] }
let(:registry_foreign_key_field_name) { args[:registry_foreign_key_field_name] } let(:registry_foreign_key_field_name) { args[:registry_foreign_key_field_name] }
let(:feature_flag) { Geo.const_get(registry_class_name, false).replicator_class.replication_enabled_feature_key }
let(:registry_foreign_key) { registry_foreign_key_field_name.underscore } let(:registry_foreign_key) { registry_foreign_key_field_name.underscore }
let(:field_name_sym) { field_name.underscore.to_sym } let(:field_name_sym) { field_name.underscore.to_sym }
...@@ -109,7 +110,7 @@ RSpec.shared_examples 'gets registries for' do |args| ...@@ -109,7 +110,7 @@ RSpec.shared_examples 'gets registries for' do |args|
context 'when the geo_self_service_framework feature is disabled' do context 'when the geo_self_service_framework feature is disabled' do
before do before do
stub_feature_flags(geo_self_service_framework: false) stub_feature_flags(feature_flag => false)
end end
it 'errors when requesting registries' do it 'errors when requesting registries' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment