-
Notifications
You must be signed in to change notification settings - Fork 76
K8SPG-901: allow running without pgbouncer #1443
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
+327
−50
Merged
Changes from 4 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
172c718
allow running withoug pgbouncer
mayankshah1607 3ff7fb3
use primary service
mayankshah1607 2ec2260
update comment
mayankshah1607 8523f43
Merge branch 'main' into K8SPG-901
mayankshah1607 84bcbc5
add unit test
mayankshah1607 4cb911c
potential nil pointer deref
mayankshah1607 188c2d4
update ToCrunchy unit tests
mayankshah1607 e28166a
comments
mayankshah1607 c494bf7
add test for getHost
mayankshah1607 a0474fe
imports
mayankshah1607 d4a602c
linting
mayankshah1607 fe4c5fc
fix tests
mayankshah1607 a0a87ac
backward compatibility
mayankshah1607 67ecb0f
improvements
mayankshah1607 e1cb385
bug fixes
mayankshah1607 82b4dd1
linting
mayankshah1607 384bda1
linting
mayankshah1607 4e20c0e
test fix
mayankshah1607 49eb7f9
Merge branch 'main' into K8SPG-901
mayankshah1607 a6263ba
Merge branch 'main' into K8SPG-901
mayankshah1607 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ package pgcluster | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "context" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/pkg/errors" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| corev1 "k8s.io/api/core/v1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -11,16 +12,33 @@ import ( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| "k8s.io/client-go/util/retry" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/percona/percona-postgresql-operator/v2/internal/controller/postgrescluster" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/percona/percona-postgresql-operator/v2/internal/naming" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| pNaming "github.com/percona/percona-postgresql-operator/v2/percona/naming" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| v2 "github.com/percona/percona-postgresql-operator/v2/pkg/apis/pgv2.percona.com/v2" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/percona/percona-postgresql-operator/v2/pkg/apis/postgres-operator.crunchydata.com/v1beta1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (r *PGClusterReconciler) getHost(ctx context.Context, cr *v2.PerconaPGCluster) (string, error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| svcName := cr.Name + "-pgbouncer" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| postgresCluster := &v1beta1.PostgresCluster{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ObjectMeta: metav1.ObjectMeta{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Name: cr.Name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Namespace: cr.Namespace, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| svcFQDN := func(svcName, ns string) string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return fmt.Sprintf("%s.%s.svc", svcName, ns) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // If proxy is not configured, use the primary service | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if cr.Spec.Proxy == nil || cr.Spec.Proxy.PGBouncer == nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return svcFQDN(naming.ClusterPrimaryService(postgresCluster).Name, postgresCluster.Namespace), nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| return svcFQDN(naming.ClusterPrimaryService(postgresCluster).Name, postgresCluster.Namespace), nil | |
| svcName := naming.ClusterPrimaryService(postgresCluster).Name | |
| // If the primary is exposed via LoadBalancer, prefer its external hostname/IP. | |
| if cr.Spec.Expose != nil && cr.Spec.Expose.Type == string(corev1.ServiceTypeLoadBalancer) { | |
| svc := &corev1.Service{} | |
| err := r.Client.Get(ctx, types.NamespacedName{Namespace: cr.Namespace, Name: svcName}, svc) | |
| if err != nil { | |
| return "", errors.Wrapf(err, "get %s service", svcName) | |
| } | |
| var host string | |
| for _, i := range svc.Status.LoadBalancer.Ingress { | |
| if len(i.Hostname) > 0 { | |
| host = i.Hostname | |
| } else if len(i.IP) > 0 { | |
| host = i.IP | |
| } | |
| } | |
| if host != "" { | |
| return host, nil | |
| } | |
| } | |
| return svcFQDN(svcName, postgresCluster.Namespace), nil |
mayankshah1607 marked this conversation as resolved.
Outdated
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.