-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support postgres as a katib db (#1921)
* implement postgres for katib db * fix yaml lint * apply go mod tidy * Update manifests/v1beta1/components/postgres/postgres.yaml Co-authored-by: Yuki Iwai <[email protected]> * refactoring by reviews - split openconnection to common packages - add unit test for postgres db * change to install only mysql by default * remove useless import * add postgres kustomization and e2e test for it * change mysql installation files to be variable * fix shell scripts * fix lint * fix image name * set default value on github action workflow * make postgres deployment to use pvc * temporarily comments * uncomment invalid experiments * test with for loop * sleep until controller created well * add some comments * Update pkg/db/v1beta1/postgres/postgres.go Co-authored-by: Yuki Iwai <[email protected]> * Update pkg/db/v1beta1/postgres/postgres_test.go Co-authored-by: Yuki Iwai <[email protected]> * refactor by reviews Co-authored-by: Yuki Iwai <[email protected]>
- Loading branch information
1 parent
6fa3913
commit cc888af
Showing
26 changed files
with
662 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.5-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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
41 changes: 41 additions & 0 deletions
41
manifests/v1beta1/installs/katib-standalone-postgres/kustomization.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
namespace: kubeflow | ||
resources: | ||
# Namespace. | ||
- ../../components/namespace/ | ||
# Katib controller. | ||
- ../../components/controller/ | ||
# Katib CRDs. | ||
- ../../components/crd/ | ||
# Katib DB manager. | ||
- ../../components/db-manager/ | ||
# Katib DB postgres. | ||
- ../../components/postgres/ | ||
# Katib UI. | ||
- ../../components/ui/ | ||
# Katib Cert Generator | ||
- ../../components/cert-generator/ | ||
# Katib webhooks. | ||
- ../../components/webhook/ | ||
images: | ||
- name: docker.io/kubeflowkatib/katib-controller | ||
newName: docker.io/kubeflowkatib/katib-controller | ||
newTag: latest | ||
- name: docker.io/kubeflowkatib/katib-db-manager | ||
newName: docker.io/kubeflowkatib/katib-db-manager | ||
newTag: latest | ||
- name: docker.io/kubeflowkatib/katib-ui | ||
newName: docker.io/kubeflowkatib/katib-ui | ||
newTag: latest | ||
- name: docker.io/kubeflowkatib/cert-generator | ||
newName: docker.io/kubeflowkatib/cert-generator | ||
newTag: latest | ||
patchesJson6902: | ||
- target: | ||
group: apps | ||
version: v1 | ||
kind: Deployment | ||
name: katib-db-manager | ||
path: ./patches/db-manager.yaml |
8 changes: 8 additions & 0 deletions
8
manifests/v1beta1/installs/katib-standalone-postgres/patches/db-manager.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
- op: replace | ||
path: /spec/template/spec/containers/0/env | ||
value: | ||
- name: DB_NAME | ||
value: "postgres" | ||
- name: DB_PASSWORD | ||
value: "katib" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
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 common | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
"time" | ||
|
||
"k8s.io/klog" | ||
) | ||
|
||
func OpenSQLConn(driverName string, dataSourceName string, interval time.Duration, | ||
timeout time.Duration) (*sql.DB, error) { | ||
ticker := time.NewTicker(interval) | ||
defer ticker.Stop() | ||
|
||
timeoutC := time.After(timeout) | ||
for { | ||
select { | ||
case <-ticker.C: | ||
if db, err := sql.Open(driverName, dataSourceName); err == nil { | ||
if err = db.Ping(); err == nil { | ||
return db, nil | ||
} | ||
klog.Errorf("Ping to Katib db failed: %v", err) | ||
} else { | ||
klog.Errorf("Open sql connection failed: %v", err) | ||
} | ||
case <-timeoutC: | ||
return nil, fmt.Errorf("Timeout waiting for DB conn successfully opened.") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.