Skip to content

Commit

Permalink
Merge pull request #184 from zzzeek/integrate_oo_accounts
Browse files Browse the repository at this point in the history
add functions to support downstream generation of MariaDBAccounts by operators
  • Loading branch information
openshift-merge-bot[bot] authored Mar 3, 2024
2 parents 76fef73 + e4eda38 commit 438dde8
Show file tree
Hide file tree
Showing 11 changed files with 1,117 additions and 146 deletions.
34 changes: 34 additions & 0 deletions api/test/helpers/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ package helpers

import (
"context"
"fmt"
"strings"
"time"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -266,6 +268,38 @@ func (tc *TestHelper) CreateMariaDBAccount(namespace string, acctName string, sp
return name
}

// CreateMariaDBAccountAndSecret creates a new MariaDBAccount and Secret with the specified namespace in the Kubernetes cluster.
func (tc *TestHelper) CreateMariaDBAccountAndSecret(name types.NamespacedName, spec mariadbv1.MariaDBAccountSpec) (*mariadbv1.MariaDBAccount, *corev1.Secret) {
secretName := fmt.Sprintf("%s-db-secret", name.Name)
secret := tc.CreateSecret(
types.NamespacedName{Namespace: name.Namespace, Name: secretName},
map[string][]byte{
"DatabasePassword": []byte(fmt.Sprintf("%s123", name.Name)),
},
)

if spec.UserName == "" {
spec.UserName = fmt.Sprintf("%s_account", strings.Replace(name.Name, "-", "_", -1))
}
spec.Secret = secretName

instance := &mariadbv1.MariaDBAccount{
ObjectMeta: metav1.ObjectMeta{
Name: name.Name,
Namespace: name.Namespace,
},
Spec: spec,
}

gomega.Eventually(func(g gomega.Gomega) {
g.Expect(tc.K8sClient.Create(tc.Ctx, instance)).Should(gomega.Succeed())
}, tc.Timeout, tc.Interval).Should(gomega.Succeed())

tc.Logger.Info(fmt.Sprintf("Created MariaDBAccount %s, username %s, secret %s", name.Name, instance.Spec.UserName, instance.Spec.Secret))

return instance, secret
}

// GetMariaDBAccount waits for and retrieves a MariaDBAccount resource from the Kubernetes cluster
func (tc *TestHelper) GetMariaDBAccount(name types.NamespacedName) *mariadbv1.MariaDBAccount {
instance := &mariadbv1.MariaDBAccount{}
Expand Down
Loading

0 comments on commit 438dde8

Please sign in to comment.