Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/google/go-containerregistry/pkg/authn/k8schain v0.0.0-20211222182933-7c19fa370dbd
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/hpcloud/tail v1.0.1-0.20180514194441-a1dbeea552b7
github.com/lib/pq v1.10.6
github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a
github.com/onsi/gomega v1.17.0
github.com/prometheus/client_golang v1.11.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,8 @@ github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.8.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lib/pq v1.9.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lib/pq v1.10.3/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lib/pq v1.10.6 h1:jbk+ZieJ0D7EVGJYpL9QTz7/YW6UHbmdnZWYyK5cdBs=
github.com/lib/pq v1.10.6/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
Expand Down
7 changes: 2 additions & 5 deletions manifests/v1beta1/components/db-manager/db-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ spec:
image: docker.io/kubeflowkatib/katib-db-manager
env:
- name: DB_NAME
value: "mysql"
value: "postgres"
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: katib-mysql-secrets
key: MYSQL_ROOT_PASSWORD
value: "katib"
command:
- "./katib-db-manager"
ports:
Expand Down
9 changes: 9 additions & 0 deletions manifests/v1beta1/components/postgres/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- postgres.yaml
- pvc.yaml
- secret.yaml
- service.yaml
42 changes: 42 additions & 0 deletions manifests/v1beta1/components/postgres/postgres.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: katib-postgres
namespace: kubeflow
labels:
katib.kubeflow.org/component: postgres
spec:
replicas: 1
selector:
matchLabels:
katib.kubeflow.org/component: postgres
strategy:
type: Recreate
template:
metadata:
labels:
katib.kubeflow.org/component: postgres
annotations:
sidecar.istio.io/inject: "false"
spec:
containers:
- name: katib-postgres
image: postgres:14.3-alpine
envFrom:
- secretRef:
name: katib-postgres-secrets
env:
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
ports:
- name: postgres
containerPort: 5432
protocol: TCP
# volumeMounts:
# - name: katib-postgres
# mountPath: /var/lib/postgresql/data
# volumes:
# - name: katib-postgres
# persistentVolumeClaim:
# claimName: katib-postgres
12 changes: 12 additions & 0 deletions manifests/v1beta1/components/postgres/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: katib-postgres
namespace: kubeflow
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
10 changes: 10 additions & 0 deletions manifests/v1beta1/components/postgres/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: v1
kind: Secret
type: Opaque
metadata:
name: katib-postgres-secrets
data:
POSTGRES_USER: a2F0aWI= # katib
POSTGRES_PASSWORD: a2F0aWI= # katib
POSTGRES_DB: a2F0aWI= # katib
16 changes: 16 additions & 0 deletions manifests/v1beta1/components/postgres/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
apiVersion: v1
kind: Service
metadata:
name: katib-postgres
namespace: kubeflow
labels:
katib.kubeflow.org/component: postgres
spec:
type: ClusterIP
ports:
- port: 5432
protocol: TCP
name: dbapi
selector:
katib.kubeflow.org/component: postgres
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ resources:
- ../../components/crd/
# Katib DB manager.
- ../../components/db-manager/
# Katib DB mysql.
- ../../components/mysql/
# # Katib DB mysql.
# - ../../components/mysql/
# Katib DB postgres.
- ../../components/postgres/
# Katib UI.
- ../../components/ui/
# Katib Cert Generator
Expand Down
19 changes: 14 additions & 5 deletions pkg/db/v1beta1/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ limitations under the License.
package common

const (
DBUserEnvName = "DB_USER"

DBNameEnvName = "DB_NAME"
DBUserEnvName = "DB_USER"
DBNameEnvName = "DB_NAME"
DBPasswordEnvName = "DB_PASSWORD"

MySqlDBNameEnvValue = "mysql"

DBPasswordEnvName = "DB_PASSWORD"

MySQLDBHostEnvName = "KATIB_MYSQL_DB_HOST"
MySQLDBPortEnvName = "KATIB_MYSQL_DB_PORT"
MySQLDatabase = "KATIB_MYSQL_DB_DATABASE"
Expand All @@ -33,4 +31,15 @@ const (
DefaultMySQLDatabase = "katib"
DefaultMySQLHost = "katib-mysql"
DefaultMySQLPort = "3306"

PostgresSQLDBNameEnvValue = "postgres"

PostgreSQLDBHostEnvName = "KATIB_POSTGRESQL_DB_HOST"
PostgreSQLDBPortEnvName = "KATIB_POSTGRESQL_DB_PORT"
PostgreSQLDatabase = "KATIB_POSTGRESQL_DB_DATABASE"

DefaultPostgreSQLUser = "katib"
DefaultPostgreSQLDatabase = "katib"
DefaultPostgreSQLHost = "katib-postgres"
DefaultPostgreSQLPort = "5432"
)
6 changes: 6 additions & 0 deletions pkg/db/v1beta1/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ import (

"github.com/kubeflow/katib/pkg/db/v1beta1/common"
"github.com/kubeflow/katib/pkg/db/v1beta1/mysql"
"github.com/kubeflow/katib/pkg/db/v1beta1/postgres"
"k8s.io/klog"
)

func NewKatibDBInterface(dbName string) (common.KatibDBInterface, error) {

if dbName == common.MySqlDBNameEnvValue {
klog.Info("Using MySQL")
return mysql.NewDBInterface()
} else if dbName == common.PostgresSQLDBNameEnvValue {
klog.Info("Using Postgres")
return postgres.NewDBInterface()
}
return nil, errors.New("Invalid DB Name")
}
47 changes: 47 additions & 0 deletions pkg/db/v1beta1/postgres/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Copyright 2022 The Kubeflow Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package postgres

import (
"fmt"

"k8s.io/klog"
)

func (d *dbConn) DBInit() {
db := d.db
klog.Info("Initializing v1beta1 DB schema")

_, err := db.Exec(`CREATE TABLE IF NOT EXISTS observation_logs
(trial_name VARCHAR(255) NOT NULL,
id serial PRIMARY KEY,
time TIMESTAMP(6),
metric_name VARCHAR(255) NOT NULL,
value TEXT NOT NULL)`)
if err != nil {
klog.Fatalf("Error creating observation_logs table: %v", err)
}
}

func (d *dbConn) SelectOne() error {
db := d.db
_, err := db.Exec(`SELECT 1`)
if err != nil {
return fmt.Errorf("Error `SELECT 1` probing: %v", err)
}
return nil
}
Loading