@@ -66,6 +66,9 @@ type WMSSpec struct {
6666 // TODO omitting the options field or setting an empty value results in incorrect defaulting of the options
6767 Options * Options `json:"options,omitempty"`
6868
69+ // Custom healthcheck options
70+ HealthCheck * HealthCheckWMS `json:"healthCheck,omitempty"`
71+
6972 // Service specification
7073 Service WMSService `json:"service"`
7174}
@@ -132,6 +135,18 @@ func (wmsService WMSService) KeywordsIncludingInspireKeyword() []string {
132135 return keywords
133136}
134137
138+ // HealthCheck is the struct with all fields to configure custom healthchecks
139+ // +kubebuilder:validation:XValidation:rule="!has(self.querystring) || has(self.mimetype)",message="mimetype is required when a querystring is used"
140+ // +kubebuilder:validation:XValidation:rule="(has(self.boundingbox) || has(self.querystring)) && !(has(self.querystring) && has(self.boundingbox))", message="healthcheck should have querystring + mimetype or boundingbox, not both"
141+ type HealthCheckWMS struct {
142+ // +kubebuilder:validation:MinLength:=1
143+ Querystring * string `json:"querystring,omitempty"`
144+ // +kubebuilder:validation:Pattern=(image/png|text/xml|text/html)
145+ Mimetype * string `json:"mimetype,omitempty"`
146+
147+ Boundingbox * shared_model.BBox `json:"boundingbox,omitempty"`
148+ }
149+
135150// +kubebuilder:validation:XValidation:message="Either blobKeys or configMapRefs is required",rule="has(self.blobKeys) || has(self.configMapRefs)"
136151type StylingAssets struct {
137152 // +kubebuilder:validations:MinItems:=1
@@ -627,12 +642,18 @@ func (wms *WMS) GeoPackages() []*Gpkg {
627642}
628643
629644func (wms * WMS ) HealthCheckBBox () string {
630- // TODO make dynamic
645+ if hc := wms .Spec .HealthCheck ; hc != nil && hc .Boundingbox != nil {
646+ return strings .ReplaceAll (hc .Boundingbox .ToExtent (), " " , "," )
647+ }
648+
631649 return "190061.4619730016857,462435.5987861062749,202917.7508707302331,473761.6884966178914"
632650}
633651
634- func (wms * WMS ) ReadinessQueryString () (string , error ) {
635- // TODO implement healthcheck from CR
652+ func (wms * WMS ) ReadinessQueryString () (string , string , error ) {
653+ if hc := wms .Spec .HealthCheck ; hc != nil && hc .Querystring != nil {
654+ return * hc .Querystring , * hc .Mimetype , nil
655+ }
656+
636657 firstDataLayerName := ""
637658 for _ , layer := range wms .Spec .Service .GetAllLayers () {
638659 if layer .IsDataLayer () {
@@ -641,8 +662,8 @@ func (wms *WMS) ReadinessQueryString() (string, error) {
641662 }
642663 }
643664 if firstDataLayerName == "" {
644- return "" , errors .New ("cannot get readiness probe for WMS, the first datalayer could not be found" )
665+ return "" , "" , errors .New ("cannot get readiness probe for WMS, the first datalayer could not be found" )
645666 }
646667
647- return fmt .Sprintf ("SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&BBOX=%s&CRS=EPSG:28992&WIDTH=100&HEIGHT=100&LAYERS=%s&STYLES=&FORMAT=image/png" , wms .HealthCheckBBox (), firstDataLayerName ), nil
668+ return fmt .Sprintf ("SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&BBOX=%s&CRS=EPSG:28992&WIDTH=100&HEIGHT=100&LAYERS=%s&STYLES=&FORMAT=image/png" , wms .HealthCheckBBox (), firstDataLayerName ), "image/png" , nil
648669}
0 commit comments