|
5 | 5 | "crypto/sha256" |
6 | 6 | "encoding/hex" |
7 | 7 | "fmt" |
| 8 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
8 | 9 | "net/url" |
9 | 10 | "os" |
10 | 11 | "path" |
@@ -85,23 +86,24 @@ type PodInfo struct { |
85 | 86 |
|
86 | 87 | // VirtualServerEx holds a VirtualServer along with the resources that are referenced in this VirtualServer. |
87 | 88 | type VirtualServerEx struct { |
88 | | - VirtualServer *conf_v1.VirtualServer |
89 | | - HTTPPort int |
90 | | - HTTPSPort int |
91 | | - HTTPIPv4 string |
92 | | - HTTPIPv6 string |
93 | | - HTTPSIPv4 string |
94 | | - HTTPSIPv6 string |
95 | | - Endpoints map[string][]string |
96 | | - VirtualServerRoutes []*conf_v1.VirtualServerRoute |
97 | | - ExternalNameSvcs map[string]bool |
98 | | - Policies map[string]*conf_v1.Policy |
99 | | - PodsByIP map[string]PodInfo |
100 | | - SecretRefs map[string]*secrets.SecretReference |
101 | | - ApPolRefs map[string]*unstructured.Unstructured |
102 | | - LogConfRefs map[string]*unstructured.Unstructured |
103 | | - DosProtectedRefs map[string]*unstructured.Unstructured |
104 | | - DosProtectedEx map[string]*DosEx |
| 89 | + VirtualServer *conf_v1.VirtualServer |
| 90 | + HTTPPort int |
| 91 | + HTTPSPort int |
| 92 | + HTTPIPv4 string |
| 93 | + HTTPIPv6 string |
| 94 | + HTTPSIPv4 string |
| 95 | + HTTPSIPv6 string |
| 96 | + Endpoints map[string][]string |
| 97 | + VirtualServerRoutes []*conf_v1.VirtualServerRoute |
| 98 | + VirtualServerSelectorRoutes map[string][]string |
| 99 | + ExternalNameSvcs map[string]bool |
| 100 | + Policies map[string]*conf_v1.Policy |
| 101 | + PodsByIP map[string]PodInfo |
| 102 | + SecretRefs map[string]*secrets.SecretReference |
| 103 | + ApPolRefs map[string]*unstructured.Unstructured |
| 104 | + LogConfRefs map[string]*unstructured.Unstructured |
| 105 | + DosProtectedRefs map[string]*unstructured.Unstructured |
| 106 | + DosProtectedEx map[string]*DosEx |
105 | 107 | } |
106 | 108 |
|
107 | 109 | func (vsx *VirtualServerEx) String() string { |
@@ -398,6 +400,7 @@ func (vsc *virtualServerConfigurator) GenerateVirtualServerConfig( |
398 | 400 | apResources *appProtectResourcesForVS, |
399 | 401 | dosResources map[string]*appProtectDosResource, |
400 | 402 | ) (version2.VirtualServerConfig, Warnings) { |
| 403 | + //l := nl.LoggerFromContext(vsc.cfgParams.Context) |
401 | 404 | vsc.clearWarnings() |
402 | 405 |
|
403 | 406 | useCustomListeners := false |
@@ -570,10 +573,48 @@ func (vsc *virtualServerConfigurator) GenerateVirtualServerConfig( |
570 | 573 |
|
571 | 574 | continue |
572 | 575 | } else if r.RouteSelector != nil { |
573 | | - selector := r.RouteSelector |
574 | | - glog.Infof("RouteSelector: %v", selector) |
575 | 576 |
|
576 | 577 | // get vsr name |
| 578 | + |
| 579 | + selector := &metav1.LabelSelector{ |
| 580 | + MatchLabels: r.RouteSelector.MatchLabels, |
| 581 | + } |
| 582 | + sel, _ := metav1.LabelSelectorAsSelector(selector) |
| 583 | + |
| 584 | + selectorKey := sel.String() |
| 585 | + vsrKeys := vsEx.VirtualServerSelectorRoutes[selectorKey] |
| 586 | + //nl.Infof(l, "VirtualServerRoutes: %v", vsEx.VirtualServerRoutes) |
| 587 | + // |
| 588 | + //nl.Infof(l, "VirtualServerSelectorRoutes: %v", vsEx.VirtualServerSelectorRoutes) |
| 589 | + // |
| 590 | + //nl.Infof(l, "vsrKeys: %v", vsrKeys) |
| 591 | + // |
| 592 | + //nl.Infof(l, "RouteSelector: %v", selector) |
| 593 | + |
| 594 | + // store route location snippet for the referenced VirtualServerRoute in case they don't define their own |
| 595 | + if r.LocationSnippets != "" { |
| 596 | + for _, name := range vsrKeys { |
| 597 | + vsrLocationSnippetsFromVs[name] = r.LocationSnippets |
| 598 | + } |
| 599 | + } |
| 600 | + |
| 601 | + // store route error pages and route index for the referenced VirtualServerRoute in case they don't define their own |
| 602 | + if len(r.ErrorPages) > 0 { |
| 603 | + for _, name := range vsrKeys { |
| 604 | + vsrErrorPagesFromVs[name] = errorPages.pages |
| 605 | + vsrErrorPagesRouteIndex[name] = errorPages.index |
| 606 | + } |
| 607 | + } |
| 608 | + |
| 609 | + // store route policies for the referenced VirtualServerRoute in case they don't define their own |
| 610 | + if len(r.Policies) > 0 { |
| 611 | + //nl.Infof(l, "Route Policies: %v", r.Policies) |
| 612 | + for _, name := range vsrKeys { |
| 613 | + //nl.Infof(l, "Adding policy to VSR $v: %v", name, r.Policies) |
| 614 | + vsrPoliciesFromVs[name] = r.Policies |
| 615 | + } |
| 616 | + } |
| 617 | + |
577 | 618 | continue |
578 | 619 | } |
579 | 620 |
|
@@ -687,7 +728,7 @@ func (vsc *virtualServerConfigurator) GenerateVirtualServerConfig( |
687 | 728 | } |
688 | 729 | errorPageLocations = append(errorPageLocations, generateErrorPageLocations(errorPages.index, errorPages.pages)...) |
689 | 730 | vsrNamespaceName := fmt.Sprintf("%v/%v", vsr.Namespace, vsr.Name) |
690 | | - glog.Infof("vsrNamespaceName: %v", vsrNamespaceName) |
| 731 | + //glog.Infof("vsrNamespaceName: %v", vsrNamespaceName) |
691 | 732 | // use the VirtualServer error pages if the route does not define any |
692 | 733 | if r.ErrorPages == nil { |
693 | 734 | if vsErrorPages, ok := vsrErrorPagesFromVs[vsrNamespaceName]; ok { |
|
0 commit comments