Skip to content
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

Add environment variable option to set postgres ssl mode #2266

Merged
merged 1 commit into from
Mar 5, 2024

Conversation

ckcd
Copy link
Contributor

@ckcd ckcd commented Mar 1, 2024

What this PR does / why we need it:
In postgres, sslmode may has different value such as disable, prefer and require. But for now in postgres.go#L52 it only allows disable. So we should add an environment variable option to allow users to specify the value of sslmode.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #2244

Checklist:

  • Docs included if any changes are user facing

(Need to update list of Environment Variables for Katib Components on Katib DB Manager. I will create additional pull request to address the change on website.)

@ckcd
Copy link
Contributor Author

ckcd commented Mar 1, 2024

@andreyvelich @anencore94 @johnugeorge Please help to review it if you are available, thanks a lot.

Copy link
Member

@tenzen-y tenzen-y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ckcd Thank you for this contribution!
Generally lgtm

@kubeflow/wg-automl-leads Could you approve CI?

pkg/db/v1beta1/common/const.go Outdated Show resolved Hide resolved
pkg/db/v1beta1/common/const.go Outdated Show resolved Hide resolved
pkg/db/v1beta1/postgres/postgres.go Outdated Show resolved Hide resolved
pkg/db/v1beta1/postgres/postgres_test.go Outdated Show resolved Hide resolved
@ckcd
Copy link
Contributor Author

ckcd commented Mar 2, 2024

@tenzen-y Thanks for your reply! I made some changes according to your comments.

Copy link
Member

@tenzen-y tenzen-y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementations are lgtm

dbName = "host=katib-postgres port=5432 user=katib password= dbname=katib sslmode=require"
if getDbName() != dbName {
t.Errorf("getDbName returns wrong value %v", getDbName())
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

	cases := map[string]struct{
		updateEnvs map[string]string
		wantName string	
	}{
		"All parameters are default": {
		...
		},
		"Set KATIB_POSTGRESQL_SSL_MODE": {
		...
		}
	}
	for name, tc := range cases {
		t.Run(name, func(t *testsing.T) {
			// TEST
		})
	}

Please could you refine these tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tenzen-y Oh I got your point. I made the change based on your suggestion. And add more test cases for each env. Please help to review it. Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ckcd Thanks for your great refining! I'd be appreciated for your effort!

@tenzen-y
Copy link
Member

tenzen-y commented Mar 2, 2024

Also, this guide would be helpful for first time contributor: https://github.com/kubeflow/katib/blob/master/docs/developer-guide.md#go-development

@google-oss-prow google-oss-prow bot added size/M and removed size/S labels Mar 4, 2024
Copy link
Member

@tenzen-y tenzen-y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nits.
Otherwise lgtm

wantName string
}{
"All parameters are default": {
updateEnvs: map[string]string{},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
updateEnvs: map[string]string{},

I think this initialization isn't needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, remove the initialization.

dbName = "host=katib-postgres port=5432 user=katib password= dbname=katib sslmode=require"
if getDbName() != dbName {
t.Errorf("getDbName returns wrong value %v", getDbName())
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ckcd Thanks for your great refining! I'd be appreciated for your effort!

Comment on lines 183 to 186
if got := getDbName(); got != tc.wantName {
t.Errorf("getDbName() = %v, want %v", got, tc.wantName)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if got := getDbName(); got != tc.wantName {
t.Errorf("getDbName() = %v, want %v", got, tc.wantName)
}
gotName := getDbName()
if diff := cmp.Diff(tc.wantName, gotName); len(diff) != 0 {
t.Errorf("Unexpected DBName (-want,+got):\n%s", diff)
}

To improve visibility, we should use the cmp.Diff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, update to cmp.Diff.

@tenzen-y tenzen-y mentioned this pull request Mar 4, 2024
1 task
@tenzen-y
Copy link
Member

tenzen-y commented Mar 4, 2024

@ckcd Could you rebase this PR since we have fixed the CI errors here: #2267.

@ckcd
Copy link
Contributor Author

ckcd commented Mar 5, 2024

@tenzen-y thanks for your great suggestions! I rebase the code and made the changes. Please take a look, thanks.

Copy link
Member

@tenzen-y tenzen-y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a comment for a nit.

@@ -18,6 +18,7 @@ package postgres

import (
"fmt"
"github.com/google/go-cmp/cmp"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"github.com/google/go-cmp/cmp"

Could you move it to the third group? You can verify import orders to perform make lint on your local.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, update based on the lint.

@tenzen-y
Copy link
Member

tenzen-y commented Mar 5, 2024

@kubeflow/wg-automl-leads Could you approve CI?

Signed-off-by: Kun Chang <curtis@mail.ustc.edu.cn>
@ckcd
Copy link
Contributor Author

ckcd commented Mar 5, 2024

@tenzen-y thanks, update based on the lint.

@ckcd
Copy link
Contributor Author

ckcd commented Mar 5, 2024

@kubeflow/wg-automl-leads Could you approve CI?

Copy link
Member

@tenzen-y tenzen-y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

/lgtm
/approve
/hold
to wait for approved CI from @kubeflow/wg-automl-leads

Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ckcd, tenzen-y

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Member

@andreyvelich andreyvelich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making this improvement @ckcd!
Please can you submit PR to add this parameter to the Katib docs ?
https://www.kubeflow.org/docs/components/katib/env-variables/#katib-db-manager

@tenzen-y
Copy link
Member

tenzen-y commented Mar 5, 2024

/hold cancel

@google-oss-prow google-oss-prow bot merged commit a2f3fca into kubeflow:master Mar 5, 2024
59 checks passed
@ckcd
Copy link
Contributor Author

ckcd commented Mar 6, 2024

@tenzen-y @andreyvelich thanks a lot for your great help! I will submit PR for the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide an option to pass DB_SSLMODE for postgres
3 participants