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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module github.com/uselagoon/dbaas-controller
go 1.25.0

require (
github.com/onsi/ginkgo/v2 v2.27.3
github.com/onsi/gomega v1.38.2
github.com/onsi/ginkgo/v2 v2.28.1
github.com/onsi/gomega v1.39.0
github.com/prometheus/client_golang v1.23.2
k8s.io/api v0.35.0
k8s.io/apimachinery v0.35.0
k8s.io/client-go v0.35.0
sigs.k8s.io/controller-runtime v0.22.4
sigs.k8s.io/controller-runtime v0.23.1
)

require (
Expand All @@ -29,12 +29,12 @@ require (
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/crypto v0.45.0 // indirect
golang.org/x/mod v0.29.0 // indirect
golang.org/x/sync v0.18.0 // indirect
golang.org/x/crypto v0.47.0 // indirect
golang.org/x/mod v0.32.0 // indirect
golang.org/x/sync v0.19.0 // indirect
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
sigs.k8s.io/structured-merge-diff/v6 v6.3.2-0.20260122202528-d9cc6641c482 // indirect
)

require (
Expand All @@ -50,14 +50,13 @@ require (
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-sql-driver/mysql v1.9.3
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/gnostic-models v0.7.0 // indirect
github.com/google/go-cmp v0.7.0
github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 // indirect
github.com/google/pprof v0.0.0-20260115054156-294ebfa9ad83 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/lib/pq v1.10.9
github.com/lib/pq v1.11.1
github.com/mailru/easyjson v0.9.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
Expand All @@ -66,21 +65,21 @@ require (
github.com/prometheus/common v0.66.1 // indirect
github.com/prometheus/procfs v0.16.1 // indirect
github.com/spf13/pflag v1.0.9 // indirect
go.mongodb.org/mongo-driver v1.17.6
go.mongodb.org/mongo-driver v1.17.8
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/net v0.47.0 // indirect
golang.org/x/net v0.49.0 // indirect
golang.org/x/oauth2 v0.30.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/term v0.37.0 // indirect
golang.org/x/text v0.31.0
golang.org/x/sys v0.40.0 // indirect
golang.org/x/term v0.39.0 // indirect
golang.org/x/text v0.33.0
golang.org/x/time v0.9.0 // indirect
golang.org/x/tools v0.38.0 // indirect
golang.org/x/tools v0.41.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/protobuf v1.36.8 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.34.1 // indirect
k8s.io/apiextensions-apiserver v0.35.0 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 // indirect
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4 // indirect
Expand Down
86 changes: 32 additions & 54 deletions go.sum

Large diffs are not rendered by default.

26 changes: 14 additions & 12 deletions internal/controller/databaserequest_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/tools/events"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand Down Expand Up @@ -84,7 +84,7 @@ var (
type DatabaseRequestReconciler struct {
client.Client
Scheme *runtime.Scheme
Recorder record.EventRecorder
Recorder events.EventRecorder
RelationalDatabaseClient database.RelationalDatabaseInterface
Locks sync.Map
}
Expand Down Expand Up @@ -144,7 +144,7 @@ func (r *DatabaseRequestReconciler) Reconcile(ctx context.Context, req ctrl.Requ
if databaseRequest.Status.Conditions != nil && meta.IsStatusConditionTrue(databaseRequest.Status.Conditions, "Ready") {
if databaseRequest.Status.ObservedGeneration >= databaseRequest.Generation {
logger.Info("No updates to reconcile")
r.Recorder.Event(databaseRequest, v1.EventTypeNormal, "ReconcileSkipped", "No updates to reconcile")
r.Recorder.Eventf(databaseRequest, databaseRequest, v1.EventTypeNormal, "ReconcileSkipped", "No updates to reconcile", "No updates to reconcile")
return ctrl.Result{}, nil
}
}
Expand Down Expand Up @@ -235,7 +235,7 @@ func (r *DatabaseRequestReconciler) Reconcile(ctx context.Context, req ctrl.Requ
return r.handleError(ctx, databaseRequest, "update-status", err, false)
}
}
r.Recorder.Event(databaseRequest, "Normal", "DatabaseRequestUpdated", "The database request has been updated")
r.Recorder.Eventf(databaseRequest, databaseRequest, "Normal", "DatabaseRequestUpdated", "The database request has been updated", "The database request has been updated")
} else {
// set the status condition to true if the database request has been created
if meta.SetStatusCondition(&databaseRequest.Status.Conditions, metav1.Condition{
Expand All @@ -248,7 +248,7 @@ func (r *DatabaseRequestReconciler) Reconcile(ctx context.Context, req ctrl.Requ
return r.handleError(ctx, databaseRequest, "update-status", err, false)
}
}
r.Recorder.Event(databaseRequest, "Normal", "DatabaseRequestUnchanged", "The database request has been created")
r.Recorder.Eventf(databaseRequest, databaseRequest, "Normal", "DatabaseRequestUnchanged", "The database request has been created", "The database request has been created")
}
return ctrl.Result{}, nil
}
Expand All @@ -264,7 +264,7 @@ func (r *DatabaseRequestReconciler) handleError(
promDatabaseRequestReconcileErrorCounter.With(
promLabels(databaseRequest, promErr)).Inc()
promDatabaseRequestReconcileStatus.With(promLabels(databaseRequest, "")).Set(0)
r.Recorder.Event(databaseRequest, v1.EventTypeWarning, "ReconcileError", err.Error())
r.Recorder.Eventf(databaseRequest, databaseRequest, v1.EventTypeWarning, "ReconcileError", err.Error(), err.Error())

// set status condition to false
meta.SetStatusCondition(&databaseRequest.Status.Conditions, metav1.Condition{
Expand Down Expand Up @@ -365,7 +365,7 @@ func (r *DatabaseRequestReconciler) handleService(
}, service); err != nil {
if apierrors.IsNotFound(err) {
log.FromContext(ctx).Info("Creating service", "service", serviceName)
r.Recorder.Event(databaseRequest, "Normal", "CreateService", "Creating service")
r.Recorder.Eventf(databaseRequest, databaseRequest, "Normal", "CreateService", "Creating service", "Creating service")
service = &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: serviceName,
Expand All @@ -390,7 +390,7 @@ func (r *DatabaseRequestReconciler) handleService(
// update the service if the hostname has changed
if service.Spec.ExternalName != dbInfo.hostName {
log.FromContext(ctx).Info("Updating service", "service", service.Name, "hostname", dbInfo.hostName)
r.Recorder.Event(databaseRequest, "Normal", "UpdateService", "Updating service")
r.Recorder.Eventf(databaseRequest, databaseRequest, "Normal", "UpdateService", "Updating service", "Updating service")
service.Spec.ExternalName = dbInfo.hostName
if err := r.Update(ctx, service); err != nil {
return false, fmt.Errorf("failed to update service %s: %w", serviceName, err)
Expand All @@ -414,7 +414,7 @@ func (r *DatabaseRequestReconciler) handleSecret(
}, secret); err != nil {
if apierrors.IsNotFound(err) {
log.FromContext(ctx).Info("Creating secret", "secret", databaseRequest.Name)
r.Recorder.Event(databaseRequest, "Normal", "CreateSecret", "Creating secret")
r.Recorder.Eventf(databaseRequest, databaseRequest, "Normal", "CreateSecret", "Creating secret", "Creating secret")
secret = &v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: databaseRequest.Name,
Expand All @@ -436,7 +436,7 @@ func (r *DatabaseRequestReconciler) handleSecret(
diff := cmp.Diff(secret.Data, dbInfo.getSecretData(databaseRequest.Spec.Name, serviceName))
if diff != "" {
log.FromContext(ctx).Info("Updating secret due to diff")
r.Recorder.Event(databaseRequest, "Normal", "UpdateSecret", "Updating secret")
r.Recorder.Eventf(databaseRequest, databaseRequest, "Normal", "UpdateSecret", "Updating secret", "Updating secret")
secret.Data = dbInfo.getSecretData(databaseRequest.Spec.Name, serviceName)
if err := r.Update(ctx, secret); err != nil {
return false, fmt.Errorf("failed to update secret %s, %w", databaseRequest.Name, err)
Expand Down Expand Up @@ -498,11 +498,13 @@ func (r *DatabaseRequestReconciler) deleteDatabase(
}
}
// record the event
r.Recorder.Event(
r.Recorder.Eventf(
databaseRequest,
databaseRequest,
v1.EventTypeNormal,
"DeletedDatabase",
fmt.Sprintf("Deleted database %s/%s", databaseRequest.Namespace, databaseRequest.Name),
fmt.Sprintf("Deleted database %s/%s", databaseRequest.Namespace, databaseRequest.Name),
)
// cleanup metrics
promDatabaseRequestReconcileStatus.DeletePartialMatch(prometheus.Labels{
Expand Down Expand Up @@ -585,7 +587,7 @@ func (r *DatabaseRequestReconciler) SetupWithManager(mgr ctrl.Manager, maxConcur
promDatabaseRequestReconcileErrorCounter,
promDatabaseRequestReconcileStatus,
)
r.Recorder = mgr.GetEventRecorderFor("DatabaseRequestReconciler")
r.Recorder = mgr.GetEventRecorder("DatabaseRequestReconciler")
return ctrl.NewControllerManagedBy(mgr).
For(&crdv1alpha1.DatabaseRequest{}).
// do only reconcile on spec changes
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/databaserequest_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/tools/events"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

Expand Down Expand Up @@ -147,7 +147,7 @@ var _ = Describe("DatabaseRequest Controller", func() {

It("should successfully reconcile the resource", func() {
By("Reconciling the created resource")
fakeRecoder := record.NewFakeRecorder(100)
fakeRecoder := events.NewFakeRecorder(100)
controllerReconciler := &DatabaseRequestReconciler{
Client: k8sClient,
Scheme: k8sClient.Scheme(),
Expand Down
12 changes: 6 additions & 6 deletions internal/controller/mongodbprovider_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/tools/events"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand Down Expand Up @@ -74,7 +74,7 @@ var (
type MongoDBProviderReconciler struct {
client.Client
Scheme *runtime.Scheme
Recorder record.EventRecorder
Recorder events.EventRecorder
MongoDBClient mongodb.MongoDBInterface
}

Expand Down Expand Up @@ -124,7 +124,7 @@ func (r *MongoDBProviderReconciler) Reconcile(ctx context.Context, req ctrl.Requ
if instance.Status.Conditions != nil && meta.IsStatusConditionTrue(instance.Status.Conditions, "Ready") {
if instance.Status.ObservedGeneration >= instance.Generation {
logger.Info("Skipping reconcile: generation has not changed")
r.Recorder.Event(instance, v1.EventTypeNormal, "ReconcileSkipped", "No updates to reconcile")
r.Recorder.Eventf(instance, instance, v1.EventTypeNormal, "ReconcileSkipped", "No updates to reconcile", "No updates to reconcile")
return ctrl.Result{}, nil
}
}
Expand Down Expand Up @@ -262,7 +262,7 @@ func (r *MongoDBProviderReconciler) Reconcile(ctx context.Context, req ctrl.Requ
return ctrl.Result{}, err
}

r.Recorder.Event(instance, v1.EventTypeNormal, "Reconciled", "MongoDBProvider reconciled")
r.Recorder.Eventf(instance, instance, v1.EventTypeNormal, "Reconciled", "MongoDBProvider reconciled", "MongoDBProvider reconciled")
promMongoDBProviderStatus.WithLabelValues(req.Name, instance.Spec.Selector).Set(1)
return ctrl.Result{}, nil
}
Expand All @@ -275,7 +275,7 @@ func (r *MongoDBProviderReconciler) handleError(
) (ctrl.Result, error) {
promMongoDBProviderReconcileErrorCounter.WithLabelValues(instance.Name, instance.Spec.Selector, promErr).Inc()
promMongoDBProviderStatus.WithLabelValues(instance.Name, instance.Spec.Selector).Set(0)
r.Recorder.Event(instance, v1.EventTypeWarning, errTypeToEventReason(promErr), err.Error())
r.Recorder.Eventf(instance, instance, v1.EventTypeWarning, errTypeToEventReason(promErr), err.Error(), err.Error())

// set the status condition
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Expand Down Expand Up @@ -308,7 +308,7 @@ func (r *MongoDBProviderReconciler) SetupWithManager(mgr ctrl.Manager) error {
promMongoDBProviderStatus,
promMongoDBProviderConnectionVersion,
)
r.Recorder = mgr.GetEventRecorderFor("mongodbprovider-controller")
r.Recorder = mgr.GetEventRecorder("mongodbprovider-controller")
return ctrl.NewControllerManagedBy(mgr).
For(&crdv1alpha1.MongoDBProvider{}).
WithEventFilter(predicate.GenerationChangedPredicate{}).
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/mongodbprovider_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/tools/events"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -104,7 +104,7 @@ var _ = Describe("MongoDBProvider Controller", func() {
})
It("should successfully reconcile the resource", func() {
By("Reconciling the created resource")
fakeRecorder := record.NewFakeRecorder(100)
fakeRecorder := events.NewFakeRecorder(100)
controllerReconciler := &MongoDBProviderReconciler{
Client: k8sClient,
Scheme: k8sClient.Scheme(),
Expand Down
12 changes: 6 additions & 6 deletions internal/controller/relationaldatabaseprovider_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/tools/events"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand Down Expand Up @@ -75,7 +75,7 @@ var (
type RelationalDatabaseProviderReconciler struct {
client.Client
Scheme *runtime.Scheme
Recorder record.EventRecorder
Recorder events.EventRecorder
RelDBClient database.RelationalDatabaseInterface
}

Expand Down Expand Up @@ -121,7 +121,7 @@ func (r *RelationalDatabaseProviderReconciler) Reconcile(ctx context.Context, re
if instance.Status.Conditions != nil && meta.IsStatusConditionTrue(instance.Status.Conditions, "Ready") {
if instance.Status.ObservedGeneration >= instance.Generation {
logger.Info("No updates to reconcile")
r.Recorder.Event(instance, v1.EventTypeNormal, "ReconcileSkipped", "No updates to reconcile")
r.Recorder.Eventf(instance, instance, v1.EventTypeNormal, "ReconcileSkipped", "No updates to reconcile", "No updates to reconcile")
return ctrl.Result{}, nil
}
}
Expand Down Expand Up @@ -279,7 +279,7 @@ func (r *RelationalDatabaseProviderReconciler) Reconcile(ctx context.Context, re
return ctrl.Result{}, err
}

r.Recorder.Event(instance, "Normal", "Reconciled", "RelationalDatabaseProvider reconciled")
r.Recorder.Eventf(instance, instance, "Normal", "Reconciled", "RelationalDatabaseProvider reconciled", "RelationalDatabaseProvider reconciled")
promRelationalDatabaseProviderStatus.WithLabelValues(instance.Spec.Type, req.Name, instance.Spec.Selector).Set(1)
return ctrl.Result{}, nil
}
Expand All @@ -294,7 +294,7 @@ func (r *RelationalDatabaseProviderReconciler) handleError(
promRelationalDatabaseProviderReconcileErrorCounter.WithLabelValues(
instance.Spec.Type, instance.Name, instance.Spec.Selector, promErr).Inc()
promRelationalDatabaseProviderStatus.WithLabelValues(instance.Spec.Type, instance.Name, instance.Spec.Selector).Set(0)
r.Recorder.Event(instance, v1.EventTypeWarning, errTypeToEventReason(promErr), err.Error())
r.Recorder.Eventf(instance, instance, v1.EventTypeWarning, errTypeToEventReason(promErr), err.Error(), err.Error())

// set the status condition to false
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Expand Down Expand Up @@ -355,7 +355,7 @@ func (r *RelationalDatabaseProviderReconciler) SetupWithManager(mgr ctrl.Manager
promRelationalDatabaseProviderStatus,
promRelationalDatabaseProviderConnectionVersion,
)
r.Recorder = mgr.GetEventRecorderFor("relationaldatabaseprovider_controller")
r.Recorder = mgr.GetEventRecorder("relationaldatabaseprovider_controller")
return ctrl.NewControllerManagedBy(mgr).
For(&crdv1alpha1.RelationalDatabaseProvider{}).
WithEventFilter(predicate.GenerationChangedPredicate{}).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/tools/events"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -113,7 +113,7 @@ var _ = Describe("RelationalDatabaseProvider Controller", func() {
})
It("should successfully reconcile the resource", func() {
By("Reconciling the created resource")
fakeRecorder := record.NewFakeRecorder(100)
fakeRecorder := events.NewFakeRecorder(100)
controllerReconciler := &RelationalDatabaseProviderReconciler{
Client: k8sClient,
Scheme: k8sClient.Scheme(),
Expand Down
Loading