From 40e31d1e57f29f0097936af04656fd70e4bffa14 Mon Sep 17 00:00:00 2001 From: paulobressan Date: Wed, 20 Dec 2023 13:23:58 -0300 Subject: [PATCH 01/12] refactor: updated folder structure --- .github/workflows/clippy.yml | 3 + .github/workflows/validate.yml | 2 + bootstrap/crds/main.tf | 75 ++++++++++++++++++++ .gitignore => operator/.gitignore | 0 Cargo.lock => operator/Cargo.lock | 0 Cargo.toml => operator/Cargo.toml | 0 Dockerfile => operator/Dockerfile | 0 LICENSE => operator/LICENSE | 0 README.md => operator/README.md | 0 {benchmark => operator/benchmark}/.gitignore | 0 {benchmark => operator/benchmark}/Dockerfile | 0 {benchmark => operator/benchmark}/README.md | 0 {benchmark => operator/benchmark}/bench.sql | 0 {src => operator/src}/controller.rs | 0 {src => operator/src}/crdgen.rs | 0 {src => operator/src}/lib.rs | 0 {src => operator/src}/main.rs | 0 {src => operator/src}/metrics.rs | 0 {src => operator/src}/postgres.rs | 0 {test => operator/test}/manifest.yaml | 0 {test => operator/test}/validate-execution | 0 {yaml => operator/yaml}/dbsyncport.yaml | 0 {yaml => operator/yaml}/user-access.yaml | 0 {yaml => operator/yaml}/user-namespace.yaml | 0 scripts/crd.sh | 4 ++ 25 files changed, 84 insertions(+) create mode 100644 bootstrap/crds/main.tf rename .gitignore => operator/.gitignore (100%) rename Cargo.lock => operator/Cargo.lock (100%) rename Cargo.toml => operator/Cargo.toml (100%) rename Dockerfile => operator/Dockerfile (100%) rename LICENSE => operator/LICENSE (100%) rename README.md => operator/README.md (100%) rename {benchmark => operator/benchmark}/.gitignore (100%) rename {benchmark => operator/benchmark}/Dockerfile (100%) rename {benchmark => operator/benchmark}/README.md (100%) rename {benchmark => operator/benchmark}/bench.sql (100%) rename {src => operator/src}/controller.rs (100%) rename {src => operator/src}/crdgen.rs (100%) rename {src => operator/src}/lib.rs (100%) rename {src => operator/src}/main.rs (100%) rename {src => operator/src}/metrics.rs (100%) rename {src => operator/src}/postgres.rs (100%) rename {test => operator/test}/manifest.yaml (100%) rename {test => operator/test}/validate-execution (100%) rename {yaml => operator/yaml}/dbsyncport.yaml (100%) rename {yaml => operator/yaml}/user-access.yaml (100%) rename {yaml => operator/yaml}/user-namespace.yaml (100%) create mode 100755 scripts/crd.sh diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 189a0bd..7da4754 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -13,5 +13,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + with: + path: operator + - name: Clippy check lints run: cargo clippy -- -D warnings diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 0b0c9f3..9e03f0e 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -14,6 +14,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + path: operator - name: Create k8s Kind Cluster uses: helm/kind-action@v1.5.0 diff --git a/bootstrap/crds/main.tf b/bootstrap/crds/main.tf new file mode 100644 index 0000000..d35b949 --- /dev/null +++ b/bootstrap/crds/main.tf @@ -0,0 +1,75 @@ +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" = [] + "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" = {} + } + }, + ] + } + } +} diff --git a/.gitignore b/operator/.gitignore similarity index 100% rename from .gitignore rename to operator/.gitignore 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 100% rename from src/controller.rs rename to operator/src/controller.rs 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 100% rename from test/manifest.yaml rename to operator/test/manifest.yaml 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/yaml/dbsyncport.yaml b/operator/yaml/dbsyncport.yaml similarity index 100% rename from yaml/dbsyncport.yaml rename to operator/yaml/dbsyncport.yaml diff --git a/yaml/user-access.yaml b/operator/yaml/user-access.yaml similarity index 100% rename from yaml/user-access.yaml rename to operator/yaml/user-access.yaml 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 + From 6acda4acb3127af765955fd83ce7470cc8c97660 Mon Sep 17 00:00:00 2001 From: paulobressan Date: Wed, 20 Dec 2023 13:27:10 -0300 Subject: [PATCH 02/12] fix: adjusted ci checkout --- .github/workflows/clippy.yml | 2 +- .github/workflows/validate.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 7da4754..61f69d2 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -14,7 +14,7 @@ jobs: steps: - uses: actions/checkout@v3 with: - path: operator + sparse-checkout: operator - name: Clippy check lints run: cargo clippy -- -D warnings diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 9e03f0e..b47f4d4 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -15,7 +15,7 @@ jobs: - name: Checkout uses: actions/checkout@v3 with: - path: operator + sparse-checkout: operator - name: Create k8s Kind Cluster uses: helm/kind-action@v1.5.0 From 3ab9df3521554fe8709ad240b02289ab65f6ffd6 Mon Sep 17 00:00:00 2001 From: paulobressan Date: Wed, 20 Dec 2023 13:28:59 -0300 Subject: [PATCH 03/12] fix: adjusted ci checkout --- .github/workflows/clippy.yml | 7 ++++--- .github/workflows/validate.yml | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 61f69d2..8ffd3a1 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -12,9 +12,10 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - with: - sparse-checkout: operator + - name: Checkout + uses: actions/checkout@v3 + + - run: cd operator - name: Clippy check lints run: cargo clippy -- -D warnings diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index b47f4d4..c6b83f6 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -14,8 +14,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 - with: - sparse-checkout: operator + + - run: cd operator - name: Create k8s Kind Cluster uses: helm/kind-action@v1.5.0 From 178a0be371ead2cd58ac95da03cc578df1793eb7 Mon Sep 17 00:00:00 2001 From: paulobressan Date: Wed, 20 Dec 2023 13:33:40 -0300 Subject: [PATCH 04/12] fix: adjusted ci checkout --- .github/workflows/clippy.yml | 14 ++++++++++---- .github/workflows/validate.yml | 16 ++++++++++------ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 8ffd3a1..3af24ce 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -3,13 +3,19 @@ name: Clippy on: push: branches: - - main - pull_request: - branches: - - main + - "main" + paths: + - ".github/workflows/clippy.yml" + - "operator/**" jobs: lint: + strategy: + fail-fast: false + matrix: + include: + - context: operator + runs-on: ubuntu-latest steps: - name: Checkout diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index c6b83f6..da27f98 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -3,19 +3,23 @@ name: Validate controller on: push: branches: - - main - pull_request: - branches: - - main + - "main" + paths: + - ".github/workflows/validate.yml" + - "operator/**" jobs: run-controller: + strategy: + fail-fast: false + matrix: + include: + - context: operator + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 - - - run: cd operator - name: Create k8s Kind Cluster uses: helm/kind-action@v1.5.0 From 3e7cdd08d7c88b4a3611a0dd68ac76de91c26e74 Mon Sep 17 00:00:00 2001 From: paulobressan Date: Wed, 20 Dec 2023 13:35:12 -0300 Subject: [PATCH 05/12] fix: adjusted ci checkout --- .github/workflows/clippy.yml | 8 ++++---- .github/workflows/validate.yml | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 3af24ce..8aa2c1a 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -3,10 +3,10 @@ name: Clippy on: push: branches: - - "main" - paths: - - ".github/workflows/clippy.yml" - - "operator/**" + - main + pull_request: + branches: + - main jobs: lint: diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index da27f98..23d7592 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -3,10 +3,10 @@ name: Validate controller on: push: branches: - - "main" - paths: - - ".github/workflows/validate.yml" - - "operator/**" + - main + pull_request: + branches: + - main jobs: run-controller: From 78ee6159bddcadd44e306cccca06e393224d38d0 Mon Sep 17 00:00:00 2001 From: paulobressan Date: Wed, 20 Dec 2023 13:35:51 -0300 Subject: [PATCH 06/12] fix: adjusted ci checkout --- .github/workflows/clippy.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 8aa2c1a..a9d0431 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -21,7 +21,5 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - run: cd operator - - name: Clippy check lints run: cargo clippy -- -D warnings From 418a5dfe36f0e3d78f1ec6dd7f7e9e7cdaaea74f Mon Sep 17 00:00:00 2001 From: paulobressan Date: Wed, 20 Dec 2023 13:38:29 -0300 Subject: [PATCH 07/12] fix: adjusted ci checkout --- .github/workflows/clippy.yml | 9 +++------ .github/workflows/validate.yml | 9 +++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index a9d0431..a2d5d57 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -10,13 +10,10 @@ on: jobs: lint: - strategy: - fail-fast: false - matrix: - include: - - context: operator - runs-on: ubuntu-latest + defaults: + run: + working-directory: ./operator steps: - name: Checkout uses: actions/checkout@v3 diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 23d7592..10574c7 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -10,13 +10,10 @@ on: jobs: run-controller: - strategy: - fail-fast: false - matrix: - include: - - context: operator - runs-on: ubuntu-latest + defaults: + run: + working-directory: ./operator steps: - name: Checkout uses: actions/checkout@v3 From 2d9b9058014b394d9b62979b1b7f92c0a1b0ea16 Mon Sep 17 00:00:00 2001 From: paulobressan Date: Wed, 20 Dec 2023 13:53:12 -0300 Subject: [PATCH 08/12] chore: added kube printColumn and updated the crd version --- operator/src/controller.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/operator/src/controller.rs b/operator/src/controller.rs index 35cd572..9d1bf9f 100644 --- a/operator/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, } From 1ebb70bd92da2dcab4b4f35880be9dd409327d5b Mon Sep 17 00:00:00 2001 From: paulobressan Date: Wed, 20 Dec 2023 13:58:10 -0300 Subject: [PATCH 09/12] chore: updated crd tf --- bootstrap/crds/main.tf | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/bootstrap/crds/main.tf b/bootstrap/crds/main.tf index d35b949..151acca 100644 --- a/bootstrap/crds/main.tf +++ b/bootstrap/crds/main.tf @@ -17,8 +17,24 @@ resource "kubernetes_manifest" "customresourcedefinition_dbsyncports_demeter_run "scope" = "Namespaced" "versions" = [ { - "additionalPrinterColumns" = [] - "name" = "v1" + "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`" From aca2282160482e1186165b214baba319e14661d3 Mon Sep 17 00:00:00 2001 From: paulobressan Date: Wed, 20 Dec 2023 13:59:38 -0300 Subject: [PATCH 10/12] chore: updated yaml crd --- operator/yaml/dbsyncport.yaml | 81 +++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 36 deletions(-) diff --git a/operator/yaml/dbsyncport.yaml b/operator/yaml/dbsyncport.yaml index a5e6002..c9f3f5e 100644 --- a/operator/yaml/dbsyncport.yaml +++ b/operator/yaml/dbsyncport.yaml @@ -12,39 +12,48 @@ spec: 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: {} + - 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: {} From 1b26fa6c93045d880cd24562877de34ae9570526 Mon Sep 17 00:00:00 2001 From: paulobressan Date: Wed, 20 Dec 2023 14:41:03 -0300 Subject: [PATCH 11/12] chore: updated test manifests --- operator/test/manifest.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/operator/test/manifest.yaml b/operator/test/manifest.yaml index 719d77c..2406b49 100644 --- a/operator/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 From 6b95229a83f0c4f299121b4e4bb55f68b08147af Mon Sep 17 00:00:00 2001 From: paulobressan Date: Thu, 21 Dec 2023 19:17:36 -0300 Subject: [PATCH 12/12] fix: updated version on patch crd --- operator/.gitignore | 3 ++- operator/src/controller.rs | 2 +- operator/yaml/user-access.yaml | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/operator/.gitignore b/operator/.gitignore index 0b745e2..4469ff8 100644 --- a/operator/.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/operator/src/controller.rs b/operator/src/controller.rs index 9d1bf9f..75405ee 100644 --- a/operator/src/controller.rs +++ b/operator/src/controller.rs @@ -80,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/operator/yaml/user-access.yaml b/operator/yaml/user-access.yaml index 9a17e30..7b07ba6 100644 --- a/operator/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