Skip to content

Commit

Permalink
Modify Pre/Post-Reconciliation Extensions to provide a Resolver (#3105)
Browse files Browse the repository at this point in the history
* Modify PreReconciliationChecker to use a resolver
* Modify PostReconciliationChecker to use a resolver
* Tidy imports
  • Loading branch information
theunrepentantgeek authored Jul 3, 2023
1 parent e4b65d6 commit d505950
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import (
"sigs.k8s.io/controller-runtime/pkg/conversion"

containerservice "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20230201storage"
"github.com/Azure/azure-service-operator/v2/internal/genericarmclient"
. "github.com/Azure/azure-service-operator/v2/internal/logging"

"github.com/Azure/azure-service-operator/v2/internal/genericarmclient"
"github.com/Azure/azure-service-operator/v2/internal/resolver"
"github.com/Azure/azure-service-operator/v2/internal/set"
"github.com/Azure/azure-service-operator/v2/internal/util/kubeclient"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/extensions"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/secrets"
Expand Down Expand Up @@ -142,7 +143,7 @@ func (ext *ManagedClusterExtension) PreReconcileCheck(
_ context.Context,
obj genruntime.MetaObject,
_ genruntime.MetaObject,
_ kubeclient.Client,
_ *resolver.Resolver,
_ *genericarmclient.GenericClient,
_ logr.Logger,
_ extensions.PreReconcileCheckFunc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/conversion"

containerservice "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20230201storage"

"github.com/Azure/azure-service-operator/v2/internal/genericarmclient"
"github.com/Azure/azure-service-operator/v2/internal/resolver"
"github.com/Azure/azure-service-operator/v2/internal/set"
"github.com/Azure/azure-service-operator/v2/internal/util/kubeclient"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/extensions"
)
Expand All @@ -38,7 +39,7 @@ func (ext *ManagedClustersAgentPoolExtension) PreReconcileCheck(
_ context.Context,
obj genruntime.MetaObject,
owner genruntime.MetaObject,
_ kubeclient.Client,
_ *resolver.Resolver,
_ *genericarmclient.GenericClient,
_ logr.Logger,
_ extensions.PreReconcileCheckFunc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import (
"sigs.k8s.io/controller-runtime/pkg/conversion"

postgresql "github.com/Azure/azure-service-operator/v2/api/dbforpostgresql/v1api20210601storage"
"github.com/Azure/azure-service-operator/v2/internal/genericarmclient"
. "github.com/Azure/azure-service-operator/v2/internal/logging"

"github.com/Azure/azure-service-operator/v2/internal/genericarmclient"
"github.com/Azure/azure-service-operator/v2/internal/resolver"
"github.com/Azure/azure-service-operator/v2/internal/set"
"github.com/Azure/azure-service-operator/v2/internal/util/kubeclient"
"github.com/Azure/azure-service-operator/v2/internal/util/to"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/extensions"
Expand Down Expand Up @@ -102,7 +103,7 @@ func (ext *FlexibleServerExtension) PreReconcileCheck(
_ context.Context,
obj genruntime.MetaObject,
owner genruntime.MetaObject,
_ kubeclient.Client,
_ *resolver.Resolver,
_ *genericarmclient.GenericClient,
_ logr.Logger,
_ extensions.PreReconcileCheckFunc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
"context"
"fmt"

"github.com/Azure/azure-service-operator/v2/internal/util/kubeclient"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/extensions"

"github.com/go-logr/logr"

api "github.com/Azure/azure-service-operator/v2/api/dbforpostgresql/v1api20210601"
hub "github.com/Azure/azure-service-operator/v2/api/dbforpostgresql/v1api20210601storage"

"github.com/Azure/azure-service-operator/v2/internal/genericarmclient"
"github.com/Azure/azure-service-operator/v2/internal/resolver"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/extensions"
)

var _ extensions.PreReconciliationChecker = &FlexibleServersDatabaseExtension{}
Expand All @@ -26,7 +26,7 @@ func (extension *FlexibleServersDatabaseExtension) PreReconcileCheck(
_ context.Context,
_ genruntime.MetaObject,
owner genruntime.MetaObject,
_ kubeclient.Client,
_ *resolver.Resolver,
_ *genericarmclient.GenericClient,
_ logr.Logger,
_ extensions.PreReconcileCheckFunc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"context"
"fmt"

"github.com/Azure/azure-service-operator/v2/internal/util/kubeclient"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/extensions"

"github.com/go-logr/logr"

postgresql "github.com/Azure/azure-service-operator/v2/api/dbforpostgresql/v1api20210601storage"

"github.com/Azure/azure-service-operator/v2/internal/genericarmclient"
"github.com/Azure/azure-service-operator/v2/internal/resolver"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/extensions"
)

var _ extensions.PreReconciliationChecker = &FlexibleServersFirewallRuleExtension{}
Expand All @@ -25,7 +25,7 @@ func (ext *FlexibleServersFirewallRuleExtension) PreReconcileCheck(
_ context.Context,
_ genruntime.MetaObject,
owner genruntime.MetaObject,
_ kubeclient.Client,
_ *resolver.Resolver,
_ *genericarmclient.GenericClient,
_ logr.Logger,
_ extensions.PreReconcileCheckFunc,
Expand Down
5 changes: 3 additions & 2 deletions v2/api/network/customizations/private_endpoints_extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
"sigs.k8s.io/controller-runtime/pkg/conversion"

network "github.com/Azure/azure-service-operator/v2/api/network/v1api20220701storage"

"github.com/Azure/azure-service-operator/v2/internal/genericarmclient"
"github.com/Azure/azure-service-operator/v2/internal/util/kubeclient"
"github.com/Azure/azure-service-operator/v2/internal/resolver"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/extensions"
)
Expand All @@ -24,7 +25,7 @@ func (extension *PrivateEndpointExtension) PostReconcileCheck(
_ context.Context,
obj genruntime.MetaObject,
_ genruntime.MetaObject,
_ kubeclient.Client,
_ *resolver.Resolver,
_ *genericarmclient.GenericClient,
_ logr.Logger,
_ extensions.PostReconcileCheckFunc) (extensions.PostReconcileCheckResult, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func newAzureDeploymentReconcilerInstance(
log logr.Logger,
recorder record.EventRecorder,
connection Connection,
reconciler AzureDeploymentReconciler) *azureDeploymentReconcilerInstance {

reconciler AzureDeploymentReconciler,
) *azureDeploymentReconcilerInstance {
return &azureDeploymentReconcilerInstance{
Obj: metaObj,
Log: log,
Expand Down Expand Up @@ -357,7 +357,7 @@ func (r *azureDeploymentReconcilerInstance) preReconciliationCheck(ctx context.C
}

// Run our pre-reconciliation checker
check, checkErr := checker(ctx, r.Obj, owner, r.KubeClient, r.ARMConnection.Client(), r.Log)
check, checkErr := checker(ctx, r.Obj, owner, r.ResourceResolver, r.ARMConnection.Client(), r.Log)
if checkErr != nil {
// Something went wrong running the check.
return extensions.PreReconcileCheckResult{}, checkErr
Expand Down Expand Up @@ -487,7 +487,7 @@ func (r *azureDeploymentReconcilerInstance) postReconciliationCheck(ctx context.
}

// Run our post-reconciliation checker
check, checkErr := checker(ctx, r.Obj, owner, r.KubeClient, r.ARMConnection.Client(), r.Log)
check, checkErr := checker(ctx, r.Obj, owner, r.ResourceResolver, r.ARMConnection.Client(), r.Log)
if checkErr != nil {
// Something went wrong running the check.
return extensions.PostReconcileCheckResult{}, checkErr
Expand Down
12 changes: 6 additions & 6 deletions v2/pkg/genruntime/extensions/postreconciliation_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ package extensions

import (
"context"
"github.com/Azure/azure-service-operator/v2/internal/resolver"

"github.com/go-logr/logr"
"github.com/pkg/errors"

"github.com/Azure/azure-service-operator/v2/internal/genericarmclient"
. "github.com/Azure/azure-service-operator/v2/internal/logging"
"github.com/Azure/azure-service-operator/v2/internal/util/kubeclient"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/conditions"
)
Expand All @@ -35,7 +35,7 @@ type PostReconciliationChecker interface {
ctx context.Context,
obj genruntime.MetaObject,
owner genruntime.MetaObject,
kubeClient kubeclient.Client,
resourceResolver *resolver.Resolver,
armClient *genericarmclient.GenericClient,
log logr.Logger,
next PostReconcileCheckFunc,
Expand All @@ -46,7 +46,7 @@ type PostReconcileCheckFunc func(
ctx context.Context,
obj genruntime.MetaObject,
owner genruntime.MetaObject,
kubeClient kubeclient.Client,
resourceResolver *resolver.Resolver,
armClient *genericarmclient.GenericClient,
log logr.Logger,
) (PostReconcileCheckResult, error)
Expand Down Expand Up @@ -123,13 +123,13 @@ func CreatePostReconciliationChecker(
ctx context.Context,
obj genruntime.MetaObject,
owner genruntime.MetaObject,
kubeClient kubeclient.Client,
resourceResolver *resolver.Resolver,
armClient *genericarmclient.GenericClient,
log logr.Logger,
) (PostReconcileCheckResult, error) {
log.V(Status).Info("Extension post-reconcile check running")

result, err := impl.PostReconcileCheck(ctx, obj, owner, kubeClient, armClient, log, alwaysSucceed)
result, err := impl.PostReconcileCheck(ctx, obj, owner, resourceResolver, armClient, log, alwaysSucceed)
if err != nil {
log.V(Status).Info(
"Extension post-reconcile check failed",
Expand All @@ -152,7 +152,7 @@ func alwaysSucceed(
_ context.Context,
_ genruntime.MetaObject,
_ genruntime.MetaObject,
_ kubeclient.Client,
_ *resolver.Resolver,
_ *genericarmclient.GenericClient,
_ logr.Logger,
) (PostReconcileCheckResult, error) {
Expand Down
12 changes: 6 additions & 6 deletions v2/pkg/genruntime/extensions/prereconciliation_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"context"
"github.com/Azure/azure-service-operator/v2/internal/genericarmclient"
. "github.com/Azure/azure-service-operator/v2/internal/logging"
"github.com/Azure/azure-service-operator/v2/internal/util/kubeclient"
"github.com/Azure/azure-service-operator/v2/internal/resolver"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/conditions"
"github.com/go-logr/logr"
Expand All @@ -33,7 +33,7 @@ type PreReconciliationChecker interface {
ctx context.Context,
obj genruntime.MetaObject,
owner genruntime.MetaObject,
kubeClient kubeclient.Client,
resourceResolver *resolver.Resolver,
armClient *genericarmclient.GenericClient,
log logr.Logger,
next PreReconcileCheckFunc,
Expand All @@ -44,7 +44,7 @@ type PreReconcileCheckFunc func(
ctx context.Context,
obj genruntime.MetaObject,
owner genruntime.MetaObject,
kubeClient kubeclient.Client,
resourceResolver *resolver.Resolver,
armClient *genericarmclient.GenericClient,
log logr.Logger,
) (PreReconcileCheckResult, error)
Expand Down Expand Up @@ -132,13 +132,13 @@ func CreatePreReconciliationChecker(
ctx context.Context,
obj genruntime.MetaObject,
owner genruntime.MetaObject,
kubeClient kubeclient.Client,
resourceResolver *resolver.Resolver,
armClient *genericarmclient.GenericClient,
log logr.Logger,
) (PreReconcileCheckResult, error) {
log.V(Status).Info("Extension pre-reconcile check running")

result, err := impl.PreReconcileCheck(ctx, obj, owner, kubeClient, armClient, log, alwaysReconcile)
result, err := impl.PreReconcileCheck(ctx, obj, owner, resourceResolver, armClient, log, alwaysReconcile)
if err != nil {
log.V(Status).Info(
"Extension pre-reconcile check failed",
Expand All @@ -164,7 +164,7 @@ func alwaysReconcile(
_ context.Context,
_ genruntime.MetaObject,
_ genruntime.MetaObject,
_ kubeclient.Client,
_ *resolver.Resolver,
_ *genericarmclient.GenericClient,
_ logr.Logger,
) (PreReconcileCheckResult, error) {
Expand Down

0 comments on commit d505950

Please sign in to comment.