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

Dynamic resources endpoints #319

Draft
wants to merge 32 commits into
base: main
Choose a base branch
from

Conversation

Adam0Brien
Copy link
Contributor

@Adam0Brien Adam0Brien commented Jan 31, 2025

PR Template:

Describe your changes

make run

Create a k8s_ cluster

curl -X PUT http://localhost:8000/api/inventory/v1beta1/resources/k8s_cluster \
-H "Content-Type: application/json" \
-d '{
  "resource": {
	"metadata": {
  	"resource_type": "k8s_cluster",
  	"workspace_id": "01932c7e-e93e-719c-a488-3159877367b0"
	},
	"reporter_data": {
  	"reporter_type": "ACM",
  	"reporter_version": "0.1",
  	"local_resource_id": "2",
  	"api_href": "www.example.com",
  	"console_href": "www.rhel.example.com"
	},
	"resource_data": {
  	"external_cluster_id": "1234",
  	"cluster_status": "READY",
  	"cluster_reason": "All systems operational",
  	"kube_version": "1.31",
  	"kube_vendor": "OPENSHIFT",
  	"vendor_version": "4.16",
  	"cloud_platform": "AWS_UPI",
  	"nodes": [
    	{
      	"name": "www.example.com",
      	"cpu": "7500m",
      	"memory": "30973224Ki",
      	"labels": [
        	{
          	"key": "has_monster_gpu",
          	"value": "yes"
        	}
      	]
    	}
  	]
	}
  }
}'

Create a k8s_ policy

 curl -X PUT http://localhost:8000/api/inventory/v1beta1/resources/k8s_policies \
-H "Content-Type: application/json" \
-d '{
  "resource": {
    "metadata": {
      "org_id": "org-123",
      "workspace_id": "ws-456",
      "resource_type": "k8s_policy"
    },
    "resource_data": {
      "disabled": true,
      "severity": "MEDIUM"
    },
    "reporter_data": {
      "reporter_type": "ACM",
      "console_href": "https://console.k8s.example.com",
      "api_href": "https://api.k8s.example.com",
      "local_resource_id": "k8s-policy-001",
      "reporter_version": "1.0"
    }
  }
}'

Create a rhel_host

curl -X PUT http://localhost:8000/api/inventory/v1beta1/resources/rhel_host \
-H "Content-Type: application/json" \
-d '{
  "resource": {
    "metadata": {
      "org_id": "org-123",
      "workspace_id": "ws-456",
      "resource_type": "rhel_host"
    },
    "reporter_data": {
      "reporter_type": "HBI",
      "console_href": "https://console.rhel.example.com",
      "api_href": "https://api.rhel.example.com",
      "local_resource_id": "rhel-host-001",
      "reporter_version": "1.0"
    }
  }
}'

Create a notification integration

curl -X PUT http://localhost:8000/api/inventory/v1beta1/resources/notifications-integrations \
-H "Content-Type: application/json" \
-d '{
  "resource": {
    "metadata": {
      "org_id": "org-123",
      "workspace_id": "ws-456",
      "resource_type": "notifications/integrations"
    },
    "reporter_data": {
      "reporter_type": "NOTIFICATIONS",
      "reporter_instance_id": "service-account-1",
      "console_href": "https://console.notifications.example.com",
      "api_href": "https://api.notifications.example.com",
      "local_resource_id": "notifications-001",
      "reporter_version": "1.0"
    }
  }
}'
curl -X PUT http://localhost:8000/api/inventory/v1beta1/resources/notifications-integrations \
-H "Content-Type: application/json" \
-d '{
  "integration": {
    "metadata": {
      "workspace_id": "ws-456",
      "resource_type": "notification/integration"
    },
    "reporter_data": {
      "reporter_type": "NOTIFICATIONS",
      "console_href": "https://console.notifications.example.com",
      "api_href": "https://api.notifications.example.com",
      "local_resource_id": "notifications-001",
      "reporter_version": "1.0"
    }
  }
}'

Error handling

If JSON data is missing the JSON_VALIDATOR will catch the missing data and tell the user:

curl -X PUT http://localhost:8000/api/inventory/v1beta1/resources/notifications-integrations \
-H "Content-Type: application/json" \
-d '{
  "resource": {
    "metadata": {
      "org_id": "org-123",
      "workspace_id": "ws-456",
      "resource_type": "notifications/integrations"
    },
    "reporter_data": {
      "reporter_type": "NOTIFICATIONS",
      "console_href": "https://console.notifications.example.com",
      "api_href": "https://api.notifications.example.com",
      "local_resource_id": "notifications-001",
      "reporter_version": "1.0"
    }
  }
}'

{"code":400, "reason":"JSON_VALIDATOR", "message":"reporter validation failed: validation failed: (root): reporter_instance_id is required", "metadata":{}}%   

Ticket reference (if applicable)

Fixes #

Checklist

  • Are the agreed upon acceptance criteria fulfilled?

  • Was the 4-eye-principle applied? (async PR review, pairing, ensembling)

  • Do your changes have passing automated tests and sufficient observability?

  • Are the work steps you introduced repeatable by others, either through automation or documentation?

    • If automation is possible but not done due to other constraints, a ticket to the tech debt sprint is added
    • An SOP (Standard Operating Procedure) was created
  • The Changes were automatically built, tested, and - if needed, behind a feature flag - deployed to our production environment. (Please check this when the new deployment is done and you could verify it.)

  • Are the agreed upon coding/architectural practices applied?

  • Are security needs fullfilled? (e.g. no internal URL)

  • Is the corresponding Ticket in the right state? (should be on "review" now, put to done when this change made it to production)

  • For changes to the public API / code dependencies: Was the whole team (or a sufficient amount of ppl) able to review?

@Adam0Brien Adam0Brien mentioned this pull request Jan 31, 2025
11 tasks
@Adam0Brien Adam0Brien force-pushed the dynamic-resources-poc branch 3 times, most recently from a5e6074 to 9d9b0d9 Compare February 4, 2025 11:53
@app-sre-bot
Copy link
Collaborator

Can one of the admins verify this patch?

@@ -15,6 +15,7 @@ COPY api ./api
COPY cmd ./cmd
COPY internal ./internal
COPY main.go Makefile ./
COPY data/resources ./data/resources
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed extracting the resources to a separate image. Let's keep it here for now, until we have a use case to separate it! +1 to this

@Adam0Brien Adam0Brien force-pushed the dynamic-resources-poc branch from e207c85 to 930aee6 Compare February 7, 2025 11:50
@Adam0Brien Adam0Brien force-pushed the dynamic-resources-poc branch from 626983a to 946cf36 Compare February 7, 2025 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants