Skip to content
Closed
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
25 changes: 19 additions & 6 deletions backend/pkg/app/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import (
)

type Backend struct {
clock utilsclock.PassiveClock
options *BackendOptions
}

Expand Down Expand Up @@ -125,6 +126,7 @@ func (o *BackendOptions) metricsGatherer() prometheus.Gatherer {

func NewBackend(options *BackendOptions) *Backend {
return &Backend{
clock: utilsclock.RealClock{},
options: options,
}
}
Expand Down Expand Up @@ -316,79 +318,90 @@ func (b *Backend) runBackendControllersUnderLeaderElection(ctx context.Context,
billingDumpController := datadumpcontrollers.NewBillingDumpController(b.options.CosmosDBClient, activeOperationLister, backendInformers)
doNothingController := controllers.NewDoNothingExampleController(b.options.CosmosDBClient, subscriptionLister)
dispatchRequestCredentialController := operationcontrollers.NewDispatchRequestCredentialController(
utilsclock.RealClock{},
b.clock,
b.options.CosmosDBClient,
b.options.ClustersServiceClient,
activeOperationInformer,
)
dispatchRevokeCredentialsController := operationcontrollers.NewDispatchRevokeCredentialsController(
utilsclock.RealClock{},
b.clock,
b.options.CosmosDBClient,
b.options.ClustersServiceClient,
activeOperationInformer,
)
operationClusterCreateController := operationcontrollers.NewOperationClusterCreateController(
b.clock,
b.options.CosmosDBClient,
b.options.ClustersServiceClient,
http.DefaultClient,
activeOperationInformer,
backendInformers,
)
operationClusterUpdateController := operationcontrollers.NewOperationClusterUpdateController(
b.clock,
b.options.CosmosDBClient,
b.options.ClustersServiceClient,
http.DefaultClient,
activeOperationInformer,
)
operationClusterDeleteController := operationcontrollers.NewOperationClusterDeleteController(
b.clock,
b.options.CosmosDBClient,
b.options.ClustersServiceClient,
http.DefaultClient,
activeOperationInformer,
)
operationNodePoolCreateController := operationcontrollers.NewOperationNodePoolCreateController(
b.clock,
b.options.CosmosDBClient,
b.options.ClustersServiceClient,
http.DefaultClient,
activeOperationInformer,
)
operationNodePoolUpdateController := operationcontrollers.NewOperationNodePoolUpdateController(
b.clock,
b.options.CosmosDBClient,
b.options.ClustersServiceClient,
http.DefaultClient,
activeOperationInformer,
)
operationNodePoolDeleteController := operationcontrollers.NewOperationNodePoolDeleteController(
b.clock,
b.options.CosmosDBClient,
b.options.ClustersServiceClient,
http.DefaultClient,
activeOperationInformer,
)
operationExternalAuthCreateController := operationcontrollers.NewOperationExternalAuthCreateController(
b.clock,
b.options.CosmosDBClient,
b.options.ClustersServiceClient,
http.DefaultClient,
activeOperationInformer,
)
operationExternalAuthUpdateController := operationcontrollers.NewOperationExternalAuthUpdateController(
b.clock,
b.options.CosmosDBClient,
b.options.ClustersServiceClient,
http.DefaultClient,
activeOperationInformer,
)
operationExternalAuthDeleteController := operationcontrollers.NewOperationExternalAuthDeleteController(
b.clock,
b.options.CosmosDBClient,
b.options.ClustersServiceClient,
http.DefaultClient,
activeOperationInformer,
)
operationRequestCredentialController := operationcontrollers.NewOperationRequestCredentialController(
b.clock,
b.options.CosmosDBClient,
b.options.ClustersServiceClient,
http.DefaultClient,
activeOperationInformer,
)
operationRevokeCredentialsController := operationcontrollers.NewOperationRevokeCredentialsController(
b.clock,
b.options.CosmosDBClient,
b.options.ClustersServiceClient,
http.DefaultClient,
Expand All @@ -397,7 +410,7 @@ func (b *Backend) runBackendControllersUnderLeaderElection(ctx context.Context,
clusterServiceMatchingClusterController := mismatchcontrollers.NewClusterServiceClusterMatchingController(b.options.CosmosDBClient, subscriptionLister, b.options.ClustersServiceClient)
cosmosMatchingNodePoolController := mismatchcontrollers.NewCosmosNodePoolMatchingController(b.options.CosmosDBClient, b.options.ClustersServiceClient, backendInformers)
cosmosMatchingExternalAuthController := mismatchcontrollers.NewCosmosExternalAuthMatchingController(b.options.CosmosDBClient, b.options.ClustersServiceClient, backendInformers)
cosmosMatchingClusterController := mismatchcontrollers.NewCosmosClusterMatchingController(utilsclock.RealClock{}, b.options.CosmosDBClient, b.options.ClustersServiceClient, backendInformers)
cosmosMatchingClusterController := mismatchcontrollers.NewCosmosClusterMatchingController(b.clock, b.options.CosmosDBClient, b.options.ClustersServiceClient, backendInformers)
alwaysSuccessClusterValidationController := validationcontrollers.NewClusterValidationController(
validations.NewAlwaysSuccessValidation(),
activeOperationLister,
Expand All @@ -407,11 +420,11 @@ func (b *Backend) runBackendControllersUnderLeaderElection(ctx context.Context,
deleteOrphanedCosmosResourcesController := mismatchcontrollers.NewDeleteOrphanedCosmosResourcesController(b.options.CosmosDBClient, subscriptionLister)
backfillClusterUIDController := controllerutils.NewClusterWatchingController(
"BackfillClusterUID", b.options.CosmosDBClient, backendInformers, 60*time.Minute,
mismatchcontrollers.NewBackfillClusterUIDController(utilsclock.RealClock{}, b.options.CosmosDBClient, clusterLister))
orphanedBillingCleanupController := billingcontrollers.NewOrphanedBillingCleanupController(utilsclock.RealClock{}, b.options.CosmosDBClient, clusterLister, billingLister)
mismatchcontrollers.NewBackfillClusterUIDController(b.clock, b.options.CosmosDBClient, clusterLister))
orphanedBillingCleanupController := billingcontrollers.NewOrphanedBillingCleanupController(b.clock, b.options.CosmosDBClient, clusterLister, billingLister)
createBillingDocController := controllerutils.NewClusterWatchingController(
"CreateBillingDoc", b.options.CosmosDBClient, backendInformers, 60*time.Second,
billingcontrollers.NewCreateBillingDocController(utilsclock.RealClock{}, b.options.AzureLocation, b.options.CosmosDBClient, clusterLister, billingLister))
billingcontrollers.NewCreateBillingDocController(b.clock, b.options.AzureLocation, b.options.CosmosDBClient, clusterLister, billingLister))
controlPlaneActiveVersionController := upgradecontrollers.NewControlPlaneActiveVersionController(
b.options.CosmosDBClient,
activeOperationLister,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/client-go/tools/cache"
utilsclock "k8s.io/utils/clock"

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/hypershift/api/hypershift/v1beta1"
Expand All @@ -43,6 +44,7 @@ import (
)

type operationClusterCreate struct {
clock utilsclock.PassiveClock
clusterLister listers.ClusterLister
clusterManagementClusterContentLister listers.ManagementClusterContentLister
cosmosClient database.DBClient
Expand All @@ -65,6 +67,7 @@ type operationClusterCreate struct {
// any of "Succeeded", "Failed", or "Canceled". Once the operation status reaches
// a terminal value, there will be no further updates to the operation document.
func NewOperationClusterCreateController(
clock utilsclock.PassiveClock,
cosmosClient database.DBClient,
clusterServiceClient ocm.ClusterServiceClientSpec,
notificationClient *http.Client,
Expand All @@ -74,6 +77,7 @@ func NewOperationClusterCreateController(
_, clusterLister := informers.Clusters()
_, clusterManagementClusterContentLister := informers.ManagementClusterContents()
syncer := &operationClusterCreate{
clock: clock,
clusterLister: clusterLister,
clusterManagementClusterContentLister: clusterManagementClusterContentLister,
cosmosClient: cosmosClient,
Expand Down Expand Up @@ -151,7 +155,7 @@ func (c *operationClusterCreate) SynchronizeOperation(ctx context.Context, key c
}

logger.Info("updating status")
err = UpdateOperationStatus(ctx, c.cosmosClient, operation, newOperationStatus, opError, postAsyncNotificationFn(c.notificationClient))
err = UpdateOperationStatus(ctx, c.clock, c.cosmosClient, operation, newOperationStatus, opError, postAsyncNotificationFn(c.notificationClient))
if err != nil {
return utils.TrackError(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kruntime "k8s.io/apimachinery/pkg/runtime"
utilsclock "k8s.io/utils/clock"

azcorearm "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"

Expand Down Expand Up @@ -123,6 +124,7 @@ func TestOperationClusterCreate_SynchronizeOperation(t *testing.T) {
})

controller := &operationClusterCreate{
clock: utilsclock.RealClock{},
cosmosClient: mockDB,
clusterServiceClient: mockCSClient,
notificationClient: nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ type operationClusterDelete struct {
// any of "Succeeded", "Failed", or "Canceled". Once the operation status reaches
// a terminal value, there will be no further updates to the operation document.
func NewOperationClusterDeleteController(
clock utilsclock.PassiveClock,
cosmosClient database.DBClient,
clusterServiceClient ocm.ClusterServiceClientSpec,
notificationClient *http.Client,
activeOperationInformer cache.SharedIndexInformer,
) controllerutils.Controller {
syncer := &operationClusterDelete{
clock: utilsclock.RealClock{},
clock: clock,
cosmosClient: cosmosClient,
clusterServiceClient: clusterServiceClient,
notificationClient: notificationClient,
Expand Down Expand Up @@ -129,7 +130,7 @@ func (c *operationClusterDelete) SynchronizeOperation(ctx context.Context, key c
return utils.TrackError(err)
}

err = SetDeleteOperationAsCompleted(ctx, c.cosmosClient, operation, postAsyncNotificationFn(c.notificationClient))
err = SetDeleteOperationAsCompleted(ctx, c.clock, c.cosmosClient, operation, postAsyncNotificationFn(c.notificationClient))
if err != nil {
return utils.TrackError(err)
}
Expand All @@ -145,7 +146,7 @@ func (c *operationClusterDelete) SynchronizeOperation(ctx context.Context, key c
return utils.TrackError(err)
}

err = UpdateOperationStatus(ctx, c.cosmosClient, operation, newOperationStatus, newOperationError, postAsyncNotificationFn(c.notificationClient))
err = UpdateOperationStatus(ctx, c.clock, c.cosmosClient, operation, newOperationStatus, newOperationError, postAsyncNotificationFn(c.notificationClient))
if err != nil {
return utils.TrackError(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/cache"
"k8s.io/utils/clock"
utilsclock "k8s.io/utils/clock"
"k8s.io/utils/lru"

"github.com/Azure/ARO-HCP/backend/pkg/controllers/controllerutils"
Expand All @@ -40,10 +40,10 @@ import (
)

type operationClusterUpdate struct {
clock utilsclock.PassiveClock
cosmosClient database.DBClient
clusterServiceClient ocm.ClusterServiceClientSpec
notificationClient *http.Client
clock clock.PassiveClock
desiredVersionMismatchFirstSeen *lru.Cache
}

Expand All @@ -62,16 +62,17 @@ type operationClusterUpdate struct {
// any of "Succeeded", "Failed", or "Canceled". Once the operation status reaches
// a terminal value, there will be no further updates to the operation document.
func NewOperationClusterUpdateController(
clock utilsclock.PassiveClock,
cosmosClient database.DBClient,
clusterServiceClient ocm.ClusterServiceClientSpec,
notificationClient *http.Client,
activeOperationInformer cache.SharedIndexInformer,
) controllerutils.Controller {
syncer := &operationClusterUpdate{
clock: clock,
cosmosClient: cosmosClient,
clusterServiceClient: clusterServiceClient,
notificationClient: notificationClient,
clock: clock.RealClock{},
desiredVersionMismatchFirstSeen: lru.New(100000),
}

Expand Down Expand Up @@ -133,7 +134,7 @@ func (c *operationClusterUpdate) SynchronizeOperation(ctx context.Context, key c
}

logger.Info("updating status")
if err := UpdateOperationStatus(ctx, c.cosmosClient, operation, operationalState.provisioningState, persistErr, postAsyncNotificationFn(c.notificationClient)); err != nil {
if err := UpdateOperationStatus(ctx, c.clock, c.cosmosClient, operation, operationalState.provisioningState, persistErr, postAsyncNotificationFn(c.notificationClient)); err != nil {
return utils.TrackError(err)
}
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

"k8s.io/client-go/tools/cache"
utilsclock "k8s.io/utils/clock"

"github.com/Azure/ARO-HCP/backend/pkg/controllers/controllerutils"
"github.com/Azure/ARO-HCP/internal/api"
Expand All @@ -31,6 +32,7 @@ import (
)

type operationExternalAuthCreate struct {
clock utilsclock.PassiveClock
cosmosClient database.DBClient
clusterServiceClient ocm.ClusterServiceClientSpec
notificationClient *http.Client
Expand All @@ -51,12 +53,14 @@ type operationExternalAuthCreate struct {
// any of "Succeeded", "Failed", or "Canceled". Once the operation status reaches
// a terminal value, there will be no further updates to the operation document.
func NewOperationExternalAuthCreateController(
clock utilsclock.PassiveClock,
cosmosClient database.DBClient,
clusterServiceClient ocm.ClusterServiceClientSpec,
notificationClient *http.Client,
activeOperationInformer cache.SharedIndexInformer,
) controllerutils.Controller {
syncer := &operationExternalAuthCreate{
clock: clock,
cosmosClient: cosmosClient,
clusterServiceClient: clusterServiceClient,
notificationClient: notificationClient,
Expand Down Expand Up @@ -101,5 +105,5 @@ func (c *operationExternalAuthCreate) SynchronizeOperation(ctx context.Context,
return nil // no work to do
}

return pollExternalAuthStatus(ctx, c.cosmosClient, c.clusterServiceClient, operation, c.notificationClient)
return pollExternalAuthStatus(ctx, c.clock, c.cosmosClient, c.clusterServiceClient, operation, c.notificationClient)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"

utilsclock "k8s.io/utils/clock"

arohcpv1alpha1 "github.com/openshift-online/ocm-sdk-go/arohcp/v1alpha1"

"github.com/Azure/ARO-HCP/internal/api/arm"
Expand Down Expand Up @@ -97,6 +99,7 @@ func TestOperationExternalAuthCreate_SynchronizeOperation(t *testing.T) {
mockCSClient := tt.setupMock(ctrl, fixture)

controller := &operationExternalAuthCreate{
clock: utilsclock.RealClock{},
cosmosClient: mockDB,
clusterServiceClient: mockCSClient,
notificationClient: nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

"k8s.io/client-go/tools/cache"
utilsclock "k8s.io/utils/clock"

ocmerrors "github.com/openshift-online/ocm-sdk-go/errors"

Expand All @@ -34,6 +35,7 @@ import (
)

type operationExternalAuthDelete struct {
clock utilsclock.PassiveClock
cosmosClient database.DBClient
clusterServiceClient ocm.ClusterServiceClientSpec
notificationClient *http.Client
Expand All @@ -54,12 +56,14 @@ type operationExternalAuthDelete struct {
// any of "Succeeded", "Failed", or "Canceled". Once the operation status reaches
// a terminal value, there will be no further updates to the operation document.
func NewOperationExternalAuthDeleteController(
clock utilsclock.PassiveClock,
cosmosClient database.DBClient,
clusterServiceClient ocm.ClusterServiceClientSpec,
notificationClient *http.Client,
activeOperationInformer cache.SharedIndexInformer,
) controllerutils.Controller {
syncer := &operationExternalAuthDelete{
clock: clock,
cosmosClient: cosmosClient,
clusterServiceClient: clusterServiceClient,
notificationClient: notificationClient,
Expand Down Expand Up @@ -109,7 +113,7 @@ func (c *operationExternalAuthDelete) SynchronizeOperation(ctx context.Context,
if err != nil && errors.As(err, &ocmGetExternalAuthError) && ocmGetExternalAuthError.Status() == http.StatusNotFound {
logger.Info("external auth was deleted")

err = SetDeleteOperationAsCompleted(ctx, c.cosmosClient, operation, postAsyncNotificationFn(c.notificationClient))
err = SetDeleteOperationAsCompleted(ctx, c.clock, c.cosmosClient, operation, postAsyncNotificationFn(c.notificationClient))
if err != nil {
return utils.TrackError(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"

utilsclock "k8s.io/utils/clock"

arohcpv1alpha1 "github.com/openshift-online/ocm-sdk-go/arohcp/v1alpha1"
ocmerrors "github.com/openshift-online/ocm-sdk-go/errors"

Expand Down Expand Up @@ -107,6 +109,7 @@ func TestOperationExternalAuthDelete_SynchronizeOperation(t *testing.T) {
mockCSClient := tt.setupMock(ctrl, fixture)

controller := &operationExternalAuthDelete{
clock: utilsclock.RealClock{},
cosmosClient: mockDB,
clusterServiceClient: mockCSClient,
notificationClient: nil,
Expand Down
Loading
Loading