From d7f3f070168e50e50fd6078958232dfc0db1ba12 Mon Sep 17 00:00:00 2001 From: Wouter Remijn Date: Tue, 20 May 2025 11:12:48 +0200 Subject: [PATCH 1/5] fix funlen openapi-update + remove old crds --- config/crd/bases/pdok.nl_wfses.yaml | 431 ------------------------ config/crd/bases/pdok.nl_wmses.yaml | 491 ---------------------------- config/crd/update_openapi.go | 83 ++--- 3 files changed, 42 insertions(+), 963 deletions(-) delete mode 100644 config/crd/bases/pdok.nl_wfses.yaml delete mode 100644 config/crd/bases/pdok.nl_wmses.yaml diff --git a/config/crd/bases/pdok.nl_wfses.yaml b/config/crd/bases/pdok.nl_wfses.yaml deleted file mode 100644 index c912252..0000000 --- a/config/crd/bases/pdok.nl_wfses.yaml +++ /dev/null @@ -1,431 +0,0 @@ ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.17.1 - name: wfses.pdok.nl -spec: - group: pdok.nl - names: - kind: WFS - listKind: WFSList - plural: wfses - singular: wfs - scope: Namespaced - versions: - - name: v2beta1 - schema: - openAPIV3Schema: - description: WFS is the Schema for the wfs API. - properties: - apiVersion: - description: |- - APIVersion defines the versioned schema of this representation of an object. - Servers should convert recognized schemas to the latest internal value, and - may reject unrecognized values. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources - type: string - kind: - description: |- - Kind is a string value representing the REST resource this object represents. - Servers may infer this from the endpoint the client submits requests to. - Cannot be updated. - In CamelCase. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - metadata: - type: object - spec: - description: WFSSpec is the struct for all fields defined in the WFS CRD - properties: - general: - description: General is the struct with all generic fields for the - crds - properties: - dataVersion: - type: string - dataset: - type: string - datasetOwner: - type: string - serviceVersion: - type: string - theme: - type: string - required: - - dataset - - datasetOwner - type: object - kubernetes: - description: Kubernetes is the struct with all fields that can be - defined in kubernetes fields in the crds - properties: - autoscaling: - description: Autoscaling is the struct with all fields to configure - autoscalers for the crs - properties: - averageCpuUtilization: - type: integer - maxReplicas: - type: integer - minReplicas: - type: integer - type: object - healthCheck: - description: HealthCheck is the struct with all fields to configure - healthchecks for the crs - properties: - boundingbox: - type: string - mimetype: - type: string - querystring: - type: string - type: object - lifecycle: - description: Lifecycle is the struct with the fields to configure - lifecycle settings for the resources - properties: - ttlInDays: - type: integer - type: object - resources: - description: ResourceRequirements describes the compute resource - requirements. - properties: - claims: - description: |- - Claims lists the names of resources, defined in spec.resourceClaims, - that are used by this container. - - This is an alpha field and requires enabling the - DynamicResourceAllocation feature gate. - - This field is immutable. It can only be set for containers. - items: - description: ResourceClaim references one entry in PodSpec.ResourceClaims. - properties: - name: - description: |- - Name must match the name of one entry in pod.spec.resourceClaims of - the Pod where this field is used. It makes that resource available - inside a container. - type: string - request: - description: |- - Request is the name chosen for a request in the referenced claim. - If empty, everything from the claim is made available, otherwise - only the result of this request. - type: string - required: - - name - type: object - type: array - x-kubernetes-list-map-keys: - - name - x-kubernetes-list-type: map - limits: - additionalProperties: - anyOf: - - type: integer - - type: string - pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ - x-kubernetes-int-or-string: true - description: |- - Limits describes the maximum amount of compute resources allowed. - More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ - type: object - requests: - additionalProperties: - anyOf: - - type: integer - - type: string - pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ - x-kubernetes-int-or-string: true - description: |- - Requests describes the minimum amount of compute resources required. - If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, - otherwise to an implementation-defined value. Requests cannot exceed Limits. - More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ - type: object - type: object - type: object - options: - description: WMSWFSOptions is the struct with options available in - the operator - properties: - automaticCasing: - type: boolean - disableWebserviceProxy: - type: boolean - includeIngress: - type: boolean - prefetchData: - type: boolean - rewriteGroupToDataLayers: - type: boolean - validateChildStyleNameEqual: - type: boolean - validateRequests: - type: boolean - required: - - automaticCasing - - includeIngress - type: object - service: - description: WFSService is the struct with all service specific options - properties: - abstract: - type: string - accessConstraints: - default: https://creativecommons.org/publicdomain/zero/1.0/deed.nl - type: string - authority: - description: Authority is a struct for the authority fields in - WMS and WFS crds - properties: - name: - type: string - url: - type: string - required: - - name - - url - type: object - dataEPSG: - type: string - extent: - type: string - featureTypes: - items: - description: FeatureType is the struct for all feature type - level fields - properties: - abstract: - type: string - data: - description: Data is a struct for the data field for a WMSLayer - or WFS FeatureType - properties: - gpkg: - description: GPKG is a struct for the gpkg field for - a WMSLayer or WFS FeatureType - properties: - aliases: - additionalProperties: - type: string - description: In a new version Aliases should become - part of Columns - type: object - blobKey: - type: string - columns: - items: - type: string - type: array - geometryType: - type: string - table: - type: string - required: - - blobKey - - columns - - geometryType - - table - type: object - postgis: - description: |- - Postgis is a struct for the Postgis db config for a WMSLayer or WFS FeatureType - connection details are passed through the environment - properties: - aliases: - additionalProperties: - type: string - description: In a new version Aliases should become - part of Columns - type: object - columns: - items: - type: string - type: array - geometryType: - type: string - table: - type: string - required: - - columns - - geometryType - - table - type: object - tif: - description: Tif is a struct for the Tif field for a - WMSLayer - properties: - blobKey: - type: string - getFeatureInfoIncludesClass: - type: boolean - offsite: - type: string - resample: - type: string - required: - - blobKey - type: object - type: object - datasetMetadataIdentifier: - type: string - extent: - type: string - keywords: - items: - type: string - type: array - name: - type: string - sourceMetadataIdentifier: - type: string - title: - type: string - required: - - abstract - - data - - datasetMetadataIdentifier - - keywords - - name - - sourceMetadataIdentifier - - title - type: object - type: array - inspire: - type: boolean - keywords: - items: - type: string - type: array - mapfile: - description: Mapfile contains the ConfigMapKeyRef containing a - mapfile - properties: - configMapKeyRef: - description: Selects a key from a ConfigMap. - properties: - key: - description: The key to select. - type: string - name: - default: "" - description: |- - Name of the referent. - This field is effectively required, but due to backwards compatibility is - allowed to be empty. Instances of this type with an empty value here are - almost certainly wrong. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names - type: string - optional: - description: Specify whether the ConfigMap or its key - must be defined - type: boolean - required: - - key - type: object - x-kubernetes-map-type: atomic - required: - - configMapKeyRef - type: object - maxfeatures: - type: string - metadataIdentifier: - type: string - title: - type: string - required: - - abstract - - accessConstraints - - authority - - dataEPSG - - featureTypes - - inspire - - keywords - - metadataIdentifier - - title - type: object - required: - - general - - kubernetes - - service - type: object - status: - description: Status - The status for custom resources managed by the operator-sdk. - properties: - conditions: - items: - description: |- - Condition - the condition for the ansible operator - https://github.com/operator-framework/operator-sdk/blob/master/internal/ansible/controller/status/types.go#L101 - properties: - ansibleResult: - description: ResultAnsible - encapsulation of the ansible result. - 'AnsibleResult' is turned around in struct to comply with - linting - properties: - changed: - type: integer - completion: - type: string - failures: - type: integer - ok: - type: integer - skipped: - type: integer - required: - - changed - - completion - - failures - - ok - - skipped - type: object - lastTransitionTime: - format: date-time - type: string - message: - type: string - reason: - type: string - status: - description: ConditionStatus specifies a string for field ConditionType - type: string - type: - description: ConditionType specifies a string for field ConditionType - type: string - required: - - lastTransitionTime - - message - - reason - - status - - type - type: object - type: array - deployment: - type: string - resources: - items: - description: Resources is the struct for the resources field within - status - properties: - apiversion: - type: string - kind: - type: string - name: - type: string - type: object - type: array - type: object - type: object - served: true - storage: true - subresources: - status: {} diff --git a/config/crd/bases/pdok.nl_wmses.yaml b/config/crd/bases/pdok.nl_wmses.yaml deleted file mode 100644 index 86bb8b4..0000000 --- a/config/crd/bases/pdok.nl_wmses.yaml +++ /dev/null @@ -1,491 +0,0 @@ ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.17.1 - name: wmses.pdok.nl -spec: - group: pdok.nl - names: - kind: WMS - listKind: WMSList - plural: wmses - singular: wms - scope: Namespaced - versions: - - name: v2beta1 - schema: - openAPIV3Schema: - description: WMS is the Schema for the wms API. - properties: - apiVersion: - description: |- - APIVersion defines the versioned schema of this representation of an object. - Servers should convert recognized schemas to the latest internal value, and - may reject unrecognized values. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources - type: string - kind: - description: |- - Kind is a string value representing the REST resource this object represents. - Servers may infer this from the endpoint the client submits requests to. - Cannot be updated. - In CamelCase. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - metadata: - type: object - spec: - description: WMSSpec is the struct for all fields defined in the WMS CRD - properties: - general: - description: General is the struct with all generic fields for the - crds - properties: - dataVersion: - type: string - dataset: - type: string - datasetOwner: - type: string - serviceVersion: - type: string - theme: - type: string - required: - - dataset - - datasetOwner - type: object - kubernetes: - description: Kubernetes is the struct with all fields that can be - defined in kubernetes fields in the crds - properties: - autoscaling: - description: Autoscaling is the struct with all fields to configure - autoscalers for the crs - properties: - averageCpuUtilization: - type: integer - maxReplicas: - type: integer - minReplicas: - type: integer - type: object - healthCheck: - description: HealthCheck is the struct with all fields to configure - healthchecks for the crs - properties: - boundingbox: - type: string - mimetype: - type: string - querystring: - type: string - type: object - lifecycle: - description: Lifecycle is the struct with the fields to configure - lifecycle settings for the resources - properties: - ttlInDays: - type: integer - type: object - resources: - description: ResourceRequirements describes the compute resource - requirements. - properties: - claims: - description: |- - Claims lists the names of resources, defined in spec.resourceClaims, - that are used by this container. - - This is an alpha field and requires enabling the - DynamicResourceAllocation feature gate. - - This field is immutable. It can only be set for containers. - items: - description: ResourceClaim references one entry in PodSpec.ResourceClaims. - properties: - name: - description: |- - Name must match the name of one entry in pod.spec.resourceClaims of - the Pod where this field is used. It makes that resource available - inside a container. - type: string - request: - description: |- - Request is the name chosen for a request in the referenced claim. - If empty, everything from the claim is made available, otherwise - only the result of this request. - type: string - required: - - name - type: object - type: array - x-kubernetes-list-map-keys: - - name - x-kubernetes-list-type: map - limits: - additionalProperties: - anyOf: - - type: integer - - type: string - pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ - x-kubernetes-int-or-string: true - description: |- - Limits describes the maximum amount of compute resources allowed. - More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ - type: object - requests: - additionalProperties: - anyOf: - - type: integer - - type: string - pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ - x-kubernetes-int-or-string: true - description: |- - Requests describes the minimum amount of compute resources required. - If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, - otherwise to an implementation-defined value. Requests cannot exceed Limits. - More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ - type: object - type: object - type: object - options: - description: WMSWFSOptions is the struct with options available in - the operator - properties: - automaticCasing: - type: boolean - disableWebserviceProxy: - type: boolean - includeIngress: - type: boolean - prefetchData: - type: boolean - rewriteGroupToDataLayers: - type: boolean - validateChildStyleNameEqual: - type: boolean - validateRequests: - type: boolean - required: - - automaticCasing - - includeIngress - type: object - service: - description: WMSService is the struct for all service level fields - properties: - abstract: - type: string - accessConstraints: - default: https://creativecommons.org/publicdomain/zero/1.0/deed.nl - type: string - authority: - description: Authority is a struct for the authority fields in - WMS and WFS crds - properties: - name: - type: string - url: - type: string - required: - - name - - url - type: object - dataEPSG: - type: string - defResolution: - type: integer - extent: - type: string - inspire: - type: boolean - keywords: - items: - type: string - type: array - layers: - items: - description: WMSLayer is the struct for all layer level fields - properties: - abstract: - type: string - data: - description: Data is a struct for the data field for a WMSLayer - or WFS FeatureType - properties: - gpkg: - description: GPKG is a struct for the gpkg field for - a WMSLayer or WFS FeatureType - properties: - aliases: - additionalProperties: - type: string - description: In a new version Aliases should become - part of Columns - type: object - blobKey: - type: string - columns: - items: - type: string - type: array - geometryType: - type: string - table: - type: string - required: - - blobKey - - columns - - geometryType - - table - type: object - postgis: - description: |- - Postgis is a struct for the Postgis db config for a WMSLayer or WFS FeatureType - connection details are passed through the environment - properties: - aliases: - additionalProperties: - type: string - description: In a new version Aliases should become - part of Columns - type: object - columns: - items: - type: string - type: array - geometryType: - type: string - table: - type: string - required: - - columns - - geometryType - - table - type: object - tif: - description: Tif is a struct for the Tif field for a - WMSLayer - properties: - blobKey: - type: string - getFeatureInfoIncludesClass: - type: boolean - offsite: - type: string - resample: - type: string - required: - - blobKey - type: object - type: object - datasetMetadataIdentifier: - type: string - extent: - type: string - group: - type: string - keywords: - items: - type: string - type: array - labelNoClip: - type: boolean - maxScale: - type: number - minScale: - type: number - name: - type: string - sourceMetadataIdentifier: - type: string - styles: - items: - description: Style is the struct for all style level fields - properties: - abstract: - type: string - legendFile: - description: LegendFile is the struct containing the - location of the legendfile - properties: - blobKey: - type: string - required: - - blobKey - type: object - name: - type: string - title: - type: string - visualization: - type: string - required: - - name - type: object - type: array - title: - type: string - visible: - type: boolean - required: - - name - - styles - - visible - type: object - type: array - mapfile: - description: Mapfile contains the ConfigMapKeyRef containing a - mapfile - properties: - configMapKeyRef: - description: Selects a key from a ConfigMap. - properties: - key: - description: The key to select. - type: string - name: - default: "" - description: |- - Name of the referent. - This field is effectively required, but due to backwards compatibility is - allowed to be empty. Instances of this type with an empty value here are - almost certainly wrong. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names - type: string - optional: - description: Specify whether the ConfigMap or its key - must be defined - type: boolean - required: - - key - type: object - x-kubernetes-map-type: atomic - required: - - configMapKeyRef - type: object - maxSize: - type: number - metadataIdentifier: - type: string - resolution: - type: integer - stylingAssets: - description: StylingAssets is the struct containing the location - of styling assets - properties: - blobKeys: - items: - type: string - type: array - configMapRefs: - items: - description: |- - ConfigMapRef contains all the config map name and all keys in that mapserver that are relevant - the Keys can be empty, so that the v1 WMS can convert to the v2beta1 WMS - properties: - keys: - items: - type: string - type: array - name: - type: string - required: - - name - type: object - type: array - type: object - title: - type: string - required: - - abstract - - accessConstraints - - authority - - dataEPSG - - inspire - - keywords - - layers - - metadataIdentifier - - title - type: object - required: - - general - - kubernetes - - options - - service - type: object - status: - description: Status - The status for custom resources managed by the operator-sdk. - properties: - conditions: - items: - description: |- - Condition - the condition for the ansible operator - https://github.com/operator-framework/operator-sdk/blob/master/internal/ansible/controller/status/types.go#L101 - properties: - ansibleResult: - description: ResultAnsible - encapsulation of the ansible result. - 'AnsibleResult' is turned around in struct to comply with - linting - properties: - changed: - type: integer - completion: - type: string - failures: - type: integer - ok: - type: integer - skipped: - type: integer - required: - - changed - - completion - - failures - - ok - - skipped - type: object - lastTransitionTime: - format: date-time - type: string - message: - type: string - reason: - type: string - status: - description: ConditionStatus specifies a string for field ConditionType - type: string - type: - description: ConditionType specifies a string for field ConditionType - type: string - required: - - lastTransitionTime - - message - - reason - - status - - type - type: object - type: array - deployment: - type: string - resources: - items: - description: Resources is the struct for the resources field within - status - properties: - apiversion: - type: string - kind: - type: string - name: - type: string - type: object - type: array - type: object - type: object - served: true - storage: true - subresources: - status: {} diff --git a/config/crd/update_openapi.go b/config/crd/update_openapi.go index 34467e8..8b66c82 100644 --- a/config/crd/update_openapi.go +++ b/config/crd/update_openapi.go @@ -18,9 +18,6 @@ func main() { updateWMSV3Layers(crdDir) } -// TODO fix linting (funlen) -// -//nolint:funlen func updateWMSV3Layers(crdDir string) { path := filepath.Join(crdDir, "pdok.nl_wms.yaml") @@ -38,44 +35,7 @@ func updateWMSV3Layers(crdDir string) { versions := make([]v1.CustomResourceDefinitionVersion, 0) for _, version := range crd.Spec.Versions { if version.Name == "v3" { - schema := version.Schema.OpenAPIV3Schema - spec := schema.Properties["spec"] - service := spec.Properties["service"] - layer := service.Properties["layer"] - - // Level 3 - layerSpecLevel3 := layer.DeepCopy() - layerSpecLevel3.Required = append(layerSpecLevel3.Required, "name") - delete(layerSpecLevel3.Properties, "layers") - xvals := v1.ValidationRules{} - for _, xval := range layerSpecLevel3.XValidations { - if !strings.Contains(xval.Rule, "self.layers") { - xvals = append(xvals, xval) - } - } - layerSpecLevel3.XValidations = xvals - - // Level 2 - layerSpecLevel2 := layer.DeepCopy() - layerSpecLevel2.Required = append(layerSpecLevel2.Required, "name") - layerSpecLevel2.Properties["layers"] = v1.JSONSchemaProps{ - Type: "array", - Description: "[OpenAPI spec injected by mapserver-operator/cmd/update_openapi.go]", - Items: &v1.JSONSchemaPropsOrArray{Schema: layerSpecLevel3}, - } - - layer.Properties["layers"] = v1.JSONSchemaProps{ - Type: "array", - Description: "[OpenAPI spec injected by mapserver-operator/cmd/update_openapi.go]", - Items: &v1.JSONSchemaPropsOrArray{Schema: layerSpecLevel2}, - } - - service.Properties["layer"] = layer - spec.Properties["service"] = service - schema.Properties["spec"] = spec - version.Schema = &v1.CustomResourceValidation{ - OpenAPIV3Schema: schema, - } + updateLayersV3(&version) versions = append(versions, version) } else { @@ -100,3 +60,44 @@ func updateWMSV3Layers(crdDir string) { enc.SetIndent(2) _ = enc.Encode(rawData) } + +func updateLayersV3(version *v1.CustomResourceDefinitionVersion) { + schema := version.Schema.OpenAPIV3Schema + spec := schema.Properties["spec"] + service := spec.Properties["service"] + layer := service.Properties["layer"] + + // Level 3 + layerSpecLevel3 := layer.DeepCopy() + layerSpecLevel3.Required = append(layerSpecLevel3.Required, "name") + delete(layerSpecLevel3.Properties, "layers") + xvals := v1.ValidationRules{} + for _, xval := range layerSpecLevel3.XValidations { + if !strings.Contains(xval.Rule, "self.layers") { + xvals = append(xvals, xval) + } + } + layerSpecLevel3.XValidations = xvals + + // Level 2 + layerSpecLevel2 := layer.DeepCopy() + layerSpecLevel2.Required = append(layerSpecLevel2.Required, "name") + layerSpecLevel2.Properties["layers"] = v1.JSONSchemaProps{ + Type: "array", + Description: "[OpenAPI spec injected by mapserver-operator/cmd/update_openapi.go]", + Items: &v1.JSONSchemaPropsOrArray{Schema: layerSpecLevel3}, + } + + layer.Properties["layers"] = v1.JSONSchemaProps{ + Type: "array", + Description: "[OpenAPI spec injected by mapserver-operator/cmd/update_openapi.go]", + Items: &v1.JSONSchemaPropsOrArray{Schema: layerSpecLevel2}, + } + + service.Properties["layer"] = layer + spec.Properties["service"] = service + schema.Properties["spec"] = spec + version.Schema = &v1.CustomResourceValidation{ + OpenAPIV3Schema: schema, + } +} From 5ea491a3d42b0cbc17b5ac579b3baa088bd4403a Mon Sep 17 00:00:00 2001 From: Wouter Remijn Date: Tue, 20 May 2025 11:44:37 +0200 Subject: [PATCH 2/5] fix funlen linting capabilitiesgenerator --- .../capabilitiesgenerator/mapper.go | 442 +++++++++--------- 1 file changed, 223 insertions(+), 219 deletions(-) diff --git a/internal/controller/capabilitiesgenerator/mapper.go b/internal/controller/capabilitiesgenerator/mapper.go index 38395b8..22cf939 100644 --- a/internal/controller/capabilitiesgenerator/mapper.go +++ b/internal/controller/capabilitiesgenerator/mapper.go @@ -24,6 +24,124 @@ const ( metadataMediaType = "application/vnd.ogc.csw.GetRecordByIdResponse_xml" ) +var defaultCrs = []wms130.CRS{{ + Namespace: "EPSG", + Code: 28992, +}, { + Namespace: "EPSG", + Code: 25831, +}, { + Namespace: "EPSG", + Code: 25832, +}, { + Namespace: "EPSG", + Code: 3034, +}, { + Namespace: "EPSG", + Code: 3035, +}, { + Namespace: "EPSG", + Code: 3857, +}, { + Namespace: "EPSG", + Code: 4258, +}, { + Namespace: "EPSG", + Code: 4326, +}, { + Namespace: "CRS", + Code: 84, +}} +var defaultBoundingBox = wms130.EXGeographicBoundingBox{ + WestBoundLongitude: 2.52713, + EastBoundLongitude: 7.37403, + SouthBoundLatitude: 50.2129, + NorthBoundLatitude: 55.7212, +} +var allDefaultBoundingBoxes = []*wms130.LayerBoundingBox{ + { + CRS: "EPSG:28992", + Minx: -25000, + Miny: 250000, + Maxx: 280000, + Maxy: 860000, + Resx: 0, + Resy: 0, + }, + { + CRS: "EPSG:25831", + Minx: -470271, + Miny: 5.56231e+06, + Maxx: 795163, + Maxy: 6.18197e+06, + Resx: 0, + Resy: 0, + }, + { + CRS: "EPSG:25832", + Minx: 62461.6, + Miny: 5.56555e+06, + Maxx: 397827, + Maxy: 6.19042e+06, + Resx: 0, + Resy: 0, + }, + { + CRS: "EPSG:3034", + Minx: 2.61336e+06, + Miny: 3.509e+06, + Maxx: 3.22007e+06, + Maxy: 3.84003e+06, + Resx: 0, + Resy: 0, + }, + { + CRS: "EPSG:3035", + Minx: 3.01676e+06, + Miny: 3.81264e+06, + Maxx: 3.64485e+06, + Maxy: 4.15586e+06, + Resx: 0, + Resy: 0, + }, + { + CRS: "EPSG:3857", + Minx: 281318, + Miny: 6.48322e+06, + Maxx: 820873, + Maxy: 7.50311e+06, + Resx: 0, + Resy: 0, + }, + { + CRS: "EPSG:4258", + Minx: 50.2129, + Miny: 2.52713, + Maxx: 55.7212, + Maxy: 7.37403, + Resx: 0, + Resy: 0, + }, + { + CRS: "EPSG:4326", + Minx: 50.2129, + Miny: 2.52713, + Maxx: 55.7212, + Maxy: 7.37403, + Resx: 0, + Resy: 0, + }, + { + CRS: "CRS:84", + Minx: 2.52713, + Miny: 50.2129, + Maxx: 7.37403, + Maxy: 55.7212, + Resx: 0, + Resy: 0, + }, +} + func MapWFSToCapabilitiesGeneratorInput(wfs *pdoknlv3.WFS, ownerInfo *smoothoperatorv1.OwnerInfo) (*capabilitiesgenerator.Config, error) { featureTypeList, err := getFeatureTypeList(wfs, ownerInfo) if err != nil { @@ -374,138 +492,9 @@ func getDcpType(url string, fillPost bool) *wms130.DCPType { return &result } -// TODO fix linting (funlen) -// -//nolint:funlen func getLayers(wms *pdoknlv3.WMS, canonicalURL string) []wms130.Layer { result := make([]wms130.Layer, 0) referenceLayer := wms.Spec.Service.Layer - title := referenceLayer.Title - if title != nil { - title = smoothoperatorutils.Pointer(mapperutils.EscapeQuotes(*referenceLayer.Title)) - } else { - title = smoothoperatorutils.Pointer("") - } - - defaultCrs := []wms130.CRS{{ - Namespace: "EPSG", - Code: 28992, - }, { - Namespace: "EPSG", - Code: 25831, - }, { - Namespace: "EPSG", - Code: 25832, - }, { - Namespace: "EPSG", - Code: 3034, - }, { - Namespace: "EPSG", - Code: 3035, - }, { - Namespace: "EPSG", - Code: 3857, - }, { - Namespace: "EPSG", - Code: 4258, - }, { - Namespace: "EPSG", - Code: 4326, - }, { - Namespace: "CRS", - Code: 84, - }} - - defaultBoundingBox := wms130.EXGeographicBoundingBox{ - WestBoundLongitude: 2.52713, - EastBoundLongitude: 7.37403, - SouthBoundLatitude: 50.2129, - NorthBoundLatitude: 55.7212, - } - - allDefaultBoundingBoxes := make([]*wms130.LayerBoundingBox, 0) - allDefaultBoundingBoxes = append(allDefaultBoundingBoxes, - &wms130.LayerBoundingBox{ - CRS: "EPSG:28992", - Minx: -25000, - Miny: 250000, - Maxx: 280000, - Maxy: 860000, - Resx: 0, - Resy: 0, - }, - &wms130.LayerBoundingBox{ - CRS: "EPSG:25831", - Minx: -470271, - Miny: 5.56231e+06, - Maxx: 795163, - Maxy: 6.18197e+06, - Resx: 0, - Resy: 0, - }, - &wms130.LayerBoundingBox{ - CRS: "EPSG:25832", - Minx: 62461.6, - Miny: 5.56555e+06, - Maxx: 397827, - Maxy: 6.19042e+06, - Resx: 0, - Resy: 0, - }, - &wms130.LayerBoundingBox{ - CRS: "EPSG:3034", - Minx: 2.61336e+06, - Miny: 3.509e+06, - Maxx: 3.22007e+06, - Maxy: 3.84003e+06, - Resx: 0, - Resy: 0, - }, - &wms130.LayerBoundingBox{ - CRS: "EPSG:3035", - Minx: 3.01676e+06, - Miny: 3.81264e+06, - Maxx: 3.64485e+06, - Maxy: 4.15586e+06, - Resx: 0, - Resy: 0, - }, - &wms130.LayerBoundingBox{ - CRS: "EPSG:3857", - Minx: 281318, - Miny: 6.48322e+06, - Maxx: 820873, - Maxy: 7.50311e+06, - Resx: 0, - Resy: 0, - }, - &wms130.LayerBoundingBox{ - CRS: "EPSG:4258", - Minx: 50.2129, - Miny: 2.52713, - Maxx: 55.7212, - Maxy: 7.37403, - Resx: 0, - Resy: 0, - }, - &wms130.LayerBoundingBox{ - CRS: "EPSG:4326", - Minx: 50.2129, - Miny: 2.52713, - Maxx: 55.7212, - Maxy: 7.37403, - Resx: 0, - Resy: 0, - }, - &wms130.LayerBoundingBox{ - CRS: "CRS:84", - Minx: 2.52713, - Miny: 50.2129, - Maxx: 7.37403, - Maxy: 55.7212, - Resx: 0, - Resy: 0, - }) var authorityURL *wms130.AuthorityURL var identifier *wms130.Identifier @@ -525,7 +514,111 @@ func getLayers(wms *pdoknlv3.WMS, canonicalURL string) []wms130.Layer { } } - topLayer := wms130.Layer{ + topLayer := getTopLayer(wms, referenceLayer, authorityURL, identifier) + + for _, layer := range referenceLayer.Layers { + nestedLayer := getNestedLayer(layer, authorityURL, canonicalURL) + + topLayer.Layer = append(topLayer.Layer, &nestedLayer) + } + + result = append(result, topLayer) + return result +} + +func getNestedLayer(layer pdoknlv3.Layer, authorityURL *wms130.AuthorityURL, canonicalURL string) wms130.Layer { + var minScaleDenom *float64 + var maxScaleDenom *float64 + var innerIdentifier *wms130.Identifier + metadataUrls := make([]*wms130.MetadataURL, 0) + + if layer.MinScaleDenominator != nil { + float, err := strconv.ParseFloat(*layer.MinScaleDenominator, 64) + if err == nil { + minScaleDenom = &float + } + } + + if layer.MaxScaleDenominator != nil { + float, err := strconv.ParseFloat(*layer.MaxScaleDenominator, 64) + if err == nil { + maxScaleDenom = &float + } + } + + if layer.DatasetMetadataURL != nil { + metadataUrls = append(metadataUrls, &wms130.MetadataURL{ + Type: smoothoperatorutils.Pointer("TC211"), + Format: smoothoperatorutils.Pointer("text/plain"), + OnlineResource: wms130.OnlineResource{ + Xlink: nil, + Type: smoothoperatorutils.Pointer("simple"), + Href: smoothoperatorutils.Pointer("https://www.nationaalgeoregister.nl/geonetwork/srv/dut/csw?service=CSW&version=2.0.2&request=GetRecordById&outputschema=http://www.isotc211.org/2005/gmd&elementsetname=full&id=" + layer.DatasetMetadataURL.CSW.MetadataIdentifier), + }, + }) + } + + if layer.Authority != nil { + innerIdentifier = &wms130.Identifier{ + Authority: layer.Authority.Name, + Value: layer.Authority.SpatialDatasetIdentifier, + } + } + + nestedLayer := wms130.Layer{ + Queryable: smoothoperatorutils.Pointer(1), + Opaque: nil, + Name: layer.Name, + Title: smoothoperatorutils.PointerVal(layer.Title, ""), + Abstract: layer.Abstract, + KeywordList: &wms130.Keywords{ + Keyword: layer.Keywords, + }, + CRS: defaultCrs, + EXGeographicBoundingBox: &defaultBoundingBox, + BoundingBox: allDefaultBoundingBoxes, + Dimension: nil, + Attribution: nil, + AuthorityURL: authorityURL, + Identifier: innerIdentifier, + MetadataURL: metadataUrls, + DataURL: nil, + FeatureListURL: nil, + Style: []*wms130.Style{}, + MinScaleDenominator: minScaleDenom, + MaxScaleDenominator: maxScaleDenom, + Layer: nil, + } + for _, style := range layer.Styles { + newStyle := wms130.Style{ + Name: style.Name, + Title: smoothoperatorutils.PointerVal(style.Title, ""), + Abstract: style.Abstract, + LegendURL: &wms130.LegendURL{ + Width: 78, + Height: 20, + Format: "image/png", + OnlineResource: wms130.OnlineResource{ + Xlink: nil, + Type: smoothoperatorutils.Pointer("simple"), + Href: smoothoperatorutils.Pointer(canonicalURL + "/legend/" + *layer.Name + "/" + style.Name + ".png"), + }, + }, + StyleSheetURL: nil, + } + nestedLayer.Style = append(nestedLayer.Style, &newStyle) + } + return nestedLayer +} + +func getTopLayer(wms *pdoknlv3.WMS, referenceLayer pdoknlv3.Layer, authorityURL *wms130.AuthorityURL, identifier *wms130.Identifier) wms130.Layer { + title := referenceLayer.Title + if title != nil { + title = smoothoperatorutils.Pointer(mapperutils.EscapeQuotes(*referenceLayer.Title)) + } else { + title = smoothoperatorutils.Pointer("") + } + return wms130.Layer{ Queryable: smoothoperatorutils.Pointer(1), Opaque: nil, Name: nil, @@ -547,93 +640,4 @@ func getLayers(wms *pdoknlv3.WMS, canonicalURL string) []wms130.Layer { MaxScaleDenominator: nil, Layer: []*wms130.Layer{}, } - - for _, layer := range referenceLayer.Layers { - var minScaleDenom *float64 - var maxScaleDenom *float64 - var innerIdentifier *wms130.Identifier - metadataUrls := make([]*wms130.MetadataURL, 0) - - if layer.MinScaleDenominator != nil { - float, err := strconv.ParseFloat(*layer.MinScaleDenominator, 64) - if err == nil { - minScaleDenom = &float - } - } - - if layer.MaxScaleDenominator != nil { - float, err := strconv.ParseFloat(*layer.MaxScaleDenominator, 64) - if err == nil { - maxScaleDenom = &float - } - } - - if layer.DatasetMetadataURL != nil { - metadataUrls = append(metadataUrls, &wms130.MetadataURL{ - Type: smoothoperatorutils.Pointer("TC211"), - Format: smoothoperatorutils.Pointer("text/plain"), - OnlineResource: wms130.OnlineResource{ - Xlink: nil, - Type: smoothoperatorutils.Pointer("simple"), - Href: smoothoperatorutils.Pointer("https://www.nationaalgeoregister.nl/geonetwork/srv/dut/csw?service=CSW&version=2.0.2&request=GetRecordById&outputschema=http://www.isotc211.org/2005/gmd&elementsetname=full&id=" + layer.DatasetMetadataURL.CSW.MetadataIdentifier), - }, - }) - } - - if layer.Authority != nil { - innerIdentifier = &wms130.Identifier{ - Authority: layer.Authority.Name, - Value: layer.Authority.SpatialDatasetIdentifier, - } - } - - nestedLayer := wms130.Layer{ - Queryable: smoothoperatorutils.Pointer(1), - Opaque: nil, - Name: layer.Name, - Title: smoothoperatorutils.PointerVal(layer.Title, ""), - Abstract: layer.Abstract, - KeywordList: &wms130.Keywords{ - Keyword: layer.Keywords, - }, - CRS: defaultCrs, - EXGeographicBoundingBox: &defaultBoundingBox, - BoundingBox: allDefaultBoundingBoxes, - Dimension: nil, - Attribution: nil, - AuthorityURL: authorityURL, - Identifier: innerIdentifier, - MetadataURL: metadataUrls, - DataURL: nil, - FeatureListURL: nil, - Style: []*wms130.Style{}, - MinScaleDenominator: minScaleDenom, - MaxScaleDenominator: maxScaleDenom, - Layer: nil, - } - for _, style := range layer.Styles { - newStyle := wms130.Style{ - Name: style.Name, - Title: smoothoperatorutils.PointerVal(style.Title, ""), - Abstract: style.Abstract, - LegendURL: &wms130.LegendURL{ - Width: 78, - Height: 20, - Format: "image/png", - OnlineResource: wms130.OnlineResource{ - Xlink: nil, - Type: smoothoperatorutils.Pointer("simple"), - Href: smoothoperatorutils.Pointer(canonicalURL + "/legend/" + *layer.Name + "/" + style.Name + ".png"), - }, - }, - StyleSheetURL: nil, - } - nestedLayer.Style = append(nestedLayer.Style, &newStyle) - } - - topLayer.Layer = append(topLayer.Layer, &nestedLayer) - } - - result = append(result, topLayer) - return result } From c4fab3db10a5c73b295c040fc6e2af5ec61850fe Mon Sep 17 00:00:00 2001 From: Wouter Remijn Date: Tue, 20 May 2025 12:26:15 +0200 Subject: [PATCH 3/5] fix funlen/cyclop for createorupdateall --- internal/controller/shared_controller.go | 180 +++++++++-------------- 1 file changed, 71 insertions(+), 109 deletions(-) diff --git a/internal/controller/shared_controller.go b/internal/controller/shared_controller.go index a48e8d3..09a4e7f 100644 --- a/internal/controller/shared_controller.go +++ b/internal/controller/shared_controller.go @@ -59,11 +59,14 @@ const ( ) var ( - AppLabelKey = "app" - MapserverName = "mapserver" - LegendGeneratorName = "legend-generator" - FeatureInfoGeneratorName = "featureinfo-generator" - OgcWebserviceProxyName = "ogc-webservice-proxy" + AppLabelKey = "app" + MapserverName = "mapserver" + LegendGeneratorName = "legend-generator" + FeatureInfoGeneratorName = "featureinfo-generator" + OgcWebserviceProxyName = "ogc-webservice-proxy" + MapfileGeneratorName = "mapfile-generator" + CapabilitiesGeneratorName = "capabilities-generator" + InitScriptsName = "init-scripts" // Service ports mapserverPortName = "mapserver" @@ -1020,106 +1023,12 @@ func updateStatus[R Reconciler](ctx context.Context, r R, obj client.Object, con } } -// TODO fix linting (cyclop,funlen) -// -//nolint:cyclop,funlen func createOrUpdateAllForWMSWFS[R Reconciler, O pdoknlv3.WMSWFS](ctx context.Context, r R, obj O, ownerInfo *smoothoperatorv1.OwnerInfo) (operationResults map[string]controllerutil.OperationResult, err error) { - operationResults = make(map[string]controllerutil.OperationResult) reconcilerClient := getReconcilerClient(r) - hashedConfigMapNames := types.HashedConfigMapNames{} - - // region ConfigMap - { - configMap := getBareConfigMap(obj, MapserverName) - if err = mutateConfigMap(r, obj, configMap); err != nil { - return operationResults, err - } - operationResults[smoothoperatorutils.GetObjectFullName(reconcilerClient, configMap)], err = controllerutil.CreateOrUpdate(ctx, reconcilerClient, configMap, func() error { - return mutateConfigMap(r, obj, configMap) - }) - if err != nil { - return operationResults, fmt.Errorf("unable to create/update resource %s: %w", smoothoperatorutils.GetObjectFullName(reconcilerClient, configMap), err) - } - hashedConfigMapNames.ConfigMap = configMap.Name - } - // end region ConfigMap - - // region ConfigMap-MapfileGenerator - if obj.Mapfile() == nil { - configMapMfg := getBareConfigMapMapfileGenerator(obj) - if err = mutateConfigMapMapfileGenerator(r, obj, configMapMfg, ownerInfo); err != nil { - return operationResults, err - } - operationResults[smoothoperatorutils.GetObjectFullName(reconcilerClient, configMapMfg)], err = controllerutil.CreateOrUpdate(ctx, reconcilerClient, configMapMfg, func() error { - return mutateConfigMapMapfileGenerator(r, obj, configMapMfg, ownerInfo) - }) - if err != nil { - return operationResults, fmt.Errorf("unable to create/update resource %s: %w", smoothoperatorutils.GetObjectFullName(reconcilerClient, configMapMfg), err) - } - hashedConfigMapNames.MapfileGenerator = configMapMfg.Name - } - // end region ConfigMap-MapfileGenerator - - // region ConfigMap-CapabilitiesGenerator - { - configMapCg := getBareConfigMapCapabilitiesGenerator(obj) - if err = mutateConfigMapCapabilitiesGenerator(r, obj, configMapCg, ownerInfo); err != nil { - return operationResults, err - } - operationResults[smoothoperatorutils.GetObjectFullName(reconcilerClient, configMapCg)], err = controllerutil.CreateOrUpdate(ctx, reconcilerClient, configMapCg, func() error { - return mutateConfigMapCapabilitiesGenerator(r, obj, configMapCg, ownerInfo) - }) - if err != nil { - return operationResults, fmt.Errorf("unable to create/update resource %s: %w", smoothoperatorutils.GetObjectFullName(reconcilerClient, configMapCg), err) - } - hashedConfigMapNames.CapabilitiesGenerator = configMapCg.Name - } - // end region ConfigMap-CapabilitiesGenerator - - // region ConfigMap-BlobDownload - if obj.Options().PrefetchData { - configMapBd := getBareConfigMapBlobDownload(obj) - if err = mutateConfigMapBlobDownload(r, obj, configMapBd); err != nil { - return operationResults, err - } - operationResults[smoothoperatorutils.GetObjectFullName(reconcilerClient, configMapBd)], err = controllerutil.CreateOrUpdate(ctx, reconcilerClient, configMapBd, func() error { - return mutateConfigMapBlobDownload(r, obj, configMapBd) - }) - if err != nil { - return operationResults, fmt.Errorf("unable to create/update resource %s: %w", smoothoperatorutils.GetObjectFullName(reconcilerClient, configMapBd), err) - } - hashedConfigMapNames.BlobDownload = configMapBd.Name - } - // end region ConfigMap-BlobDownload - - if obj.Type() == pdoknlv3.ServiceTypeWMS { - wms, _ := any(obj).(*pdoknlv3.WMS) - wmsReconciler := (*WMSReconciler)(r) - - 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 or != nil { - operationResults[smoothoperatorutils.GetObjectFullName(reconcilerClient, cm)] = *or - } - if err != nil { - return operationResults, err - } - switch cmName { - case LegendGeneratorName: - hashedConfigMapNames.LegendGenerator = cm.Name - case FeatureInfoGeneratorName: - hashedConfigMapNames.FeatureInfoGenerator = cm.Name - case OgcWebserviceProxyName: - hashedConfigMapNames.OgcWebserviceProxy = cm.Name - } - } + hashedConfigMapNames, operationResults, err := createOrUpdateConfigMaps(ctx, r, obj, ownerInfo) + if err != nil { + return operationResults, err } // region Deployment @@ -1128,12 +1037,6 @@ func createOrUpdateAllForWMSWFS[R Reconciler, O pdoknlv3.WMSWFS](ctx context.Con operationResults[smoothoperatorutils.GetObjectFullName(reconcilerClient, deployment)], err = controllerutil.CreateOrUpdate(ctx, reconcilerClient, deployment, func() error { return mutateDeployment(r, obj, deployment, hashedConfigMapNames) }) - // if operationResults[smoothoperatorutils.GetObjectFullName(reconcilerClient, deployment)] == controllerutil.OperationResultUpdated { - // deployment = getBareDeployment(obj) - // smoothoperatork8s.ShowDiff(ctx, reconcilerClient, deployment, func() error { - // return mutateDeployment(r, obj, deployment, hashedConfigMapNames) - // }) - // } if err != nil { return operationResults, fmt.Errorf("unable to create/update resource %s: %w", smoothoperatorutils.GetObjectFullName(reconcilerClient, deployment), err) } @@ -1203,7 +1106,66 @@ 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) { +func createOrUpdateConfigMaps[R Reconciler, O pdoknlv3.WMSWFS](ctx context.Context, r R, obj O, ownerInfo *smoothoperatorv1.OwnerInfo) (hashedConfigMapNames types.HashedConfigMapNames, operationResults map[string]controllerutil.OperationResult, err error) { + operationResults, configMaps := make(map[string]controllerutil.OperationResult), make(map[string]func(R, O, *corev1.ConfigMap) error) + configMaps[MapserverName] = mutateConfigMap + if obj.Mapfile() == nil { + configMaps[MapfileGeneratorName] = func(r R, o O, cm *corev1.ConfigMap) error { + return mutateConfigMapMapfileGenerator(r, o, cm, ownerInfo) + } + } + configMaps[CapabilitiesGeneratorName] = func(r R, o O, cm *corev1.ConfigMap) error { + return mutateConfigMapCapabilitiesGenerator(r, o, cm, ownerInfo) + } + if obj.Options().PrefetchData { + configMaps[InitScriptsName] = mutateConfigMapBlobDownload + } + if obj.Type() == pdoknlv3.ServiceTypeWMS { + wms, _ := any(obj).(*pdoknlv3.WMS) + wmsReconciler := (*WMSReconciler)(r) + + configMaps[LegendGeneratorName] = func(_ R, _ O, cm *corev1.ConfigMap) error { + return mutateConfigMapLegendGenerator(wmsReconciler, wms, cm) + } + configMaps[FeatureInfoGeneratorName] = func(_ R, _ O, cm *corev1.ConfigMap) error { + return mutateConfigMapFeatureinfoGenerator(wmsReconciler, wms, cm) + } + configMaps[OgcWebserviceProxyName] = func(_ R, _ O, cm *corev1.ConfigMap) error { + return mutateConfigMapOgcWebserviceProxy(wmsReconciler, wms, cm) + } + } + for cmName, mutate := range configMaps { + cm, or, err := createOrUpdateConfigMap(ctx, obj, r, cmName, func(r R, o O, cm *corev1.ConfigMap) error { + return mutate(r, o, cm) + }) + if or != nil { + operationResults[smoothoperatorutils.GetObjectFullName(getReconcilerClient(r), cm)] = *or + } + if err != nil { + return hashedConfigMapNames, operationResults, err + } + switch cmName { + case MapserverName: + hashedConfigMapNames.ConfigMap = cm.Name + case MapfileGeneratorName: + hashedConfigMapNames.MapfileGenerator = cm.Name + case CapabilitiesGeneratorName: + hashedConfigMapNames.CapabilitiesGenerator = cm.Name + case InitScriptsName: + hashedConfigMapNames.BlobDownload = cm.Name + case LegendGeneratorName: + hashedConfigMapNames.LegendGenerator = cm.Name + case FeatureInfoGeneratorName: + hashedConfigMapNames.FeatureInfoGenerator = cm.Name + case OgcWebserviceProxyName: + hashedConfigMapNames.OgcWebserviceProxy = cm.Name + } + } + + return hashedConfigMapNames, operationResults, err +} + +func createOrUpdateConfigMap[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 { From 18834514930ac7f6f919c7d32e6aafe1817fa074 Mon Sep 17 00:00:00 2001 From: Wouter Remijn Date: Tue, 20 May 2025 12:29:14 +0200 Subject: [PATCH 4/5] fix cyclop for main (removed duplicate code) --- cmd/main.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index f94e905..a0b6b5a 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -78,9 +78,7 @@ func init() { // +kubebuilder:scaffold:scheme } -// TODO fix linting (cyclop,funlen) -// -//nolint:cyclop,funlen +//nolint:funlen func main() { var metricsAddr string var certDir string @@ -233,12 +231,6 @@ func main() { } } - if os.Getenv("ENABLE_WEBHOOKS") != EnvFalse { - if err = webhookpdoknlv3.SetupWFSWebhookWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create webhook", "webhook", "WFS") - os.Exit(1) - } - } // +kubebuilder:scaffold:builder if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { From fe98c554fa36933d9a35dfdbaa796f80d04da20f Mon Sep 17 00:00:00 2001 From: Wouter Remijn Date: Tue, 20 May 2025 12:37:55 +0200 Subject: [PATCH 5/5] removed unneeded getbare functions --- internal/controller/shared_controller.go | 33 ++----------------- internal/controller/shared_controller_test.go | 6 ++-- internal/controller/wfs_controller_test.go | 6 ++-- internal/controller/wms_controller_test.go | 6 ++-- 4 files changed, 12 insertions(+), 39 deletions(-) diff --git a/internal/controller/shared_controller.go b/internal/controller/shared_controller.go index 09a4e7f..b40aa62 100644 --- a/internal/controller/shared_controller.go +++ b/internal/controller/shared_controller.go @@ -131,13 +131,13 @@ func getSharedBareObjects[O pdoknlv3.WMSWFS](obj O) []client.Object { getBareDeployment(obj), getBareIngressRoute(obj), getBareHorizontalPodAutoScaler(obj), - getBareConfigMapBlobDownload(obj), + getBareConfigMap(obj, InitScriptsName), getBareConfigMap(obj, MapserverName), getBareService(obj), getBareCorsHeadersMiddleware(obj), getBarePodDisruptionBudget(obj), - getBareConfigMapMapfileGenerator(obj), - getBareConfigMapCapabilitiesGenerator(obj), + getBareConfigMap(obj, MapfileGeneratorName), + getBareConfigMap(obj, CapabilitiesGeneratorName), } } @@ -563,24 +563,6 @@ func getLegendMatchRule(wms *pdoknlv3.WMS) string { return "(Host(`localhost`) || Host(`" + host + "`)) && PathPrefix(`/" + pdoknlv3.GetBaseURLPath(wms) + "/legend`)" } -func getBareConfigMapMapfileGenerator[O pdoknlv3.WMSWFS](obj O) *corev1.ConfigMap { - return &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{ - Name: getSuffixedName(obj, "mapfile-generator"), - Namespace: obj.GetNamespace(), - }, - } -} - -func getBareConfigMapCapabilitiesGenerator[O pdoknlv3.WMSWFS](obj O) *corev1.ConfigMap { - return &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{ - Name: getSuffixedName(obj, "capabilities-generator"), - Namespace: obj.GetNamespace(), - }, - } -} - func mutateConfigMapCapabilitiesGenerator[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O, configMap *corev1.ConfigMap, ownerInfo *smoothoperatorv1.OwnerInfo) error { reconcilerClient := getReconcilerClient(r) @@ -734,15 +716,6 @@ func mutateHorizontalPodAutoscaler[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O, return ctrl.SetControllerReference(obj, autoscaler, getReconcilerScheme(r)) } -func getBareConfigMapBlobDownload[O pdoknlv3.WMSWFS](obj O) *corev1.ConfigMap { - return &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{ - Name: getSuffixedName(obj, "init-scripts"), - Namespace: obj.GetNamespace(), - }, - } -} - func mutateConfigMapBlobDownload[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O, configMap *corev1.ConfigMap) error { reconcilerClient := getReconcilerClient(r) diff --git a/internal/controller/shared_controller_test.go b/internal/controller/shared_controller_test.go index cd85f0f..f762953 100644 --- a/internal/controller/shared_controller_test.go +++ b/internal/controller/shared_controller_test.go @@ -60,7 +60,7 @@ func getExpectedObjects[O pdoknlv3.WMSWFS](ctx context.Context, obj O, includeBl objects = append(objects, cm) if includeMapfileGeneratorConfigMap { - cm = getBareConfigMapMapfileGenerator(obj) + cm = getBareConfigMap(obj, MapfileGeneratorName) hashedName, err = getHashedConfigMapNameFromClient(ctx, obj, mapserver.ConfigMapMapfileGeneratorVolumeName) if err != nil { return objects, err @@ -69,7 +69,7 @@ func getExpectedObjects[O pdoknlv3.WMSWFS](ctx context.Context, obj O, includeBl objects = append(objects, cm) } - cm = getBareConfigMapCapabilitiesGenerator(obj) + cm = getBareConfigMap(obj, CapabilitiesGeneratorName) hashedName, err = getHashedConfigMapNameFromClient(ctx, obj, mapserver.ConfigMapCapabilitiesGeneratorVolumeName) if err != nil { return objects, err @@ -78,7 +78,7 @@ func getExpectedObjects[O pdoknlv3.WMSWFS](ctx context.Context, obj O, includeBl objects = append(objects, cm) if includeBlobDownload { - cm = getBareConfigMapBlobDownload(obj) + cm = getBareConfigMap(obj, InitScriptsName) hashedName, err = getHashedConfigMapNameFromClient(ctx, obj, mapserver.ConfigMapBlobDownloadVolumeName) if err != nil { return objects, err diff --git a/internal/controller/wfs_controller_test.go b/internal/controller/wfs_controller_test.go index 78e0163..f1e6c53 100644 --- a/internal/controller/wfs_controller_test.go +++ b/internal/controller/wfs_controller_test.go @@ -399,7 +399,7 @@ var _ = Describe("WFS Controller", func() { By("Reconciling the WFS and checking the configMap") reconcileWFS(controllerReconciler, wfs, typeNamespacedNameWfs) - configMap := getBareConfigMapMapfileGenerator(wfs) + configMap := getBareConfigMap(wfs, MapfileGeneratorName) configMapName, err := getHashedConfigMapNameFromClient(ctx, wfs, mapserver.ConfigMapMapfileGeneratorVolumeName) Expect(err).NotTo(HaveOccurred()) Eventually(func() bool { @@ -424,7 +424,7 @@ var _ = Describe("WFS Controller", func() { By("Reconciling the WFS and checking the configMap") reconcileWFS(controllerReconciler, wfs, typeNamespacedNameWfs) - configMap := getBareConfigMapBlobDownload(wfs) + configMap := getBareConfigMap(wfs, InitScriptsName) configMapName, err := getHashedConfigMapNameFromClient(ctx, wfs, mapserver.ConfigMapBlobDownloadVolumeName) Expect(err).NotTo(HaveOccurred()) Eventually(func() bool { @@ -449,7 +449,7 @@ var _ = Describe("WFS Controller", func() { By("Reconciling the WFS and checking the configMap") reconcileWFS(controllerReconciler, wfs, typeNamespacedNameWfs) - configMap := getBareConfigMapCapabilitiesGenerator(wfs) + configMap := getBareConfigMap(wfs, CapabilitiesGeneratorName) configMapName, err := getHashedConfigMapNameFromClient(ctx, wfs, mapserver.ConfigMapCapabilitiesGeneratorVolumeName) Expect(err).NotTo(HaveOccurred()) Eventually(func() bool { diff --git a/internal/controller/wms_controller_test.go b/internal/controller/wms_controller_test.go index aeff31c..30bc651 100644 --- a/internal/controller/wms_controller_test.go +++ b/internal/controller/wms_controller_test.go @@ -575,7 +575,7 @@ var _ = Describe("WMS Controller", func() { By("Reconciling the WMS and checking the configMap") reconcileWMS(controllerReconciler, wms, typeNamespacedNameWms) - configMap := getBareConfigMapMapfileGenerator(wms) + configMap := getBareConfigMap(wms, mapfileGeneratorInput) configMapName, err := getHashedConfigMapNameFromClient(ctx, wms, mapserver.ConfigMapMapfileGeneratorVolumeName) Expect(err).NotTo(HaveOccurred()) Eventually(func() bool { @@ -600,7 +600,7 @@ var _ = Describe("WMS Controller", func() { By("Reconciling the WMS and checking the configMap") reconcileWMS(controllerReconciler, wms, typeNamespacedNameWms) - configMap := getBareConfigMapBlobDownload(wms) + configMap := getBareConfigMap(wms, InitScriptsName) configMapName, err := getHashedConfigMapNameFromClient(ctx, wms, mapserver.ConfigMapBlobDownloadVolumeName) Expect(err).NotTo(HaveOccurred()) Eventually(func() bool { @@ -625,7 +625,7 @@ var _ = Describe("WMS Controller", func() { By("Reconciling the WMS and checking the configMap") reconcileWMS(controllerReconciler, wms, typeNamespacedNameWms) - configMap := getBareConfigMapCapabilitiesGenerator(wms) + configMap := getBareConfigMap(wms, CapabilitiesGeneratorName) configMapName, err := getHashedConfigMapNameFromClient(ctx, wms, mapserver.ConfigMapCapabilitiesGeneratorVolumeName) Expect(err).NotTo(HaveOccurred()) Eventually(func() bool {