Skip to content

Commit

Permalink
chore: use v2 client with context support
Browse files Browse the repository at this point in the history
  • Loading branch information
byashimov committed Sep 14, 2023
1 parent db26b18 commit 3ed02c6
Show file tree
Hide file tree
Showing 71 changed files with 357 additions and 344 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Make `projectVpcId` and `projectVPCRef` mutable
- Fix panic on `nil` user config conversion
- Use aiven-go-client with context support

## v0.13.0 - 2023-08-18

Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ boilerplate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto,
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

.PHONY: generate
generate: boilerplate userconfigs manifests docs charts
generate: boilerplate userconfigs imports manifests docs charts

.PHONY: fmt
fmt: ## Run go fmt against code.
Expand Down Expand Up @@ -340,3 +340,8 @@ endif
--set resources.requests.memory=0 \
--set webhooks.enabled=${WEBHOOKS_ENABLED} \
aiven-operator charts/aiven-operator

# On MACOS requires gnu-sed. Run `brew info gnu-sed` and follow instructions to replace default sed.
imports:
find . -type f -name '*.go' -exec sed -zi 's/"\n\+\t"/"\n"/g' {} +
goimports -local "github.com/aiven/aiven-operator" -w .

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions api/v1alpha1/userconfig/service/pg/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions controllers/basic_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"time"

"github.com/aiven/aiven-go-client"
"github.com/aiven/aiven-go-client/v2"
"github.com/go-logr/logr"
"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"
Expand Down Expand Up @@ -45,20 +45,20 @@ type (
// of the Aiven services lifecycle.
Handlers interface {
// create or updates an instance on the Aiven side.
createOrUpdate(*aiven.Client, client.Object, []client.Object) error
createOrUpdate(ctx context.Context, avn *aiven.Client, obj client.Object, refs []client.Object) error

// delete removes an instance on Aiven side.
// If an object is already deleted and cannot be found, it should not be an error. For other deletion
// errors, return an error.
delete(*aiven.Client, client.Object) (bool, error)
delete(ctx context.Context, avn *aiven.Client, obj client.Object) (bool, error)

// get retrieve an object and a secret (for example, connection credentials) that is generated on the
// fly based on data from Aiven API. When not applicable to service, it should return nil.
get(*aiven.Client, client.Object) (*corev1.Secret, error)
get(ctx context.Context, avn *aiven.Client, obj client.Object) (*corev1.Secret, error)

// checkPreconditions check whether all preconditions for creating (or updating) the resource are in place.
// For example, it is applicable when a service needs to be running before this resource can be created.
checkPreconditions(*aiven.Client, client.Object) (bool, error)
checkPreconditions(ctx context.Context, avn *aiven.Client, obj client.Object) (bool, error)
}

aivenManagedObject interface {
Expand Down Expand Up @@ -212,7 +212,7 @@ func (i instanceReconcilerHelper) reconcileInstance(ctx context.Context, o clien

if !isAlreadyProcessed(o) {
i.rec.Event(o, corev1.EventTypeNormal, eventCreateOrUpdatedAtAiven, "about to create instance at aiven")
if err := i.createOrUpdateInstance(o, refs); err != nil {
if err := i.createOrUpdateInstance(ctx, o, refs); err != nil {
i.rec.Event(o, corev1.EventTypeWarning, eventUnableToCreateOrUpdateAtAiven, err.Error())
return ctrl.Result{}, fmt.Errorf("unable to create or update instance at aiven: %w", err)
}
Expand Down Expand Up @@ -262,7 +262,7 @@ func (i instanceReconcilerHelper) checkPreconditions(ctx context.Context, o clie
i.log.Info("all references are good")
}

check, err := i.h.checkPreconditions(i.avn, o)
check, err := i.h.checkPreconditions(ctx, i.avn, o)
if err != nil {
i.rec.Event(o, corev1.EventTypeWarning, eventUnableToWaitForPreconditions, err.Error())
return false, fmt.Errorf("unable to wait for preconditions: %w", err)
Expand Down Expand Up @@ -317,7 +317,7 @@ func (i instanceReconcilerHelper) getObjectRefs(ctx context.Context, o client.Ob
func (i instanceReconcilerHelper) finalize(ctx context.Context, o client.Object) (ctrl.Result, error) {
i.rec.Event(o, corev1.EventTypeNormal, eventTryingToDeleteAtAiven, "trying to delete instance at aiven")

finalised, err := i.h.delete(i.avn, o)
finalised, err := i.h.delete(ctx, i.avn, o)

// There are dependencies on Aiven side, resets error, so it goes for requeue
// Handlers does not have logger, it goes here
Expand Down Expand Up @@ -376,13 +376,13 @@ func (i instanceReconcilerHelper) isInvalidTokenError(err error) bool {
return strings.Contains(msg, "Invalid token") || strings.Contains(msg, "Missing (expired) db token")
}

func (i instanceReconcilerHelper) createOrUpdateInstance(o client.Object, refs []client.Object) error {
func (i instanceReconcilerHelper) createOrUpdateInstance(ctx context.Context, o client.Object, refs []client.Object) error {
i.log.Info("generation wasn't processed, creation or updating instance on aiven side")
a := o.GetAnnotations()
delete(a, processedGenerationAnnotation)
delete(a, instanceIsRunningAnnotation)

if err := i.h.createOrUpdate(i.avn, o, refs); err != nil {
if err := i.h.createOrUpdate(ctx, i.avn, o, refs); err != nil {
return fmt.Errorf("unable to create or update aiven instance: %w", err)
}

Expand Down Expand Up @@ -415,7 +415,7 @@ func (i instanceReconcilerHelper) updateInstanceStateAndSecretUntilRunning(ctx c
err = err.(*multierror.Error).ErrorOrNil()
}()

serviceSecret, err := i.h.get(i.avn, o)
serviceSecret, err := i.h.get(ctx, i.avn, o)
if err != nil {
return false, err
} else if serviceSecret != nil {
Expand Down
4 changes: 2 additions & 2 deletions controllers/cassandra_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"strings"

"github.com/aiven/aiven-go-client"
"github.com/aiven/aiven-go-client/v2"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -66,7 +66,7 @@ func (a *cassandraAdapter) getUserConfig() any {
return &a.Spec.UserConfig
}

func (a *cassandraAdapter) newSecret(s *aiven.Service) (*corev1.Secret, error) {
func (a *cassandraAdapter) newSecret(ctx context.Context, s *aiven.Service) (*corev1.Secret, error) {
stringData := map[string]string{
"HOST": s.URIParams["host"],
"PORT": s.URIParams["port"],
Expand Down
4 changes: 2 additions & 2 deletions controllers/clickhouse_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"context"
"fmt"

"github.com/aiven/aiven-go-client"
"github.com/aiven/aiven-go-client/v2"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -65,7 +65,7 @@ func (a *clickhouseAdapter) getUserConfig() any {
return &a.Spec.UserConfig
}

func (a *clickhouseAdapter) newSecret(s *aiven.Service) (*corev1.Secret, error) {
func (a *clickhouseAdapter) newSecret(ctx context.Context, s *aiven.Service) (*corev1.Secret, error) {
prefix := getSecretPrefix(a)
stringData := map[string]string{
prefix + "HOST": s.URIParams["host"],
Expand Down
Loading

0 comments on commit 3ed02c6

Please sign in to comment.