Skip to content

Commit

Permalink
Fix policy in case of hostless VS (#3328)
Browse files Browse the repository at this point in the history
  • Loading branch information
arzzon authored Mar 13, 2024
1 parent 5a33ccf commit 6c7fcca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions pkg/controller/resourceConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -3043,15 +3043,14 @@ func hasWildcardHost(hosts []string) bool {
// getUniqueHosts returns unique hosts from host and hostAliases
func getUniqueHosts(host string, hostAliases []string) []string {
uniqueHostsMap := make(map[string]struct{})
if host != "" {
uniqueHostsMap[host] = struct{}{}
}
for _, host := range hostAliases {
uniqueHostsMap[host] = struct{}{}
}
uniqueHostsMap[host] = struct{}{}
var uniqueHosts []string
for host := range uniqueHostsMap {
uniqueHosts = append(uniqueHosts, host)
uniqueHosts = append(uniqueHosts, host)
for _, host := range hostAliases {
if _, ok := uniqueHostsMap[host]; !ok {
uniqueHostsMap[host] = struct{}{}
uniqueHosts = append(uniqueHosts, host)
}
}
return uniqueHosts
}
4 changes: 2 additions & 2 deletions pkg/controller/resourceConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1802,9 +1802,9 @@ var _ = Describe("Resource Config Tests", func() {
It("Verifies getUniqueHosts", func() {
Expect(getUniqueHosts(vs.Spec.Host, vs.Spec.HostAliases)).To(ConsistOf([]string{vs.Spec.Host}), "Incorrect unique hosts")
vs.Spec.Host = ""
Expect(getUniqueHosts(vs.Spec.Host, vs.Spec.HostAliases)).To(BeNil(), "Incorrect unique hosts")
Expect(getUniqueHosts(vs.Spec.Host, vs.Spec.HostAliases)).To(ConsistOf([]string{""}), "Incorrect unique hosts")
vs.Spec.HostAliases = []string{"test1.com", "test2.com", "test1.com", "test1.com", "test2.com"}
Expect(getUniqueHosts(vs.Spec.Host, vs.Spec.HostAliases)).To(ConsistOf([]string{"test1.com", "test2.com"}), "Incorrect unique hosts")
Expect(getUniqueHosts(vs.Spec.Host, vs.Spec.HostAliases)).To(ConsistOf([]string{"", "test1.com", "test2.com"}), "Incorrect unique hosts")
vs.Spec.Host = "test.com"
Expect(getUniqueHosts(vs.Spec.Host, vs.Spec.HostAliases)).To(ConsistOf([]string{"test.com", "test1.com", "test2.com"}), "Incorrect unique hosts")
vs.Spec.Host = "test1.com"
Expand Down

0 comments on commit 6c7fcca

Please sign in to comment.