Skip to content

Commit

Permalink
Merge pull request #283 from hasheddan/poll-interval
Browse files Browse the repository at this point in the history
  • Loading branch information
hasheddan authored Aug 19, 2021
2 parents 56d101f + 9067597 commit faab5b5
Show file tree
Hide file tree
Showing 18 changed files with 128 additions and 78 deletions.
9 changes: 5 additions & 4 deletions cmd/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ func main() {
var (
app = kingpin.New(filepath.Base(os.Args[0]), "Azure support for Crossplane.").DefaultEnvars()
debug = app.Flag("debug", "Run with debug logging.").Short('d').Bool()
syncPeriod = app.Flag("sync", "Controller manager sync period duration such as 300ms, 1.5h or 2h45m").Short('s').Default("1h").Duration()
syncInterval = app.Flag("sync", "Sync interval controls how often all resources will be double checked for drift.").Short('s').Default("1h").Duration()
pollInterval = app.Flag("poll", "Poll interval controls how often an individual resource should be checked for drift.").Default("1m").Duration()
leaderElection = app.Flag("leader-election", "Use leader election for the conroller manager.").Short('l').Default("false").OverrideDefaultFromEnvar("LEADER_ELECTION").Bool()
)
kingpin.MustParse(app.Parse(os.Args[1:]))
Expand All @@ -49,20 +50,20 @@ func main() {
ctrl.SetLogger(zl)
}

log.Debug("Starting", "sync-period", syncPeriod.String())
log.Debug("Starting", "sync-period", syncInterval.String())

cfg, err := ctrl.GetConfig()
kingpin.FatalIfError(err, "Cannot get API server rest config")

mgr, err := ctrl.NewManager(cfg, ctrl.Options{
LeaderElection: *leaderElection,
LeaderElectionID: "crossplane-leader-election-provider-azure",
SyncPeriod: syncPeriod,
SyncPeriod: syncInterval,
})
kingpin.FatalIfError(err, "Cannot create controller manager")

kingpin.FatalIfError(apis.AddToScheme(mgr.GetScheme()), "Cannot add Azure APIs to scheme")
kingpin.FatalIfError(controller.Setup(mgr, log, ratelimiter.NewDefaultProviderRateLimiter(ratelimiter.DefaultProviderRPS)), "Cannot setup Azure controllers")
kingpin.FatalIfError(controller.Setup(mgr, log, ratelimiter.NewDefaultProviderRateLimiter(ratelimiter.DefaultProviderRPS), *pollInterval), "Cannot setup Azure controllers")
kingpin.FatalIfError(mgr.Start(ctrl.SetupSignalHandler()), "Cannot start controller manager")

}
11 changes: 6 additions & 5 deletions pkg/controller/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package controller

import (
"time"

"k8s.io/client-go/util/workqueue"
ctrl "sigs.k8s.io/controller-runtime"

Expand All @@ -40,9 +42,8 @@ import (
)

// Setup Azure controllers.
func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
for _, setup := range []func(ctrl.Manager, logging.Logger, workqueue.RateLimiter) error{
config.Setup,
func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, poll time.Duration) error {
for _, setup := range []func(ctrl.Manager, logging.Logger, workqueue.RateLimiter, time.Duration) error{
cache.SetupRedis,
compute.SetupAKSCluster,
mysqlserver.Setup,
Expand All @@ -58,9 +59,9 @@ func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
account.Setup,
container.Setup,
} {
if err := setup(mgr, l, rl); err != nil {
if err := setup(mgr, l, rl, poll); err != nil {
return err
}
}
return nil
return config.Setup(mgr, l, rl)
}
4 changes: 3 additions & 1 deletion pkg/controller/cache/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cache
import (
"context"
"strconv"
"time"

"github.com/Azure/azure-sdk-for-go/profiles/latest/redis/mgmt/redis"
"github.com/Azure/azure-sdk-for-go/profiles/latest/redis/mgmt/redis/redisapi"
Expand Down Expand Up @@ -54,7 +55,7 @@ const (
)

// SetupRedis adds a controller that reconciles Redis resources.
func SetupRedis(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
func SetupRedis(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, poll time.Duration) error {
name := managed.ControllerName(v1beta1.RedisGroupKind)

return ctrl.NewControllerManagedBy(mgr).
Expand All @@ -67,6 +68,7 @@ func SetupRedis(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) er
resource.ManagedKind(v1beta1.RedisGroupVersionKind),
managed.WithExternalConnecter(&connector{kube: mgr.GetClient()}),
managed.WithReferenceResolver(managed.NewAPISimpleReferenceResolver(mgr.GetClient())),
managed.WithPollInterval(poll),
managed.WithLogger(l.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name)))))
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/compute/managed.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package compute

import (
"context"
"time"

"github.com/Azure/go-autorest/autorest/to"
"github.com/pkg/errors"
Expand Down Expand Up @@ -52,7 +53,7 @@ const (
)

// SetupAKSCluster adds a controller that reconciles AKSClusters.
func SetupAKSCluster(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
func SetupAKSCluster(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, poll time.Duration) error {
name := managed.ControllerName(v1alpha3.AKSClusterGroupKind)

return ctrl.NewControllerManagedBy(mgr).
Expand All @@ -65,6 +66,7 @@ func SetupAKSCluster(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimite
resource.ManagedKind(v1alpha3.AKSClusterGroupVersionKind),
managed.WithExternalConnecter(&connecter{client: mgr.GetClient()}),
managed.WithReferenceResolver(managed.NewAPISimpleReferenceResolver(mgr.GetClient())),
managed.WithPollInterval(poll),
managed.WithLogger(l.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name)))))
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/database/cosmosdb/managed.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cosmosdb
import (
"context"
"net/http"
"time"

"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2015-04-08/documentdb"
"github.com/pkg/errors"
Expand Down Expand Up @@ -49,7 +50,7 @@ const (
)

// Setup adds a controller that reconciles NoSQLAccount.
func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, poll time.Duration) error {
name := managed.ControllerName(v1alpha3.CosmosDBAccountGroupKind)

return ctrl.NewControllerManagedBy(mgr).
Expand All @@ -63,6 +64,7 @@ func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
managed.WithConnectionPublishers(),
managed.WithExternalConnecter(&connecter{kube: mgr.GetClient()}),
managed.WithReferenceResolver(managed.NewAPISimpleReferenceResolver(mgr.GetClient())),
managed.WithPollInterval(poll),
managed.WithLogger(l.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name)))))
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/database/mysqlserver/managed.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package mysqlserver
import (
"context"
"fmt"
"time"

"github.com/Azure/azure-sdk-for-go/services/mysql/mgmt/2017-12-01/mysql"
"k8s.io/client-go/util/workqueue"
Expand Down Expand Up @@ -55,7 +56,7 @@ const (
)

// Setup adds a controller that reconciles MySQLServers.
func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, poll time.Duration) error {
name := managed.ControllerName(v1beta1.MySQLServerGroupKind)

return ctrl.NewControllerManagedBy(mgr).
Expand All @@ -68,6 +69,7 @@ func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
resource.ManagedKind(v1beta1.MySQLServerGroupVersionKind),
managed.WithExternalConnecter(&connecter{client: mgr.GetClient()}),
managed.WithReferenceResolver(managed.NewAPISimpleReferenceResolver(mgr.GetClient())),
managed.WithPollInterval(poll),
managed.WithLogger(l.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name)))))
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/database/mysqlserverfirewallrule/managed.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package mysqlserverfirewallrule

import (
"context"
"time"

"github.com/Azure/azure-sdk-for-go/services/mysql/mgmt/2017-12-01/mysql"
"github.com/Azure/azure-sdk-for-go/services/mysql/mgmt/2017-12-01/mysql/mysqlapi"
Expand Down Expand Up @@ -50,7 +51,7 @@ const (
)

// Setup adds a controller that reconciles MySQLServerFirewallRules.
func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, poll time.Duration) error {
name := managed.ControllerName(v1alpha3.MySQLServerFirewallRuleGroupKind)

return ctrl.NewControllerManagedBy(mgr).
Expand All @@ -64,6 +65,7 @@ func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
managed.WithConnectionPublishers(),
managed.WithExternalConnecter(&connecter{client: mgr.GetClient()}),
managed.WithReferenceResolver(managed.NewAPISimpleReferenceResolver(mgr.GetClient())),
managed.WithPollInterval(poll),
managed.WithLogger(l.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name)))))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package mysqlservervirtualnetworkrule

import (
"context"
"time"

"github.com/Azure/azure-sdk-for-go/services/mysql/mgmt/2017-12-01/mysql"
"github.com/Azure/azure-sdk-for-go/services/mysql/mgmt/2017-12-01/mysql/mysqlapi"
Expand Down Expand Up @@ -50,7 +51,7 @@ const (
)

// Setup adds a controller that reconciles MySQLServerVirtualNetworkRules.
func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, poll time.Duration) error {
name := managed.ControllerName(v1alpha3.MySQLServerVirtualNetworkRuleGroupKind)

return ctrl.NewControllerManagedBy(mgr).
Expand All @@ -64,6 +65,7 @@ func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
managed.WithConnectionPublishers(),
managed.WithExternalConnecter(&connecter{client: mgr.GetClient()}),
managed.WithReferenceResolver(managed.NewAPISimpleReferenceResolver(mgr.GetClient())),
managed.WithPollInterval(poll),
managed.WithLogger(l.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name)))))
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/database/postgresqlserver/managed.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package postgresqlserver
import (
"context"
"fmt"
"time"

"github.com/Azure/azure-sdk-for-go/services/postgresql/mgmt/2017-12-01/postgresql"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -58,7 +59,7 @@ const (
)

// Setup adds a controller that reconciles PostgreSQLInstances.
func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, poll time.Duration) error {
name := managed.ControllerName(v1beta1.PostgreSQLServerGroupKind)

return ctrl.NewControllerManagedBy(mgr).
Expand All @@ -71,6 +72,7 @@ func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
resource.ManagedKind(v1beta1.PostgreSQLServerGroupVersionKind),
managed.WithExternalConnecter(&connecter{client: mgr.GetClient()}),
managed.WithReferenceResolver(managed.NewAPISimpleReferenceResolver(mgr.GetClient())),
managed.WithPollInterval(poll),
managed.WithLogger(l.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name)))))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package postgresqlserverfirewallrule

import (
"context"
"time"

"github.com/Azure/azure-sdk-for-go/services/postgresql/mgmt/2017-12-01/postgresql"
"github.com/Azure/azure-sdk-for-go/services/postgresql/mgmt/2017-12-01/postgresql/postgresqlapi"
Expand Down Expand Up @@ -50,7 +51,7 @@ const (
)

// Setup adds a controller that reconciles PostgreSQLServerFirewallRules.
func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, poll time.Duration) error {
name := managed.ControllerName(v1alpha3.PostgreSQLServerFirewallRuleGroupKind)

return ctrl.NewControllerManagedBy(mgr).
Expand All @@ -64,6 +65,7 @@ func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
managed.WithConnectionPublishers(),
managed.WithExternalConnecter(&connecter{client: mgr.GetClient()}),
managed.WithReferenceResolver(managed.NewAPISimpleReferenceResolver(mgr.GetClient())),
managed.WithPollInterval(poll),
managed.WithLogger(l.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name)))))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package postgresqlservervirtualnetworkrule

import (
"context"
"time"

"github.com/Azure/azure-sdk-for-go/services/postgresql/mgmt/2017-12-01/postgresql/postgresqlapi"
"k8s.io/client-go/util/workqueue"
Expand Down Expand Up @@ -52,7 +53,7 @@ const (
)

// Setup adds a controller that reconciles PostgreSQLServerVirtualNetworkRules.
func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, poll time.Duration) error {
name := managed.ControllerName(v1alpha3.PostgreSQLServerVirtualNetworkRuleGroupKind)

return ctrl.NewControllerManagedBy(mgr).
Expand All @@ -66,6 +67,7 @@ func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
managed.WithConnectionPublishers(),
managed.WithExternalConnecter(&connecter{client: mgr.GetClient()}),
managed.WithReferenceResolver(managed.NewAPISimpleReferenceResolver(mgr.GetClient())),
managed.WithPollInterval(poll),
managed.WithLogger(l.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name)))))
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/network/subnet/managed.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package subnet

import (
"context"
"time"

azurenetwork "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network/networkapi"
Expand Down Expand Up @@ -50,7 +51,7 @@ const (
)

// Setup adds a controller that reconciles Subnets.
func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, poll time.Duration) error {
name := managed.ControllerName(v1alpha3.SubnetGroupKind)

return ctrl.NewControllerManagedBy(mgr).
Expand All @@ -64,6 +65,7 @@ func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
managed.WithConnectionPublishers(),
managed.WithExternalConnecter(&connecter{client: mgr.GetClient()}),
managed.WithReferenceResolver(managed.NewAPISimpleReferenceResolver(mgr.GetClient())),
managed.WithPollInterval(poll),
managed.WithLogger(l.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name)))))
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/network/virtualnetwork/managed.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package virtualnetwork

import (
"context"
"time"

azurenetwork "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network/networkapi"
Expand Down Expand Up @@ -50,7 +51,7 @@ const (
)

// Setup adds a controller that reconciles VirtualNetworks.
func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, poll time.Duration) error {
name := managed.ControllerName(v1alpha3.VirtualNetworkGroupKind)

return ctrl.NewControllerManagedBy(mgr).
Expand All @@ -64,6 +65,7 @@ func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
managed.WithConnectionPublishers(),
managed.WithExternalConnecter(&connecter{client: mgr.GetClient()}),
managed.WithReferenceResolver(managed.NewAPISimpleReferenceResolver(mgr.GetClient())),
managed.WithPollInterval(poll),
managed.WithLogger(l.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name)))))
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/resourcegroup/resourcegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package resourcegroup
import (
"context"
"net/http"
"time"

"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-05-01/resources"
"k8s.io/client-go/util/workqueue"
Expand Down Expand Up @@ -53,7 +54,7 @@ const (
)

// Setup adds a controller that reconciles ResourceGroups.
func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, poll time.Duration) error {
name := managed.ControllerName(v1alpha3.ResourceGroupGroupKind)

return ctrl.NewControllerManagedBy(mgr).
Expand All @@ -66,6 +67,7 @@ func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
resource.ManagedKind(v1alpha3.ResourceGroupGroupVersionKind),
managed.WithConnectionPublishers(),
managed.WithExternalConnecter(&connecter{kube: mgr.GetClient()}),
managed.WithPollInterval(poll),
managed.WithLogger(l.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name)))))
}
Expand Down
Loading

0 comments on commit faab5b5

Please sign in to comment.