Skip to content

Commit c8dfbf7

Browse files
Merge pull request #61 from PDOK/jd/status-subresource
Use shared status update
2 parents 2aa7149 + 195d6dd commit c8dfbf7

File tree

8 files changed

+69
-91
lines changed

8 files changed

+69
-91
lines changed

api/v3/atom_types.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,21 @@ type SRS struct {
229229
// versionName=v3
230230
// +kubebuilder:storageversion
231231
// +kubebuilder:resource:categories=pdok
232+
// +kubebuilder:printcolumn:name="ReadyPods",type=integer,JSONPath=`.status.podSummary[0].ready`
233+
// +kubebuilder:printcolumn:name="DesiredPods",type=integer,JSONPath=`.status.podSummary[0].total`
234+
// +kubebuilder:printcolumn:name="ReconcileStatus",type=string,JSONPath=`.status.conditions[?(@.type == "Reconciled")].reason`
232235

233236
// Atom is the Schema for the atoms API.
234237
type Atom struct {
235238
metav1.TypeMeta `json:",inline"`
236239
metav1.ObjectMeta `json:"metadata,omitempty"`
237240

238-
Spec AtomSpec `json:"spec"`
239-
Status *smoothoperatormodel.OperatorStatus `json:"status,omitempty"`
241+
Spec AtomSpec `json:"spec"`
242+
Status smoothoperatormodel.OperatorStatus `json:"status,omitempty"`
243+
}
244+
245+
func (a *Atom) OperatorStatus() *smoothoperatormodel.OperatorStatus {
246+
return &a.Status
240247
}
241248

242249
// +kubebuilder:object:root=true
@@ -268,8 +275,8 @@ func GetBlobEndpoint() string {
268275
return blobEndpoint
269276
}
270277

271-
func (r *Atom) GetDownloadLinks() (downloadLinks []DownloadLink) {
272-
for _, datasetFeed := range r.Spec.Service.DatasetFeeds {
278+
func (a *Atom) GetDownloadLinks() (downloadLinks []DownloadLink) {
279+
for _, datasetFeed := range a.Spec.Service.DatasetFeeds {
273280
for _, entry := range datasetFeed.Entries {
274281
downloadLinks = append(downloadLinks, entry.DownloadLinks...)
275282
}

api/v3/zz_generated.deepcopy.go

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/pdok.nl_atoms.yaml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,17 @@ spec:
1616
singular: atom
1717
scope: Namespaced
1818
versions:
19-
- name: v3
19+
- additionalPrinterColumns:
20+
- jsonPath: .status.podSummary[0].ready
21+
name: ReadyPods
22+
type: integer
23+
- jsonPath: .status.podSummary[0].total
24+
name: DesiredPods
25+
type: integer
26+
- jsonPath: .status.conditions[?(@.type == "Reconciled")].reason
27+
name: ReconcileStatus
28+
type: string
29+
name: v3
2030
schema:
2131
openAPIV3Schema:
2232
description: Atom is the Schema for the atoms API.
@@ -487,6 +497,33 @@ spec:
487497
description: The result of creating or updating of each derived resource
488498
for this Atom.
489499
type: object
500+
podSummary:
501+
description: Summary of status of pods that belong to this resource
502+
items:
503+
properties:
504+
available:
505+
format: int32
506+
type: integer
507+
generation:
508+
format: int32
509+
type: integer
510+
ready:
511+
format: int32
512+
type: integer
513+
total:
514+
format: int32
515+
type: integer
516+
unavailable:
517+
format: int32
518+
type: integer
519+
required:
520+
- available
521+
- generation
522+
- ready
523+
- total
524+
- unavailable
525+
type: object
526+
type: array
490527
type: object
491528
required:
492529
- spec

config/rbac/role.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ rules:
2727
- list
2828
- update
2929
- watch
30+
- apiGroups:
31+
- apps
32+
resources:
33+
- replicasets
34+
verbs:
35+
- get
36+
- list
37+
- watch
3038
- apiGroups:
3139
- pdok.nl
3240
resources:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/onsi/ginkgo/v2 v2.22.1
1212
github.com/onsi/gomega v1.36.2
1313
github.com/pdok/atom-generator v0.6.4
14-
github.com/pdok/smooth-operator v1.0.0
14+
github.com/pdok/smooth-operator v1.2.0
1515
github.com/peterbourgon/ff v1.7.1
1616
github.com/pkg/errors v0.9.1
1717
github.com/stretchr/testify v1.10.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaR
152152
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
153153
github.com/pdok/atom-generator v0.6.4 h1:UpTTSKskdWLnxTAhSNOlz8dF2tBousD97V03kWzCV2k=
154154
github.com/pdok/atom-generator v0.6.4/go.mod h1:IlPwti5ocXDTjB4xmz0ZpHCOW/suuW5gQMfjfwPX6uM=
155-
github.com/pdok/smooth-operator v1.0.0 h1:Gp5DG2FQ3uujxWQX/647ZcyVk2EhNZPBD+lMxpLHotI=
156-
github.com/pdok/smooth-operator v1.0.0/go.mod h1:przwM7mBGmNPqabyhImKVZ15WL4zbqLqH4ExbuWKhWE=
155+
github.com/pdok/smooth-operator v1.2.0 h1:KFFNsFzk16IfcHPmHkgJnmbhIIY69k7crhPft3lXih8=
156+
github.com/pdok/smooth-operator v1.2.0/go.mod h1:tqr/CDCXZHNzQzQVlSAnCmsPlx9tWAObsj8hg9mSSEU=
157157
github.com/pelletier/go-toml v1.6.0/go.mod h1:5N711Q9dKgbdkxHL+MEfF31hpT7l0S0s/t2kKREewys=
158158
github.com/peterbourgon/ff v1.7.1 h1:xt1lxTG+Nr2+tFtysY7abFgPoH3Lug8CwYJMOmJRXhk=
159159
github.com/peterbourgon/ff v1.7.1/go.mod h1:fYI5YA+3RDqQRExmFbHnBjEeWzh9TrS8rnRpEq7XIg0=

internal/controller/atom_controller.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ package controller
2828
import (
2929
"context"
3030
"fmt"
31+
"strings"
3132
"time"
3233

3334
"github.com/pkg/errors"
@@ -39,6 +40,7 @@ import (
3940

4041
pdoknlv3 "github.com/pdok/atom-operator/api/v3"
4142
smoothoperatorv1 "github.com/pdok/smooth-operator/api/v1"
43+
smoothoperatorstatus "github.com/pdok/smooth-operator/pkg/status"
4244
smoothutil "github.com/pdok/smooth-operator/pkg/util"
4345

4446
traefikiov1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
@@ -51,12 +53,6 @@ import (
5153
logf "sigs.k8s.io/controller-runtime/pkg/log"
5254
)
5355

54-
const (
55-
reconciledConditionType = "Reconciled"
56-
reconciledConditionReasonSuccess = "Success"
57-
reconciledConditionReasonError = "Error"
58-
)
59-
6056
const (
6157
appLabelKey = "pdok.nl/app"
6258
appName = "atom-service"
@@ -87,6 +83,7 @@ type AtomReconciler struct {
8783
// +kubebuilder:rbac:groups=pdok.nl,resources=ownerinfo,verbs=get;list;watch
8884
// +kubebuilder:rbac:groups=pdok.nl,resources=ownerinfo/status,verbs=get
8985
// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;delete
86+
// +kubebuilder:rbac:groups=apps,resources=replicasets,verbs=get;list;watch;
9087
// +kubebuilder:rbac:groups=core,resources=configmaps;services,verbs=watch;create;get;update;list;delete
9188
// +kubebuilder:rbac:groups=traefik.io,resources=ingressroutes;middlewares,verbs=get;list;watch;create;update;delete
9289
// +kubebuilder:rbac:groups=policy,resources=poddisruptionbudgets,verbs=create;update;delete;list;watch
@@ -138,7 +135,7 @@ func (r *AtomReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resul
138135
defer func() {
139136
if rec := recover(); rec != nil {
140137
err = recoveredPanicToError(rec)
141-
r.logAndUpdateStatusError(ctx, atom, err)
138+
smoothoperatorstatus.LogAndUpdateStatusError(ctx, r.Client, atom, err)
142139
}
143140
}()
144141

@@ -153,11 +150,11 @@ func (r *AtomReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resul
153150
operationResults, err := r.createOrUpdateAllForAtom(ctx, atom, ownerInfo)
154151
if err != nil {
155152
lgr.Info("failed creating resources for atom", "atom", atom)
156-
r.logAndUpdateStatusError(ctx, atom, err)
153+
smoothoperatorstatus.LogAndUpdateStatusError(ctx, r.Client, atom, err)
157154
return result, err
158155
}
159156
lgr.Info("finished creating resources for atom", "atom", atom)
160-
r.logAndUpdateStatusFinished(ctx, atom, operationResults)
157+
smoothoperatorstatus.LogAndUpdateStatusFinished(ctx, r.Client, atom, operationResults)
161158

162159
return result, err
163160
}
@@ -186,7 +183,7 @@ func (r *AtomReconciler) createOrUpdateAllForAtom(ctx context.Context, atom *pdo
186183
operationResults[smoothutil.GetObjectFullName(r.Client, deployment)], err = controllerutil.CreateOrUpdate(ctx, r.Client, deployment, func() error {
187184
return r.mutateDeployment(atom, deployment, configMap.GetName())
188185
})
189-
if err != nil {
186+
if err != nil && !strings.Contains(err.Error(), "the object has been modified; please apply your changes to the latest version and try again") {
190187
return operationResults, fmt.Errorf("unable to create/update resource %s: %w", smoothutil.GetObjectFullName(c, deployment), err)
191188
}
192189
// endregion
@@ -267,6 +264,7 @@ func (r *AtomReconciler) SetupWithManager(mgr ctrl.Manager) error {
267264
Owns(&traefikiov1alpha1.IngressRoute{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
268265
Owns(&policyv1.PodDisruptionBudget{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
269266
Owns(&smoothoperatorv1.OwnerInfo{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
267+
Watches(&appsv1.ReplicaSet{}, smoothoperatorstatus.GetReplicaSetEventHandlerForObj(mgr, "Atom")).
270268
Complete(r)
271269
}
272270

internal/controller/status.go

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)