Skip to content

Commit

Permalink
address pr feedback and fix merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
fenic-fawkes committed Jun 17, 2024
1 parent dfe0428 commit 919062d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
41 changes: 21 additions & 20 deletions pkg/controllers/vrep/replication_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 919062d

Please sign in to comment.