Skip to content

Commit 675530d

Browse files
committed
remove unneeded code/tests
1 parent 91f2404 commit 675530d

File tree

7 files changed

+45
-387
lines changed

7 files changed

+45
-387
lines changed

internal/controller/constants/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ const (
2424
ConfigMapCustomMapfileVolumeName = "mapfile"
2525

2626
HTMLTemplatesPath = "/srv/data/config/templates"
27+
MapserverPortNr int32 = 80
2728
ApachePortNr int32 = 9117
2829
)

internal/controller/ingressroute.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66

77
"github.com/pdok/mapserver-operator/internal/controller/constants"
88

9-
"github.com/pdok/mapserver-operator/internal/controller/mapserver"
10-
119
"github.com/pdok/mapserver-operator/internal/controller/utils"
1210

1311
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
@@ -67,7 +65,7 @@ func mutateIngressRoute[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O, ingressRout
6765
Kind: "Service",
6866
Port: intstr.IntOrString{
6967
Type: intstr.Int,
70-
IntVal: mapserver.MapserverPortNr,
68+
IntVal: constants.MapserverPortNr,
7169
},
7270
},
7371
}

internal/controller/mapserver/deployment.go

Lines changed: 4 additions & 297 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,16 @@ import (
99
"github.com/pdok/mapserver-operator/internal/controller/utils"
1010

1111
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
12-
"github.com/pdok/mapserver-operator/internal/controller/mapperutils"
1312
"github.com/pdok/mapserver-operator/internal/controller/static"
1413
"github.com/pdok/mapserver-operator/internal/controller/types"
15-
smoothoperatorutils "github.com/pdok/smooth-operator/pkg/util"
1614
corev1 "k8s.io/api/core/v1"
1715
"k8s.io/apimachinery/pkg/api/resource"
1816
)
1917

20-
const (
21-
MapserverPortNr int32 = 80
22-
23-
// TODO How should we determine this boundingbox?
24-
// healthCheckBbox = "190061.4619730016857,462435.5987861062749,202917.7508707302331,473761.6884966178914"
25-
26-
mimeTextXML = "text/xml"
27-
)
18+
const mimeTextXML = "text/xml"
2819

2920
func GetMapserverContainer[O pdoknlv3.WMSWFS](obj O, images types.Images, blobsSecretName string) (*corev1.Container, error) {
30-
livenessProbe, readinessProbe, startupProbe, err := GetProbesForDeployment(obj)
21+
livenessProbe, readinessProbe, startupProbe, err := getProbes(obj)
3122
if err != nil {
3223
return nil, err
3324
}
@@ -36,7 +27,7 @@ func GetMapserverContainer[O pdoknlv3.WMSWFS](obj O, images types.Images, blobsS
3627
Name: constants.MapserverName,
3728
Image: images.MapserverImage,
3829
ImagePullPolicy: corev1.PullIfNotPresent,
39-
Ports: []corev1.ContainerPort{{ContainerPort: MapserverPortNr, Protocol: corev1.ProtocolTCP}},
30+
Ports: []corev1.ContainerPort{{ContainerPort: constants.MapserverPortNr, Protocol: corev1.ProtocolTCP}},
4031
Env: []corev1.EnvVar{
4132
{
4233
Name: "SERVICE_TYPE",
@@ -100,169 +91,6 @@ func getVolumeMounts(customMapfile bool) []corev1.VolumeMount {
10091
return volumeMounts
10192
}
10293

103-
var storageClassName string
104-
105-
func SetStorageClassName(name string) {
106-
storageClassName = name
107-
}
108-
109-
// TODO fix linting (funlen)
110-
//
111-
//nolint:funlen
112-
func GetVolumesForDeployment[O pdoknlv3.WMSWFS](obj O, configMapNames types.HashedConfigMapNames) []corev1.Volume {
113-
baseVolume := corev1.Volume{Name: constants.BaseVolumeName}
114-
if use, size := mapperutils.UseEphemeralVolume(obj); use {
115-
baseVolume.Ephemeral = &corev1.EphemeralVolumeSource{
116-
VolumeClaimTemplate: &corev1.PersistentVolumeClaimTemplate{
117-
Spec: corev1.PersistentVolumeClaimSpec{
118-
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
119-
Resources: corev1.VolumeResourceRequirements{
120-
Requests: corev1.ResourceList{
121-
corev1.ResourceStorage: *size,
122-
},
123-
},
124-
},
125-
},
126-
}
127-
128-
if storageClassName != "" {
129-
baseVolume.Ephemeral.VolumeClaimTemplate.Spec.StorageClassName = &storageClassName
130-
}
131-
} else {
132-
baseVolume.VolumeSource = corev1.VolumeSource{
133-
EmptyDir: &corev1.EmptyDirVolumeSource{},
134-
}
135-
}
136-
137-
newVolumeSource := func(name string) corev1.VolumeSource {
138-
return corev1.VolumeSource{
139-
ConfigMap: &corev1.ConfigMapVolumeSource{
140-
DefaultMode: smoothoperatorutils.Pointer(int32(0644)),
141-
LocalObjectReference: corev1.LocalObjectReference{
142-
Name: name,
143-
},
144-
},
145-
}
146-
}
147-
148-
volumes := []corev1.Volume{
149-
baseVolume,
150-
{
151-
Name: constants.DataVolumeName,
152-
VolumeSource: corev1.VolumeSource{
153-
EmptyDir: &corev1.EmptyDirVolumeSource{},
154-
},
155-
},
156-
{
157-
Name: constants.MapserverName,
158-
VolumeSource: newVolumeSource(configMapNames.Mapserver),
159-
},
160-
}
161-
162-
if mapfile := obj.Mapfile(); mapfile != nil {
163-
volumes = append(volumes, corev1.Volume{
164-
Name: constants.ConfigMapCustomMapfileVolumeName,
165-
VolumeSource: newVolumeSource(mapfile.ConfigMapKeyRef.Name),
166-
})
167-
}
168-
169-
if obj.Type() == pdoknlv3.ServiceTypeWMS && obj.Options().UseWebserviceProxy() {
170-
volumes = append(volumes, corev1.Volume{
171-
Name: constants.ConfigMapOgcWebserviceProxyVolumeName,
172-
VolumeSource: newVolumeSource(configMapNames.OgcWebserviceProxy),
173-
})
174-
}
175-
176-
if obj.Options().PrefetchData {
177-
vol := newVolumeSource(configMapNames.InitScripts)
178-
vol.ConfigMap.DefaultMode = smoothoperatorutils.Pointer(int32(0777))
179-
volumes = append(volumes, corev1.Volume{
180-
Name: constants.InitScriptsName,
181-
VolumeSource: vol,
182-
})
183-
}
184-
185-
// Add capabilitiesgenerator config here to get the same order as the ansible operator
186-
// Needed to compare deployments from the ansible operator and this one
187-
volumes = append(volumes, corev1.Volume{
188-
Name: constants.ConfigMapCapabilitiesGeneratorVolumeName,
189-
VolumeSource: newVolumeSource(configMapNames.CapabilitiesGenerator),
190-
})
191-
192-
// Add mapfilegenerator config and styling-files (if applicable) here to get the same order as the ansible operator
193-
// Needed to compare deployments from the ansible operator and this one
194-
if obj.Mapfile() == nil {
195-
volumes = append(volumes, corev1.Volume{
196-
Name: constants.ConfigMapMapfileGeneratorVolumeName,
197-
VolumeSource: newVolumeSource(configMapNames.MapfileGenerator),
198-
})
199-
}
200-
201-
if obj.Type() == pdoknlv3.ServiceTypeWMS {
202-
if obj.Mapfile() == nil {
203-
wms, _ := any(obj).(*pdoknlv3.WMS)
204-
stylingFilesVolumeProjections := []corev1.VolumeProjection{}
205-
if wms.Spec.Service.StylingAssets != nil && wms.Spec.Service.StylingAssets.ConfigMapRefs != nil {
206-
for _, cf := range wms.Spec.Service.StylingAssets.ConfigMapRefs {
207-
stylingFilesVolumeProjections = append(stylingFilesVolumeProjections, corev1.VolumeProjection{
208-
ConfigMap: &corev1.ConfigMapProjection{
209-
LocalObjectReference: corev1.LocalObjectReference{
210-
Name: cf.Name,
211-
},
212-
},
213-
})
214-
}
215-
}
216-
217-
stylingFilesVolume := corev1.Volume{
218-
Name: constants.ConfigMapStylingFilesVolumeName,
219-
VolumeSource: corev1.VolumeSource{
220-
Projected: &corev1.ProjectedVolumeSource{
221-
Sources: stylingFilesVolumeProjections,
222-
},
223-
},
224-
}
225-
226-
volumes = append(volumes, stylingFilesVolume)
227-
}
228-
229-
lgVolume := corev1.Volume{
230-
Name: constants.ConfigMapLegendGeneratorVolumeName,
231-
VolumeSource: newVolumeSource(configMapNames.LegendGenerator),
232-
}
233-
figVolume := corev1.Volume{
234-
Name: constants.ConfigMapFeatureinfoGeneratorVolumeName,
235-
VolumeSource: newVolumeSource(configMapNames.FeatureInfoGenerator),
236-
}
237-
volumes = append(volumes, figVolume, lgVolume)
238-
}
239-
240-
return volumes
241-
}
242-
243-
func GetVolumeMountsForDeployment[O pdoknlv3.WMSWFS](obj O) []corev1.VolumeMount {
244-
volumeMounts := []corev1.VolumeMount{
245-
utils.GetBaseVolumeMount(),
246-
utils.GetDataVolumeMount(),
247-
}
248-
249-
staticFiles, _ := static.GetStaticFiles()
250-
for _, name := range staticFiles {
251-
volumeMounts = append(volumeMounts, corev1.VolumeMount{
252-
Name: constants.MapserverName,
253-
MountPath: "/srv/mapserver/config/" + name,
254-
SubPath: name,
255-
})
256-
}
257-
258-
// Custom mapfile
259-
if mapfile := obj.Mapfile(); mapfile != nil {
260-
volumeMounts = append(volumeMounts, utils.GetMapfileVolumeMount())
261-
}
262-
263-
return volumeMounts
264-
}
265-
26694
func GetMapfileEnvVar[O pdoknlv3.WMSWFS](obj O) corev1.EnvVar {
26795
mapFileName := "service.map"
26896
if obj.Mapfile() != nil {
@@ -275,128 +103,7 @@ func GetMapfileEnvVar[O pdoknlv3.WMSWFS](obj O) corev1.EnvVar {
275103
}
276104
}
277105

278-
func GetEnvVarsForDeployment[O pdoknlv3.WMSWFS](obj O, blobsSecretName string) []corev1.EnvVar {
279-
return []corev1.EnvVar{
280-
{
281-
Name: "SERVICE_TYPE",
282-
Value: string(obj.Type()),
283-
}, {
284-
Name: "MAPSERVER_CONFIG_FILE",
285-
Value: "/srv/mapserver/config/default_mapserver.conf",
286-
},
287-
GetMapfileEnvVar(obj),
288-
{
289-
Name: "AZURE_STORAGE_CONNECTION_STRING",
290-
ValueFrom: &corev1.EnvVarSource{
291-
SecretKeyRef: &corev1.SecretKeySelector{
292-
LocalObjectReference: corev1.LocalObjectReference{
293-
Name: blobsSecretName, // TODO
294-
},
295-
Key: "AZURE_STORAGE_CONNECTION_STRING",
296-
},
297-
},
298-
},
299-
}
300-
}
301-
302-
// TODO fix linting (cyclop,funlen)
303-
// Resources for mapserver container
304-
//
305-
//nolint:cyclop,funlen
306-
func GetResourcesForDeployment[O pdoknlv3.WMSWFS](obj O) corev1.ResourceRequirements {
307-
resources := corev1.ResourceRequirements{
308-
Limits: corev1.ResourceList{},
309-
Requests: corev1.ResourceList{},
310-
}
311-
312-
maxResourceVal := func(v1 *resource.Quantity, v2 *resource.Quantity) *resource.Quantity {
313-
switch {
314-
case v1 != nil && v2 != nil:
315-
if v1.Value() > v2.Value() {
316-
return v1
317-
}
318-
return v2
319-
case v1 != nil && v2 == nil:
320-
return v1
321-
case v1 == nil || v2 != nil:
322-
return v2
323-
default:
324-
325-
}
326-
327-
return &resource.Quantity{}
328-
}
329-
330-
objResources := &corev1.ResourceRequirements{}
331-
if obj.PodSpecPatch() != nil {
332-
found := false
333-
for _, container := range obj.PodSpecPatch().Containers {
334-
if container.Name == constants.MapserverName {
335-
objResources = &container.Resources
336-
found = true
337-
break
338-
}
339-
}
340-
341-
if !found && obj.PodSpecPatch().Resources != nil {
342-
objResources = obj.PodSpecPatch().Resources
343-
}
344-
345-
}
346-
347-
/**
348-
Set CPU request and limit
349-
*/
350-
cpuRequest := objResources.Requests.Cpu()
351-
if cpuRequest == nil || cpuRequest.IsZero() {
352-
cpuRequest = smoothoperatorutils.Pointer(resource.MustParse("0.15"))
353-
if obj.Type() == pdoknlv3.ServiceTypeWMS && obj.Options().UseWebserviceProxy() {
354-
cpuRequest = smoothoperatorutils.Pointer(resource.MustParse("0.1"))
355-
}
356-
}
357-
resources.Requests[corev1.ResourceCPU] = *cpuRequest
358-
359-
cpuLimit := objResources.Limits.Cpu()
360-
if cpuLimit != nil && !cpuLimit.IsZero() {
361-
resources.Limits[corev1.ResourceCPU] = *maxResourceVal(cpuLimit, cpuRequest)
362-
}
363-
364-
/**
365-
Set memory limit/request if the request is higher than the limit the request is used as limit
366-
*/
367-
memoryRequest := objResources.Requests.Memory()
368-
if memoryRequest != nil && !memoryRequest.IsZero() {
369-
resources.Requests[corev1.ResourceMemory] = *memoryRequest
370-
}
371-
372-
memoryLimit := objResources.Limits.Memory()
373-
if memoryLimit == nil || memoryLimit.IsZero() {
374-
memoryLimit = smoothoperatorutils.Pointer(resource.MustParse("800M"))
375-
}
376-
resources.Limits[corev1.ResourceMemory] = *maxResourceVal(memoryLimit, memoryRequest)
377-
378-
/**
379-
Set ephemeral-storage if there is no ephemeral volume
380-
*/
381-
// TODO fix linting (nestif)
382-
if use, _ := mapperutils.UseEphemeralVolume(obj); !use {
383-
ephemeralStorageRequest := mapperutils.EphemeralStorageRequest(obj)
384-
if ephemeralStorageRequest != nil {
385-
resources.Requests[corev1.ResourceEphemeralStorage] = *ephemeralStorageRequest
386-
}
387-
388-
ephemeralStorageLimit := mapperutils.EphemeralStorageLimit(obj)
389-
defaultEphemeralStorageLimit := resource.MustParse("200M")
390-
if ephemeralStorageLimit == nil || ephemeralStorageLimit.IsZero() || ephemeralStorageLimit.Value() < defaultEphemeralStorageLimit.Value() {
391-
ephemeralStorageLimit = smoothoperatorutils.Pointer(defaultEphemeralStorageLimit)
392-
}
393-
resources.Limits[corev1.ResourceEphemeralStorage] = *maxResourceVal(ephemeralStorageLimit, ephemeralStorageRequest)
394-
}
395-
396-
return resources
397-
}
398-
399-
func GetProbesForDeployment[O pdoknlv3.WMSWFS](obj O) (livenessProbe *corev1.Probe, readinessProbe *corev1.Probe, startupProbe *corev1.Probe, err error) {
106+
func getProbes[O pdoknlv3.WMSWFS](obj O) (livenessProbe *corev1.Probe, readinessProbe *corev1.Probe, startupProbe *corev1.Probe, err error) {
400107
livenessProbe = getLivenessProbe(obj)
401108
switch obj.Type() {
402109
case pdoknlv3.ServiceTypeWFS:

0 commit comments

Comments
 (0)