Skip to content

Commit

Permalink
Move versionStatusUpdater to mockery mocks (#2381)
Browse files Browse the repository at this point in the history
  • Loading branch information
0sewa0 authored Nov 17, 2023
1 parent d5d6555 commit 0202ee4
Show file tree
Hide file tree
Showing 6 changed files with 558 additions and 95 deletions.
3 changes: 3 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ filename: "{{.InterfaceName | snakecase}}.go"
outpkg: mocks
dir: "test/mocks/{{.InterfaceDirRelative}}"
packages:
github.com/Dynatrace/dynatrace-operator/pkg/controllers/dynakube/version:
interfaces:
StatusUpdater:
github.com/Dynatrace/dynatrace-operator/cmd/config:
interfaces:
Provider:
Expand Down
17 changes: 6 additions & 11 deletions pkg/controllers/dynakube/version/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
TmpCAPath = "/tmp/dynatrace-operator"
TmpCAName = "dynatraceCustomCA.crt"
)

type Reconciler struct {
dynakube *dynatracev1beta1.DynaKube
dtClient dtclient.Client
Expand All @@ -41,7 +36,7 @@ func NewReconciler(dynakube *dynatracev1beta1.DynaKube, apiReader client.Reader,

// Reconcile updates the version status used by the dynakube
func (reconciler *Reconciler) Reconcile(ctx context.Context) error {
updaters := []versionStatusUpdater{
updaters := []StatusUpdater{
newActiveGateUpdater(reconciler.dynakube, reconciler.apiReader, reconciler.dtClient, reconciler.registryClient),
newOneAgentUpdater(reconciler.dynakube, reconciler.apiReader, reconciler.dtClient, reconciler.registryClient),
newCodeModulesUpdater(reconciler.dynakube, reconciler.dtClient),
Expand All @@ -55,7 +50,7 @@ func (reconciler *Reconciler) Reconcile(ctx context.Context) error {
return nil
}

func (reconciler *Reconciler) updateVersionStatuses(ctx context.Context, updaters []versionStatusUpdater) error {
func (reconciler *Reconciler) updateVersionStatuses(ctx context.Context, updaters []StatusUpdater) error {
for _, updater := range updaters {
log.Info("updating version status", "updater", updater.Name())
err := reconciler.run(ctx, updater)
Expand All @@ -76,8 +71,8 @@ func (reconciler *Reconciler) updateVersionStatuses(ctx context.Context, updater
return nil
}

func (reconciler *Reconciler) needsReconcile(updaters []versionStatusUpdater) []versionStatusUpdater {
neededUpdaters := []versionStatusUpdater{}
func (reconciler *Reconciler) needsReconcile(updaters []StatusUpdater) []StatusUpdater {
neededUpdaters := []StatusUpdater{}
for _, updater := range updaters {
if reconciler.needsUpdate(updater) {
neededUpdaters = append(neededUpdaters, updater)
Expand All @@ -86,7 +81,7 @@ func (reconciler *Reconciler) needsReconcile(updaters []versionStatusUpdater) []
return neededUpdaters
}

func (reconciler *Reconciler) needsUpdate(updater versionStatusUpdater) bool {
func (reconciler *Reconciler) needsUpdate(updater StatusUpdater) bool {
if !updater.IsEnabled() {
log.Info("skipping version status update for disabled section", "updater", updater.Name())
return false
Expand All @@ -108,7 +103,7 @@ func (reconciler *Reconciler) needsUpdate(updater versionStatusUpdater) bool {
return true
}

func hasCustomFieldChanged(updater versionStatusUpdater) bool {
func hasCustomFieldChanged(updater StatusUpdater) bool {
if updater.Target().Source == status.CustomImageVersionSource {
oldImage := updater.Target().ImageID
newImage := updater.CustomImage()
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/dynakube/version/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestReconcile(t *testing.T) {
},
}, nil
}
fakeImage.ConfigFile()
_, _ = fakeImage.ConfigFile()
testImage := containerv1.Image(fakeImage)

t.Run("no update if hash provider returns error", func(t *testing.T) {
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestNeedsReconcile(t *testing.T) {
dynakube: &dynakube,
timeProvider: timeProvider,
}
updaters := []versionStatusUpdater{
updaters := []StatusUpdater{
newOneAgentUpdater(&dynakube, fake.NewClient(), nil, nil),
newActiveGateUpdater(&dynakube, fake.NewClient(), nil, nil),
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/controllers/dynakube/version/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/pkg/errors"
)

type versionStatusUpdater interface {
type StatusUpdater interface {
Name() string
IsEnabled() bool
Target() *status.VersionStatus
Expand All @@ -28,7 +28,7 @@ type versionStatusUpdater interface {
UseTenantRegistry(context.Context) error
}

func (reconciler *Reconciler) run(ctx context.Context, updater versionStatusUpdater) error {
func (reconciler *Reconciler) run(ctx context.Context, updater StatusUpdater) error {
currentSource := determineSource(updater)
var err error
defer func() {
Expand Down Expand Up @@ -76,7 +76,7 @@ func (reconciler *Reconciler) run(ctx context.Context, updater versionStatusUpda
return updater.ValidateStatus()
}

func (reconciler *Reconciler) processPublicRegistry(ctx context.Context, updater versionStatusUpdater) error {
func (reconciler *Reconciler) processPublicRegistry(ctx context.Context, updater StatusUpdater) error {
log.Info("updating version status according to public registry", "updater", updater.Name())
var publicImage *dtclient.LatestImageInfo
publicImage, err := updater.LatestImageInfo()
Expand All @@ -97,7 +97,7 @@ func (reconciler *Reconciler) processPublicRegistry(ctx context.Context, updater
return nil
}

func determineSource(updater versionStatusUpdater) status.VersionSource {
func determineSource(updater StatusUpdater) status.VersionSource {
if updater.CustomImage() != "" {
return status.CustomImageVersionSource
}
Expand Down
Loading

0 comments on commit 0202ee4

Please sign in to comment.