Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sud82 committed May 16, 2024
1 parent b20f8b9 commit 64e1ad4
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 24 deletions.
3 changes: 2 additions & 1 deletion api/v1/aerospikecluster_validating_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,8 @@ func validateRequiredFileStorageForFeatureConf(
for _, path := range allPaths {
if !storage.isVolumePresentForAerospikePath(filepath.Dir(path)) {
return fmt.Errorf(
"feature-key-file paths or tls paths or default-password-file path are not mounted - create an entry for '%v' in 'storage.volumes'",
"feature-key-file paths or tls paths or default-password-file path "+
"are not mounted - create an entry for '%v' in 'storage.volumes'",
path,
)
}
Expand Down
29 changes: 22 additions & 7 deletions test/access_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1331,8 +1331,6 @@ var _ = Describe(
Context(
"When cluster is not deployed", func() {

ctx := goctx.Background()

clusterName := "ac-invalid"
clusterNamespacedName := getNamespacedName(
clusterName, namespace,
Expand Down Expand Up @@ -1626,8 +1624,6 @@ var _ = Describe(
)
Context(
"When cluster is deployed", func() {
ctx := goctx.Background()

It(
"SecurityEnable: should enable security in running cluster",
func() {
Expand Down Expand Up @@ -2148,6 +2144,23 @@ var _ = Describe(
)

Context("Using default-password-file", func() {
var clusterNamespacedName = getNamespacedName(
"default-password-file", namespace,
)

It("Should fail if volume is not present for default-password-file", func() {
aeroCluster := createDummyAerospikeCluster(clusterNamespacedName, 4)
racks := getDummyRackConf(1, 2)
aeroCluster.Spec.RackConfig.Racks = racks
aeroCluster.Spec.RackConfig.Namespaces = []string{"test"}
aeroCluster.Spec.AerospikeConfig.Value["security"] = map[string]interface{}{
"default-password-file": "randompath",
}

err := k8sClient.Create(ctx, aeroCluster)
Expect(err).To(HaveOccurred())
})

It("Should use default-password-file when configured", func() {
By("Creating cluster")

Expand All @@ -2163,7 +2176,7 @@ var _ = Describe(

// Get default password from secret.
secretNamespcedName := types.NamespacedName{
Name: aerospikeConfigSecret,
Name: aerospikeSecretName,
Namespace: aeroCluster.Namespace,
}
passFileName := "password.conf"
Expand All @@ -2182,12 +2195,14 @@ var _ = Describe(
}

nodes := client.GetNodeNames()
Expect(nodes).ToNot(BeNil())
if len(nodes) == 0 {
return fmt.Errorf("No nodes found")
}

pkgLog.Info("Connected to cluster", "nodes", nodes)

return nil
}, 2*time.Minute).ShouldNot(HaveOccurred())
}, 3*time.Minute).ShouldNot(HaveOccurred())
})
})
},
Expand Down
10 changes: 5 additions & 5 deletions test/cluster_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func rollingRestartClusterByEnablingTLS(
aeroCluster.Spec.OperatorClientCertSpec = &asdbv1.AerospikeOperatorClientCertSpec{
AerospikeOperatorCertSource: asdbv1.AerospikeOperatorCertSource{
SecretCertSource: &asdbv1.AerospikeSecretCertSource{
SecretName: tlsSecretName,
SecretName: aerospikeSecretName,
CaCertsFilename: "cacert.pem",
ClientCertFilename: "svc_cluster_chain.pem",
ClientKeyFilename: "svc_key.pem",
Expand Down Expand Up @@ -862,7 +862,7 @@ func createAerospikeClusterPost460(
OperatorClientCertSpec: &asdbv1.AerospikeOperatorClientCertSpec{
AerospikeOperatorCertSource: asdbv1.AerospikeOperatorCertSource{
SecretCertSource: &asdbv1.AerospikeSecretCertSource{
SecretName: tlsSecretName,
SecretName: aerospikeSecretName,
CaCertsFilename: "cacert.pem",
ClientCertFilename: "svc_cluster_chain.pem",
ClientKeyFilename: "svc_key.pem",
Expand Down Expand Up @@ -925,7 +925,7 @@ func createAerospikeClusterPost560(
OperatorClientCertSpec: &asdbv1.AerospikeOperatorClientCertSpec{
AerospikeOperatorCertSource: asdbv1.AerospikeOperatorCertSource{
SecretCertSource: &asdbv1.AerospikeSecretCertSource{
SecretName: tlsSecretName,
SecretName: aerospikeSecretName,
CaCertsFilename: "cacert.pem",
ClientCertFilename: "svc_cluster_chain.pem",
ClientKeyFilename: "svc_key.pem",
Expand Down Expand Up @@ -1312,7 +1312,7 @@ func createBasicTLSCluster(
OperatorClientCertSpec: &asdbv1.AerospikeOperatorClientCertSpec{
AerospikeOperatorCertSource: asdbv1.AerospikeOperatorCertSource{
SecretCertSource: &asdbv1.AerospikeSecretCertSource{
SecretName: tlsSecretName,
SecretName: aerospikeSecretName,
CaCertsFilename: "cacert.pem",
ClientCertFilename: "svc_cluster_chain.pem",
ClientKeyFilename: "svc_key.pem",
Expand Down Expand Up @@ -1535,7 +1535,7 @@ func getStorageVolumeForSecret() asdbv1.VolumeSpec {
Name: aerospikeConfigSecret,
Source: asdbv1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: tlsSecretName,
SecretName: aerospikeSecretName,
},
},
Aerospike: &asdbv1.AerospikeServerVolumeAttachment{
Expand Down
2 changes: 1 addition & 1 deletion test/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ func UpdateClusterTest(ctx goctx.Context) {
aeroCluster.Spec.OperatorClientCertSpec = &asdbv1.AerospikeOperatorClientCertSpec{
AerospikeOperatorCertSource: asdbv1.AerospikeOperatorCertSource{
SecretCertSource: &asdbv1.AerospikeSecretCertSource{
SecretName: tlsSecretName,
SecretName: aerospikeSecretName,
CaCertsFilename: "cacert.pem",
ClientCertFilename: "svc_cluster_chain.pem",
ClientKeyFilename: "svc_key.pem",
Expand Down
13 changes: 7 additions & 6 deletions test/dynamic_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"golang.org/x/net/context"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"

Expand All @@ -29,16 +30,15 @@ type podID struct {

const clName = "dynamic-config-test"

var clusterNamespacedName = getNamespacedName(
clName, namespace,
)

var configWithMaxDefaultVal = mapset.NewSet("info-max-ms", "flush-max-ms")

var _ = Describe(
"DynamicConfig", func() {

ctx := goctx.Background()
var clusterNamespacedName = getNamespacedName(
clName, namespace,
)

Context(
"When doing valid operations", func() {
Expand Down Expand Up @@ -571,7 +571,8 @@ var _ = Describe(
validateServerRestart(ctx, aeroCluster, podPIDMap, false)

By("Verify XDR Context configs dynamically")
err = validateXDRContextDynamically(ctx, flatServer, flatSpec, aeroCluster, dynamic)
err = validateXDRContextDynamically(clusterNamespacedName,
ctx, flatServer, flatSpec, aeroCluster, dynamic)
Expect(err).ToNot(HaveOccurred())

aeroCluster, err = getCluster(
Expand Down Expand Up @@ -832,7 +833,7 @@ func validateSecurityContextDynamically(
return updateCluster(k8sClient, ctx, aeroCluster)
}

func validateXDRContextDynamically(
func validateXDRContextDynamically(clusterNamespacedName types.NamespacedName,
ctx goctx.Context, flatServer, flatSpec *asconfig.Conf,
aeroCluster *asdbv1.AerospikeCluster, dynamic mapset.Set[string],
) error {
Expand Down
7 changes: 3 additions & 4 deletions test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package test

import (
"bytes"
"context"
goctx "context"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -45,7 +44,7 @@ var cacertSecrets map[string][]byte
const secretDir = "../config/samples/secrets" //nolint:gosec // for testing
const cacertSecretDir = "../config/samples/secrets/cacerts" //nolint:gosec // for testing

const tlsSecretName = "aerospike-secret"
const aerospikeSecretName = "aerospike-secret"
const tlsCacertSecretName = "aerospike-cacert-secret" //nolint:gosec // for testing
const authSecretName = "auth-secret"
const authSecretNameForUpdate = "auth-update"
Expand Down Expand Up @@ -192,7 +191,7 @@ func createConfigSecret(
// Create configSecret
s := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: tlsSecretName,
Name: aerospikeSecretName,
Namespace: namespace,
Labels: labels,
},
Expand Down Expand Up @@ -802,7 +801,7 @@ func getPasswordFromSecret(k8sClient client.Client,
) (string, error) {
secret := &corev1.Secret{}

err := k8sClient.Get(context.TODO(), secretNamespcedName, secret)
err := k8sClient.Get(goctx.TODO(), secretNamespcedName, secret)
if err != nil {
return "", fmt.Errorf("failed to get secret %s: %v", secretNamespcedName, err)
}
Expand Down

0 comments on commit 64e1ad4

Please sign in to comment.