diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 189a0bd..a2d5d57 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -11,7 +11,12 @@ on: jobs: lint: runs-on: ubuntu-latest + defaults: + run: + working-directory: ./operator steps: - - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v3 + - name: Clippy check lints run: cargo clippy -- -D warnings diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 0b0c9f3..10574c7 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -11,6 +11,9 @@ on: jobs: run-controller: runs-on: ubuntu-latest + defaults: + run: + working-directory: ./operator steps: - name: Checkout uses: actions/checkout@v3 diff --git a/bootstrap/crds/main.tf b/bootstrap/crds/main.tf new file mode 100644 index 0000000..151acca --- /dev/null +++ b/bootstrap/crds/main.tf @@ -0,0 +1,91 @@ +resource "kubernetes_manifest" "customresourcedefinition_dbsyncports_demeter_run" { + manifest = { + "apiVersion" = "apiextensions.k8s.io/v1" + "kind" = "CustomResourceDefinition" + "metadata" = { + "name" = "dbsyncports.demeter.run" + } + "spec" = { + "group" = "demeter.run" + "names" = { + "categories" = [] + "kind" = "DbSyncPort" + "plural" = "dbsyncports" + "shortNames" = [] + "singular" = "dbsyncport" + } + "scope" = "Namespaced" + "versions" = [ + { + "additionalPrinterColumns" = [ + { + "jsonPath" = ".spec.network" + "name" = "Network" + "type" = "string" + }, + { + "jsonPath" = ".status.username" + "name" = "Username" + "type" = "string" + }, + { + "jsonPath" = ".status.password" + "name" = "Password" + "type" = "string" + }, + ] + "name" = "v1alpha1" + "schema" = { + "openAPIV3Schema" = { + "description" = "Auto-generated derived type for DbSyncPortSpec via `CustomResource`" + "properties" = { + "spec" = { + "properties" = { + "network" = { + "enum" = [ + "mainnet", + "preprod", + "preview", + ] + "type" = "string" + } + } + "required" = [ + "network", + ] + "type" = "object" + } + "status" = { + "nullable" = true + "properties" = { + "password" = { + "type" = "string" + } + "username" = { + "type" = "string" + } + } + "required" = [ + "password", + "username", + ] + "type" = "object" + } + } + "required" = [ + "spec", + ] + "title" = "DbSyncPort" + "type" = "object" + } + } + "served" = true + "storage" = true + "subresources" = { + "status" = {} + } + }, + ] + } + } +} diff --git a/.gitignore b/operator/.gitignore similarity index 53% rename from .gitignore rename to operator/.gitignore index 0b745e2..4469ff8 100644 --- a/.gitignore +++ b/operator/.gitignore @@ -1,2 +1,3 @@ /target -.env \ No newline at end of file +.env +ci \ No newline at end of file diff --git a/Cargo.lock b/operator/Cargo.lock similarity index 100% rename from Cargo.lock rename to operator/Cargo.lock diff --git a/Cargo.toml b/operator/Cargo.toml similarity index 100% rename from Cargo.toml rename to operator/Cargo.toml diff --git a/Dockerfile b/operator/Dockerfile similarity index 100% rename from Dockerfile rename to operator/Dockerfile diff --git a/LICENSE b/operator/LICENSE similarity index 100% rename from LICENSE rename to operator/LICENSE diff --git a/README.md b/operator/README.md similarity index 100% rename from README.md rename to operator/README.md diff --git a/benchmark/.gitignore b/operator/benchmark/.gitignore similarity index 100% rename from benchmark/.gitignore rename to operator/benchmark/.gitignore diff --git a/benchmark/Dockerfile b/operator/benchmark/Dockerfile similarity index 100% rename from benchmark/Dockerfile rename to operator/benchmark/Dockerfile diff --git a/benchmark/README.md b/operator/benchmark/README.md similarity index 100% rename from benchmark/README.md rename to operator/benchmark/README.md diff --git a/benchmark/bench.sql b/operator/benchmark/bench.sql similarity index 100% rename from benchmark/bench.sql rename to operator/benchmark/bench.sql diff --git a/src/controller.rs b/operator/src/controller.rs similarity index 89% rename from src/controller.rs rename to operator/src/controller.rs index 35cd572..75405ee 100644 --- a/src/controller.rs +++ b/operator/src/controller.rs @@ -16,7 +16,7 @@ use serde_json::json; use std::{sync::Arc, time::Duration}; use tracing::error; -use crate::{postgres::Postgres, Config, Error, Metrics, State, Network}; +use crate::{postgres::Postgres, Config, Error, Metrics, Network, State}; pub static DB_SYNC_PORT_FINALIZER: &str = "dbsyncports.demeter.run"; @@ -36,8 +36,18 @@ impl Context { } #[derive(CustomResource, Deserialize, Serialize, Clone, Debug, JsonSchema)] -#[kube(kind = "DbSyncPort", group = "demeter.run", version = "v1", namespaced)] +#[kube( + kind = "DbSyncPort", + group = "demeter.run", + version = "v1alpha1", + namespaced +)] #[kube(status = "DbSyncPortStatus")] +#[kube(printcolumn = r#" + {"name": "Network", "jsonPath": ".spec.network", "type": "string"}, + {"name": "Username", "jsonPath": ".status.username", "type": "string"}, + {"name": "Password", "jsonPath": ".status.password", "type": "string"} + "#)] pub struct DbSyncPortSpec { pub network: Network, } @@ -70,7 +80,7 @@ impl DbSyncPort { }; let new_status = Patch::Apply(json!({ - "apiVersion": "demeter.run/v1", + "apiVersion": "demeter.run/v1alpha1", "kind": "DbSyncPort", "status": DbSyncPortStatus { username: username.clone(), diff --git a/src/crdgen.rs b/operator/src/crdgen.rs similarity index 100% rename from src/crdgen.rs rename to operator/src/crdgen.rs diff --git a/src/lib.rs b/operator/src/lib.rs similarity index 100% rename from src/lib.rs rename to operator/src/lib.rs diff --git a/src/main.rs b/operator/src/main.rs similarity index 100% rename from src/main.rs rename to operator/src/main.rs diff --git a/src/metrics.rs b/operator/src/metrics.rs similarity index 100% rename from src/metrics.rs rename to operator/src/metrics.rs diff --git a/src/postgres.rs b/operator/src/postgres.rs similarity index 100% rename from src/postgres.rs rename to operator/src/postgres.rs diff --git a/test/manifest.yaml b/operator/test/manifest.yaml similarity index 99% rename from test/manifest.yaml rename to operator/test/manifest.yaml index 719d77c..2406b49 100644 --- a/test/manifest.yaml +++ b/operator/test/manifest.yaml @@ -197,7 +197,7 @@ spec: targetPort: 80 protocol: TCP --- -apiVersion: demeter.run/v1 +apiVersion: demeter.run/v1alpha1 kind: DbSyncPort metadata: name: ci-user diff --git a/test/validate-execution b/operator/test/validate-execution similarity index 100% rename from test/validate-execution rename to operator/test/validate-execution diff --git a/operator/yaml/dbsyncport.yaml b/operator/yaml/dbsyncport.yaml new file mode 100644 index 0000000..c9f3f5e --- /dev/null +++ b/operator/yaml/dbsyncport.yaml @@ -0,0 +1,59 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: dbsyncports.demeter.run +spec: + group: demeter.run + names: + categories: [] + kind: DbSyncPort + plural: dbsyncports + shortNames: [] + singular: dbsyncport + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .spec.network + name: Network + type: string + - jsonPath: .status.username + name: Username + type: string + - jsonPath: .status.password + name: Password + type: string + name: v1alpha1 + schema: + openAPIV3Schema: + description: Auto-generated derived type for DbSyncPortSpec via `CustomResource` + properties: + spec: + properties: + network: + enum: + - mainnet + - preprod + - preview + type: string + required: + - network + type: object + status: + nullable: true + properties: + password: + type: string + username: + type: string + required: + - password + - username + type: object + required: + - spec + title: DbSyncPort + type: object + served: true + storage: true + subresources: + status: {} diff --git a/yaml/user-access.yaml b/operator/yaml/user-access.yaml similarity index 76% rename from yaml/user-access.yaml rename to operator/yaml/user-access.yaml index 9a17e30..7b07ba6 100644 --- a/yaml/user-access.yaml +++ b/operator/yaml/user-access.yaml @@ -1,4 +1,4 @@ -apiVersion: demeter.run/v1 +apiVersion: demeter.run/v1alpha1 kind: DbSyncPort metadata: name: mainnet-user diff --git a/yaml/user-namespace.yaml b/operator/yaml/user-namespace.yaml similarity index 100% rename from yaml/user-namespace.yaml rename to operator/yaml/user-namespace.yaml diff --git a/scripts/crd.sh b/scripts/crd.sh new file mode 100755 index 0000000..560fffc --- /dev/null +++ b/scripts/crd.sh @@ -0,0 +1,4 @@ +#!/bin/bash +cd ../operator +cargo run --bin crdgen | tfk8s > ../bootstrap/crds/main.tf + diff --git a/yaml/dbsyncport.yaml b/yaml/dbsyncport.yaml deleted file mode 100644 index a5e6002..0000000 --- a/yaml/dbsyncport.yaml +++ /dev/null @@ -1,50 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - name: dbsyncports.demeter.run -spec: - group: demeter.run - names: - categories: [] - kind: DbSyncPort - plural: dbsyncports - shortNames: [] - singular: dbsyncport - scope: Namespaced - versions: - - additionalPrinterColumns: [] - name: v1 - schema: - openAPIV3Schema: - description: Auto-generated derived type for DbSyncPortSpec via `CustomResource` - properties: - spec: - properties: - network: - enum: - - mainnet - - preprod - - preview - type: string - required: - - network - type: object - status: - nullable: true - properties: - password: - type: string - username: - type: string - required: - - password - - username - type: object - required: - - spec - title: DbSyncPort - type: object - served: true - storage: true - subresources: - status: {}