-
Notifications
You must be signed in to change notification settings - Fork 492
Support postgres as a katib db #1921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
google-oss-prow
merged 23 commits into
kubeflow:master
from
anencore94:feature/postgres-for-katib-backend-db
Aug 19, 2022
Merged
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
ca8712c
implement postgres for katib db
anencore94 edfec08
fix yaml lint
anencore94 507741a
apply go mod tidy
anencore94 9fce9dd
Update manifests/v1beta1/components/postgres/postgres.yaml
anencore94 7cdc885
refactoring by reviews
anencore94 3d970cc
Merge branch 'feature/postgres-for-katib-backend-db' of https://githu…
anencore94 a3ca70d
change to install only mysql by default
anencore94 661ede8
remove useless import
anencore94 c1c0a90
add postgres kustomization and e2e test for it
anencore94 850c54a
change mysql installation files to be variable
anencore94 886b473
fix shell scripts
anencore94 e41d3e4
fix lint
anencore94 eb473c4
fix image name
anencore94 10715b4
set default value on github action workflow
anencore94 0fb784e
make postgres deployment to use pvc
anencore94 68ba595
temporarily comments
anencore94 7a68213
uncomment invalid experiments
anencore94 1d38d04
test with for loop
anencore94 a516dec
sleep until controller created well
anencore94 e309a42
add some comments
anencore94 aacdaea
Update pkg/db/v1beta1/postgres/postgres.go
anencore94 d12e632
Update pkg/db/v1beta1/postgres/postgres_test.go
anencore94 13cf73b
refactor by reviews
anencore94 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.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 | ||
This file contains hidden or 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 hidden or 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 hidden or 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 |
46 changes: 46 additions & 0 deletions
46
manifests/v1beta1/installs/katib-standalone-postgres/kustomization.yaml
This file contains hidden or 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,46 @@ | ||
| --- | ||
| 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 | ||
| patches: | ||
| - patch: |- | ||
anencore94 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - op: replace | ||
| path: /spec/template/spec/containers/0/env | ||
| value: | ||
| - name: DB_NAME | ||
| value: "postgres" | ||
| - name: DB_PASSWORD | ||
| value: "katib" | ||
| target: | ||
| kind: Deployment | ||
| labelSelector: "katib.kubeflow.org/component=db-manager" | ||
This file contains hidden or 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,49 @@ | ||
| /* | ||
| 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 db, err := sql.Open(driverName, dataSourceName); err == nil { | ||
anencore94 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.