From 919062dae86e73dc7b0752fea1a494bea2a4c3cf Mon Sep 17 00:00:00 2001 From: fenic fawkes <164062544+fenic-fawkes@users.noreply.github.com> Date: Mon, 17 Jun 2024 13:24:08 -0400 Subject: [PATCH] address pr feedback and fix merge conflict --- go.mod | 4 +- go.sum | 4 +- .../vrep/replication_reconciler.go | 41 ++++++++++--------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index 3b11e920f..4f2c86454 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/onsi/gomega v1.24.2 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.14.0 - github.com/vertica/vcluster v1.2.1-0.20240610161328-bdbde51b8c0b + github.com/vertica/vcluster v1.2.1-0.20240617145840-3a04de02312c github.com/vertica/vertica-sql-go v1.1.1 go.uber.org/zap v1.25.0 golang.org/x/text v0.14.0 @@ -100,5 +100,3 @@ require ( sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect sigs.k8s.io/yaml v1.3.0 // indirect ) - -replace github.com/vertica/vcluster => github.com/fenic-fawkes/vcluster v0.0.3 diff --git a/go.sum b/go.sum index f1e1e3861..99c9c5b13 100644 --- a/go.sum +++ b/go.sum @@ -92,8 +92,6 @@ github.com/evanphx/json-patch/v5 v5.6.0 h1:b91NhWfaz02IuVxO9faSllyAtNXHMPkC5J8sJ github.com/evanphx/json-patch/v5 v5.6.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4= github.com/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w= github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg= -github.com/fenic-fawkes/vcluster v0.0.3 h1:XXqgqlY4wj7xHmE2J1YcBe77f0VVv9Egx9PQyV37NY8= -github.com/fenic-fawkes/vcluster v0.0.3/go.mod h1:zkTLy1hF6LzTeWmXiGYLFzihbi397WTQhPZ9xX4B+FY= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= @@ -324,6 +322,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/theckman/yacspin v0.13.12 h1:CdZ57+n0U6JMuh2xqjnjRq5Haj6v1ner2djtLQRzJr4= github.com/theckman/yacspin v0.13.12/go.mod h1:Rd2+oG2LmQi5f3zC3yeZAOl245z8QOvrH4OPOJNZxLg= github.com/tonglil/buflogr v1.0.1 h1:WXFZLKxLfqcVSmckwiMCF8jJwjIgmStJmg63YKRF1p0= +github.com/vertica/vcluster v1.2.1-0.20240617145840-3a04de02312c h1:P/JNHZL+NDI8x6/1VBsm2H4A4sp/tQn+7bUKtU/7Sms= +github.com/vertica/vcluster v1.2.1-0.20240617145840-3a04de02312c/go.mod h1:zkTLy1hF6LzTeWmXiGYLFzihbi397WTQhPZ9xX4B+FY= github.com/vertica/vertica-sql-go v1.1.1 h1:sZYijzBbvdAbJcl4cYlKjR+Eh/X1hGKzukWuhh8PjvI= github.com/vertica/vertica-sql-go v1.1.1/go.mod h1:fGr44VWdEvL+f+Qt5LkKLOT7GoxaWdoUCnPBU9h6t04= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/pkg/controllers/vrep/replication_reconciler.go b/pkg/controllers/vrep/replication_reconciler.go index 301b99c7f..b9459247e 100644 --- a/pkg/controllers/vrep/replication_reconciler.go +++ b/pkg/controllers/vrep/replication_reconciler.go @@ -37,7 +37,6 @@ import ( vrepstatus "github.com/vertica/vertica-kubernetes/pkg/vrepstatus" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -237,38 +236,40 @@ func (r *ReplicationReconciler) checkSandboxExists() error { return nil } +// used below to avoid a really messy if condition +func shouldPickService(vdb *vapi.VerticaDB, sc *vapi.Subcluster, sandboxName, svcName string) bool { + if svcName != "" { + return sc.ServiceName == svcName + } + + if vdb.GetSubclusterSandboxName(sc.Name) != sandboxName { + return false + } + + return sc.IsPrimary() +} + // filters services based on svcName if not empty and main/sandbox cluster // picks first service that matches. if svcName is empty this will be the first service assigned to the database // if svcName is non-empty it will be the service matching that name // returns a valid hostname for the service or an error if a valid matching service couldn't be found func (r *ReplicationReconciler) getServiceHostname(vdb *vapi.VerticaDB, sandboxName, svcName string) (ip string, err error) { - clusterName := vdb.Name - if sandboxName != vapi.MainCluster { - clusterName += " (sandbox " + sandboxName + ")" - } - - if svcName != "" { - inputName := types.NamespacedName{Namespace: vdb.Namespace, Name: svcName} - for i := range vdb.Spec.Subclusters { - sc := &vdb.Spec.Subclusters[i] - scSvcName := names.GenExtSvcName(vdb, sc) - if inputName == scSvcName && sandboxName == vdb.GetSubclusterSandboxName(sc.Name) { - return fmt.Sprintf("%s.%s.svc.cluster.local", scSvcName.Name, scSvcName.Namespace), nil - } - } - - return "", fmt.Errorf("could not find service %s in %s", svcName, clusterName) - } - for i := range vdb.Spec.Subclusters { sc := &vdb.Spec.Subclusters[i] - if sandboxName == vdb.GetSubclusterSandboxName(sc.Name) && sc.IsPrimary() { + if shouldPickService(vdb, sc, sandboxName, svcName) { scSvcName := names.GenExtSvcName(vdb, sc) return fmt.Sprintf("%s.%s.svc.cluster.local", scSvcName.Name, scSvcName.Namespace), nil } } + clusterName := "the main cluster" + if sandboxName != vapi.MainCluster { + clusterName = "sandbox " + sandboxName + } + if svcName != "" { + return "", fmt.Errorf("could not find service %s in %s", svcName, clusterName) + } return "", fmt.Errorf("could not find service in %s", clusterName) }