Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 36 additions & 33 deletions internal/controller/capabilitiesgenerator/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func MapWFSToCapabilitiesGeneratorInput(wfs *pdoknlv3.WFS, ownerInfo *smoothoper

if wfs.Spec.Service.Inspire != nil {
config.Global.AdditionalSchemaLocations = inspireSchemaLocations
metadataURL, _ := replaceMustachTemplate(ownerInfo.Spec.MetadataUrls.CSW.HrefTemplate, wfs.Spec.Service.Inspire.ServiceMetadataURL.CSW.MetadataIdentifier)
metadataURL, _ := replaceMustacheTemplate(ownerInfo.Spec.MetadataUrls.CSW.HrefTemplate, wfs.Spec.Service.Inspire.ServiceMetadataURL.CSW.MetadataIdentifier)

config.Services.WFS200Config.Wfs200.Capabilities.OperationsMetadata = &wfs200.OperationsMetadata{
ExtendedCapabilities: &wfs200.ExtendedCapabilities{
Expand Down Expand Up @@ -106,7 +106,7 @@ func getFeatureTypeList(wfs *pdoknlv3.WFS, ownerInfo *smoothoperatorv1.OwnerInfo
otherCRS = append(otherCRS, CRS)
}

metadataURL, err := replaceMustachTemplate(ownerInfo.Spec.MetadataUrls.CSW.HrefTemplate, fType.DatasetMetadataURL.CSW.MetadataIdentifier)
metadataURL, err := replaceMustacheTemplate(ownerInfo.Spec.MetadataUrls.CSW.HrefTemplate, fType.DatasetMetadataURL.CSW.MetadataIdentifier)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -148,7 +148,7 @@ func createCRSFromEpsgString(epsgString string) (*wfs200.CRS, error) {
}, nil
}

func replaceMustachTemplate(hrefTemplate string, identifier string) (string, error) {
func replaceMustacheTemplate(hrefTemplate string, identifier string) (string, error) {
templateVariable := map[string]string{"identifier": identifier}
return mustache.Render(hrefTemplate, templateVariable)
}
Expand All @@ -165,48 +165,51 @@ func mapServiceProvider(provider *smoothoperatorv1.ServiceProvider) (serviceProv
}
}

// TODO fix linting (nestif)
//nolint:nestif
if provider.ServiceContact != nil {
serviceProvider.ServiceContact = &wfs200.ServiceContact{
IndividualName: provider.ServiceContact.IndividualName,
PositionName: provider.ServiceContact.PositionName,
Role: provider.ServiceContact.Role,
}
if provider.ServiceContact.ContactInfo != nil {
serviceProvider.ServiceContact.ContactInfo = &wfs200.ContactInfo{
Text: provider.ServiceContact.ContactInfo.Text,
HoursOfService: provider.ServiceContact.ContactInfo.HoursOfService,
ContactInstructions: provider.ServiceContact.ContactInfo.ContactInstructions,
}
if provider.ServiceContact.ContactInfo.Phone != nil {
serviceProvider.ServiceContact.ContactInfo.Phone = &wfs200.Phone{
Voice: provider.ServiceContact.ContactInfo.Phone.Voice,
Facsimile: provider.ServiceContact.ContactInfo.Phone.Facsimile,
}
}
if provider.ServiceContact.ContactInfo.Address != nil {
serviceProvider.ServiceContact.ContactInfo.Address = &wfs200.Address{
DeliveryPoint: provider.ServiceContact.ContactInfo.Address.DeliveryPoint,
City: provider.ServiceContact.ContactInfo.Address.City,
AdministrativeArea: provider.ServiceContact.ContactInfo.Address.AdministrativeArea,
PostalCode: provider.ServiceContact.ContactInfo.Address.PostalCode,
Country: provider.ServiceContact.ContactInfo.Address.Country,
ElectronicMailAddress: provider.ServiceContact.ContactInfo.Address.ElectronicMailAddress,
}
}
if provider.ServiceContact.ContactInfo.OnlineResource != nil {
serviceProvider.ServiceContact.ContactInfo.OnlineResource = &wfs200.OnlineResource{
Type: provider.ServiceContact.ContactInfo.OnlineResource.Type,
Href: provider.ServiceContact.ContactInfo.OnlineResource.Href,
}
}
serviceProvider.ServiceContact.ContactInfo = mapContactInfo(*provider.ServiceContact.ContactInfo)
}
}

return serviceProvider
}

func mapContactInfo(contactInfo smoothoperatorv1.ContactInfo) (serviceContactInfo *wfs200.ContactInfo) {
serviceContactInfo = &wfs200.ContactInfo{
Text: contactInfo.Text,
HoursOfService: contactInfo.HoursOfService,
ContactInstructions: contactInfo.ContactInstructions,
}
if contactInfo.Phone != nil {
serviceContactInfo.Phone = &wfs200.Phone{
Voice: contactInfo.Phone.Voice,
Facsimile: contactInfo.Phone.Facsimile,
}
}
if contactInfo.Address != nil {
serviceContactInfo.Address = &wfs200.Address{
DeliveryPoint: contactInfo.Address.DeliveryPoint,
City: contactInfo.Address.City,
AdministrativeArea: contactInfo.Address.AdministrativeArea,
PostalCode: contactInfo.Address.PostalCode,
Country: contactInfo.Address.Country,
ElectronicMailAddress: contactInfo.Address.ElectronicMailAddress,
}
}
if contactInfo.OnlineResource != nil {
serviceContactInfo.OnlineResource = &wfs200.OnlineResource{
Type: contactInfo.OnlineResource.Type,
Href: contactInfo.OnlineResource.Href,
}
}
return
}

func MapWMSToCapabilitiesGeneratorInput(wms *pdoknlv3.WMS, ownerInfo *smoothoperatorv1.OwnerInfo) (*capabilitiesgenerator.Config, error) {
hostBaseURL := "https://service.pdok.nl"
canonicalServiceURL := hostBaseURL + "/" + pdoknlv3.GetBaseURLPath(wms)
Expand Down Expand Up @@ -271,7 +274,7 @@ func MapWMSToCapabilitiesGeneratorInput(wms *pdoknlv3.WMS, ownerInfo *smoothoper

if wms.Spec.Service.Inspire != nil {
config.Global.AdditionalSchemaLocations = inspireSchemaLocations
metadataURL, _ := replaceMustachTemplate(ownerInfo.Spec.MetadataUrls.CSW.HrefTemplate, wms.Spec.Service.Inspire.ServiceMetadataURL.CSW.MetadataIdentifier)
metadataURL, _ := replaceMustacheTemplate(ownerInfo.Spec.MetadataUrls.CSW.HrefTemplate, wms.Spec.Service.Inspire.ServiceMetadataURL.CSW.MetadataIdentifier)

defaultLanguage := wms130.Language{Language: wms.Spec.Service.Inspire.Language}

Expand Down
99 changes: 45 additions & 54 deletions internal/controller/shared_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ const (
)

var (
AppLabelKey = "app"
MapserverName = "mapserver"
AppLabelKey = "app"
MapserverName = "mapserver"
LegendGeneratorName = "legend-generator"
FeatureInfoGeneratorName = "featureinfo-generator"
OgcWebserviceProxyName = "ogc-webservice-proxy"

// Service ports
mapserverPortName = "mapserver"
Expand Down Expand Up @@ -126,7 +129,7 @@ func getSharedBareObjects[O pdoknlv3.WMSWFS](obj O) []client.Object {
getBareIngressRoute(obj),
getBareHorizontalPodAutoScaler(obj),
getBareConfigMapBlobDownload(obj),
getBareConfigMap(obj),
getBareConfigMap(obj, MapserverName),
getBareService(obj),
getBareCorsHeadersMiddleware(obj),
getBarePodDisruptionBudget(obj),
Expand Down Expand Up @@ -790,7 +793,7 @@ func mutateService[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O, service *corev1.
if obj.Type() == pdoknlv3.ServiceTypeWMS {
if obj.Options().UseWebserviceProxy() {
ports = append(ports, corev1.ServicePort{
Name: "ogc-webservice-proxy",
Name: OgcWebserviceProxyName,
Port: 9111,
})
}
Expand Down Expand Up @@ -888,10 +891,10 @@ func mutatePodDisruptionBudget[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O, podD
return ctrl.SetControllerReference(obj, podDisruptionBudget, getReconcilerScheme(r))
}

func getBareConfigMap[O pdoknlv3.WMSWFS](obj O) *corev1.ConfigMap {
func getBareConfigMap[O pdoknlv3.WMSWFS](obj O, name string) *corev1.ConfigMap {
return &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: getSuffixedName(obj, MapserverName),
Name: getSuffixedName(obj, name),
Namespace: obj.GetNamespace(),
},
}
Expand Down Expand Up @@ -1032,7 +1035,7 @@ func createOrUpdateAllForWMSWFS[R Reconciler, O pdoknlv3.WMSWFS](ctx context.Con

// region ConfigMap
{
configMap := getBareConfigMap(obj)
configMap := getBareConfigMap(obj, MapserverName)
if err = mutateConfigMap(r, obj, configMap); err != nil {
return operationResults, err
}
Expand Down Expand Up @@ -1094,60 +1097,33 @@ func createOrUpdateAllForWMSWFS[R Reconciler, O pdoknlv3.WMSWFS](ctx context.Con
}
// end region ConfigMap-BlobDownload

// TODO fix linting (nestif)
//nolint:nestif
if obj.Type() == pdoknlv3.ServiceTypeWMS {
wms, _ := any(obj).(*pdoknlv3.WMS)
wmsReconciler := (*WMSReconciler)(r)

// region ConfigMap-LegendGenerator
{
configMapLg := getBareConfigMapLegendGenerator(wms)
if err = mutateConfigMapLegendGenerator(wmsReconciler, wms, configMapLg); err != nil {
return operationResults, err
}
operationResults[smoothoperatorutils.GetObjectFullName(reconcilerClient, configMapLg)], err = controllerutil.CreateOrUpdate(ctx, reconcilerClient, configMapLg, func() error {
return mutateConfigMapLegendGenerator(wmsReconciler, wms, configMapLg)
configMaps := make(map[string]func(*WMSReconciler, *pdoknlv3.WMS, *corev1.ConfigMap) error)
configMaps[LegendGeneratorName] = mutateConfigMapLegendGenerator
configMaps[FeatureInfoGeneratorName] = mutateConfigMapFeatureinfoGenerator
configMaps[OgcWebserviceProxyName] = mutateConfigMapOgcWebserviceProxy
for cmName, mutate := range configMaps {
cm, or, err := getConfigMap(ctx, wms, wmsReconciler, cmName, func(r *WMSReconciler, w *pdoknlv3.WMS, cm *corev1.ConfigMap) error {
return mutate(r, w, cm)
})
if err != nil {
return operationResults, fmt.Errorf("unable to create/update resource %s: %w", smoothoperatorutils.GetObjectFullName(reconcilerClient, configMapLg), err)
}
hashedConfigMapNames.LegendGenerator = configMapLg.Name
}
// end region ConfigMap-LegendGenerator

// region ConfigMap-FeatureinfoGenerator
{
configMapFig := getBareConfigMapFeatureinfoGenerator(wms)
if err = mutateConfigMapFeatureinfoGenerator(wmsReconciler, wms, configMapFig); err != nil {
return operationResults, err
if or != nil {
operationResults[smoothoperatorutils.GetObjectFullName(reconcilerClient, cm)] = *or
}
operationResults[smoothoperatorutils.GetObjectFullName(reconcilerClient, configMapFig)], err = controllerutil.CreateOrUpdate(ctx, reconcilerClient, configMapFig, func() error {
return mutateConfigMapFeatureinfoGenerator(wmsReconciler, wms, configMapFig)
})
if err != nil {
return operationResults, fmt.Errorf("unable to create/update resource %s: %w", smoothoperatorutils.GetObjectFullName(reconcilerClient, configMapFig), err)
}
hashedConfigMapNames.FeatureInfoGenerator = configMapFig.Name
}

// end region ConfigMap-FeatureinfoGenerator

// region ConfigMap-OgcWebserviceProxy
{
configMapOwp := getBareConfigMapOgcWebserviceProxy(wms)
if err = mutateConfigMapOgcWebserviceProxy(wmsReconciler, wms, configMapOwp); err != nil {
return operationResults, err
}
operationResults[smoothoperatorutils.GetObjectFullName(reconcilerClient, configMapOwp)], err = controllerutil.CreateOrUpdate(ctx, reconcilerClient, configMapOwp, func() error {
return mutateConfigMapOgcWebserviceProxy(wmsReconciler, wms, configMapOwp)
})
if err != nil {
return operationResults, fmt.Errorf("unable to create/update resource %s: %w", smoothoperatorutils.GetObjectFullName(reconcilerClient, configMapOwp), err)
switch cmName {
case LegendGeneratorName:
hashedConfigMapNames.LegendGenerator = cm.Name
case FeatureInfoGeneratorName:
hashedConfigMapNames.FeatureInfoGenerator = cm.Name
case OgcWebserviceProxyName:
hashedConfigMapNames.OgcWebserviceProxy = cm.Name
}
hashedConfigMapNames.OgcWebserviceProxy = configMapOwp.Name
}
// end region ConfigMap-OgcWebserviceProxy
}

// region Deployment
Expand Down Expand Up @@ -1231,6 +1207,21 @@ func createOrUpdateAllForWMSWFS[R Reconciler, O pdoknlv3.WMSWFS](ctx context.Con
return operationResults, nil
}

func getConfigMap[O pdoknlv3.WMSWFS, R Reconciler](ctx context.Context, obj O, reconciler R, name string, mutate func(R, O, *corev1.ConfigMap) error) (*corev1.ConfigMap, *controllerutil.OperationResult, error) {
reconcilerClient := getReconcilerClient(reconciler)
cm := getBareConfigMap(obj, name)
if err := mutate(reconciler, obj, cm); err != nil {
return cm, nil, err
}
or, err := controllerutil.CreateOrUpdate(ctx, reconcilerClient, cm, func() error {
return mutate(reconciler, obj, cm)
})
if err != nil {
return cm, &or, fmt.Errorf("unable to create/update resource %s: %w", smoothoperatorutils.GetObjectFullName(reconcilerClient, cm), err)
}
return cm, &or, nil
}

// TODO fix linting (funlen)
//
//nolint:funlen
Expand All @@ -1246,7 +1237,7 @@ func deleteAllForWMSWFS[R Reconciler, O pdoknlv3.WMSWFS](ctx context.Context, r
}

// ConfigMap
cm := getBareConfigMap(obj)
cm := getBareConfigMap(obj, MapserverName)
err = mutateConfigMap(r, obj, cm)
if err != nil {
return err
Expand Down Expand Up @@ -1282,23 +1273,23 @@ func deleteAllForWMSWFS[R Reconciler, O pdoknlv3.WMSWFS](ctx context.Context, r
wmsReconciler := (*WMSReconciler)(r)

// ConfigMap-LegendGenerator
cmLg := getBareConfigMapLegendGenerator(wms)
cmLg := getBareConfigMap(wms, LegendGeneratorName)
err = mutateConfigMapLegendGenerator(wmsReconciler, wms, cmLg)
if err != nil {
return err
}
objects = append(objects, cmLg)

// ConfigMap-FeatureInfo
cmFi := getBareConfigMapFeatureinfoGenerator(wms)
cmFi := getBareConfigMap(wms, FeatureInfoGeneratorName)
err = mutateConfigMapFeatureinfoGenerator(wmsReconciler, wms, cmFi)
if err != nil {
return err
}
objects = append(objects, cmFi)

// ConfigMap-OgcWebserviceProxy
cmOwp := getBareConfigMapOgcWebserviceProxy(wms)
cmOwp := getBareConfigMap(wms, OgcWebserviceProxyName)
err = mutateConfigMapOgcWebserviceProxy(wmsReconciler, wms, cmOwp)
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions internal/controller/shared_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func getExpectedObjects[O pdoknlv3.WMSWFS](ctx context.Context, obj O, includeBl
}

// Add all ConfigMaps with hashed names
cm := getBareConfigMap(obj)
cm := getBareConfigMap(obj, MapserverName)
hashedName, err := getHashedConfigMapNameFromClient(ctx, obj, mapserver.ConfigMapVolumeName)
if err != nil {
return objects, err
Expand Down Expand Up @@ -87,15 +87,15 @@ func getExpectedObjects[O pdoknlv3.WMSWFS](ctx context.Context, obj O, includeBl

if obj.Type() == pdoknlv3.ServiceTypeWMS {
wms, _ := any(obj).(*pdoknlv3.WMS)
cm = getBareConfigMapLegendGenerator(wms)
cm = getBareConfigMap(wms, LegendGeneratorName)
hashedName, err = getHashedConfigMapNameFromClient(ctx, obj, mapserver.ConfigMapLegendGeneratorVolumeName)
if err != nil {
return objects, err
}
cm.Name = hashedName
objects = append(objects, cm)

cm = getBareConfigMapFeatureinfoGenerator(wms)
cm = getBareConfigMap(wms, FeatureInfoGeneratorName)
hashedName, err = getHashedConfigMapNameFromClient(ctx, obj, mapserver.ConfigMapFeatureinfoGeneratorVolumeName)
if err != nil {
return objects, err
Expand All @@ -104,7 +104,7 @@ func getExpectedObjects[O pdoknlv3.WMSWFS](ctx context.Context, obj O, includeBl
objects = append(objects, cm)

if obj.Options().UseWebserviceProxy() {
cm = getBareConfigMapOgcWebserviceProxy(wms)
cm = getBareConfigMap(wms, OgcWebserviceProxyName)
hashedName, err = getHashedConfigMapNameFromClient(ctx, obj, mapserver.ConfigMapOgcWebserviceProxyVolumeName)
if err != nil {
return objects, err
Expand Down
1 change: 0 additions & 1 deletion internal/controller/wfs_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ type WFSReconciler struct {
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
// TODO fix linting (dupl)
//
//nolint:dupl
func (r *WFSReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, err error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/wfs_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ var _ = Describe("WFS Controller", func() {
By("Reconciling the WFS and checking the configMap")
reconcileWFS(controllerReconciler, wfs, typeNamespacedNameWfs)

configMap := getBareConfigMap(wfs)
configMap := getBareConfigMap(wfs, MapserverName)
configMapName, err := getHashedConfigMapNameFromClient(ctx, wfs, mapserver.ConfigMapVolumeName)
Expect(err).NotTo(HaveOccurred())
Eventually(func() bool {
Expand Down
Loading
Loading