From 0fa61a0f94f6ef3cd818660b9ac7519597371771 Mon Sep 17 00:00:00 2001 From: Kemal <223029+disq@users.noreply.github.com> Date: Sun, 23 Jan 2022 09:24:48 +0000 Subject: [PATCH] feat: Testable Migrations (#42) * feat: All migrations as files * Update SDK Co-authored-by: Kemal Hadimli --- .github/workflows/test_migration.yml | 85 + client/testing.go | 2 +- go.mod | 4 +- go.sum | 14 +- .../migrations/postgres/1_v0.4.0.down.sql | 104 ++ .../migrations/postgres/1_v0.4.0.up.sql | 1346 +++++++++++++++ .../migrations/timescale/1_v0.4.0.down.sql | 104 ++ .../migrations/timescale/1_v0.4.0.up.sql | 1484 +++++++++++++++++ resources/provider/provider.go | 6 + resources/provider/provider_test.go | 12 + tools/migrations/main.go | 17 + 11 files changed, 3164 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/test_migration.yml create mode 100644 resources/provider/migrations/postgres/1_v0.4.0.down.sql create mode 100644 resources/provider/migrations/postgres/1_v0.4.0.up.sql create mode 100644 resources/provider/migrations/timescale/1_v0.4.0.down.sql create mode 100644 resources/provider/migrations/timescale/1_v0.4.0.up.sql create mode 100644 resources/provider/provider_test.go create mode 100644 tools/migrations/main.go diff --git a/.github/workflows/test_migration.yml b/.github/workflows/test_migration.yml new file mode 100644 index 0000000..c92aa50 --- /dev/null +++ b/.github/workflows/test_migration.yml @@ -0,0 +1,85 @@ +name: test_migration + +on: + push: + branches: + - main + pull_request: + branches: [main] + workflow_dispatch: + +jobs: + + should_run: + runs-on: ubuntu-latest + outputs: + should_run: ${{ steps.cache-migrations.cache-hit != 'true' }} + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + + - name: Cache Migrations + id: cache-migrations + uses: actions/cache@v2 + with: + path: resources/provider/migrations + key: ${{ runner.os }}-${{ hashFiles('resources/provider/migrations') }} + + test_migration: + needs: should_run + if: github.repository == 'cloudquery/cq-provider-k8s' && needs.should_run.outputs.should_run == 'true' + strategy: + matrix: + dbversion: [ "postgres:latest" ] + go: [ "1.17" ] + platform: [ ubuntu-latest ] # can not run in macOS and windowsOS + runs-on: ${{ matrix.platform }} + services: + postgres: + image: ${{ matrix.dbversion }} + env: + POSTGRES_PASSWORD: pass + POSTGRES_USER: postgres + POSTGRES_DB: postgres + ports: + - 5432:5432 + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: ^1.17 + + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + + - name: Get dependencies + run: | + go get -v -t -d ./... + + - name: Test migrations for Postgres + run: | + go test -v ./resources/provider/provider_test.go + env: + CQ_MIGRATION_TEST_DSN: postgres://postgres:pass@localhost:5432/postgres?sslmode=disable + + - name: Test migrations for Timescale + run: | + go test -v ./resources/provider/provider_test.go + env: + CQ_MIGRATION_TEST_DSN: tsdb://postgres:pass@localhost:5432/postgres?sslmode=disable + + - name: Slack Notification + uses: rtCamp/action-slack-notify@v2 + if: ${{ failure() }} + env: + SLACK_CHANNEL: oss-tests + SLACK_COLOR: ${{ job.status }} + SLACK_MESSAGE: 'K8S - migration test failed' + SLACK_TITLE: K8S - migration test failed + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} \ No newline at end of file diff --git a/client/testing.go b/client/testing.go index 8711c42..d308456 100644 --- a/client/testing.go +++ b/client/testing.go @@ -43,7 +43,7 @@ func K8sMockTestHelper(t *testing.T, table *schema.Table, builder func(*testing. providertest.TestResource(t, providertest.ResourceTestCase{ Provider: &provider.Provider{ - Name: "aws_mock_test_provider", + Name: "k8s_mock_test_provider", Version: "development", Configure: func(logger hclog.Logger, _ interface{}) (schema.ClientMeta, error) { c := &Client{ diff --git a/go.mod b/go.mod index 35d99cc..faf11a2 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/cloudquery/cq-provider-k8s go 1.17 require ( - github.com/cloudquery/cq-provider-sdk v0.6.1 + github.com/cloudquery/cq-provider-sdk v0.7.0-alpha2 github.com/cloudquery/faker/v3 v3.7.5 github.com/golang/mock v1.6.0 github.com/hashicorp/go-hclog v1.0.0 @@ -45,8 +45,6 @@ require ( github.com/hashicorp/go-version v1.3.0 // indirect github.com/hashicorp/hcl/v2 v2.10.1 // indirect github.com/hashicorp/yamux v0.0.0-20210826001029-26ff87cf9493 // indirect - github.com/huandu/go-sqlbuilder v1.13.0 // indirect - github.com/huandu/xstrings v1.3.2 // indirect github.com/iancoleman/strcase v0.2.0 // indirect github.com/imdario/mergo v0.3.12 // indirect github.com/jackc/chunkreader/v2 v2.0.1 // indirect diff --git a/go.sum b/go.sum index 1de8420..6043efe 100644 --- a/go.sum +++ b/go.sum @@ -182,8 +182,8 @@ github.com/cilium/ebpf v0.4.0/go.mod h1:4tRaxcgiL706VnOzHOdBlY8IEAIdxINsQBcU4xJJ github.com/cilium/ebpf v0.6.2/go.mod h1:4tRaxcgiL706VnOzHOdBlY8IEAIdxINsQBcU4xJJXRs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80= -github.com/cloudquery/cq-provider-sdk v0.6.1 h1:pyHabGR81AdsnwtZF0oaJhF9VPK5tHiC8DukA5JEW/A= -github.com/cloudquery/cq-provider-sdk v0.6.1/go.mod h1:lLjzStk8uqMiunTDnAp26QXyQ3XAMexOqzuo8T2riMc= +github.com/cloudquery/cq-provider-sdk v0.7.0-alpha2 h1:GY0NJLEYf5JSHluVJsdAfFN00ygX5A+HZHw6/LDif5Q= +github.com/cloudquery/cq-provider-sdk v0.7.0-alpha2/go.mod h1:T+ngRXzcjJ6otKDGkWnPrHTsZuHUe3KZKtyhSLcvHCs= github.com/cloudquery/faker/v3 v3.7.4/go.mod h1:1b8WVG9Gh0T2hVo1a8dWeXfu0AhqSB6J/mmJaesqOeo= github.com/cloudquery/faker/v3 v3.7.5 h1:G7ANdEEcm8TvAAjIwNWSLrYK36CFCiSlrCqOTGCccL0= github.com/cloudquery/faker/v3 v3.7.5/go.mod h1:1b8WVG9Gh0T2hVo1a8dWeXfu0AhqSB6J/mmJaesqOeo= @@ -233,8 +233,8 @@ github.com/containerd/containerd v1.5.0-beta.1/go.mod h1:5HfvG1V2FsKesEGQ17k5/T7 github.com/containerd/containerd v1.5.0-beta.3/go.mod h1:/wr9AVtEM7x9c+n0+stptlo/uBBoBORwEx6ardVcmKU= github.com/containerd/containerd v1.5.0-beta.4/go.mod h1:GmdgZd2zA2GYIBZ0w09ZvgqEq8EfBp/m3lcVZIvPHhI= github.com/containerd/containerd v1.5.0-rc.0/go.mod h1:V/IXoMqNGgBlabz3tHD2TWDoTJseu1FGOKuoA4nNb2s= -github.com/containerd/containerd v1.5.8 h1:NmkCC1/QxyZFBny8JogwLpOy2f+VEbO/f6bV2Mqtwuw= -github.com/containerd/containerd v1.5.8/go.mod h1:YdFSv5bTFLpG2HIYmfqDpSYYTDX+mc5qtSuYx1YUb/s= +github.com/containerd/containerd v1.5.9 h1:rs6Xg1gtIxaeyG+Smsb/0xaSDu1VgFhOCKBXxMxbsF4= +github.com/containerd/containerd v1.5.9/go.mod h1:fvQqCfadDGga5HZyn3j4+dx56qj2I9YwBrlSdalvJYQ= github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= github.com/containerd/continuity v0.0.0-20190815185530-f2a389ac0a02/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= github.com/containerd/continuity v0.0.0-20191127005431-f65d91d395eb/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= @@ -592,12 +592,6 @@ github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKe github.com/hashicorp/yamux v0.0.0-20210826001029-26ff87cf9493 h1:brI5vBRUlAlM34VFmnLPwjnCL/FxAJp9XvOdX6Zt+XE= github.com/hashicorp/yamux v0.0.0-20210826001029-26ff87cf9493/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/huandu/go-assert v1.1.5 h1:fjemmA7sSfYHJD7CUqs9qTwwfdNAx7/j2/ZlHXzNB3c= -github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0JrPVhn/06U= -github.com/huandu/go-sqlbuilder v1.13.0 h1:IN1VRzcyQ+Kx74L0g5ZAY5qDaRJjwMWVmb6GrFAF8Jc= -github.com/huandu/go-sqlbuilder v1.13.0/go.mod h1:LILlbQo0MOYjlIiGgOSR3UcWQpd5Y/oZ7HLNGyAUz0E= -github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw= -github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0= github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= diff --git a/resources/provider/migrations/postgres/1_v0.4.0.down.sql b/resources/provider/migrations/postgres/1_v0.4.0.down.sql new file mode 100644 index 0000000..1d1aa6b --- /dev/null +++ b/resources/provider/migrations/postgres/1_v0.4.0.down.sql @@ -0,0 +1,104 @@ +-- Autogenerated by migration tool on 2022-01-19 11:52:48 + +-- Resource: apps.daemon_sets +DROP TABLE IF EXISTS k8s_apps_daemon_set_selector_match_expressions; +DROP TABLE IF EXISTS k8s_apps_daemon_set_status_conditions; +DROP TABLE IF EXISTS k8s_apps_daemon_sets; + +-- Resource: apps.deployments +DROP TABLE IF EXISTS k8s_apps_deployment_selector_match_expressions; +DROP TABLE IF EXISTS k8s_apps_deployment_status_conditions; +DROP TABLE IF EXISTS k8s_apps_deployments; + +-- Resource: apps.replica_sets +DROP TABLE IF EXISTS k8s_apps_replica_set_selector_match_expressions; +DROP TABLE IF EXISTS k8s_apps_replica_set_status_conditions; +DROP TABLE IF EXISTS k8s_apps_replica_sets; + +-- Resource: apps.stateful_sets +DROP TABLE IF EXISTS k8s_apps_stateful_set_selector_match_expressions; +DROP TABLE IF EXISTS k8s_apps_stateful_set_status_conditions; +DROP TABLE IF EXISTS k8s_apps_stateful_sets; + +-- Resource: batch.cron_jobs +DROP TABLE IF EXISTS k8s_batch_cron_jobs; + +-- Resource: batch.jobs +DROP TABLE IF EXISTS k8s_batch_job_selector_match_expressions; +DROP TABLE IF EXISTS k8s_batch_job_status_conditions; +DROP TABLE IF EXISTS k8s_batch_jobs; + +-- Resource: core.endpoints +DROP TABLE IF EXISTS k8s_core_endpoint_subset_addresses; +DROP TABLE IF EXISTS k8s_core_endpoint_subset_not_ready_addresses; +DROP TABLE IF EXISTS k8s_core_endpoint_subset_ports; +DROP TABLE IF EXISTS k8s_core_endpoint_subsets; +DROP TABLE IF EXISTS k8s_core_endpoints; + +-- Resource: core.limit_ranges +DROP TABLE IF EXISTS k8s_core_limit_range_limits; +DROP TABLE IF EXISTS k8s_core_limit_ranges; + +-- Resource: core.namespaces +DROP TABLE IF EXISTS k8s_meta_owner_references; +DROP TABLE IF EXISTS k8s_core_namespaces; + +-- Resource: core.nodes +DROP TABLE IF EXISTS k8s_core_node_images; +DROP TABLE IF EXISTS k8s_core_node_volumes_attached; +DROP TABLE IF EXISTS k8s_core_nodes; + +-- Resource: core.pods +DROP TABLE IF EXISTS k8s_core_pod_init_container_ports; +DROP TABLE IF EXISTS k8s_core_pod_init_container_envs; +DROP TABLE IF EXISTS k8s_core_pod_init_container_volume_mounts; +DROP TABLE IF EXISTS k8s_core_pod_init_container_volume_devices; +DROP TABLE IF EXISTS k8s_core_pod_init_containers; +DROP TABLE IF EXISTS k8s_core_pod_container_ports; +DROP TABLE IF EXISTS k8s_core_pod_container_envs; +DROP TABLE IF EXISTS k8s_core_pod_container_volume_mounts; +DROP TABLE IF EXISTS k8s_core_pod_container_volume_devices; +DROP TABLE IF EXISTS k8s_core_pod_containers; +DROP TABLE IF EXISTS k8s_core_pod_ephemeral_container_ports; +DROP TABLE IF EXISTS k8s_core_pod_ephemeral_container_envs; +DROP TABLE IF EXISTS k8s_core_pod_ephemeral_container_volume_mounts; +DROP TABLE IF EXISTS k8s_core_pod_ephemeral_container_volume_devices; +DROP TABLE IF EXISTS k8s_core_pod_ephemeral_containers; +DROP TABLE IF EXISTS k8s_core_pod_volumes; +DROP TABLE IF EXISTS k8s_core_pod_init_container_statuses; +DROP TABLE IF EXISTS k8s_core_pod_container_statuses; +DROP TABLE IF EXISTS k8s_core_pod_ephemeral_container_statuses; +DROP TABLE IF EXISTS k8s_core_pods; + +-- Resource: core.resource_quotas +DROP TABLE IF EXISTS k8s_core_resource_quota_scope_selector_match_expressions; +DROP TABLE IF EXISTS k8s_core_resource_quotas; + +-- Resource: core.service_accounts +DROP TABLE IF EXISTS k8s_core_service_account_secrets; +DROP TABLE IF EXISTS k8s_core_service_accounts; + +-- Resource: core.services +DROP TABLE IF EXISTS k8s_core_service_ports; +DROP TABLE IF EXISTS k8s_core_service_load_balancer_ingress_ports; +DROP TABLE IF EXISTS k8s_core_service_load_balancer_ingresses; +DROP TABLE IF EXISTS k8s_core_service_conditions; +DROP TABLE IF EXISTS k8s_core_services; + +-- Resource: networking.network_policies +DROP TABLE IF EXISTS k8s_networking_network_policy_pod_selector_match_expressions; +DROP TABLE IF EXISTS k8s_networking_network_policy_ingress_ports; +DROP TABLE IF EXISTS k8s_networking_network_policy_ingress_from; +DROP TABLE IF EXISTS k8s_networking_network_policy_ingress; +DROP TABLE IF EXISTS k8s_networking_network_policy_egress_ports; +DROP TABLE IF EXISTS k8s_networking_network_policy_egress_to; +DROP TABLE IF EXISTS k8s_networking_network_policy_egress; +DROP TABLE IF EXISTS k8s_networking_network_policies; + +-- Resource: rbac.role_bindings +DROP TABLE IF EXISTS k8s_rbac_role_binding_subjects; +DROP TABLE IF EXISTS k8s_rbac_role_bindings; + +-- Resource: rbac.roles +DROP TABLE IF EXISTS k8s_rbac_role_rules; +DROP TABLE IF EXISTS k8s_rbac_roles; diff --git a/resources/provider/migrations/postgres/1_v0.4.0.up.sql b/resources/provider/migrations/postgres/1_v0.4.0.up.sql new file mode 100644 index 0000000..430074c --- /dev/null +++ b/resources/provider/migrations/postgres/1_v0.4.0.up.sql @@ -0,0 +1,1346 @@ +-- Autogenerated by migration tool on 2022-01-19 11:52:48 + +-- Resource: apps.daemon_sets +CREATE TABLE IF NOT EXISTS "k8s_apps_daemon_sets" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "context" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + "selector_match_labels" jsonb, + "template" jsonb, + "update_strategy_type" text, + "update_strategy_rolling_update_max_unavailable_type" bigint, + "update_strategy_rolling_update_max_unavailable_int_val" integer, + "update_strategy_rolling_update_max_unavailable_str_val" text, + "update_strategy_rolling_update_max_surge_type" bigint, + "update_strategy_rolling_update_max_surge_int_val" integer, + "update_strategy_rolling_update_max_surge_str_val" text, + "min_ready_seconds" integer, + "revision_history_limit" integer, + "status_current_number_scheduled" integer, + "status_number_misscheduled" integer, + "status_desired_number_scheduled" integer, + "status_number_ready" integer, + "status_observed_generation" bigint, + "status_updated_number_scheduled" integer, + "status_number_available" integer, + "status_number_unavailable" integer, + "status_collision_count" integer, + CONSTRAINT k8s_apps_daemon_sets_pk PRIMARY KEY(uid), + UNIQUE(cq_id) +); +CREATE TABLE IF NOT EXISTS "k8s_apps_daemon_set_selector_match_expressions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "daemon_set_cq_id" uuid, + "key" text, + "operator" text, + "values" text[], + CONSTRAINT k8s_apps_daemon_set_selector_match_expressions_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (daemon_set_cq_id) REFERENCES k8s_apps_daemon_sets(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_apps_daemon_set_status_conditions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "daemon_set_cq_id" uuid, + "type" text, + "status" text, + "reason" text, + "message" text, + CONSTRAINT k8s_apps_daemon_set_status_conditions_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (daemon_set_cq_id) REFERENCES k8s_apps_daemon_sets(cq_id) ON DELETE CASCADE +); + +-- Resource: apps.deployments +CREATE TABLE IF NOT EXISTS "k8s_apps_deployments" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + "replicas" integer, + "selector_match_labels" jsonb, + "template" jsonb, + "strategy_type" text, + "strategy_rolling_update_max_unavailable_type" bigint, + "strategy_rolling_update_max_unavailable_int_val" integer, + "strategy_rolling_update_max_unavailable_str_val" text, + "strategy_rolling_update_max_surge_type" bigint, + "strategy_rolling_update_max_surge_int_val" integer, + "strategy_rolling_update_max_surge_str_val" text, + "min_ready_seconds" integer, + "revision_history_limit" integer, + "paused" boolean, + "progress_deadline_seconds" integer, + "status_observed_generation" bigint, + "status_replicas" integer, + "status_updated_replicas" integer, + "status_ready_replicas" integer, + "status_available_replicas" integer, + "status_unavailable_replicas" integer, + "status_collision_count" integer, + CONSTRAINT k8s_apps_deployments_pk PRIMARY KEY(uid), + UNIQUE(cq_id) +); +CREATE TABLE IF NOT EXISTS "k8s_apps_deployment_selector_match_expressions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "deployment_cq_id" uuid, + "key" text, + "operator" text, + "values" text[], + CONSTRAINT k8s_apps_deployment_selector_match_expressions_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (deployment_cq_id) REFERENCES k8s_apps_deployments(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_apps_deployment_status_conditions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "deployment_cq_id" uuid, + "type" text, + "status" text, + "reason" text, + "message" text, + CONSTRAINT k8s_apps_deployment_status_conditions_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (deployment_cq_id) REFERENCES k8s_apps_deployments(cq_id) ON DELETE CASCADE +); + +-- Resource: apps.replica_sets +CREATE TABLE IF NOT EXISTS "k8s_apps_replica_sets" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "context" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + "replicas" integer, + "min_ready_seconds" integer, + "selector_match_labels" jsonb, + "template" jsonb, + "status_replicas" integer, + "status_fully_labeled_replicas" integer, + "status_ready_replicas" integer, + "status_available_replicas" integer, + "status_observed_generation" bigint, + CONSTRAINT k8s_apps_replica_sets_pk PRIMARY KEY(uid), + UNIQUE(cq_id) +); +CREATE TABLE IF NOT EXISTS "k8s_apps_replica_set_selector_match_expressions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "replica_set_cq_id" uuid, + "key" text, + "operator" text, + "values" text[], + CONSTRAINT k8s_apps_replica_set_selector_match_expressions_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (replica_set_cq_id) REFERENCES k8s_apps_replica_sets(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_apps_replica_set_status_conditions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "replica_set_cq_id" uuid, + "type" text, + "status" text, + "reason" text, + "message" text, + CONSTRAINT k8s_apps_replica_set_status_conditions_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (replica_set_cq_id) REFERENCES k8s_apps_replica_sets(cq_id) ON DELETE CASCADE +); + +-- Resource: apps.stateful_sets +CREATE TABLE IF NOT EXISTS "k8s_apps_stateful_sets" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "context" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + "replicas" integer, + "selector_match_labels" jsonb, + "template" jsonb, + "volume_claim_templates" jsonb, + "service_name" text, + "pod_management_policy" text, + "update_strategy_type" text, + "update_strategy_rolling_update_partition" integer, + "revision_history_limit" integer, + "min_ready_seconds" integer, + "status_observed_generation" bigint, + "status_replicas" integer, + "status_ready_replicas" integer, + "status_current_replicas" integer, + "status_updated_replicas" integer, + "status_current_revision" text, + "status_update_revision" text, + "status_collision_count" integer, + "status_available_replicas" integer, + CONSTRAINT k8s_apps_stateful_sets_pk PRIMARY KEY(uid), + UNIQUE(cq_id) +); +CREATE TABLE IF NOT EXISTS "k8s_apps_stateful_set_selector_match_expressions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "stateful_set_cq_id" uuid, + "key" text, + "operator" text, + "values" text[], + CONSTRAINT k8s_apps_stateful_set_selector_match_expressions_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (stateful_set_cq_id) REFERENCES k8s_apps_stateful_sets(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_apps_stateful_set_status_conditions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "stateful_set_cq_id" uuid, + "type" text, + "status" text, + "reason" text, + "message" text, + CONSTRAINT k8s_apps_stateful_set_status_conditions_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (stateful_set_cq_id) REFERENCES k8s_apps_stateful_sets(cq_id) ON DELETE CASCADE +); + +-- Resource: batch.cron_jobs +CREATE TABLE IF NOT EXISTS "k8s_batch_cron_jobs" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "context" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + "schedule" text, + "starting_deadline_seconds" bigint, + "concurrency_policy" text, + "suspend" boolean, + "job_template" jsonb, + "successful_jobs_history_limit" integer, + "failed_jobs_history_limit" integer, + "status" jsonb, + CONSTRAINT k8s_batch_cron_jobs_pk PRIMARY KEY(uid), + UNIQUE(cq_id) +); + +-- Resource: batch.jobs +CREATE TABLE IF NOT EXISTS "k8s_batch_jobs" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "context" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + "parallelism" integer, + "completions" integer, + "active_deadline_seconds" bigint, + "backoff_limit" integer, + "selector_match_labels" jsonb, + "manual_selector" boolean, + "template" jsonb, + "ttl_seconds_after_finished" integer, + "completion_mode" text, + "suspend" boolean, + "status_active" integer, + "status_succeeded" integer, + "status_failed" integer, + "status_completed_indexes" text, + "status_uncounted_terminated_pods_succeeded" text[], + "status_uncounted_terminated_pods_failed" text[], + CONSTRAINT k8s_batch_jobs_pk PRIMARY KEY(uid), + UNIQUE(cq_id) +); +CREATE TABLE IF NOT EXISTS "k8s_batch_job_selector_match_expressions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "job_cq_id" uuid, + "key" text, + "operator" text, + "values" text[], + CONSTRAINT k8s_batch_job_selector_match_expressions_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (job_cq_id) REFERENCES k8s_batch_jobs(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_batch_job_status_conditions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "job_cq_id" uuid, + "type" text, + "status" text, + "reason" text, + "message" text, + CONSTRAINT k8s_batch_job_status_conditions_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (job_cq_id) REFERENCES k8s_batch_jobs(cq_id) ON DELETE CASCADE +); + +-- Resource: core.endpoints +CREATE TABLE IF NOT EXISTS "k8s_core_endpoints" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + CONSTRAINT k8s_core_endpoints_pk PRIMARY KEY(uid), + UNIQUE(cq_id) +); +CREATE TABLE IF NOT EXISTS "k8s_core_endpoint_subsets" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "endpoint_cq_id" uuid, + "endpoint_name" text, + "endpoint_uid" text, + CONSTRAINT k8s_core_endpoint_subsets_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (endpoint_cq_id) REFERENCES k8s_core_endpoints(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_endpoint_subset_addresses" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "endpoint_subset_cq_id" uuid, + "ip" inet, + "hostname" text, + "node_name" text, + "target_ref_kind" text, + "target_ref_namespace" text, + "target_ref_name" text, + "target_ref_uid" text, + "target_ref_api_version" text, + "target_ref_resource_version" text, + "target_ref_field_path" text, + CONSTRAINT k8s_core_endpoint_subset_addresses_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (endpoint_subset_cq_id) REFERENCES k8s_core_endpoint_subsets(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_endpoint_subset_not_ready_addresses" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "endpoint_subset_cq_id" uuid, + "ip" inet, + "hostname" text, + "node_name" text, + "target_ref_kind" text, + "target_ref_namespace" text, + "target_ref_name" text, + "target_ref_uid" text, + "target_ref_api_version" text, + "target_ref_resource_version" text, + "target_ref_field_path" text, + CONSTRAINT k8s_core_endpoint_subset_not_ready_addresses_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (endpoint_subset_cq_id) REFERENCES k8s_core_endpoint_subsets(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_endpoint_subset_ports" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "endpoint_subset_cq_id" uuid, + "name" text, + "port" integer, + "protocol" text, + "app_protocol" text, + CONSTRAINT k8s_core_endpoint_subset_ports_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (endpoint_subset_cq_id) REFERENCES k8s_core_endpoint_subsets(cq_id) ON DELETE CASCADE +); + +-- Resource: core.limit_ranges +CREATE TABLE IF NOT EXISTS "k8s_core_limit_ranges" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + CONSTRAINT k8s_core_limit_ranges_pk PRIMARY KEY(uid), + UNIQUE(cq_id) +); +CREATE TABLE IF NOT EXISTS "k8s_core_limit_range_limits" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "limit_range_cq_id" uuid, + "type" text, + "max" jsonb, + "min" jsonb, + "default" jsonb, + "default_request" jsonb, + "max_limit_request_ratio" jsonb, + CONSTRAINT k8s_core_limit_range_limits_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (limit_range_cq_id) REFERENCES k8s_core_limit_ranges(cq_id) ON DELETE CASCADE +); + +-- Resource: core.namespaces +CREATE TABLE IF NOT EXISTS "k8s_core_namespaces" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + "spec_finalizers" text[], + "phase" text, + "conditions" jsonb, + CONSTRAINT k8s_core_namespaces_pk PRIMARY KEY(uid), + UNIQUE(cq_id) +); +CREATE TABLE IF NOT EXISTS "k8s_meta_owner_references" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "namespace_cq_id" uuid, + "resource_uid" text, + "api_version" text, + "kind" text, + "name" text, + "owner_uid" text, + "controller" boolean, + "block_owner_deletion" boolean, + CONSTRAINT k8s_meta_owner_references_pk PRIMARY KEY(resource_uid,owner_uid), + UNIQUE(cq_id), + FOREIGN KEY (namespace_cq_id) REFERENCES k8s_core_namespaces(cq_id) ON DELETE CASCADE +); + +-- Resource: core.nodes +CREATE TABLE IF NOT EXISTS "k8s_core_nodes" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "namespace" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "pod_cidr" cidr, + "pod_cidrs" cidr[], + "provider_id" text, + "unschedulable" boolean, + "taints" jsonb, + "capacity" jsonb, + "allocatable" jsonb, + "phase" text, + "conditions" jsonb, + "daemon_endpoints_kubelet_endpoint_port" integer, + "machine_id" text, + "system_uuid" text, + "boot_id" text, + "kernel_version" text, + "os_image" text, + "container_runtime_version" text, + "kubelet_version" text, + "kube_proxy_version" text, + "operating_system" text, + "architecture" text, + "volumes_in_use" text[], + "config" jsonb, + "hostname" text, + "internal_ip" inet, + "external_ip" inet, + CONSTRAINT k8s_core_nodes_pk PRIMARY KEY(uid), + UNIQUE(cq_id) +); +CREATE TABLE IF NOT EXISTS "k8s_core_node_images" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "node_cq_id" uuid, + "names" text[], + "size_bytes" bigint, + CONSTRAINT k8s_core_node_images_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (node_cq_id) REFERENCES k8s_core_nodes(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_node_volumes_attached" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "node_cq_id" uuid, + "name" text, + "device_path" text, + CONSTRAINT k8s_core_node_volumes_attached_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (node_cq_id) REFERENCES k8s_core_nodes(cq_id) ON DELETE CASCADE +); + +-- Resource: core.pods +CREATE TABLE IF NOT EXISTS "k8s_core_pods" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "namespace" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "restart_policy" text, + "termination_grace_period_seconds" bigint, + "active_deadline_seconds" bigint, + "dns_policy" text, + "node_selector" jsonb, + "service_account_name" text, + "automount_service_account_token" boolean, + "node_name" text, + "host_network" boolean, + "host_pid" boolean, + "host_ipc" boolean, + "share_process_namespace" boolean, + "security_context" jsonb, + "image_pull_secrets" jsonb, + "hostname" text, + "subdomain" text, + "affinity" jsonb, + "scheduler_name" text, + "tolerations" jsonb, + "host_aliases" jsonb, + "priority_class_name" text, + "priority" integer, + "dns_config" jsonb, + "readiness_gates" jsonb, + "runtime_class_name" text, + "enable_service_links" boolean, + "preemption_policy" text, + "overhead" jsonb, + "topology_spread_constraints" jsonb, + "set_hostname_as_fqdn" boolean, + "phase" text, + "conditions" jsonb, + "message" text, + "reason" text, + "nominated_node_name" text, + "host_ip" inet, + "pod_ip" inet, + "pod_ips" inet[], + "qos_class" text, + CONSTRAINT k8s_core_pods_pk PRIMARY KEY(uid), + UNIQUE(cq_id) +); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_init_containers" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "pod_cq_id" uuid, + "name" text, + "image" text, + "command" text[], + "args" text[], + "working_dir" text, + "env_from" jsonb, + "resources_limits" jsonb, + "resources_requests" jsonb, + "liveness_probe" jsonb, + "readiness_probe" jsonb, + "startup_probe" jsonb, + "lifecycle" jsonb, + "termination_message_path" text, + "termination_message_policy" text, + "image_pull_policy" text, + "security_context" jsonb, + "stdin" boolean, + "stdin_once" boolean, + "tty" boolean, + CONSTRAINT k8s_core_pod_init_containers_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (pod_cq_id) REFERENCES k8s_core_pods(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_init_container_ports" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "pod_init_container_cq_id" uuid, + "name" text, + "host_port" integer, + "container_port" integer, + "protocol" text, + "host_ip" text, + CONSTRAINT k8s_core_pod_init_container_ports_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (pod_init_container_cq_id) REFERENCES k8s_core_pod_init_containers(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_init_container_envs" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "pod_init_container_cq_id" uuid, + "name" text, + "value" text, + "value_from_field_ref_api_version" text, + "value_from_field_ref_field_path" text, + "value_from_resource_field_ref_container_name" text, + "value_from_resource_field_ref_resource" text, + "value_from_resource_field_ref_divisor_format" text, + "value_from_config_map_key_ref_local_object_reference_name" text, + "value_from_config_map_key_ref_key" text, + "value_from_config_map_key_ref_optional" boolean, + "value_from_secret_key_ref_local_object_reference_name" text, + "value_from_secret_key_ref_key" text, + "value_from_secret_key_ref_optional" boolean, + CONSTRAINT k8s_core_pod_init_container_envs_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (pod_init_container_cq_id) REFERENCES k8s_core_pod_init_containers(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_init_container_volume_mounts" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "pod_init_container_cq_id" uuid, + "name" text, + "read_only" boolean, + "mount_path" text, + "sub_path" text, + "mount_propagation" text, + "sub_path_expr" text, + CONSTRAINT k8s_core_pod_init_container_volume_mounts_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (pod_init_container_cq_id) REFERENCES k8s_core_pod_init_containers(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_init_container_volume_devices" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "pod_init_container_cq_id" uuid, + "name" text, + "device_path" text, + CONSTRAINT k8s_core_pod_init_container_volume_devices_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (pod_init_container_cq_id) REFERENCES k8s_core_pod_init_containers(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_containers" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "pod_cq_id" uuid, + "name" text, + "image" text, + "command" text[], + "args" text[], + "working_dir" text, + "env_from" jsonb, + "resources_limits" jsonb, + "resources_requests" jsonb, + "liveness_probe" jsonb, + "readiness_probe" jsonb, + "startup_probe" jsonb, + "lifecycle" jsonb, + "termination_message_path" text, + "termination_message_policy" text, + "image_pull_policy" text, + "security_context" jsonb, + "stdin" boolean, + "stdin_once" boolean, + "tty" boolean, + CONSTRAINT k8s_core_pod_containers_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (pod_cq_id) REFERENCES k8s_core_pods(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_container_ports" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "pod_container_cq_id" uuid, + "name" text, + "host_port" integer, + "container_port" integer, + "protocol" text, + "host_ip" text, + CONSTRAINT k8s_core_pod_container_ports_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (pod_container_cq_id) REFERENCES k8s_core_pod_containers(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_container_envs" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "pod_container_cq_id" uuid, + "name" text, + "value" text, + "value_from_field_ref_api_version" text, + "value_from_field_ref_field_path" text, + "value_from_resource_field_ref_container_name" text, + "value_from_resource_field_ref_resource" text, + "value_from_resource_field_ref_divisor_format" text, + "value_from_config_map_key_ref_local_object_reference_name" text, + "value_from_config_map_key_ref_key" text, + "value_from_config_map_key_ref_optional" boolean, + "value_from_secret_key_ref_local_object_reference_name" text, + "value_from_secret_key_ref_key" text, + "value_from_secret_key_ref_optional" boolean, + CONSTRAINT k8s_core_pod_container_envs_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (pod_container_cq_id) REFERENCES k8s_core_pod_containers(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_container_volume_mounts" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "pod_container_cq_id" uuid, + "name" text, + "read_only" boolean, + "mount_path" text, + "sub_path" text, + "mount_propagation" text, + "sub_path_expr" text, + CONSTRAINT k8s_core_pod_container_volume_mounts_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (pod_container_cq_id) REFERENCES k8s_core_pod_containers(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_container_volume_devices" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "pod_container_cq_id" uuid, + "name" text, + "device_path" text, + CONSTRAINT k8s_core_pod_container_volume_devices_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (pod_container_cq_id) REFERENCES k8s_core_pod_containers(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_ephemeral_containers" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "target_container_name" text, + "pod_cq_id" uuid, + "name" text, + "image" text, + "command" text[], + "args" text[], + "working_dir" text, + "env_from" jsonb, + "resources_limits" jsonb, + "resources_requests" jsonb, + "liveness_probe" jsonb, + "readiness_probe" jsonb, + "startup_probe" jsonb, + "lifecycle" jsonb, + "termination_message_path" text, + "termination_message_policy" text, + "image_pull_policy" text, + "security_context" jsonb, + "stdin" boolean, + "stdin_once" boolean, + "tty" boolean, + CONSTRAINT k8s_core_pod_ephemeral_containers_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (pod_cq_id) REFERENCES k8s_core_pods(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_ephemeral_container_ports" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "pod_ephemeral_container_cq_id" uuid, + "name" text, + "host_port" integer, + "container_port" integer, + "protocol" text, + "host_ip" text, + CONSTRAINT k8s_core_pod_ephemeral_container_ports_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (pod_ephemeral_container_cq_id) REFERENCES k8s_core_pod_ephemeral_containers(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_ephemeral_container_envs" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "pod_ephemeral_container_cq_id" uuid, + "name" text, + "value" text, + "value_from_field_ref_api_version" text, + "value_from_field_ref_field_path" text, + "value_from_resource_field_ref_container_name" text, + "value_from_resource_field_ref_resource" text, + "value_from_resource_field_ref_divisor_format" text, + "value_from_config_map_key_ref_local_object_reference_name" text, + "value_from_config_map_key_ref_key" text, + "value_from_config_map_key_ref_optional" boolean, + "value_from_secret_key_ref_local_object_reference_name" text, + "value_from_secret_key_ref_key" text, + "value_from_secret_key_ref_optional" boolean, + CONSTRAINT k8s_core_pod_ephemeral_container_envs_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (pod_ephemeral_container_cq_id) REFERENCES k8s_core_pod_ephemeral_containers(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_ephemeral_container_volume_mounts" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "pod_ephemeral_container_cq_id" uuid, + "name" text, + "read_only" boolean, + "mount_path" text, + "sub_path" text, + "mount_propagation" text, + "sub_path_expr" text, + CONSTRAINT k8s_core_pod_ephemeral_container_volume_mounts_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (pod_ephemeral_container_cq_id) REFERENCES k8s_core_pod_ephemeral_containers(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_ephemeral_container_volume_devices" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "pod_ephemeral_container_cq_id" uuid, + "name" text, + "device_path" text, + CONSTRAINT k8s_core_pod_ephemeral_container_volume_devices_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (pod_ephemeral_container_cq_id) REFERENCES k8s_core_pod_ephemeral_containers(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_volumes" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "pod_cq_id" uuid, + "name" text, + "host_path" jsonb, + "empty_dir" jsonb, + "gce_persistent_disk" jsonb, + "aws_elastic_block_store" jsonb, + "secret" jsonb, + "nfs" jsonb, + "iscsi" jsonb, + "glusterfs" jsonb, + "persistent_volume_claim" jsonb, + "rbd" jsonb, + "flex_volume" jsonb, + "cinder" jsonb, + "ceph_fs" jsonb, + "flocker" jsonb, + "downward_api" jsonb, + "fc" jsonb, + "azure_file" jsonb, + "config_map" jsonb, + "vsphere_volume" jsonb, + "quobyte" jsonb, + "azure_disk" jsonb, + "photon_persistent_disk" jsonb, + "projected" jsonb, + "portworx_volume" jsonb, + "scale_io" jsonb, + "storage_os" jsonb, + "csi" jsonb, + "ephemeral" jsonb, + CONSTRAINT k8s_core_pod_volumes_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (pod_cq_id) REFERENCES k8s_core_pods(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_init_container_statuses" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "pod_cq_id" uuid, + "name" text, + "state" jsonb, + "last_state" jsonb, + "ready" boolean, + "restart_count" integer, + "image" text, + "image_id" text, + "container_id" text, + "started" boolean, + CONSTRAINT k8s_core_pod_init_container_statuses_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (pod_cq_id) REFERENCES k8s_core_pods(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_container_statuses" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "pod_cq_id" uuid, + "name" text, + "state" jsonb, + "last_state" jsonb, + "ready" boolean, + "restart_count" integer, + "image" text, + "image_id" text, + "container_id" text, + "started" boolean, + CONSTRAINT k8s_core_pod_container_statuses_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (pod_cq_id) REFERENCES k8s_core_pods(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_ephemeral_container_statuses" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "pod_cq_id" uuid, + "name" text, + "state" jsonb, + "last_state" jsonb, + "ready" boolean, + "restart_count" integer, + "image" text, + "image_id" text, + "container_id" text, + "started" boolean, + CONSTRAINT k8s_core_pod_ephemeral_container_statuses_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (pod_cq_id) REFERENCES k8s_core_pods(cq_id) ON DELETE CASCADE +); + +-- Resource: core.resource_quotas +CREATE TABLE IF NOT EXISTS "k8s_core_resource_quotas" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + "hard" jsonb, + "scopes" text[], + "status_hard" jsonb, + "status_used" jsonb, + CONSTRAINT k8s_core_resource_quotas_pk PRIMARY KEY(uid), + UNIQUE(cq_id) +); +CREATE TABLE IF NOT EXISTS "k8s_core_resource_quota_scope_selector_match_expressions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "resource_quota_cq_id" uuid, + "scope_name" text, + "operator" text, + "values" text[], + CONSTRAINT k8s_core_resource_quota_scope_selector_match_expressions_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (resource_quota_cq_id) REFERENCES k8s_core_resource_quotas(cq_id) ON DELETE CASCADE +); + +-- Resource: core.service_accounts +CREATE TABLE IF NOT EXISTS "k8s_core_service_accounts" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + "automount_service_account_token" boolean, + "pull_secret_names" text[], + CONSTRAINT k8s_core_service_accounts_pk PRIMARY KEY(uid), + UNIQUE(cq_id) +); +CREATE TABLE IF NOT EXISTS "k8s_core_service_account_secrets" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "service_account_cq_id" uuid, + "kind" text, + "namespace" text, + "name" text, + "uid" text, + "api_version" text, + "resource_version" text, + "field_path" text, + CONSTRAINT k8s_core_service_account_secrets_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (service_account_cq_id) REFERENCES k8s_core_service_accounts(cq_id) ON DELETE CASCADE +); + +-- Resource: core.services +CREATE TABLE IF NOT EXISTS "k8s_core_services" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "namespace" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "selector" jsonb, + "cluster_ip" inet, + "cluster_ips" inet[], + "type" text, + "external_ips" inet[], + "session_affinity" text, + "load_balancer_ip" text, + "load_balancer_source_ranges" text[], + "external_name" text, + "external_traffic_policy" text, + "health_check_node_port" integer, + "publish_not_ready_addresses" boolean, + "session_affinity_config_client_ip_timeout_seconds" integer, + "ip_families" text[], + "ip_family_policy" text, + "allocate_load_balancer_node_ports" boolean, + "load_balancer_class" text, + "internal_traffic_policy" text, + CONSTRAINT k8s_core_services_pk PRIMARY KEY(uid), + UNIQUE(cq_id) +); +CREATE TABLE IF NOT EXISTS "k8s_core_service_ports" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "service_cq_id" uuid, + "name" text, + "protocol" text, + "app_protocol" text, + "port" integer, + "target_port_type" bigint, + "target_port_int_val" integer, + "target_port_str_val" text, + "node_port" integer, + CONSTRAINT k8s_core_service_ports_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (service_cq_id) REFERENCES k8s_core_services(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_service_load_balancer_ingresses" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "service_cq_id" uuid, + "ip" text, + "hostname" text, + CONSTRAINT k8s_core_service_load_balancer_ingresses_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (service_cq_id) REFERENCES k8s_core_services(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_service_load_balancer_ingress_ports" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "service_load_balancer_ingress_cq_id" uuid, + "port" integer, + "protocol" text, + "error" text, + CONSTRAINT k8s_core_service_load_balancer_ingress_ports_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (service_load_balancer_ingress_cq_id) REFERENCES k8s_core_service_load_balancer_ingresses(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_core_service_conditions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "service_cq_id" uuid, + "type" text, + "status" text, + "observed_generation" bigint, + "reason" text, + "message" text, + CONSTRAINT k8s_core_service_conditions_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (service_cq_id) REFERENCES k8s_core_services(cq_id) ON DELETE CASCADE +); + +-- Resource: networking.network_policies +CREATE TABLE IF NOT EXISTS "k8s_networking_network_policies" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + "pod_selector_match_labels" jsonb, + "policy_types" text[], + CONSTRAINT k8s_networking_network_policies_pk PRIMARY KEY(uid), + UNIQUE(cq_id) +); +CREATE TABLE IF NOT EXISTS "k8s_networking_network_policy_pod_selector_match_expressions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "network_policy_cq_id" uuid, + "key" text, + "operator" text, + "values" text[], + CONSTRAINT k8s_networking_network_policy_pod_selector_match_expressions_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (network_policy_cq_id) REFERENCES k8s_networking_network_policies(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_networking_network_policy_ingress" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "network_policy_cq_id" uuid, + "network_policy_uid" text, + CONSTRAINT k8s_networking_network_policy_ingress_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (network_policy_cq_id) REFERENCES k8s_networking_network_policies(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_networking_network_policy_ingress_ports" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "network_policy_ingress_cq_id" uuid, + "protocol" text, + "port_type" bigint, + "port_int_val" integer, + "port_str_val" text, + "end_port" integer, + CONSTRAINT k8s_networking_network_policy_ingress_ports_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (network_policy_ingress_cq_id) REFERENCES k8s_networking_network_policy_ingress(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_networking_network_policy_ingress_from" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "network_policy_ingress_cq_id" uuid, + "pod_selector_match_labels" jsonb, + "pod_selector_match_expressions" jsonb, + "namespace_selector_match_labels" jsonb, + "namespace_selector_match_expressions" jsonb, + "ip_block_cidr" text, + "ip_block_except" text[], + CONSTRAINT k8s_networking_network_policy_ingress_from_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (network_policy_ingress_cq_id) REFERENCES k8s_networking_network_policy_ingress(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_networking_network_policy_egress" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "network_policy_cq_id" uuid, + "network_policy_uid" text, + CONSTRAINT k8s_networking_network_policy_egress_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (network_policy_cq_id) REFERENCES k8s_networking_network_policies(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_networking_network_policy_egress_ports" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "network_policy_egress_cq_id" uuid, + "protocol" text, + "port_type" bigint, + "port_int_val" integer, + "port_str_val" text, + "end_port" integer, + CONSTRAINT k8s_networking_network_policy_egress_ports_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (network_policy_egress_cq_id) REFERENCES k8s_networking_network_policy_egress(cq_id) ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "k8s_networking_network_policy_egress_to" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "network_policy_egress_cq_id" uuid, + "pod_selector_match_labels" jsonb, + "pod_selector_match_expressions" jsonb, + "namespace_selector_match_labels" jsonb, + "namespace_selector_match_expressions" jsonb, + "ip_block_cidr" text, + "ip_block_except" text[], + CONSTRAINT k8s_networking_network_policy_egress_to_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (network_policy_egress_cq_id) REFERENCES k8s_networking_network_policy_egress(cq_id) ON DELETE CASCADE +); + +-- Resource: rbac.role_bindings +CREATE TABLE IF NOT EXISTS "k8s_rbac_role_bindings" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + "role_ref_api_group" text, + "role_ref_kind" text, + "role_ref_name" text, + CONSTRAINT k8s_rbac_role_bindings_pk PRIMARY KEY(uid), + UNIQUE(cq_id) +); +CREATE TABLE IF NOT EXISTS "k8s_rbac_role_binding_subjects" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "role_binding_cq_id" uuid, + "kind" text, + "api_group" text, + "name" text, + "namespace" text, + CONSTRAINT k8s_rbac_role_binding_subjects_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (role_binding_cq_id) REFERENCES k8s_rbac_role_bindings(cq_id) ON DELETE CASCADE +); + +-- Resource: rbac.roles +CREATE TABLE IF NOT EXISTS "k8s_rbac_roles" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + CONSTRAINT k8s_rbac_roles_pk PRIMARY KEY(uid), + UNIQUE(cq_id) +); +CREATE TABLE IF NOT EXISTS "k8s_rbac_role_rules" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "role_cq_id" uuid, + "verbs" text[], + "api_groups" text[], + "resources" text[], + "resource_names" text[], + "non_resource_urls" text[], + CONSTRAINT k8s_rbac_role_rules_pk PRIMARY KEY(cq_id), + UNIQUE(cq_id), + FOREIGN KEY (role_cq_id) REFERENCES k8s_rbac_roles(cq_id) ON DELETE CASCADE +); diff --git a/resources/provider/migrations/timescale/1_v0.4.0.down.sql b/resources/provider/migrations/timescale/1_v0.4.0.down.sql new file mode 100644 index 0000000..1d1aa6b --- /dev/null +++ b/resources/provider/migrations/timescale/1_v0.4.0.down.sql @@ -0,0 +1,104 @@ +-- Autogenerated by migration tool on 2022-01-19 11:52:48 + +-- Resource: apps.daemon_sets +DROP TABLE IF EXISTS k8s_apps_daemon_set_selector_match_expressions; +DROP TABLE IF EXISTS k8s_apps_daemon_set_status_conditions; +DROP TABLE IF EXISTS k8s_apps_daemon_sets; + +-- Resource: apps.deployments +DROP TABLE IF EXISTS k8s_apps_deployment_selector_match_expressions; +DROP TABLE IF EXISTS k8s_apps_deployment_status_conditions; +DROP TABLE IF EXISTS k8s_apps_deployments; + +-- Resource: apps.replica_sets +DROP TABLE IF EXISTS k8s_apps_replica_set_selector_match_expressions; +DROP TABLE IF EXISTS k8s_apps_replica_set_status_conditions; +DROP TABLE IF EXISTS k8s_apps_replica_sets; + +-- Resource: apps.stateful_sets +DROP TABLE IF EXISTS k8s_apps_stateful_set_selector_match_expressions; +DROP TABLE IF EXISTS k8s_apps_stateful_set_status_conditions; +DROP TABLE IF EXISTS k8s_apps_stateful_sets; + +-- Resource: batch.cron_jobs +DROP TABLE IF EXISTS k8s_batch_cron_jobs; + +-- Resource: batch.jobs +DROP TABLE IF EXISTS k8s_batch_job_selector_match_expressions; +DROP TABLE IF EXISTS k8s_batch_job_status_conditions; +DROP TABLE IF EXISTS k8s_batch_jobs; + +-- Resource: core.endpoints +DROP TABLE IF EXISTS k8s_core_endpoint_subset_addresses; +DROP TABLE IF EXISTS k8s_core_endpoint_subset_not_ready_addresses; +DROP TABLE IF EXISTS k8s_core_endpoint_subset_ports; +DROP TABLE IF EXISTS k8s_core_endpoint_subsets; +DROP TABLE IF EXISTS k8s_core_endpoints; + +-- Resource: core.limit_ranges +DROP TABLE IF EXISTS k8s_core_limit_range_limits; +DROP TABLE IF EXISTS k8s_core_limit_ranges; + +-- Resource: core.namespaces +DROP TABLE IF EXISTS k8s_meta_owner_references; +DROP TABLE IF EXISTS k8s_core_namespaces; + +-- Resource: core.nodes +DROP TABLE IF EXISTS k8s_core_node_images; +DROP TABLE IF EXISTS k8s_core_node_volumes_attached; +DROP TABLE IF EXISTS k8s_core_nodes; + +-- Resource: core.pods +DROP TABLE IF EXISTS k8s_core_pod_init_container_ports; +DROP TABLE IF EXISTS k8s_core_pod_init_container_envs; +DROP TABLE IF EXISTS k8s_core_pod_init_container_volume_mounts; +DROP TABLE IF EXISTS k8s_core_pod_init_container_volume_devices; +DROP TABLE IF EXISTS k8s_core_pod_init_containers; +DROP TABLE IF EXISTS k8s_core_pod_container_ports; +DROP TABLE IF EXISTS k8s_core_pod_container_envs; +DROP TABLE IF EXISTS k8s_core_pod_container_volume_mounts; +DROP TABLE IF EXISTS k8s_core_pod_container_volume_devices; +DROP TABLE IF EXISTS k8s_core_pod_containers; +DROP TABLE IF EXISTS k8s_core_pod_ephemeral_container_ports; +DROP TABLE IF EXISTS k8s_core_pod_ephemeral_container_envs; +DROP TABLE IF EXISTS k8s_core_pod_ephemeral_container_volume_mounts; +DROP TABLE IF EXISTS k8s_core_pod_ephemeral_container_volume_devices; +DROP TABLE IF EXISTS k8s_core_pod_ephemeral_containers; +DROP TABLE IF EXISTS k8s_core_pod_volumes; +DROP TABLE IF EXISTS k8s_core_pod_init_container_statuses; +DROP TABLE IF EXISTS k8s_core_pod_container_statuses; +DROP TABLE IF EXISTS k8s_core_pod_ephemeral_container_statuses; +DROP TABLE IF EXISTS k8s_core_pods; + +-- Resource: core.resource_quotas +DROP TABLE IF EXISTS k8s_core_resource_quota_scope_selector_match_expressions; +DROP TABLE IF EXISTS k8s_core_resource_quotas; + +-- Resource: core.service_accounts +DROP TABLE IF EXISTS k8s_core_service_account_secrets; +DROP TABLE IF EXISTS k8s_core_service_accounts; + +-- Resource: core.services +DROP TABLE IF EXISTS k8s_core_service_ports; +DROP TABLE IF EXISTS k8s_core_service_load_balancer_ingress_ports; +DROP TABLE IF EXISTS k8s_core_service_load_balancer_ingresses; +DROP TABLE IF EXISTS k8s_core_service_conditions; +DROP TABLE IF EXISTS k8s_core_services; + +-- Resource: networking.network_policies +DROP TABLE IF EXISTS k8s_networking_network_policy_pod_selector_match_expressions; +DROP TABLE IF EXISTS k8s_networking_network_policy_ingress_ports; +DROP TABLE IF EXISTS k8s_networking_network_policy_ingress_from; +DROP TABLE IF EXISTS k8s_networking_network_policy_ingress; +DROP TABLE IF EXISTS k8s_networking_network_policy_egress_ports; +DROP TABLE IF EXISTS k8s_networking_network_policy_egress_to; +DROP TABLE IF EXISTS k8s_networking_network_policy_egress; +DROP TABLE IF EXISTS k8s_networking_network_policies; + +-- Resource: rbac.role_bindings +DROP TABLE IF EXISTS k8s_rbac_role_binding_subjects; +DROP TABLE IF EXISTS k8s_rbac_role_bindings; + +-- Resource: rbac.roles +DROP TABLE IF EXISTS k8s_rbac_role_rules; +DROP TABLE IF EXISTS k8s_rbac_roles; diff --git a/resources/provider/migrations/timescale/1_v0.4.0.up.sql b/resources/provider/migrations/timescale/1_v0.4.0.up.sql new file mode 100644 index 0000000..c2cc135 --- /dev/null +++ b/resources/provider/migrations/timescale/1_v0.4.0.up.sql @@ -0,0 +1,1484 @@ +-- Autogenerated by migration tool on 2022-01-19 11:52:48 + +-- Resource: apps.daemon_sets +CREATE TABLE IF NOT EXISTS "k8s_apps_daemon_sets" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "context" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + "selector_match_labels" jsonb, + "template" jsonb, + "update_strategy_type" text, + "update_strategy_rolling_update_max_unavailable_type" bigint, + "update_strategy_rolling_update_max_unavailable_int_val" integer, + "update_strategy_rolling_update_max_unavailable_str_val" text, + "update_strategy_rolling_update_max_surge_type" bigint, + "update_strategy_rolling_update_max_surge_int_val" integer, + "update_strategy_rolling_update_max_surge_str_val" text, + "min_ready_seconds" integer, + "revision_history_limit" integer, + "status_current_number_scheduled" integer, + "status_number_misscheduled" integer, + "status_desired_number_scheduled" integer, + "status_number_ready" integer, + "status_observed_generation" bigint, + "status_updated_number_scheduled" integer, + "status_number_available" integer, + "status_number_unavailable" integer, + "status_collision_count" integer, + CONSTRAINT k8s_apps_daemon_sets_pk PRIMARY KEY(cq_fetch_date,uid), + UNIQUE(cq_fetch_date,cq_id) +); +SELECT setup_tsdb_parent('k8s_apps_daemon_sets'); +CREATE TABLE IF NOT EXISTS "k8s_apps_daemon_set_selector_match_expressions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "daemon_set_cq_id" uuid, + "key" text, + "operator" text, + "values" text[], + CONSTRAINT k8s_apps_daemon_set_selector_match_expressions_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_apps_daemon_set_selector_match_expressions (cq_fetch_date, daemon_set_cq_id); +SELECT setup_tsdb_child('k8s_apps_daemon_set_selector_match_expressions', 'daemon_set_cq_id', 'k8s_apps_daemon_sets', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_apps_daemon_set_status_conditions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "daemon_set_cq_id" uuid, + "type" text, + "status" text, + "reason" text, + "message" text, + CONSTRAINT k8s_apps_daemon_set_status_conditions_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_apps_daemon_set_status_conditions (cq_fetch_date, daemon_set_cq_id); +SELECT setup_tsdb_child('k8s_apps_daemon_set_status_conditions', 'daemon_set_cq_id', 'k8s_apps_daemon_sets', 'cq_id'); + +-- Resource: apps.deployments +CREATE TABLE IF NOT EXISTS "k8s_apps_deployments" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + "replicas" integer, + "selector_match_labels" jsonb, + "template" jsonb, + "strategy_type" text, + "strategy_rolling_update_max_unavailable_type" bigint, + "strategy_rolling_update_max_unavailable_int_val" integer, + "strategy_rolling_update_max_unavailable_str_val" text, + "strategy_rolling_update_max_surge_type" bigint, + "strategy_rolling_update_max_surge_int_val" integer, + "strategy_rolling_update_max_surge_str_val" text, + "min_ready_seconds" integer, + "revision_history_limit" integer, + "paused" boolean, + "progress_deadline_seconds" integer, + "status_observed_generation" bigint, + "status_replicas" integer, + "status_updated_replicas" integer, + "status_ready_replicas" integer, + "status_available_replicas" integer, + "status_unavailable_replicas" integer, + "status_collision_count" integer, + CONSTRAINT k8s_apps_deployments_pk PRIMARY KEY(cq_fetch_date,uid), + UNIQUE(cq_fetch_date,cq_id) +); +SELECT setup_tsdb_parent('k8s_apps_deployments'); +CREATE TABLE IF NOT EXISTS "k8s_apps_deployment_selector_match_expressions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "deployment_cq_id" uuid, + "key" text, + "operator" text, + "values" text[], + CONSTRAINT k8s_apps_deployment_selector_match_expressions_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_apps_deployment_selector_match_expressions (cq_fetch_date, deployment_cq_id); +SELECT setup_tsdb_child('k8s_apps_deployment_selector_match_expressions', 'deployment_cq_id', 'k8s_apps_deployments', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_apps_deployment_status_conditions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "deployment_cq_id" uuid, + "type" text, + "status" text, + "reason" text, + "message" text, + CONSTRAINT k8s_apps_deployment_status_conditions_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_apps_deployment_status_conditions (cq_fetch_date, deployment_cq_id); +SELECT setup_tsdb_child('k8s_apps_deployment_status_conditions', 'deployment_cq_id', 'k8s_apps_deployments', 'cq_id'); + +-- Resource: apps.replica_sets +CREATE TABLE IF NOT EXISTS "k8s_apps_replica_sets" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "context" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + "replicas" integer, + "min_ready_seconds" integer, + "selector_match_labels" jsonb, + "template" jsonb, + "status_replicas" integer, + "status_fully_labeled_replicas" integer, + "status_ready_replicas" integer, + "status_available_replicas" integer, + "status_observed_generation" bigint, + CONSTRAINT k8s_apps_replica_sets_pk PRIMARY KEY(cq_fetch_date,uid), + UNIQUE(cq_fetch_date,cq_id) +); +SELECT setup_tsdb_parent('k8s_apps_replica_sets'); +CREATE TABLE IF NOT EXISTS "k8s_apps_replica_set_selector_match_expressions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "replica_set_cq_id" uuid, + "key" text, + "operator" text, + "values" text[], + CONSTRAINT k8s_apps_replica_set_selector_match_expressions_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_apps_replica_set_selector_match_expressions (cq_fetch_date, replica_set_cq_id); +SELECT setup_tsdb_child('k8s_apps_replica_set_selector_match_expressions', 'replica_set_cq_id', 'k8s_apps_replica_sets', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_apps_replica_set_status_conditions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "replica_set_cq_id" uuid, + "type" text, + "status" text, + "reason" text, + "message" text, + CONSTRAINT k8s_apps_replica_set_status_conditions_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_apps_replica_set_status_conditions (cq_fetch_date, replica_set_cq_id); +SELECT setup_tsdb_child('k8s_apps_replica_set_status_conditions', 'replica_set_cq_id', 'k8s_apps_replica_sets', 'cq_id'); + +-- Resource: apps.stateful_sets +CREATE TABLE IF NOT EXISTS "k8s_apps_stateful_sets" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "context" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + "replicas" integer, + "selector_match_labels" jsonb, + "template" jsonb, + "volume_claim_templates" jsonb, + "service_name" text, + "pod_management_policy" text, + "update_strategy_type" text, + "update_strategy_rolling_update_partition" integer, + "revision_history_limit" integer, + "min_ready_seconds" integer, + "status_observed_generation" bigint, + "status_replicas" integer, + "status_ready_replicas" integer, + "status_current_replicas" integer, + "status_updated_replicas" integer, + "status_current_revision" text, + "status_update_revision" text, + "status_collision_count" integer, + "status_available_replicas" integer, + CONSTRAINT k8s_apps_stateful_sets_pk PRIMARY KEY(cq_fetch_date,uid), + UNIQUE(cq_fetch_date,cq_id) +); +SELECT setup_tsdb_parent('k8s_apps_stateful_sets'); +CREATE TABLE IF NOT EXISTS "k8s_apps_stateful_set_selector_match_expressions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "stateful_set_cq_id" uuid, + "key" text, + "operator" text, + "values" text[], + CONSTRAINT k8s_apps_stateful_set_selector_match_expressions_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_apps_stateful_set_selector_match_expressions (cq_fetch_date, stateful_set_cq_id); +SELECT setup_tsdb_child('k8s_apps_stateful_set_selector_match_expressions', 'stateful_set_cq_id', 'k8s_apps_stateful_sets', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_apps_stateful_set_status_conditions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "stateful_set_cq_id" uuid, + "type" text, + "status" text, + "reason" text, + "message" text, + CONSTRAINT k8s_apps_stateful_set_status_conditions_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_apps_stateful_set_status_conditions (cq_fetch_date, stateful_set_cq_id); +SELECT setup_tsdb_child('k8s_apps_stateful_set_status_conditions', 'stateful_set_cq_id', 'k8s_apps_stateful_sets', 'cq_id'); + +-- Resource: batch.cron_jobs +CREATE TABLE IF NOT EXISTS "k8s_batch_cron_jobs" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "context" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + "schedule" text, + "starting_deadline_seconds" bigint, + "concurrency_policy" text, + "suspend" boolean, + "job_template" jsonb, + "successful_jobs_history_limit" integer, + "failed_jobs_history_limit" integer, + "status" jsonb, + CONSTRAINT k8s_batch_cron_jobs_pk PRIMARY KEY(cq_fetch_date,uid), + UNIQUE(cq_fetch_date,cq_id) +); +SELECT setup_tsdb_parent('k8s_batch_cron_jobs'); + +-- Resource: batch.jobs +CREATE TABLE IF NOT EXISTS "k8s_batch_jobs" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "context" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + "parallelism" integer, + "completions" integer, + "active_deadline_seconds" bigint, + "backoff_limit" integer, + "selector_match_labels" jsonb, + "manual_selector" boolean, + "template" jsonb, + "ttl_seconds_after_finished" integer, + "completion_mode" text, + "suspend" boolean, + "status_active" integer, + "status_succeeded" integer, + "status_failed" integer, + "status_completed_indexes" text, + "status_uncounted_terminated_pods_succeeded" text[], + "status_uncounted_terminated_pods_failed" text[], + CONSTRAINT k8s_batch_jobs_pk PRIMARY KEY(cq_fetch_date,uid), + UNIQUE(cq_fetch_date,cq_id) +); +SELECT setup_tsdb_parent('k8s_batch_jobs'); +CREATE TABLE IF NOT EXISTS "k8s_batch_job_selector_match_expressions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "job_cq_id" uuid, + "key" text, + "operator" text, + "values" text[], + CONSTRAINT k8s_batch_job_selector_match_expressions_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_batch_job_selector_match_expressions (cq_fetch_date, job_cq_id); +SELECT setup_tsdb_child('k8s_batch_job_selector_match_expressions', 'job_cq_id', 'k8s_batch_jobs', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_batch_job_status_conditions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "job_cq_id" uuid, + "type" text, + "status" text, + "reason" text, + "message" text, + CONSTRAINT k8s_batch_job_status_conditions_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_batch_job_status_conditions (cq_fetch_date, job_cq_id); +SELECT setup_tsdb_child('k8s_batch_job_status_conditions', 'job_cq_id', 'k8s_batch_jobs', 'cq_id'); + +-- Resource: core.endpoints +CREATE TABLE IF NOT EXISTS "k8s_core_endpoints" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + CONSTRAINT k8s_core_endpoints_pk PRIMARY KEY(cq_fetch_date,uid), + UNIQUE(cq_fetch_date,cq_id) +); +SELECT setup_tsdb_parent('k8s_core_endpoints'); +CREATE TABLE IF NOT EXISTS "k8s_core_endpoint_subsets" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "endpoint_cq_id" uuid, + "endpoint_name" text, + "endpoint_uid" text, + CONSTRAINT k8s_core_endpoint_subsets_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_endpoint_subsets (cq_fetch_date, endpoint_cq_id); +SELECT setup_tsdb_child('k8s_core_endpoint_subsets', 'endpoint_cq_id', 'k8s_core_endpoints', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_endpoint_subset_addresses" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "endpoint_subset_cq_id" uuid, + "ip" inet, + "hostname" text, + "node_name" text, + "target_ref_kind" text, + "target_ref_namespace" text, + "target_ref_name" text, + "target_ref_uid" text, + "target_ref_api_version" text, + "target_ref_resource_version" text, + "target_ref_field_path" text, + CONSTRAINT k8s_core_endpoint_subset_addresses_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_endpoint_subset_addresses (cq_fetch_date, endpoint_subset_cq_id); +SELECT setup_tsdb_child('k8s_core_endpoint_subset_addresses', 'endpoint_subset_cq_id', 'k8s_core_endpoint_subsets', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_endpoint_subset_not_ready_addresses" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "endpoint_subset_cq_id" uuid, + "ip" inet, + "hostname" text, + "node_name" text, + "target_ref_kind" text, + "target_ref_namespace" text, + "target_ref_name" text, + "target_ref_uid" text, + "target_ref_api_version" text, + "target_ref_resource_version" text, + "target_ref_field_path" text, + CONSTRAINT k8s_core_endpoint_subset_not_ready_addresses_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_endpoint_subset_not_ready_addresses (cq_fetch_date, endpoint_subset_cq_id); +SELECT setup_tsdb_child('k8s_core_endpoint_subset_not_ready_addresses', 'endpoint_subset_cq_id', 'k8s_core_endpoint_subsets', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_endpoint_subset_ports" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "endpoint_subset_cq_id" uuid, + "name" text, + "port" integer, + "protocol" text, + "app_protocol" text, + CONSTRAINT k8s_core_endpoint_subset_ports_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_endpoint_subset_ports (cq_fetch_date, endpoint_subset_cq_id); +SELECT setup_tsdb_child('k8s_core_endpoint_subset_ports', 'endpoint_subset_cq_id', 'k8s_core_endpoint_subsets', 'cq_id'); + +-- Resource: core.limit_ranges +CREATE TABLE IF NOT EXISTS "k8s_core_limit_ranges" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + CONSTRAINT k8s_core_limit_ranges_pk PRIMARY KEY(cq_fetch_date,uid), + UNIQUE(cq_fetch_date,cq_id) +); +SELECT setup_tsdb_parent('k8s_core_limit_ranges'); +CREATE TABLE IF NOT EXISTS "k8s_core_limit_range_limits" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "limit_range_cq_id" uuid, + "type" text, + "max" jsonb, + "min" jsonb, + "default" jsonb, + "default_request" jsonb, + "max_limit_request_ratio" jsonb, + CONSTRAINT k8s_core_limit_range_limits_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_limit_range_limits (cq_fetch_date, limit_range_cq_id); +SELECT setup_tsdb_child('k8s_core_limit_range_limits', 'limit_range_cq_id', 'k8s_core_limit_ranges', 'cq_id'); + +-- Resource: core.namespaces +CREATE TABLE IF NOT EXISTS "k8s_core_namespaces" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + "spec_finalizers" text[], + "phase" text, + "conditions" jsonb, + CONSTRAINT k8s_core_namespaces_pk PRIMARY KEY(cq_fetch_date,uid), + UNIQUE(cq_fetch_date,cq_id) +); +SELECT setup_tsdb_parent('k8s_core_namespaces'); +CREATE TABLE IF NOT EXISTS "k8s_meta_owner_references" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "namespace_cq_id" uuid, + "resource_uid" text, + "api_version" text, + "kind" text, + "name" text, + "owner_uid" text, + "controller" boolean, + "block_owner_deletion" boolean, + CONSTRAINT k8s_meta_owner_references_pk PRIMARY KEY(cq_fetch_date,resource_uid,owner_uid), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_meta_owner_references (cq_fetch_date, namespace_cq_id); +SELECT setup_tsdb_child('k8s_meta_owner_references', 'namespace_cq_id', 'k8s_core_namespaces', 'cq_id'); + +-- Resource: core.nodes +CREATE TABLE IF NOT EXISTS "k8s_core_nodes" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "namespace" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "pod_cidr" cidr, + "pod_cidrs" cidr[], + "provider_id" text, + "unschedulable" boolean, + "taints" jsonb, + "capacity" jsonb, + "allocatable" jsonb, + "phase" text, + "conditions" jsonb, + "daemon_endpoints_kubelet_endpoint_port" integer, + "machine_id" text, + "system_uuid" text, + "boot_id" text, + "kernel_version" text, + "os_image" text, + "container_runtime_version" text, + "kubelet_version" text, + "kube_proxy_version" text, + "operating_system" text, + "architecture" text, + "volumes_in_use" text[], + "config" jsonb, + "hostname" text, + "internal_ip" inet, + "external_ip" inet, + CONSTRAINT k8s_core_nodes_pk PRIMARY KEY(cq_fetch_date,uid), + UNIQUE(cq_fetch_date,cq_id) +); +SELECT setup_tsdb_parent('k8s_core_nodes'); +CREATE TABLE IF NOT EXISTS "k8s_core_node_images" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "node_cq_id" uuid, + "names" text[], + "size_bytes" bigint, + CONSTRAINT k8s_core_node_images_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_node_images (cq_fetch_date, node_cq_id); +SELECT setup_tsdb_child('k8s_core_node_images', 'node_cq_id', 'k8s_core_nodes', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_node_volumes_attached" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "node_cq_id" uuid, + "name" text, + "device_path" text, + CONSTRAINT k8s_core_node_volumes_attached_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_node_volumes_attached (cq_fetch_date, node_cq_id); +SELECT setup_tsdb_child('k8s_core_node_volumes_attached', 'node_cq_id', 'k8s_core_nodes', 'cq_id'); + +-- Resource: core.pods +CREATE TABLE IF NOT EXISTS "k8s_core_pods" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "namespace" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "restart_policy" text, + "termination_grace_period_seconds" bigint, + "active_deadline_seconds" bigint, + "dns_policy" text, + "node_selector" jsonb, + "service_account_name" text, + "automount_service_account_token" boolean, + "node_name" text, + "host_network" boolean, + "host_pid" boolean, + "host_ipc" boolean, + "share_process_namespace" boolean, + "security_context" jsonb, + "image_pull_secrets" jsonb, + "hostname" text, + "subdomain" text, + "affinity" jsonb, + "scheduler_name" text, + "tolerations" jsonb, + "host_aliases" jsonb, + "priority_class_name" text, + "priority" integer, + "dns_config" jsonb, + "readiness_gates" jsonb, + "runtime_class_name" text, + "enable_service_links" boolean, + "preemption_policy" text, + "overhead" jsonb, + "topology_spread_constraints" jsonb, + "set_hostname_as_fqdn" boolean, + "phase" text, + "conditions" jsonb, + "message" text, + "reason" text, + "nominated_node_name" text, + "host_ip" inet, + "pod_ip" inet, + "pod_ips" inet[], + "qos_class" text, + CONSTRAINT k8s_core_pods_pk PRIMARY KEY(cq_fetch_date,uid), + UNIQUE(cq_fetch_date,cq_id) +); +SELECT setup_tsdb_parent('k8s_core_pods'); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_init_containers" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "pod_cq_id" uuid, + "name" text, + "image" text, + "command" text[], + "args" text[], + "working_dir" text, + "env_from" jsonb, + "resources_limits" jsonb, + "resources_requests" jsonb, + "liveness_probe" jsonb, + "readiness_probe" jsonb, + "startup_probe" jsonb, + "lifecycle" jsonb, + "termination_message_path" text, + "termination_message_policy" text, + "image_pull_policy" text, + "security_context" jsonb, + "stdin" boolean, + "stdin_once" boolean, + "tty" boolean, + CONSTRAINT k8s_core_pod_init_containers_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_pod_init_containers (cq_fetch_date, pod_cq_id); +SELECT setup_tsdb_child('k8s_core_pod_init_containers', 'pod_cq_id', 'k8s_core_pods', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_init_container_ports" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "pod_init_container_cq_id" uuid, + "name" text, + "host_port" integer, + "container_port" integer, + "protocol" text, + "host_ip" text, + CONSTRAINT k8s_core_pod_init_container_ports_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_pod_init_container_ports (cq_fetch_date, pod_init_container_cq_id); +SELECT setup_tsdb_child('k8s_core_pod_init_container_ports', 'pod_init_container_cq_id', 'k8s_core_pod_init_containers', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_init_container_envs" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "pod_init_container_cq_id" uuid, + "name" text, + "value" text, + "value_from_field_ref_api_version" text, + "value_from_field_ref_field_path" text, + "value_from_resource_field_ref_container_name" text, + "value_from_resource_field_ref_resource" text, + "value_from_resource_field_ref_divisor_format" text, + "value_from_config_map_key_ref_local_object_reference_name" text, + "value_from_config_map_key_ref_key" text, + "value_from_config_map_key_ref_optional" boolean, + "value_from_secret_key_ref_local_object_reference_name" text, + "value_from_secret_key_ref_key" text, + "value_from_secret_key_ref_optional" boolean, + CONSTRAINT k8s_core_pod_init_container_envs_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_pod_init_container_envs (cq_fetch_date, pod_init_container_cq_id); +SELECT setup_tsdb_child('k8s_core_pod_init_container_envs', 'pod_init_container_cq_id', 'k8s_core_pod_init_containers', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_init_container_volume_mounts" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "pod_init_container_cq_id" uuid, + "name" text, + "read_only" boolean, + "mount_path" text, + "sub_path" text, + "mount_propagation" text, + "sub_path_expr" text, + CONSTRAINT k8s_core_pod_init_container_volume_mounts_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_pod_init_container_volume_mounts (cq_fetch_date, pod_init_container_cq_id); +SELECT setup_tsdb_child('k8s_core_pod_init_container_volume_mounts', 'pod_init_container_cq_id', 'k8s_core_pod_init_containers', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_init_container_volume_devices" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "pod_init_container_cq_id" uuid, + "name" text, + "device_path" text, + CONSTRAINT k8s_core_pod_init_container_volume_devices_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_pod_init_container_volume_devices (cq_fetch_date, pod_init_container_cq_id); +SELECT setup_tsdb_child('k8s_core_pod_init_container_volume_devices', 'pod_init_container_cq_id', 'k8s_core_pod_init_containers', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_containers" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "pod_cq_id" uuid, + "name" text, + "image" text, + "command" text[], + "args" text[], + "working_dir" text, + "env_from" jsonb, + "resources_limits" jsonb, + "resources_requests" jsonb, + "liveness_probe" jsonb, + "readiness_probe" jsonb, + "startup_probe" jsonb, + "lifecycle" jsonb, + "termination_message_path" text, + "termination_message_policy" text, + "image_pull_policy" text, + "security_context" jsonb, + "stdin" boolean, + "stdin_once" boolean, + "tty" boolean, + CONSTRAINT k8s_core_pod_containers_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_pod_containers (cq_fetch_date, pod_cq_id); +SELECT setup_tsdb_child('k8s_core_pod_containers', 'pod_cq_id', 'k8s_core_pods', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_container_ports" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "pod_container_cq_id" uuid, + "name" text, + "host_port" integer, + "container_port" integer, + "protocol" text, + "host_ip" text, + CONSTRAINT k8s_core_pod_container_ports_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_pod_container_ports (cq_fetch_date, pod_container_cq_id); +SELECT setup_tsdb_child('k8s_core_pod_container_ports', 'pod_container_cq_id', 'k8s_core_pod_containers', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_container_envs" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "pod_container_cq_id" uuid, + "name" text, + "value" text, + "value_from_field_ref_api_version" text, + "value_from_field_ref_field_path" text, + "value_from_resource_field_ref_container_name" text, + "value_from_resource_field_ref_resource" text, + "value_from_resource_field_ref_divisor_format" text, + "value_from_config_map_key_ref_local_object_reference_name" text, + "value_from_config_map_key_ref_key" text, + "value_from_config_map_key_ref_optional" boolean, + "value_from_secret_key_ref_local_object_reference_name" text, + "value_from_secret_key_ref_key" text, + "value_from_secret_key_ref_optional" boolean, + CONSTRAINT k8s_core_pod_container_envs_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_pod_container_envs (cq_fetch_date, pod_container_cq_id); +SELECT setup_tsdb_child('k8s_core_pod_container_envs', 'pod_container_cq_id', 'k8s_core_pod_containers', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_container_volume_mounts" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "pod_container_cq_id" uuid, + "name" text, + "read_only" boolean, + "mount_path" text, + "sub_path" text, + "mount_propagation" text, + "sub_path_expr" text, + CONSTRAINT k8s_core_pod_container_volume_mounts_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_pod_container_volume_mounts (cq_fetch_date, pod_container_cq_id); +SELECT setup_tsdb_child('k8s_core_pod_container_volume_mounts', 'pod_container_cq_id', 'k8s_core_pod_containers', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_container_volume_devices" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "pod_container_cq_id" uuid, + "name" text, + "device_path" text, + CONSTRAINT k8s_core_pod_container_volume_devices_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_pod_container_volume_devices (cq_fetch_date, pod_container_cq_id); +SELECT setup_tsdb_child('k8s_core_pod_container_volume_devices', 'pod_container_cq_id', 'k8s_core_pod_containers', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_ephemeral_containers" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "target_container_name" text, + "pod_cq_id" uuid, + "name" text, + "image" text, + "command" text[], + "args" text[], + "working_dir" text, + "env_from" jsonb, + "resources_limits" jsonb, + "resources_requests" jsonb, + "liveness_probe" jsonb, + "readiness_probe" jsonb, + "startup_probe" jsonb, + "lifecycle" jsonb, + "termination_message_path" text, + "termination_message_policy" text, + "image_pull_policy" text, + "security_context" jsonb, + "stdin" boolean, + "stdin_once" boolean, + "tty" boolean, + CONSTRAINT k8s_core_pod_ephemeral_containers_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_pod_ephemeral_containers (cq_fetch_date, pod_cq_id); +SELECT setup_tsdb_child('k8s_core_pod_ephemeral_containers', 'pod_cq_id', 'k8s_core_pods', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_ephemeral_container_ports" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "pod_ephemeral_container_cq_id" uuid, + "name" text, + "host_port" integer, + "container_port" integer, + "protocol" text, + "host_ip" text, + CONSTRAINT k8s_core_pod_ephemeral_container_ports_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_pod_ephemeral_container_ports (cq_fetch_date, pod_ephemeral_container_cq_id); +SELECT setup_tsdb_child('k8s_core_pod_ephemeral_container_ports', 'pod_ephemeral_container_cq_id', 'k8s_core_pod_ephemeral_containers', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_ephemeral_container_envs" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "pod_ephemeral_container_cq_id" uuid, + "name" text, + "value" text, + "value_from_field_ref_api_version" text, + "value_from_field_ref_field_path" text, + "value_from_resource_field_ref_container_name" text, + "value_from_resource_field_ref_resource" text, + "value_from_resource_field_ref_divisor_format" text, + "value_from_config_map_key_ref_local_object_reference_name" text, + "value_from_config_map_key_ref_key" text, + "value_from_config_map_key_ref_optional" boolean, + "value_from_secret_key_ref_local_object_reference_name" text, + "value_from_secret_key_ref_key" text, + "value_from_secret_key_ref_optional" boolean, + CONSTRAINT k8s_core_pod_ephemeral_container_envs_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_pod_ephemeral_container_envs (cq_fetch_date, pod_ephemeral_container_cq_id); +SELECT setup_tsdb_child('k8s_core_pod_ephemeral_container_envs', 'pod_ephemeral_container_cq_id', 'k8s_core_pod_ephemeral_containers', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_ephemeral_container_volume_mounts" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "pod_ephemeral_container_cq_id" uuid, + "name" text, + "read_only" boolean, + "mount_path" text, + "sub_path" text, + "mount_propagation" text, + "sub_path_expr" text, + CONSTRAINT k8s_core_pod_ephemeral_container_volume_mounts_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_pod_ephemeral_container_volume_mounts (cq_fetch_date, pod_ephemeral_container_cq_id); +SELECT setup_tsdb_child('k8s_core_pod_ephemeral_container_volume_mounts', 'pod_ephemeral_container_cq_id', 'k8s_core_pod_ephemeral_containers', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_ephemeral_container_volume_devices" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "pod_ephemeral_container_cq_id" uuid, + "name" text, + "device_path" text, + CONSTRAINT k8s_core_pod_ephemeral_container_volume_devices_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_pod_ephemeral_container_volume_devices (cq_fetch_date, pod_ephemeral_container_cq_id); +SELECT setup_tsdb_child('k8s_core_pod_ephemeral_container_volume_devices', 'pod_ephemeral_container_cq_id', 'k8s_core_pod_ephemeral_containers', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_volumes" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "pod_cq_id" uuid, + "name" text, + "host_path" jsonb, + "empty_dir" jsonb, + "gce_persistent_disk" jsonb, + "aws_elastic_block_store" jsonb, + "secret" jsonb, + "nfs" jsonb, + "iscsi" jsonb, + "glusterfs" jsonb, + "persistent_volume_claim" jsonb, + "rbd" jsonb, + "flex_volume" jsonb, + "cinder" jsonb, + "ceph_fs" jsonb, + "flocker" jsonb, + "downward_api" jsonb, + "fc" jsonb, + "azure_file" jsonb, + "config_map" jsonb, + "vsphere_volume" jsonb, + "quobyte" jsonb, + "azure_disk" jsonb, + "photon_persistent_disk" jsonb, + "projected" jsonb, + "portworx_volume" jsonb, + "scale_io" jsonb, + "storage_os" jsonb, + "csi" jsonb, + "ephemeral" jsonb, + CONSTRAINT k8s_core_pod_volumes_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_pod_volumes (cq_fetch_date, pod_cq_id); +SELECT setup_tsdb_child('k8s_core_pod_volumes', 'pod_cq_id', 'k8s_core_pods', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_init_container_statuses" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "pod_cq_id" uuid, + "name" text, + "state" jsonb, + "last_state" jsonb, + "ready" boolean, + "restart_count" integer, + "image" text, + "image_id" text, + "container_id" text, + "started" boolean, + CONSTRAINT k8s_core_pod_init_container_statuses_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_pod_init_container_statuses (cq_fetch_date, pod_cq_id); +SELECT setup_tsdb_child('k8s_core_pod_init_container_statuses', 'pod_cq_id', 'k8s_core_pods', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_container_statuses" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "pod_cq_id" uuid, + "name" text, + "state" jsonb, + "last_state" jsonb, + "ready" boolean, + "restart_count" integer, + "image" text, + "image_id" text, + "container_id" text, + "started" boolean, + CONSTRAINT k8s_core_pod_container_statuses_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_pod_container_statuses (cq_fetch_date, pod_cq_id); +SELECT setup_tsdb_child('k8s_core_pod_container_statuses', 'pod_cq_id', 'k8s_core_pods', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_pod_ephemeral_container_statuses" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "pod_cq_id" uuid, + "name" text, + "state" jsonb, + "last_state" jsonb, + "ready" boolean, + "restart_count" integer, + "image" text, + "image_id" text, + "container_id" text, + "started" boolean, + CONSTRAINT k8s_core_pod_ephemeral_container_statuses_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_pod_ephemeral_container_statuses (cq_fetch_date, pod_cq_id); +SELECT setup_tsdb_child('k8s_core_pod_ephemeral_container_statuses', 'pod_cq_id', 'k8s_core_pods', 'cq_id'); + +-- Resource: core.resource_quotas +CREATE TABLE IF NOT EXISTS "k8s_core_resource_quotas" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + "hard" jsonb, + "scopes" text[], + "status_hard" jsonb, + "status_used" jsonb, + CONSTRAINT k8s_core_resource_quotas_pk PRIMARY KEY(cq_fetch_date,uid), + UNIQUE(cq_fetch_date,cq_id) +); +SELECT setup_tsdb_parent('k8s_core_resource_quotas'); +CREATE TABLE IF NOT EXISTS "k8s_core_resource_quota_scope_selector_match_expressions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "resource_quota_cq_id" uuid, + "scope_name" text, + "operator" text, + "values" text[], + CONSTRAINT k8s_core_resource_quota_scope_selector_match_expressions_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_resource_quota_scope_selector_match_expressions (cq_fetch_date, resource_quota_cq_id); +SELECT setup_tsdb_child('k8s_core_resource_quota_scope_selector_match_expressions', 'resource_quota_cq_id', 'k8s_core_resource_quotas', 'cq_id'); + +-- Resource: core.service_accounts +CREATE TABLE IF NOT EXISTS "k8s_core_service_accounts" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + "automount_service_account_token" boolean, + "pull_secret_names" text[], + CONSTRAINT k8s_core_service_accounts_pk PRIMARY KEY(cq_fetch_date,uid), + UNIQUE(cq_fetch_date,cq_id) +); +SELECT setup_tsdb_parent('k8s_core_service_accounts'); +CREATE TABLE IF NOT EXISTS "k8s_core_service_account_secrets" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "service_account_cq_id" uuid, + "kind" text, + "namespace" text, + "name" text, + "uid" text, + "api_version" text, + "resource_version" text, + "field_path" text, + CONSTRAINT k8s_core_service_account_secrets_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_service_account_secrets (cq_fetch_date, service_account_cq_id); +SELECT setup_tsdb_child('k8s_core_service_account_secrets', 'service_account_cq_id', 'k8s_core_service_accounts', 'cq_id'); + +-- Resource: core.services +CREATE TABLE IF NOT EXISTS "k8s_core_services" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "namespace" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "selector" jsonb, + "cluster_ip" inet, + "cluster_ips" inet[], + "type" text, + "external_ips" inet[], + "session_affinity" text, + "load_balancer_ip" text, + "load_balancer_source_ranges" text[], + "external_name" text, + "external_traffic_policy" text, + "health_check_node_port" integer, + "publish_not_ready_addresses" boolean, + "session_affinity_config_client_ip_timeout_seconds" integer, + "ip_families" text[], + "ip_family_policy" text, + "allocate_load_balancer_node_ports" boolean, + "load_balancer_class" text, + "internal_traffic_policy" text, + CONSTRAINT k8s_core_services_pk PRIMARY KEY(cq_fetch_date,uid), + UNIQUE(cq_fetch_date,cq_id) +); +SELECT setup_tsdb_parent('k8s_core_services'); +CREATE TABLE IF NOT EXISTS "k8s_core_service_ports" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "service_cq_id" uuid, + "name" text, + "protocol" text, + "app_protocol" text, + "port" integer, + "target_port_type" bigint, + "target_port_int_val" integer, + "target_port_str_val" text, + "node_port" integer, + CONSTRAINT k8s_core_service_ports_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_service_ports (cq_fetch_date, service_cq_id); +SELECT setup_tsdb_child('k8s_core_service_ports', 'service_cq_id', 'k8s_core_services', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_service_load_balancer_ingresses" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "service_cq_id" uuid, + "ip" text, + "hostname" text, + CONSTRAINT k8s_core_service_load_balancer_ingresses_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_service_load_balancer_ingresses (cq_fetch_date, service_cq_id); +SELECT setup_tsdb_child('k8s_core_service_load_balancer_ingresses', 'service_cq_id', 'k8s_core_services', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_service_load_balancer_ingress_ports" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "service_load_balancer_ingress_cq_id" uuid, + "port" integer, + "protocol" text, + "error" text, + CONSTRAINT k8s_core_service_load_balancer_ingress_ports_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_service_load_balancer_ingress_ports (cq_fetch_date, service_load_balancer_ingress_cq_id); +SELECT setup_tsdb_child('k8s_core_service_load_balancer_ingress_ports', 'service_load_balancer_ingress_cq_id', 'k8s_core_service_load_balancer_ingresses', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_core_service_conditions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "service_cq_id" uuid, + "type" text, + "status" text, + "observed_generation" bigint, + "reason" text, + "message" text, + CONSTRAINT k8s_core_service_conditions_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_core_service_conditions (cq_fetch_date, service_cq_id); +SELECT setup_tsdb_child('k8s_core_service_conditions', 'service_cq_id', 'k8s_core_services', 'cq_id'); + +-- Resource: networking.network_policies +CREATE TABLE IF NOT EXISTS "k8s_networking_network_policies" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + "pod_selector_match_labels" jsonb, + "policy_types" text[], + CONSTRAINT k8s_networking_network_policies_pk PRIMARY KEY(cq_fetch_date,uid), + UNIQUE(cq_fetch_date,cq_id) +); +SELECT setup_tsdb_parent('k8s_networking_network_policies'); +CREATE TABLE IF NOT EXISTS "k8s_networking_network_policy_pod_selector_match_expressions" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "network_policy_cq_id" uuid, + "key" text, + "operator" text, + "values" text[], + CONSTRAINT k8s_networking_network_policy_pod_selector_match_expressions_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_networking_network_policy_pod_selector_match_expressions (cq_fetch_date, network_policy_cq_id); +SELECT setup_tsdb_child('k8s_networking_network_policy_pod_selector_match_expressions', 'network_policy_cq_id', 'k8s_networking_network_policies', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_networking_network_policy_ingress" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "network_policy_cq_id" uuid, + "network_policy_uid" text, + CONSTRAINT k8s_networking_network_policy_ingress_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_networking_network_policy_ingress (cq_fetch_date, network_policy_cq_id); +SELECT setup_tsdb_child('k8s_networking_network_policy_ingress', 'network_policy_cq_id', 'k8s_networking_network_policies', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_networking_network_policy_ingress_ports" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "network_policy_ingress_cq_id" uuid, + "protocol" text, + "port_type" bigint, + "port_int_val" integer, + "port_str_val" text, + "end_port" integer, + CONSTRAINT k8s_networking_network_policy_ingress_ports_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_networking_network_policy_ingress_ports (cq_fetch_date, network_policy_ingress_cq_id); +SELECT setup_tsdb_child('k8s_networking_network_policy_ingress_ports', 'network_policy_ingress_cq_id', 'k8s_networking_network_policy_ingress', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_networking_network_policy_ingress_from" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "network_policy_ingress_cq_id" uuid, + "pod_selector_match_labels" jsonb, + "pod_selector_match_expressions" jsonb, + "namespace_selector_match_labels" jsonb, + "namespace_selector_match_expressions" jsonb, + "ip_block_cidr" text, + "ip_block_except" text[], + CONSTRAINT k8s_networking_network_policy_ingress_from_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_networking_network_policy_ingress_from (cq_fetch_date, network_policy_ingress_cq_id); +SELECT setup_tsdb_child('k8s_networking_network_policy_ingress_from', 'network_policy_ingress_cq_id', 'k8s_networking_network_policy_ingress', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_networking_network_policy_egress" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "network_policy_cq_id" uuid, + "network_policy_uid" text, + CONSTRAINT k8s_networking_network_policy_egress_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_networking_network_policy_egress (cq_fetch_date, network_policy_cq_id); +SELECT setup_tsdb_child('k8s_networking_network_policy_egress', 'network_policy_cq_id', 'k8s_networking_network_policies', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_networking_network_policy_egress_ports" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "network_policy_egress_cq_id" uuid, + "protocol" text, + "port_type" bigint, + "port_int_val" integer, + "port_str_val" text, + "end_port" integer, + CONSTRAINT k8s_networking_network_policy_egress_ports_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_networking_network_policy_egress_ports (cq_fetch_date, network_policy_egress_cq_id); +SELECT setup_tsdb_child('k8s_networking_network_policy_egress_ports', 'network_policy_egress_cq_id', 'k8s_networking_network_policy_egress', 'cq_id'); +CREATE TABLE IF NOT EXISTS "k8s_networking_network_policy_egress_to" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "network_policy_egress_cq_id" uuid, + "pod_selector_match_labels" jsonb, + "pod_selector_match_expressions" jsonb, + "namespace_selector_match_labels" jsonb, + "namespace_selector_match_expressions" jsonb, + "ip_block_cidr" text, + "ip_block_except" text[], + CONSTRAINT k8s_networking_network_policy_egress_to_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_networking_network_policy_egress_to (cq_fetch_date, network_policy_egress_cq_id); +SELECT setup_tsdb_child('k8s_networking_network_policy_egress_to', 'network_policy_egress_cq_id', 'k8s_networking_network_policy_egress', 'cq_id'); + +-- Resource: rbac.role_bindings +CREATE TABLE IF NOT EXISTS "k8s_rbac_role_bindings" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + "role_ref_api_group" text, + "role_ref_kind" text, + "role_ref_name" text, + CONSTRAINT k8s_rbac_role_bindings_pk PRIMARY KEY(cq_fetch_date,uid), + UNIQUE(cq_fetch_date,cq_id) +); +SELECT setup_tsdb_parent('k8s_rbac_role_bindings'); +CREATE TABLE IF NOT EXISTS "k8s_rbac_role_binding_subjects" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "role_binding_cq_id" uuid, + "kind" text, + "api_group" text, + "name" text, + "namespace" text, + CONSTRAINT k8s_rbac_role_binding_subjects_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_rbac_role_binding_subjects (cq_fetch_date, role_binding_cq_id); +SELECT setup_tsdb_child('k8s_rbac_role_binding_subjects', 'role_binding_cq_id', 'k8s_rbac_role_bindings', 'cq_id'); + +-- Resource: rbac.roles +CREATE TABLE IF NOT EXISTS "k8s_rbac_roles" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "context" text, + "kind" text, + "api_version" text, + "name" text, + "generate_name" text, + "namespace" text, + "self_link" text, + "uid" text, + "resource_version" text, + "generation" bigint, + "deletion_grace_period_seconds" bigint, + "labels" jsonb, + "annotations" jsonb, + "owner_references" jsonb, + "finalizers" text[], + "cluster_name" text, + "managed_fields" jsonb, + CONSTRAINT k8s_rbac_roles_pk PRIMARY KEY(cq_fetch_date,uid), + UNIQUE(cq_fetch_date,cq_id) +); +SELECT setup_tsdb_parent('k8s_rbac_roles'); +CREATE TABLE IF NOT EXISTS "k8s_rbac_role_rules" ( + "cq_id" uuid NOT NULL, + "cq_meta" jsonb, + "cq_fetch_date" timestamp without time zone NOT NULL, + "role_cq_id" uuid, + "verbs" text[], + "api_groups" text[], + "resources" text[], + "resource_names" text[], + "non_resource_urls" text[], + CONSTRAINT k8s_rbac_role_rules_pk PRIMARY KEY(cq_fetch_date,cq_id), + UNIQUE(cq_fetch_date,cq_id) +); +CREATE INDEX ON k8s_rbac_role_rules (cq_fetch_date, role_cq_id); +SELECT setup_tsdb_child('k8s_rbac_role_rules', 'role_cq_id', 'k8s_rbac_roles', 'cq_id'); diff --git a/resources/provider/provider.go b/resources/provider/provider.go index 484414f..03b3850 100644 --- a/resources/provider/provider.go +++ b/resources/provider/provider.go @@ -1,6 +1,8 @@ package provider import ( + "embed" + "github.com/cloudquery/cq-provider-k8s/client" "github.com/cloudquery/cq-provider-k8s/resources/services/apps" "github.com/cloudquery/cq-provider-k8s/resources/services/batch" @@ -15,6 +17,9 @@ import ( const ProviderName = "k8s" var ( + //go:embed migrations/*/*.sql + migrationFiles embed.FS + Version = "Development" ) @@ -45,5 +50,6 @@ func Provider() *provider.Provider { "rbac.role_bindings": rbac.RoleBindings(), "rbac.roles": rbac.Roles(), }, + Migrations: migrationFiles, } } diff --git a/resources/provider/provider_test.go b/resources/provider/provider_test.go new file mode 100644 index 0000000..ad688ee --- /dev/null +++ b/resources/provider/provider_test.go @@ -0,0 +1,12 @@ +package provider_test + +import ( + "testing" + + "github.com/cloudquery/cq-provider-k8s/resources/provider" + "github.com/cloudquery/cq-provider-sdk/migration" +) + +func TestMigrations(t *testing.T) { + migration.RunMigrationsTest(t, provider.Provider(), nil) +} diff --git a/tools/migrations/main.go b/tools/migrations/main.go new file mode 100644 index 0000000..96317a9 --- /dev/null +++ b/tools/migrations/main.go @@ -0,0 +1,17 @@ +package main + +import ( + "context" + "fmt" + "os" + + "github.com/cloudquery/cq-provider-k8s/resources/provider" + "github.com/cloudquery/cq-provider-sdk/migration" +) + +func main() { + if err := migration.Run(context.Background(), provider.Provider(), ""); err != nil { + fmt.Fprintf(os.Stderr, "Error: %s\n", err.Error()) + os.Exit(1) + } +}