Skip to content

Commit

Permalink
new API to allow services to generate MariaDBAccount
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzeek committed Feb 8, 2024
1 parent 4447f24 commit 5cf9420
Show file tree
Hide file tree
Showing 5 changed files with 330 additions and 56 deletions.
28 changes: 28 additions & 0 deletions api/test/helpers/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package helpers

import (
"context"
"fmt"
"time"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -216,3 +217,30 @@ func (tc *TestHelper) SimulateMariaDBAccountCompleted(name types.NamespacedName)

tc.Logger.Info("Simulated DB Account completed", "on", name)
}

// CreateMariaDBAccount creates and persists a MariaDBAccount resource and
// associated Secret in the Kubernetes cluster
func (tc *TestHelper) CreateMariaDBAccount(name types.NamespacedName) (*mariadbv1.MariaDBAccount, *corev1.Secret) {
secret := tc.CreateSecret(
types.NamespacedName{Namespace: name.Namespace, Name: fmt.Sprintf("%s-db-secret", name.Name)},
map[string][]byte{
"DatabasePassword": []byte(fmt.Sprintf("%s123", name.Name)),
},
)

instance := &mariadbv1.MariaDBAccount{
ObjectMeta: metav1.ObjectMeta{
Name: name.Name,
Namespace: name.Namespace,
},
Spec: mariadbv1.MariaDBAccountSpec{
UserName: fmt.Sprintf("%s_account", name.Name),
Secret: fmt.Sprintf("%s-db-secret", name.Name),
},
}
gomega.Eventually(func(g gomega.Gomega) {
g.Expect(tc.K8sClient.Create(tc.Ctx, instance)).Should(gomega.Succeed())
}, tc.Timeout, tc.Interval).Should(gomega.Succeed())

return instance, secret
}
Loading

0 comments on commit 5cf9420

Please sign in to comment.