Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adopting to use manage conditions from golang-commons #7

Merged
merged 1 commit into from
Apr 25, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
bin/*
Dockerfile.cross
.secret
.env

# Test binary, built with `go test -c`
*.test
Expand Down
10 changes: 6 additions & 4 deletions api/v1alpha1/account_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ func init() {
SchemeBuilder.Register(&Account{}, &AccountList{})
}

func (i *Account) GetObservedGeneration() int64 { return i.Status.ObservedGeneration }
func (i *Account) SetObservedGeneration(g int64) { i.Status.ObservedGeneration = g }
func (i *Account) GetNextReconcileTime() metav1.Time { return i.Status.NextReconcileTime }
func (i *Account) SetNextReconcileTime(time metav1.Time) { i.Status.NextReconcileTime = time }
func (i *Account) GetObservedGeneration() int64 { return i.Status.ObservedGeneration }
func (i *Account) SetObservedGeneration(g int64) { i.Status.ObservedGeneration = g }
func (i *Account) GetNextReconcileTime() metav1.Time { return i.Status.NextReconcileTime }
func (i *Account) SetNextReconcileTime(time metav1.Time) { i.Status.NextReconcileTime = time }
func (i *Account) GetConditions() []metav1.Condition { return i.Status.Conditions }
func (i *Account) SetConditions(conditions []metav1.Condition) { i.Status.Conditions = conditions }
2 changes: 1 addition & 1 deletion cmd/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func RunController(cmd *cobra.Command, args []string) { // coverage-ignore
}

accountReconciler := controller.NewAccountReconciler(log, mgr, cfg)
if err := accountReconciler.SetupWithManager(mgr, cfg); err != nil {
if err := accountReconciler.SetupWithManager(mgr, cfg, log); err != nil {
log.Fatal().Err(err).Str("controller", "Account").Msg("unable to create controller")
}

Expand Down
2 changes: 1 addition & 1 deletion config/samples/core_v1alpha1_account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ metadata:
name: new-account-debug1
namespace: default
spec:
accountRole: folder
type: folder
displayName: New Demo Account
creator: bastian.echterhoelter@sap.com
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.0
require (
github.com/onsi/ginkgo/v2 v2.14.0
github.com/onsi/gomega v1.30.0
github.com/openmfp/golang-commons v0.16.0
github.com/openmfp/golang-commons v0.21.0
github.com/rs/zerolog v1.32.0
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ github.com/onsi/ginkgo/v2 v2.14.0 h1:vSmGj2Z5YPb9JwCWT6z6ihcUvDhuXLc3sJiqd3jMKAY
github.com/onsi/ginkgo/v2 v2.14.0/go.mod h1:JkUdW7JkN0V6rFvsHcJ478egV3XH9NxpD27Hal/PhZw=
github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8=
github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/openmfp/golang-commons v0.16.0 h1:8FAS3Gw6tFOXJOlBcwDrzopppn9Tj4itnoLcXODttqQ=
github.com/openmfp/golang-commons v0.16.0/go.mod h1:7yzpBpF7KZLq4i/iVOsPwVPkVnCYiZ685PMC1AF7fZk=
github.com/openmfp/golang-commons v0.21.0 h1:WOyV4jxNZj301XarzTncuYvAcgOorUD/MUxMUrsfV5Q=
github.com/openmfp/golang-commons v0.21.0/go.mod h1:AE1DH+O57gAIKOKD6waJPAxXRo47nbDQp4V08mJ+Ux8=
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/account_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ func NewAccountReconciler(log *logger.Logger, mgr ctrl.Manager, cfg config.Confi
subs = append(subs, subroutines.NewNamespaceSubroutine(mgr.GetClient()))
}
return &AccountReconciler{
lifecycle: lifecycle.NewLifecycleManager(log, operatorName, accountReconcilerName, mgr.GetClient(), subs).WithSpreadingReconciles(),
lifecycle: lifecycle.NewLifecycleManager(log, operatorName, accountReconcilerName, mgr.GetClient(), subs).WithSpreadingReconciles().WithConditionManagement(),
}
}

func (r *AccountReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
return r.lifecycle.Reconcile(ctx, req, &corev1alpha1.Account{})
}

func (r *AccountReconciler) SetupWithManager(mgr ctrl.Manager, cfg config.Config, eventPredicates ...predicate.Predicate) error {
return r.lifecycle.SetupWithManager(mgr, cfg.MaxConcurrentReconciles, accountReconcilerName, &corev1alpha1.Account{}, cfg.DebugLabelValue, r, eventPredicates...)
func (r *AccountReconciler) SetupWithManager(mgr ctrl.Manager, cfg config.Config, log *logger.Logger, eventPredicates ...predicate.Predicate) error {
return r.lifecycle.SetupWithManager(mgr, cfg.MaxConcurrentReconciles, accountReconcilerName, &corev1alpha1.Account{}, cfg.DebugLabelValue, r, log, eventPredicates...)
}
2 changes: 1 addition & 1 deletion internal/controller/account_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (suite *AccountTestSuite) SetupSuite() {
suite.Nil(err)

accountReconciler := NewAccountReconciler(log, suite.kubernetesManager, cfg)
err = accountReconciler.SetupWithManager(suite.kubernetesManager, cfg)
err = accountReconciler.SetupWithManager(suite.kubernetesManager, cfg, log)
suite.Nil(err)

go suite.startController()
Expand Down
Loading