From b63d257cb7344e83a77bd7b3c156ad2431df1543 Mon Sep 17 00:00:00 2001 From: kevinzcf Date: Wed, 25 Jan 2023 14:09:35 +0100 Subject: [PATCH] add create db and table --- statping/deployment.yaml | 83 --------------------- statping/init-config.yaml | 110 +++++++++++++++++++++++++++- statping/kustomization.yaml | 2 +- statping/postgres-deployment.yaml | 7 +- statping/sql-sts.yaml | 116 ------------------------------ statping/statping-deployment.yaml | 41 ++++++----- 6 files changed, 134 insertions(+), 225 deletions(-) delete mode 100644 statping/deployment.yaml delete mode 100644 statping/sql-sts.yaml diff --git a/statping/deployment.yaml b/statping/deployment.yaml deleted file mode 100644 index 3445f67..0000000 --- a/statping/deployment.yaml +++ /dev/null @@ -1,83 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - labels: - app.kubernetes.io/instance: statping - app.kubernetes.io/name: statping - app.kubernetes.io/version: v0.90.74 - name: statping - namespace: default -spec: - progressDeadlineSeconds: 600 - replicas: 1 - revisionHistoryLimit: 3 - selector: - matchLabels: - app.kubernetes.io/instance: statping - app.kubernetes.io/name: statping - strategy: - type: Recreate - template: - metadata: - labels: - app.kubernetes.io/instance: statping - app.kubernetes.io/name: statping - spec: - automountServiceAccountToken: true - containers: - - env: - - name: DB_CONN - value: postgres - - name: DB_DATABASE - value: postgres - - name: DB_HOST - value: statping-postgresql - - name: DB_PASS - value: changeme - - name: DB_USER - value: postgres - - name: DESCRIPTION - value: This is a Statping instance deployed as Helm chart - - name: DISABLE_LOGS - value: "false" - - name: NAME - value: Statping Example - - name: POSTGRES_SSLMODE - value: disable - - name: TZ - value: UTC - - name: USE_CDN - value: "false" - - name: VIRTUAL_HOST - - name: VIRTUAL_PORT - value: "8080" - image: statping/statping:v0.90.74 - imagePullPolicy: IfNotPresent - livenessProbe: - failureThreshold: 3 - periodSeconds: 10 - successThreshold: 1 - tcpSocket: - port: 8080 - timeoutSeconds: 1 - name: statping - ports: - - containerPort: 8080 - name: http - protocol: TCP - readinessProbe: - failureThreshold: 3 - periodSeconds: 10 - successThreshold: 1 - tcpSocket: - port: 8080 - timeoutSeconds: 1 - resources: - startupProbe: - failureThreshold: 30 - periodSeconds: 5 - successThreshold: 1 - tcpSocket: - port: 8080 - timeoutSeconds: 1 - restartPolicy: Always diff --git a/statping/init-config.yaml b/statping/init-config.yaml index 433223a..501e195 100644 --- a/statping/init-config.yaml +++ b/statping/init-config.yaml @@ -5,11 +5,18 @@ metadata: data: init.sh: | #!/bin/bash - PGPASSWORD=YOUR_PASSWORD psql -v ON_ERROR_STOP=1 -h statping-postgres -p 5432 -U statping --dbname "statping" -f /init.d/init.sql - init.sql: | + if psql -p 5432 -l | grep statping + then + echo 'DATABASE EXIST' + else + psql -p 5432 -c 'CREATE DATABASE statping' + psql -v ON_ERROR_STOP=1 -p 5432 -d statping -f /init.d/init.sql + fi + psql -v ON_ERROR_STOP=1 -p 5432 -d statping -f /init.d/data.sql + data.sql: | TRUNCATE core; INSERT INTO "core" ("name", "description", "config", "api_secret", "style", "footer", "domain", "version", "language", "migration_id", "use_cdn", "allow_reports", "created_at", "updated_at", "oauth_providers", "gh_client_id", "gh_client_secret", "gh_users", "gh_orgs", "google_client_id", "google_client_secret", "google_users", "slack_client_id", "slack_client_secret", "slack_team", "slack_users", "custom_name", "custom_client_id", "custom_client_secret", "custom_endpoint_auth", "custom_endpoint_token", "custom_scopes", "custom_open_id") VALUES - ('demo status', 'This status page has sample data included', '', 'Siwo6GTDxM2wwl65K4kHKgu9QgmS7n6Q', '', '', 'http://localhost:8080', '0.90.74', 'en', 1674599079, 'f', 'f', '2023-01-24 22:24:39.291738+00', '2023-01-24 22:43:59.697317+00', 'local', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', NULL); + ('demo 3 status', 'This status page has sample data included', '', 'Siwo6GTDxM2wwl65K4kHKgu9QgmS7n6Q', '', '', 'http://localhost:8080', '0.90.74', 'en', 1674599079, 'f', 'f', '2023-01-24 22:24:39.291738+00', '2023-01-24 22:43:59.697317+00', 'local', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', NULL); TRUNCATE groups; INSERT INTO "groups" ("id", "name", "public", "order_id", "created_at", "updated_at") VALUES @@ -23,3 +30,100 @@ data: TRUNCATE users; INSERT INTO "users" ("id", "username", "password", "email", "api_key", "scopes", "administrator", "created_at", "updated_at") VALUES (1, 'mystatping', '$2a$14$r7n8uEuWgRegyu9Efa5mwuyazFQSejltE/xuJSB0ae6gufPV6O6oa', 'info@admin.com', '7d8b24cebdfaf57b4cd57c3b6fd803c95a5d4f838b4f7d0544842444809e2cf5', 'admin', 't', '2023-01-24 22:24:39.238789+00', '2023-01-24 22:52:19.360722+00'); + init.sql: | + CREATE TABLE "core" ( + "name" text NOT NULL, + "description" text NOT NULL, + "config" text, + "api_secret" text, + "style" text NOT NULL, + "footer" text, + "domain" text NOT NULL, + "version" text, + "language" text, + "migration_id" bigint, + "use_cdn" boolean DEFAULT false, + "allow_reports" boolean DEFAULT false, + "created_at" timestamptz, + "updated_at" timestamptz, + "oauth_providers" text, + "gh_client_id" text, + "gh_client_secret" text, + "gh_users" text, + "gh_orgs" text, + "google_client_id" text, + "google_client_secret" text, + "google_users" text, + "slack_client_id" text, + "slack_client_secret" text, + "slack_team" text, + "slack_users" text, + "custom_name" text, + "custom_client_id" text, + "custom_client_secret" text, + "custom_endpoint_auth" text, + "custom_endpoint_token" text, + "custom_scopes" text, + "custom_open_id" boolean + ) WITH (oids = false); + + CREATE SEQUENCE groups_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1; + + CREATE TABLE "groups" ( + "id" bigint DEFAULT nextval('groups_id_seq') NOT NULL, + "name" text, + "public" boolean DEFAULT true, + "order_id" integer DEFAULT '0', + "created_at" timestamptz, + "updated_at" timestamptz, + CONSTRAINT "groups_pkey" PRIMARY KEY ("id") + ) WITH (oids = false); + + CREATE SEQUENCE services_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1; + + CREATE TABLE "services" ( + "id" bigint DEFAULT nextval('services_id_seq') NOT NULL, + "name" text, + "domain" text, + "expected" text, + "expected_status" integer DEFAULT '200', + "check_interval" integer DEFAULT '30', + "check_type" text, + "method" text, + "post_data" text, + "port" integer NOT NULL, + "timeout" integer DEFAULT '30', + "order_id" integer DEFAULT '0', + "verify_ssl" boolean DEFAULT false, + "grpc_health_check" boolean DEFAULT false, + "public" boolean DEFAULT true, + "group_id" integer DEFAULT '0', + "tls_cert" text, + "tls_cert_key" text, + "tls_cert_root" text, + "headers" text, + "permalink" text, + "redirect" boolean DEFAULT false, + "created_at" timestamptz, + "updated_at" timestamptz, + "notify_after" bigint, + "allow_notifications" boolean DEFAULT true, + "notify_all_changes" boolean DEFAULT true, + CONSTRAINT "services_pkey" PRIMARY KEY ("id") + ) WITH (oids = false); + + CREATE SEQUENCE users_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1; + + CREATE TABLE "users" ( + "id" bigint DEFAULT nextval('users_id_seq') NOT NULL, + "username" character varying(100), + "password" text, + "email" character varying(100), + "api_key" text, + "scopes" text, + "administrator" boolean, + "created_at" timestamptz, + "updated_at" timestamptz, + CONSTRAINT "users_pkey" PRIMARY KEY ("id"), + CONSTRAINT "users_username_key" UNIQUE ("username") + ) WITH (oids = false); diff --git a/statping/kustomization.yaml b/statping/kustomization.yaml index 93412a2..49cd5f9 100644 --- a/statping/kustomization.yaml +++ b/statping/kustomization.yaml @@ -1,7 +1,7 @@ secretGenerator: - name: postgres-pass literals: - - password=YOUR_PASSWORD + - password=letmein resources: - postgres-deployment.yaml - init-config.yaml diff --git a/statping/postgres-deployment.yaml b/statping/postgres-deployment.yaml index c9fcec6..e6b3eae 100644 --- a/statping/postgres-deployment.yaml +++ b/statping/postgres-deployment.yaml @@ -15,7 +15,7 @@ spec: apiVersion: v1 kind: PersistentVolumeClaim metadata: - name: postgres-pv-claim + name: statping-postgres-pv-claim labels: app: statping spec: @@ -24,6 +24,7 @@ spec: resources: requests: storage: 2Gi + volumeMode: "Filesystem" --- apiVersion: apps/v1 kind: Deployment @@ -49,7 +50,7 @@ spec: name: postgres env: - name: POSTGRES_USER - value: statping + value: postgres - name: POSTGRES_PASSWORD valueFrom: secretKeyRef: @@ -64,4 +65,4 @@ spec: volumes: - name: postgres-persistent-storage persistentVolumeClaim: - claimName: postgres-pv-claim + claimName: statping-postgres-pv-claim diff --git a/statping/sql-sts.yaml b/statping/sql-sts.yaml deleted file mode 100644 index 4bba168..0000000 --- a/statping/sql-sts.yaml +++ /dev/null @@ -1,116 +0,0 @@ -apiVersion: apps/v1 -kind: StatefulSet -metadata: - labels: - app.kubernetes.io/component: primary - app.kubernetes.io/instance: statping - app.kubernetes.io/name: postgresql - name: statping-postgresql - namespace: default -spec: - podManagementPolicy: OrderedReady - replicas: 1 - revisionHistoryLimit: 10 - selector: - matchLabels: - app.kubernetes.io/component: primary - app.kubernetes.io/instance: statping - app.kubernetes.io/name: postgresql - serviceName: statping-postgresql-hl - template: - metadata: - labels: - app.kubernetes.io/component: primary - app.kubernetes.io/instance: statping - app.kubernetes.io/name: postgresql - name: statping-postgresql - spec: - containers: - - env: - - name: BITNAMI_DEBUG - value: "false" - - name: POSTGRESQL_PORT_NUMBER - value: "5432" - - name: POSTGRESQL_VOLUME_DIR - value: /bitnami/postgresql - - name: PGDATA - value: /bitnami/postgresql/data - - name: POSTGRES_PASSWORD - valueFrom: - secretKeyRef: - key: postgres-password - name: statping-postgresql - - name: POSTGRES_DB - value: postgres - - name: POSTGRESQL_ENABLE_LDAP - value: "no" - - name: POSTGRESQL_ENABLE_TLS - value: "no" - - name: POSTGRESQL_LOG_HOSTNAME - value: "false" - - name: POSTGRESQL_LOG_CONNECTIONS - value: "false" - - name: POSTGRESQL_LOG_DISCONNECTIONS - value: "false" - - name: POSTGRESQL_PGAUDIT_LOG_CATALOG - value: "off" - - name: POSTGRESQL_CLIENT_MIN_MESSAGES - value: error - - name: POSTGRESQL_SHARED_PRELOAD_LIBRARIES - value: pgaudit - image: docker.io/bitnami/postgresql:14.4.0-debian-11-r4 - imagePullPolicy: IfNotPresent - livenessProbe: - exec: - command: - - /bin/sh - - -c - - exec pg_isready -U "postgres" -d "dbname=postgres" -h 127.0.0.1 -p 5432 - failureThreshold: 6 - initialDelaySeconds: 30 - periodSeconds: 10 - successThreshold: 1 - timeoutSeconds: 5 - name: postgresql - ports: - - containerPort: 5432 - name: tcp-postgresqlh - protocol: TCP - readinessProbe: - exec: - command: - - /bin/sh - - -c - - -e - - | - exec pg_isready -U "postgres" -d "dbname=postgres" -h 127.0.0.1 -p 5432 - [ -f /opt/bitnami/postgresql/tmp/.initialized ] || [ -f /bitnami/postgresql/.initialized ] - failureThreshold: 6 - initialDelaySeconds: 5 - periodSeconds: 10 - successThreshold: 1 - timeoutSeconds: 5 - volumeMounts: - - mountPath: /dev/shm - name: dshm - - mountPath: /bitnami/postgresql - name: data - restartPolicy: Always - volumes: - - emptyDir: - medium: Memory - name: dshm - updateStrategy: - type: RollingUpdate - volumeClaimTemplates: - - apiVersion: v1 - kind: PersistentVolumeClaim - metadata: - name: data - spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 8Gi - volumeMode: Filesystem diff --git a/statping/statping-deployment.yaml b/statping/statping-deployment.yaml index d4e6128..5ec26eb 100644 --- a/statping/statping-deployment.yaml +++ b/statping/statping-deployment.yaml @@ -32,6 +32,23 @@ spec: app: statping tier: frontend spec: + initContainers: + - image: postgres:15.1 + name: postgres-importer + env: + - name: PGHOST + value: statping-postgres + - name: PGUSER + value: postgres + - name: PGPASSWORD + valueFrom: + secretKeyRef: + name: postgres-pass + key: password + volumeMounts: + - name: importer + mountPath: /init.d + command: ["/init.d/init.sh"] containers: - image: statping/statping name: statping @@ -43,7 +60,7 @@ spec: - name: DB_DATABASE value: statping - name: DB_USER - value: statping + value: postgres - name: DB_PASS valueFrom: secretKeyRef: @@ -52,22 +69,8 @@ spec: ports: - containerPort: 8080 name: statping ---- -apiVersion: v1 -kind: Pod -metadata: - name: importer -spec: - containers: - - image: postgres:15.1 - name: postgres-importer - volumeMounts: + volumes: - name: importer - mountPath: /init.d - command: ["/init.d/init.sh"] - volumes: - - name: importer - configMap: - name: importer - defaultMode: 0500 - restartPolicy: Never + configMap: + name: importer + defaultMode: 0500