-
Notifications
You must be signed in to change notification settings - Fork 72
/
cqlsh.go
60 lines (53 loc) · 1.76 KB
/
cqlsh.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package framework
import (
"context"
"github.com/k8ssandra/k8ssandra-operator/pkg/secret"
"github.com/k8ssandra/k8ssandra-operator/test/kubectl"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
)
func (f *E2eFramework) RetrieveSuperuserSecret(ctx context.Context, k8sContext, namespace, clusterName string) (*corev1.Secret, error) {
superUserSecret := &corev1.Secret{}
superUserSecretKey := ClusterKey{
NamespacedName: types.NamespacedName{
Namespace: namespace,
Name: secret.DefaultSuperuserSecretName(clusterName),
},
K8sContext: k8sContext,
}
err := f.Get(ctx, superUserSecretKey, superUserSecret)
return superUserSecret, err
}
func (f *E2eFramework) RetrieveDatabaseCredentials(ctx context.Context, k8sContext, namespace, clusterName string) (string, string, error) {
superUserSecret, err := f.RetrieveSuperuserSecret(ctx, k8sContext, namespace, clusterName)
var username, password string
if err == nil {
username = string(superUserSecret.Data["username"])
password = string(superUserSecret.Data["password"])
}
return username, password, err
}
func (f *E2eFramework) ExecuteCql(ctx context.Context, k8sContext, namespace, clusterName, pod, query string) (string, error) {
username, password, err := f.RetrieveDatabaseCredentials(ctx, k8sContext, namespace, clusterName)
if err != nil {
return "", err
}
options := kubectl.Options{Context: k8sContext, Namespace: namespace}
return kubectl.Exec(options, pod,
f.cqlshBin,
"--username",
username,
"--password",
password,
"-e",
query,
)
}
func (f *E2eFramework) ExecuteCqlNoAuth(k8sContext, namespace, pod, query string) (string, error) {
options := kubectl.Options{Context: k8sContext, Namespace: namespace}
return kubectl.Exec(options, pod,
f.cqlshBin,
"-e",
query,
)
}