From 99e8a4989af42490896c32bc5595ef24d36295a9 Mon Sep 17 00:00:00 2001 From: Damien Garros Date: Tue, 3 Dec 2024 17:55:53 +0100 Subject: [PATCH 1/8] Use the branch uuid instead of the internal database id to track the hash of the schema in the cache --- backend/infrahub/graphql/queries/status.py | 4 +++- backend/infrahub/services/component.py | 7 +++++-- changelog/+branch-hash-id.fixed.md | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 changelog/+branch-hash-id.fixed.md diff --git a/backend/infrahub/graphql/queries/status.py b/backend/infrahub/graphql/queries/status.py index 971b6dbf68..ee3f17e147 100644 --- a/backend/infrahub/graphql/queries/status.py +++ b/backend/infrahub/graphql/queries/status.py @@ -46,7 +46,9 @@ async def resolve_status( service = context.service or services.service fields = await extract_fields_first_node(info) response: dict[str, Any] = {} - workers = await service.component.list_workers(branch=context.branch.id or context.branch.name, schema_hash=True) + workers = await service.component.list_workers( + branch=str(context.branch.uuid) or context.branch.name, schema_hash=True + ) if summary := fields.get("summary"): response["summary"] = {} diff --git a/backend/infrahub/services/component.py b/backend/infrahub/services/component.py index 6f0f20e8eb..bf2a54d9f1 100644 --- a/backend/infrahub/services/component.py +++ b/backend/infrahub/services/component.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Any, Optional from infrahub.components import ComponentType +from infrahub.core.constants import GLOBAL_BRANCH_NAME from infrahub.core.registry import registry from infrahub.core.timestamp import Timestamp from infrahub.exceptions import InitializationError @@ -71,16 +72,18 @@ async def list_workers(self, branch: str, schema_hash: bool) -> list[WorkerInfo] workers[identity].add_value(key=key, value=value) return list(workers.values()) - async def refresh_schema_hash(self, branches: Optional[list[str]] = None) -> None: + async def refresh_schema_hash(self, branches: list[str] | None = None) -> None: branches = branches or list(registry.branch.keys()) for branch in branches: + if branch == GLOBAL_BRANCH_NAME: + continue schema_branch = registry.schema.get_schema_branch(name=branch) hash_value = schema_branch.get_hash() # Use branch name if we cannot find branch id in cache branch_id: Optional[str] = None if branch_obj := await registry.get_branch(branch=branch, db=self.service.database): - branch_id = branch_obj.id + branch_id = str(branch_obj.uuid) if not branch_id: branch_id = branch diff --git a/changelog/+branch-hash-id.fixed.md b/changelog/+branch-hash-id.fixed.md new file mode 100644 index 0000000000..cabe714f05 --- /dev/null +++ b/changelog/+branch-hash-id.fixed.md @@ -0,0 +1 @@ +Use the branch uuid instead of the internal database id to track the hash of the schema in the cache \ No newline at end of file From 94180950241cf7f45a78a673dfb13fbffa298335 Mon Sep 17 00:00:00 2001 From: Patrick Ogenstad Date: Mon, 9 Dec 2024 16:39:03 +0100 Subject: [PATCH 2/8] Add CoreProfile to database --- backend/infrahub/core/schema/manager.py | 5 ----- changelog/+f91354a0.fixed.md | 1 + 2 files changed, 1 insertion(+), 5 deletions(-) create mode 100644 changelog/+f91354a0.fixed.md diff --git a/backend/infrahub/core/schema/manager.py b/backend/infrahub/core/schema/manager.py index abafd790bf..b6e04b024d 100644 --- a/backend/infrahub/core/schema/manager.py +++ b/backend/infrahub/core/schema/manager.py @@ -3,9 +3,6 @@ from typing import TYPE_CHECKING, Any, Optional, Union from infrahub import lock -from infrahub.core.constants import ( - InfrahubKind, -) from infrahub.core.manager import NodeManager from infrahub.core.models import ( HashableModelDiff, @@ -234,8 +231,6 @@ async def load_schema_to_db( branch = await registry.get_branch(branch=branch, db=db) for item_kind in schema.node_names + schema.generic_names: - if item_kind == InfrahubKind.PROFILE: - continue if limit and item_kind not in limit: continue item = schema.get(name=item_kind, duplicate=False) diff --git a/changelog/+f91354a0.fixed.md b/changelog/+f91354a0.fixed.md new file mode 100644 index 0000000000..fe84855f4e --- /dev/null +++ b/changelog/+f91354a0.fixed.md @@ -0,0 +1 @@ +Store CoreProfile in database to ensure consistent initial schema hash. Prior to this the schema was reported as being out of sync when starting the application for the first time. This error wouldn't have hade any impact but was confusing. The workaround would be to load a schema or restart the application at least once after first time initialization. From 09ecf6a92ed64fc4f17352a6593b4637f0b81499 Mon Sep 17 00:00:00 2001 From: Raphael Maunier Date: Mon, 9 Dec 2024 21:58:40 +0100 Subject: [PATCH 3/8] fix typo in doc (#5167) --- docs/docs/topics/ipam.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/topics/ipam.mdx b/docs/docs/topics/ipam.mdx index ec651515f5..106254d19a 100644 --- a/docs/docs/topics/ipam.mdx +++ b/docs/docs/topics/ipam.mdx @@ -24,7 +24,7 @@ By default, Infrahub comes with a node inheriting from the `BuiltinIPNamespace` ## Building an IPAM -As mentioned in the previous section, an IPAM namespace is already provided with Infrahub, so there are no needs to redefined this unless more attributes are required. The default implementation is very minimal and attributes only include a name and a description. +As mentioned in the previous section, an IPAM namespace is already provided with Infrahub, so there is no need to redefine this unless more attributes are required. The default implementation is very minimal and attributes only include a name and a description. The below schema defines two nodes: one for IP prefixes `IpamIPPrefix` and one for IP addresses `IpamIPAddress`. Both of these nodes inherit from the built-in generics. From ba027ffdeee0526ef153ac826d8ee547342e3b11 Mon Sep 17 00:00:00 2001 From: Raphael Maunier Date: Mon, 9 Dec 2024 22:15:33 +0100 Subject: [PATCH 4/8] Rm fix doc typo shell (#5169) * fix typo in doc --- docs/docs/guides/installation.mdx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/docs/guides/installation.mdx b/docs/docs/guides/installation.mdx index cb865d9713..73bfed7d87 100644 --- a/docs/docs/guides/installation.mdx +++ b/docs/docs/guides/installation.mdx @@ -41,16 +41,16 @@ For a list of versions, check our [release notes on GitHub](https://github.com/o -`` `shell +```shell curl https://infrahub.opsmill.io | docker compose -f - up -d -`` ` +``` -`` `shell +```shell curl https://infrahub.opsmill.io | sudo docker compose -f - up -d -`` ` +``` @@ -60,16 +60,16 @@ curl https://infrahub.opsmill.io | sudo docker compose -f - up -d -`` `shell +```shell curl https://infrahub.opsmill.io | docker compose -f - down -v -`` ` +``` -`` `shell +```shell curl https://infrahub.opsmill.io | sudo docker compose -f - down -v -`` ` +``` From 2d5df80652f265455191b7a1362bb3bb3a60e352 Mon Sep 17 00:00:00 2001 From: Benoit Kohler Date: Mon, 9 Dec 2024 23:34:47 +0100 Subject: [PATCH 5/8] Add new CICD trigger to update submodule (#5166) (#5171) * add a new trigger to update the git submodule (python-sdk) --- .github/workflows/trigger-submodule.yml | 71 +++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/trigger-submodule.yml diff --git a/.github/workflows/trigger-submodule.yml b/.github/workflows/trigger-submodule.yml new file mode 100644 index 0000000000..a3c39f9480 --- /dev/null +++ b/.github/workflows/trigger-submodule.yml @@ -0,0 +1,71 @@ +--- +# yamllint disable rule:truthy rule:line-length +name: Handle Submodule Trigger + +on: + repository_dispatch: + types: + - trigger-submodule-update + +jobs: + update-dependencies: + strategy: + matrix: + branch-name: + - main + - develop + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: "${{ matrix.branch-name }}" + submodules: recursive + + - name: Set branch name + id: set-branch-name + run: | + SUBMODULE_PATH="python_sdk" + SDK_VERSION="${{ github.event.client_payload.version }}" + BRANCH_NAME="${{ matrix.branch-name}}-${SUBMODULE_PATH}-${SDK_VERSION}" + echo "SUBMODULE_PATH=$SUBMODULE_PATH" >> $GITHUB_ENV + echo "SDK_VERSION=$SDK_VERSION" >> $GITHUB_ENV + echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV + + - name: Use the version from the client payload to update the submodule + run: | + echo "Updating submodule to version: ${{ env.SDK_VERSION }}" + echo "Branch name: ${{ env.BRANCH_NAME }}" + + # Navigate to the submodule and update it to the specified version + cd ${{ env.SUBMODULE_PATH }} + git fetch --tags + git checkout ${{ env.SDK_VERSION }} + cd - + + - name: Prepare the branch for the update + id: prepare-branch + run: | + echo "Checking if branch ${{ env.BRANCH_NAME }} exists..." + BRANCH_EXISTS=$(git ls-remote --heads origin ${{ env.BRANCH_NAME }} | wc -l) + echo "BRANCH_EXISTS=$BRANCH_EXISTS" >> $GITHUB_ENV + + - name: Commit and push changes with github-actions-x/commit + uses: github-actions-x/commit@v2.9 + with: + github-token: ${{ secrets.GH_UPDATE_PACKAGE }} + push-branch: ${{ env.BRANCH_NAME }} + commit-message: "chore: update submodule ${{ env.SUBMODULE_PATH }} to version ${{ env.SDK_VERSION }}" + files: ${{ env.SUBMODULE_PATH }}/ + name: opsmill-bot + email: github-bot@opsmill.com + rebase: ${{ env.BRANCH_EXISTS == 1 }} + + - name: Create a pull request + run: | + echo ${{ secrets.GH_UPDATE_PACKAGE_OTTO }} | gh auth login --with-token + gh pr create \ + --title "Update ${{ env.SUBMODULE_PATH }} to version ${{ env.SDK_VERSION }} against ${{ matrix.branch-name}}" \ + --body "This PR updates the submodule ${{ env.SUBMODULE_PATH }} to version ${{ env.SDK_VERSION }}." \ + --base ${{ matrix.branch-name}} \ + --head ${{ env.BRANCH_NAME }} From 46d3a18b6f62bd7ee274f6aaa61203d166cb4516 Mon Sep 17 00:00:00 2001 From: Benoit Kohler Date: Tue, 10 Dec 2024 08:04:36 +0100 Subject: [PATCH 6/8] Update trigger-submodule.yml (#5174) --- .github/workflows/trigger-submodule.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/trigger-submodule.yml b/.github/workflows/trigger-submodule.yml index a3c39f9480..19315408b2 100644 --- a/.github/workflows/trigger-submodule.yml +++ b/.github/workflows/trigger-submodule.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: branch-name: - - main + - stable - develop runs-on: ubuntu-22.04 steps: From 1f5f5d4b5bc66a96fe28eb235611da894d67335b Mon Sep 17 00:00:00 2001 From: Benoit Kohler Date: Tue, 10 Dec 2024 12:10:16 +0100 Subject: [PATCH 7/8] Add trigger to update submodule in Enterprise (#5179) * add workflow to release process --- .github/workflows/release.yml | 7 ++++ .github/workflows/trigger-submodule.yml | 2 +- .github/workflows/update-submodule.yml | 44 +++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/update-submodule.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b26471e824..a9ec0e3240 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -121,3 +121,10 @@ jobs: secrets: inherit with: publish: true + + update-submodule: + needs: check_release + uses: ./.github/workflows/update-submodule.yml + secrets: inherit + with: + version: ${{ github.ref_name }} diff --git a/.github/workflows/trigger-submodule.yml b/.github/workflows/trigger-submodule.yml index 19315408b2..f7715a8985 100644 --- a/.github/workflows/trigger-submodule.yml +++ b/.github/workflows/trigger-submodule.yml @@ -53,7 +53,7 @@ jobs: - name: Commit and push changes with github-actions-x/commit uses: github-actions-x/commit@v2.9 with: - github-token: ${{ secrets.GH_UPDATE_PACKAGE }} + github-token: ${{ secrets.GH_UPDATE_PACKAGE_OTTO }} push-branch: ${{ env.BRANCH_NAME }} commit-message: "chore: update submodule ${{ env.SUBMODULE_PATH }} to version ${{ env.SDK_VERSION }}" files: ${{ env.SUBMODULE_PATH }}/ diff --git a/.github/workflows/update-submodule.yml b/.github/workflows/update-submodule.yml new file mode 100644 index 0000000000..0d0dd06574 --- /dev/null +++ b/.github/workflows/update-submodule.yml @@ -0,0 +1,44 @@ +--- +# yamllint disable rule:truthy rule:line-length +name: Trigger Submodule update + +on: + workflow_dispatch: + inputs: + runs-on: + description: "The OS to run the job on" + required: false + default: "ubuntu-22.04" + type: string + version: + type: string + required: false + description: The string to extract semver from. + default: '' + workflow_call: + inputs: + runs-on: + description: "The OS to run the job on" + required: false + default: "ubuntu-22.04" + type: string + version: + type: string + required: false + description: The string to extract semver from. + default: '' + +jobs: + trigger-submodule: + runs-on: ubuntu-22.04 + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Trigger submodule update + run: | + curl -X POST \ + -H 'Authorization: token ${{ secrets.GH_UPDATE_PACKAGE_OTTO }}' \ + -H 'Accept: application/vnd.github.v3+json' \ + 'https://api.github.com/repos/${{ secrets.INFRAHUB_ENTERPRISE_REPOSITORY }}/dispatches' \ + -d '{"event_type":"trigger-submodule-update","client_payload":{"version":"${{ inputs.version }}"}}' From fab6295f3285bc8493d69cc4c677613abe9ff7cd Mon Sep 17 00:00:00 2001 From: Benoit Kohler Date: Tue, 10 Dec 2024 14:18:22 +0100 Subject: [PATCH 8/8] Add uuid to spelling-exceptions (#5182) Need for the validate-release-notes-style in the CI --- .vale/styles/spelling-exceptions.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.vale/styles/spelling-exceptions.txt b/.vale/styles/spelling-exceptions.txt index cc56206418..7af5af85d9 100644 --- a/.vale/styles/spelling-exceptions.txt +++ b/.vale/styles/spelling-exceptions.txt @@ -116,6 +116,8 @@ validator upsert Upserting upserting +uuid +UUID validators Version Control Vitest