Skip to content

Commit 7c567ee

Browse files
authored
Merge branch 'PDOK-17552-atom-operator-v3-reconcile' into PDOK-17552-atom-operator-v3-mappings
2 parents 2f9a749 + 37191d6 commit 7c567ee

File tree

9 files changed

+933
-545
lines changed

9 files changed

+933
-545
lines changed

api/v3/atom_types.go

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ package v3
2626

2727
import (
2828
"fmt"
29+
corev1 "k8s.io/api/core/v1"
30+
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
31+
"strings"
2932

3033
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3134
)
@@ -38,6 +41,11 @@ type AtomSpec struct {
3841
Lifecycle Lifecycle `json:"lifecycle,omitempty"`
3942
Service Service `json:"service"`
4043
DatasetFeeds []DatasetFeed `json:"datasetFeeds,omitempty"`
44+
//+kubebuilder:validation:Type=object
45+
//+kubebuilder:validation:Schemaless
46+
//+kubebuilder:pruning:PreserveUnknownFields
47+
// Optional strategic merge patch for the pod in the deployment. E.g. to patch the resources or add extra env vars.
48+
PodSpecPatch *corev1.PodSpec `json:"podSpecPatch,omitempty"`
4149
}
4250

4351
// todo: move to higher level (operator-support repo)
@@ -56,6 +64,9 @@ type Service struct {
5664
ServiceMetadataLinks MetadataLink `json:"serviceMetadataLinks,omitempty"`
5765
Rights string `json:"rights,omitempty"`
5866
Author Author `json:"author,omitempty"`
67+
68+
// +kubebuilder:validation:Optional
69+
GeneratorConfig string `json:"-"` // Skip this field in the CRD schema
5970
}
6071

6172
// Link represents a link in the service or dataset feed
@@ -68,7 +79,6 @@ type Link struct {
6879
Title string `json:"title,omitempty"`
6980
}
7081

71-
// Author todo: move to higher level
7282
// Author specifies the author or owner information
7383
type Author struct {
7484
Name string `json:"name"`
@@ -82,7 +92,6 @@ type DatasetFeed struct {
8292
Subtitle string `json:"subtitle,omitempty"`
8393
Links []Link `json:"links,omitempty"` // Todo kan weg?
8494
DatasetMetadataLinks MetadataLink `json:"datasetMetadataLinks,omitempty"`
85-
//Author Author `json:"author,omitempty"`
8695
SpatialDatasetIdentifierCode string `json:"spatial_dataset_identifier_code,omitempty"`
8796
SpatialDatasetIdentifierNamespace string `json:"spatial_dataset_identifier_namespace,omitempty"`
8897
Entries []Entry `json:"entries,omitempty"`
@@ -145,7 +154,12 @@ type SRS struct {
145154
type AtomStatus struct {
146155
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
147156
// Important: Run "make" to regenerate code after modifying this file
148-
// todo: Analyse which statuses we need
157+
158+
// Each condition contains details for one aspect of the current state of this Atom.
159+
// Known .status.conditions.type are: "Reconciled"
160+
Conditions []metav1.Condition `json:"conditions,omitempty"`
161+
// The result of creating or updating of each derived resource for this Atom.
162+
OperationResults map[string]controllerutil.OperationResult `json:"operationResults,omitempty"`
149163
}
150164

151165
// +kubebuilder:object:root=true
@@ -205,3 +219,24 @@ func (r *Atom) GetURI() (URI string) {
205219
}
206220
return
207221
}
222+
223+
func (r *Atom) GetNrOfDownloadLinks() (count int) {
224+
for _, datasetFeed := range r.Spec.DatasetFeeds {
225+
for _, entry := range datasetFeed.Entries {
226+
for range entry.DownloadLinks {
227+
count++
228+
}
229+
}
230+
}
231+
return
232+
}
233+
234+
func (dl *DownloadLink) GetBlobPrefix() string {
235+
index := strings.LastIndex(dl.Data, "/") + 1
236+
return dl.Data[:index]
237+
}
238+
239+
func (dl *DownloadLink) GetBlobName() string {
240+
index := strings.LastIndex(dl.Data, "/") + 1
241+
return dl.Data[index:]
242+
}

api/v3/zz_generated.deepcopy.go

Lines changed: 23 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/main.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ import (
4747
// +kubebuilder:scaffold:imports
4848
)
4949

50+
const (
51+
defaultAtomGeneratorImage = "docker.io/pdok/atom-generator:0.6.0"
52+
defaultLighttpdImage = "docker.io/pdok/lighttpd:1.4.67"
53+
)
54+
5055
var (
5156
scheme = runtime.NewScheme()
5257
setupLog = ctrl.Log.WithName("setup")
@@ -73,6 +78,8 @@ func main() {
7378
var secureMetrics bool
7479
var enableHTTP2 bool
7580
var atomBaseURLHost string
81+
var atomGeneratorImage string
82+
var lighttpdImage string
7683
var tlsOpts []func(*tls.Config)
7784
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
7885
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
@@ -91,9 +98,10 @@ func main() {
9198
flag.StringVar(&metricsCertKey, "metrics-cert-key", "tls.key", "The name of the metrics server key file.")
9299
flag.BoolVar(&enableHTTP2, "enable-http2", false,
93100
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
94-
95101
flag.StringVar(&atomBaseURLHost, "atom-baseurl-host", "http://localhost:32788/",
96102
"The host which is used to create the Atom BaseURL.")
103+
flag.StringVar(&atomGeneratorImage, "atom-generator-image", defaultAtomGeneratorImage, "The image to use in the Atom generator init-container.")
104+
flag.StringVar(&lighttpdImage, "lighttpd-image", defaultLighttpdImage, "The image to use in the Atom pod.")
97105
opts := zap.Options{
98106
Development: true,
99107
}
@@ -218,8 +226,10 @@ func main() {
218226
}
219227

220228
if err = (&controller.AtomReconciler{
221-
Client: mgr.GetClient(),
222-
Scheme: mgr.GetScheme(),
229+
Client: mgr.GetClient(),
230+
Scheme: mgr.GetScheme(),
231+
AtomGeneratorImage: atomGeneratorImage,
232+
LighttpdImage: lighttpdImage,
223233
}).SetupWithManager(mgr); err != nil {
224234
setupLog.Error(err, "unable to create controller", "controller", "Atom")
225235
os.Exit(1)

config/crd/bases/pdok.nl_atoms.yaml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,11 @@ spec:
524524
format: int32
525525
type: integer
526526
type: object
527+
podSpecPatch:
528+
description: Optional strategic merge patch for the pod in the deployment.
529+
E.g. to patch the resources or add extra env vars.
530+
type: object
531+
x-kubernetes-preserve-unknown-fields: true
527532
service:
528533
description: Service defines the service configuration for the Atom
529534
feed
@@ -565,6 +570,74 @@ spec:
565570
type: object
566571
status:
567572
description: AtomStatus defines the observed state of Atom.
573+
properties:
574+
conditions:
575+
description: |-
576+
Each condition contains details for one aspect of the current state of this Atom.
577+
Known .status.conditions.type are: "Reconciled"
578+
items:
579+
description: Condition contains details for one aspect of the current
580+
state of this API Resource.
581+
properties:
582+
lastTransitionTime:
583+
description: |-
584+
lastTransitionTime is the last time the condition transitioned from one status to another.
585+
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
586+
format: date-time
587+
type: string
588+
message:
589+
description: |-
590+
message is a human readable message indicating details about the transition.
591+
This may be an empty string.
592+
maxLength: 32768
593+
type: string
594+
observedGeneration:
595+
description: |-
596+
observedGeneration represents the .metadata.generation that the condition was set based upon.
597+
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
598+
with respect to the current state of the instance.
599+
format: int64
600+
minimum: 0
601+
type: integer
602+
reason:
603+
description: |-
604+
reason contains a programmatic identifier indicating the reason for the condition's last transition.
605+
Producers of specific condition types may define expected values and meanings for this field,
606+
and whether the values are considered a guaranteed API.
607+
The value should be a CamelCase string.
608+
This field may not be empty.
609+
maxLength: 1024
610+
minLength: 1
611+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
612+
type: string
613+
status:
614+
description: status of the condition, one of True, False, Unknown.
615+
enum:
616+
- "True"
617+
- "False"
618+
- Unknown
619+
type: string
620+
type:
621+
description: type of condition in CamelCase or in foo.example.com/CamelCase.
622+
maxLength: 316
623+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
624+
type: string
625+
required:
626+
- lastTransitionTime
627+
- message
628+
- reason
629+
- status
630+
- type
631+
type: object
632+
type: array
633+
operationResults:
634+
additionalProperties:
635+
description: OperationResult is the action result of a CreateOrUpdate
636+
call.
637+
type: string
638+
description: The result of creating or updating of each derived resource
639+
for this Atom.
640+
type: object
568641
type: object
569642
type: object
570643
served: true

go.mod

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ require (
1111
github.com/onsi/gomega v1.35.1
1212
github.com/pdok/atom-generator v0.6.0
1313
github.com/pdok/smooth-operator v0.0.0-20250228084310-9fff7e0bf501
14+
github.com/pkg/errors v0.9.1
1415
github.com/traefik/traefik/v2 v2.11.20
1516
golang.org/x/tools v0.28.0
1617
k8s.io/api v0.32.0
1718
k8s.io/apimachinery v0.32.0
1819
k8s.io/client-go v0.32.0
1920
sigs.k8s.io/controller-runtime v0.20.0
21+
sigs.k8s.io/kustomize/api v0.19.0
22+
sigs.k8s.io/kustomize/kyaml v0.19.0
2023
sigs.k8s.io/yaml v1.4.0
2124
)
2225

@@ -37,6 +40,7 @@ require (
3740
github.com/fsnotify/fsnotify v1.8.0 // indirect
3841
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
3942
github.com/go-acme/lego/v4 v4.21.0 // indirect
43+
github.com/go-errors/errors v1.4.2 // indirect
4044
github.com/go-jose/go-jose/v4 v4.0.4 // indirect
4145
github.com/go-logr/stdr v1.2.2 // indirect
4246
github.com/go-logr/zapr v1.3.0 // indirect
@@ -48,7 +52,7 @@ require (
4852
github.com/golang/protobuf v1.5.4 // indirect
4953
github.com/google/btree v1.1.3 // indirect
5054
github.com/google/cel-go v0.22.0 // indirect
51-
github.com/google/gnostic-models v0.6.8 // indirect
55+
github.com/google/gnostic-models v0.6.9 // indirect
5256
github.com/google/go-cmp v0.6.0 // indirect
5357
github.com/google/gofuzz v1.2.0 // indirect
5458
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect
@@ -65,7 +69,6 @@ require (
6569
github.com/modern-go/reflect2 v1.0.2 // indirect
6670
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
6771
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
68-
github.com/pkg/errors v0.9.1 // indirect
6972
github.com/prometheus/client_golang v1.19.1 // indirect
7073
github.com/prometheus/client_model v0.6.1 // indirect
7174
github.com/prometheus/common v0.55.0 // indirect
@@ -109,7 +112,7 @@ require (
109112
k8s.io/apiserver v0.32.0 // indirect
110113
k8s.io/component-base v0.32.0 // indirect
111114
k8s.io/klog/v2 v2.130.1 // indirect
112-
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
115+
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 // indirect
113116
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
114117
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.0 // indirect
115118
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect

go.sum

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv
3535
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
3636
github.com/go-acme/lego/v4 v4.21.0 h1:arEW+8o5p7VI8Bk1kr/PDlgD1DrxtTH1gJ4b7mehL8o=
3737
github.com/go-acme/lego/v4 v4.21.0/go.mod h1:HrSWzm3Ckj45Ie3i+p1zKVobbQoMOaGu9m4up0dUeDI=
38+
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
39+
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
3840
github.com/go-jose/go-jose/v4 v4.0.4 h1:VsjPI33J0SB9vQM6PLmNjoHqMQNGPiZ0rHL7Ni7Q6/E=
3941
github.com/go-jose/go-jose/v4 v4.0.4/go.mod h1:NKb5HO1EZccyMpiZNbdUw/14tiXNyUJh188dfnMCAfc=
4042
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
@@ -60,8 +62,8 @@ github.com/google/btree v1.1.3 h1:CVpQJjYgC4VbzxeGVHfvZrv1ctoYCAI8vbl07Fcxlyg=
6062
github.com/google/btree v1.1.3/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
6163
github.com/google/cel-go v0.22.0 h1:b3FJZxpiv1vTMo2/5RDUqAHPxkT8mmMfJIrq1llbf7g=
6264
github.com/google/cel-go v0.22.0/go.mod h1:BuznPXXfQDpXKWQ9sPW3TzlAJN5zzFe+i9tIs0yC4s8=
63-
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
64-
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
65+
github.com/google/gnostic-models v0.6.9 h1:MU/8wDLif2qCXZmzncUQ/BOfxWfthHi63KqpoNbWqVw=
66+
github.com/google/gnostic-models v0.6.9/go.mod h1:CiWsm0s6BSQd1hRn8/QmxqB6BesYcbSZxsz9b0KuDBw=
6567
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
6668
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
6769
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
@@ -257,8 +259,8 @@ k8s.io/component-base v0.32.0 h1:d6cWHZkCiiep41ObYQS6IcgzOUQUNpywm39KVYaUqzU=
257259
k8s.io/component-base v0.32.0/go.mod h1:JLG2W5TUxUu5uDyKiH2R/7NnxJo1HlPoRIIbVLkK5eM=
258260
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
259261
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
260-
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f h1:GA7//TjRY9yWGy1poLzYYJJ4JRdzg3+O6e8I+e+8T5Y=
261-
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f/go.mod h1:R/HEjbvWI0qdfb8viZUeVZm0X6IZnxAydC7YU42CMw4=
262+
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 h1:hcha5B1kVACrLujCKLbr8XWMxCxzQx42DY8QKYJrDLg=
263+
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7/go.mod h1:GewRfANuJ70iYzvn+i4lezLDAFzvjxZYK1gn1lWcfas=
262264
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 h1:M3sRQVHv7vB20Xc2ybTt7ODCeFj6JSWYFzOFnYeS6Ro=
263265
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
264266
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.0 h1:CPT0ExVicCzcpeN4baWEV2ko2Z/AsiZgEdwgcfwLgMo=
@@ -267,6 +269,10 @@ sigs.k8s.io/controller-runtime v0.20.0 h1:jjkMo29xEXH+02Md9qaVXfEIaMESSpy3TBWPrs
267269
sigs.k8s.io/controller-runtime v0.20.0/go.mod h1:BrP3w158MwvB3ZbNpaAcIKkHQ7YGpYnzpoSTZ8E14WU=
268270
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 h1:/Rv+M11QRah1itp8VhT6HoVx1Ray9eB4DBr+K+/sCJ8=
269271
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3/go.mod h1:18nIHnGi6636UCz6m8i4DhaJ65T6EruyzmoQqI2BVDo=
272+
sigs.k8s.io/kustomize/api v0.19.0 h1:F+2HB2mU1MSiR9Hp1NEgoU2q9ItNOaBJl0I4Dlus5SQ=
273+
sigs.k8s.io/kustomize/api v0.19.0/go.mod h1:/BbwnivGVcBh1r+8m3tH1VNxJmHSk1PzP5fkP6lbL1o=
274+
sigs.k8s.io/kustomize/kyaml v0.19.0 h1:RFge5qsO1uHhwJsu3ipV7RNolC7Uozc0jUBC/61XSlA=
275+
sigs.k8s.io/kustomize/kyaml v0.19.0/go.mod h1:FeKD5jEOH+FbZPpqUghBP8mrLjJ3+zD3/rf9NNu1cwY=
270276
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 h1:MdmvkGuXi/8io6ixD5wud3vOLwc1rj0aNqRlpuvjmwA=
271277
sigs.k8s.io/structured-merge-diff/v4 v4.4.2/go.mod h1:N8f93tFZh9U6vpxwRArLiikrE5/2tiu1w1AGfACIGE4=
272278
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=

0 commit comments

Comments
 (0)