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

Support updating artifact definition targets #5101

Merged
merged 1 commit into from
Dec 3, 2024
Merged
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
8 changes: 7 additions & 1 deletion backend/infrahub/git/integrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ async def import_artifact_definitions(

artifact_defs_in_graph = {
artdef.name.value: artdef
for artdef in await self.sdk.filters(kind=CoreArtifactDefinition, branch=branch_name)
for artdef in await self.sdk.filters(
kind=CoreArtifactDefinition, branch=branch_name, prefetch_relationships=True, populate_store=True
)
}

local_artifact_defs: dict[str, InfrahubRepositoryArtifactDefinitionConfig] = {}
Expand Down Expand Up @@ -380,6 +382,7 @@ async def compare_artifact_definition(
existing_artifact_definition.artifact_name.value != local_artifact_definition.artifact_name
or existing_artifact_definition.parameters.value != local_artifact_definition.parameters
or existing_artifact_definition.content_type.value != local_artifact_definition.content_type
or existing_artifact_definition.targets.peer.name.value != local_artifact_definition.targets
):
return False

Expand All @@ -399,6 +402,9 @@ async def update_artifact_definition(
if existing_artifact_definition.content_type.value != local_artifact_definition.content_type:
existing_artifact_definition.content_type.value = local_artifact_definition.content_type

if existing_artifact_definition.targets.peer.name.value != local_artifact_definition.targets:
existing_artifact_definition.targets = local_artifact_definition.targets

await existing_artifact_definition.save()

async def get_repository_config(self, branch_name: str, commit: str) -> Optional[InfrahubRepositoryConfig]:
Expand Down
4 changes: 3 additions & 1 deletion backend/infrahub/git/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ async def generate_request_artifact_definition(model: RequestArtifactDefinitionG
await artifact_definition.targets.fetch()
group = artifact_definition.targets.peer
await group.members.fetch()
current_members = [member.id for member in group.members.peers]

existing_artifacts = await service.client.filters(
kind=InfrahubKind.ARTIFACT,
Expand All @@ -183,7 +184,8 @@ async def generate_request_artifact_definition(model: RequestArtifactDefinitionG
)
artifacts_by_member = {}
for artifact in existing_artifacts:
artifacts_by_member[artifact.object.peer.id] = artifact.id
if artifact.object.id in current_members:
artifacts_by_member[artifact.object.peer.id] = artifact.id

await artifact_definition.transformation.fetch()
transformation_repository = artifact_definition.transformation.peer.repository
Expand Down
1 change: 1 addition & 0 deletions changelog/5060.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix artifact definition targets when changed in repo so that it's reflected in the database
Loading