77 "sort"
88 "strconv"
99
10+ smoothoperatormodel "github.com/pdok/smooth-operator/model"
11+
1012 pdoknlv3 "github.com/pdok/atom-operator/api/v3"
1113 smoothutil "github.com/pdok/smooth-operator/pkg/util"
1214 traefikiov1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
@@ -40,61 +42,8 @@ func (r *AtomReconciler) mutateIngressRoute(atom *pdoknlv3.Atom, ingressRoute *t
4042 "uptime.pdok.nl/tags" : "public-stats,atom" ,
4143 }
4244
43- ingressRoute .Spec = traefikiov1alpha1.IngressRouteSpec {
44- Routes : []traefikiov1alpha1.Route {
45- {
46- Kind : "Rule" ,
47- Match : getMatchRule (baseURL .JoinPath ("index.xml" ), false ),
48- Services : []traefikiov1alpha1.Service {
49- {
50- LoadBalancerSpec : traefikiov1alpha1.LoadBalancerSpec {
51- Name : getBareService (atom ).GetName (),
52- Kind : "Service" ,
53- Port : intstr .FromInt32 (atomPortNr ),
54- },
55- },
56- },
57- Middlewares : []traefikiov1alpha1.MiddlewareRef {
58- {
59- Name : atom .Name + headersSuffix ,
60- },
61- {
62- Name : atom .Name + stripPrefixSuffix ,
63- },
64- },
65- },
66- },
67- }
68-
69- // Set additional routes per datasetFeed
70- for _ , datasetFeed := range atom .Spec .Service .DatasetFeeds {
71- matchRule := getMatchRule (baseURL .JoinPath (datasetFeed .TechnicalName + ".xml" ), false )
72- rule := getDefaultRule (atom , matchRule )
73- ingressRoute .Spec .Routes = append (ingressRoute .Spec .Routes , rule )
74- }
75-
76- azureStorageRule := traefikiov1alpha1.Route {
77- Kind : "Rule" ,
78- Match : getMatchRule (baseURL .JoinPath ("downloads/" ), true ),
79- Services : []traefikiov1alpha1.Service {
80- {
81- LoadBalancerSpec : traefikiov1alpha1.LoadBalancerSpec {
82- Name : "azure-storage" ,
83- Port : intstr.IntOrString {Type : intstr .String , StrVal : "azure-storage" },
84- PassHostHeader : smoothutil .Pointer (false ),
85- Kind : "Service" ,
86- },
87- },
88- },
89- Middlewares : []traefikiov1alpha1.MiddlewareRef {
90- {
91- Name : atom .Name + headersSuffix ,
92- },
93- },
94- }
95-
96- var downloadMiddlewares []traefikiov1alpha1.MiddlewareRef
9745 // Set additional Azure storage middleware per download link
46+ var downloadMiddlewares []traefikiov1alpha1.MiddlewareRef
9847 for _ , group := range getDownloadLinkGroups (atom .GetDownloadLinks ()) {
9948 middlewareRef := traefikiov1alpha1.MiddlewareRef {
10049 Name : atom .Name + downloadsSuffix + strconv .Itoa (* group .index ),
@@ -106,12 +55,14 @@ func (r *AtomReconciler) mutateIngressRoute(atom *pdoknlv3.Atom, ingressRoute *t
10655 return downloadMiddlewares [i ].Name < downloadMiddlewares [j ].Name
10756 })
10857
109- azureStorageRule .Middlewares = append (azureStorageRule .Middlewares , downloadMiddlewares ... )
110-
111- ingressRoute .Spec .Routes = append (ingressRoute .Spec .Routes , azureStorageRule )
112-
113- // Add finalizers
114- ingressRoute .Finalizers = []string {"uptime.pdok.nl/finalizer" }
58+ ingressRoute .Spec .Routes = []traefikiov1alpha1.Route {}
59+ if len (atom .Spec .IngressRouteURLs ) > 0 {
60+ for _ , ingressRouteURL := range atom .Spec .IngressRouteURLs {
61+ ingressRoute .Spec .Routes = append (ingressRoute .Spec .Routes , getRoutesForURL (atom , ingressRouteURL .URL , downloadMiddlewares )... )
62+ }
63+ } else {
64+ ingressRoute .Spec .Routes = getRoutesForURL (atom , atom .Spec .Service .BaseURL , downloadMiddlewares )
65+ }
11566
11667 if err := smoothutil .EnsureSetGVK (r .Client , ingressRoute , ingressRoute ); err != nil {
11768 return err
@@ -152,3 +103,41 @@ func getDefaultRule(atom *pdoknlv3.Atom, matchRule string) traefikiov1alpha1.Rou
152103 },
153104 }
154105}
106+
107+ func getRoutesForURL (atom * pdoknlv3.Atom , url smoothoperatormodel.URL , downloadMiddlewares []traefikiov1alpha1.MiddlewareRef ) []traefikiov1alpha1.Route {
108+ routes := []traefikiov1alpha1.Route {
109+ getDefaultRule (atom , getMatchRule (url .JoinPath ("index.xml" ), false )),
110+ }
111+
112+ // Set additional routes per datasetFeed
113+ for _ , datasetFeed := range atom .Spec .Service .DatasetFeeds {
114+ matchRule := getMatchRule (url .JoinPath (datasetFeed .TechnicalName + ".xml" ), false )
115+ rule := getDefaultRule (atom , matchRule )
116+ routes = append (routes , rule )
117+ }
118+
119+ // Add Azure storage rule
120+ azureStorageRule := traefikiov1alpha1.Route {
121+ Kind : "Rule" ,
122+ Match : getMatchRule (url .JoinPath ("downloads/" ), true ),
123+ Services : []traefikiov1alpha1.Service {
124+ {
125+ LoadBalancerSpec : traefikiov1alpha1.LoadBalancerSpec {
126+ Name : "azure-storage" ,
127+ Port : intstr.IntOrString {Type : intstr .String , StrVal : "azure-storage" },
128+ PassHostHeader : smoothutil .Pointer (false ),
129+ Kind : "Service" ,
130+ },
131+ },
132+ },
133+ Middlewares : append ([]traefikiov1alpha1.MiddlewareRef {
134+ {
135+ Name : atom .Name + headersSuffix ,
136+ }},
137+ downloadMiddlewares ... ,
138+ ),
139+ }
140+ routes = append (routes , azureStorageRule )
141+
142+ return routes
143+ }
0 commit comments