Skip to content

Commit

Permalink
Address review comments by @seshachalam-yv
Browse files Browse the repository at this point in the history
  • Loading branch information
anveshreddy18 committed Nov 8, 2024
1 parent 4c31696 commit ab83692
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
19 changes: 14 additions & 5 deletions pkg/miscellaneous/miscellaneous.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const (
// ScaledToMultiNodeAnnotationKey defines annotation key for scale-up to multi-node cluster.
ScaledToMultiNodeAnnotationKey = "gardener.cloud/scaled-to-multi-node"

httpProtocol = "http"
https = "https"

// etcdWrapperPort defines the port no. used by etcd-wrapper.
etcdWrapperPort = "9095"
Expand Down Expand Up @@ -610,16 +610,25 @@ func IsPeerURLTLSEnabled() (bool, error) {
if err != nil {
return false, fmt.Errorf("failed to get initial advertise peer URLs: %w", err)
}

peerURLsSchemes := make([]string, 0)
for _, peerURL := range memberPeerURLs {
parsedPeerURL, err := url.Parse(peerURL)
if err != nil {
return false, fmt.Errorf("failed to parse peer URL %s: %w", peerURL, err)
}
if parsedPeerURL.Scheme == httpProtocol {
return false, nil
}
peerURLsSchemes = append(peerURLsSchemes, parsedPeerURL.Scheme)
}
return true, nil

sort.Strings(peerURLsSchemes)

if peerURLsSchemes[0] != peerURLsSchemes[len(peerURLsSchemes)-1] {
return false, fmt.Errorf("peer URLs have different schemes")
}
if peerURLsSchemes[0] == https {
return true, nil
}
return false, nil
}

// GetPrevScheduledSnapTime returns the previous schedule snapshot time.
Expand Down
24 changes: 24 additions & 0 deletions pkg/miscellaneous/miscellaneous_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,30 @@ initial-cluster: etcd1=https://0.0.0.0:2380`
})
})

Context("with both TLS and non-TLS enabled peer url for the same pod", func() {
BeforeEach(func() {
etcdConfigYaml := `name: etcd1
initial-advertise-peer-urls:
test_pod1:
- https://etcd-main-peer.default:2380
- http://etcd-main-peer.default:2381
test_pod2:
- https://etcd-main-peer.default:2380
- https://etcd-main-peer.default:2381
test_pod3:
- https://etcd-main-peer.default:2380
- https://etcd-main-peer.default:2381
initial-cluster: etcd1=https://0.0.0.0:2380`
err := os.WriteFile(outfile, []byte(etcdConfigYaml), 0755)
Expect(err).ShouldNot(HaveOccurred())
})
It("should return error", func() {
enabled, err := IsPeerURLTLSEnabled()
Expect(err).Should(HaveOccurred())
Expect(enabled).To(BeFalse())
})
})

Context("with empty peer url passed", func() {
BeforeEach(func() {
etcdConfigYaml := `name: etcd1
Expand Down

0 comments on commit ab83692

Please sign in to comment.