Skip to content

Commit a6259c7

Browse files
Fix: e2e Tests
1 parent 8fa65d7 commit a6259c7

File tree

5 files changed

+83
-32
lines changed

5 files changed

+83
-32
lines changed

cockroachdb/templates/crdb.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,5 @@ spec:
7070
{{- if .Values.operator.service.ports.http.port }}
7171
hTTPPort: {{ .Values.operator.service.ports.http.port }}
7272
{{- end }}
73-
# All properties below are solely to pass validation. They aren't used by the
74-
# betaclusterctrl controller so the values don't matter so long as they're
75-
# valid.
7673
dataStore: {}
7774
{{- end }}

cockroachdb/values.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ iap:
713713
# clientSecret:
714714

715715
# Set the GODEBUG env var for the Go runtime. By default, disable Transparent Huge Pages,
716-
# which cause memory inefficiency for CRDB.
716+
# which cause memory inefficiency for CockroachDB.
717717
godebug:
718718
disablethp: "1"
719719

@@ -730,11 +730,11 @@ operator:
730730
nameOverride: ""
731731
fullnameOverride: ""
732732

733-
# A map of CRDB cluster settings.
733+
# A map of CockroachDB cluster settings.
734734
# See https://www.cockroachlabs.com/docs/stable/cluster-settings.html
735735
clusterSettings: ~
736736

737-
# Regions controls the number of CRDB nodes that are deployed per region.
737+
# Regions controls the number of CockroachDB nodes that are deployed per region.
738738
# regions: ~
739739
# - code: us-central1
740740
# nodes: 3
@@ -759,7 +759,7 @@ operator:
759759
# cpu: 100m
760760
# memory: 128Mi
761761

762-
# dataStore specifies the disk configuration for the CRDB Node.
762+
# dataStore specifies the disk configuration for the CockroachDB Node.
763763
dataStore:
764764
volumeClaimTemplate:
765765
metadata: {}
@@ -780,7 +780,7 @@ operator:
780780
# the number of days generated certs are valid for
781781
# validForDays: 3650
782782

783-
# External certificates for the CRDB cluster.
783+
# External certificates for the CockroachDB cluster.
784784
externalCertificates:
785785
clientCaConfigMapName: ""
786786
nodeCaConfigMapName: ""
@@ -789,7 +789,7 @@ operator:
789789
nodeSecretName: ""
790790
rootSqlClientSecretName: ""
791791

792-
# RBAC settings for CRDB nodes
792+
# RBAC settings for CockroachDB nodes
793793
rbac:
794794
# By default the service account will be the resource name. It will
795795
# be created during the installation along with a namespaced role and
@@ -823,7 +823,7 @@ operator:
823823
cloudProvider: k3d
824824
namespace: default
825825

826-
# PodLabels are the labels that should be applied to the underlying CRDB pod
826+
# PodLabels are the labels that should be applied to the underlying CockroachDB pod
827827
podLabels:
828828
app.kubernetes.io/component: cockroachdb
829829

@@ -832,14 +832,14 @@ operator:
832832
# Disable backup/restore to local disk by default.
833833
--external-io-dir: disabled
834834

835-
# Environment variables set on cockroachdb pods.
835+
# Environment variables set on CockroachDB pods.
836836
env: []
837837

838838
# Delay between cockroachdb pod restarts. Wait 3m by default to avoid
839839
# unavailability during restarts.
840840
rollingRestartDelay: 3m0s
841841

842-
# Topology spread constraints set on cockroachdb pods. Spread cockroachdb
842+
# Topology spread constraints set on CockroachDB pods. Spread CockroachDB
843843
# pods across zones by default.
844844
topologySpreadConstraints:
845845
- maxSkew: 1

tests/e2e/install/cockroachdb_helm_e2e_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ func TestCockroachDbHelmInstall(t *testing.T) {
5050
}
5151

5252
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
53-
// ... and make sure to delete the namespace at the end of the test
54-
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
53+
// ... and make sure to delete the namespace at the end of the test.
54+
defer testutil.DeleteNamespace(t, k8sClient, namespaceName)
5555

5656
const testDBName = "testdb"
5757

@@ -88,7 +88,7 @@ func TestCockroachDbHelmInstall(t *testing.T) {
8888
}
8989
}()
9090

91-
// Next we wait for the service endpoint
91+
// Next we wait for the service endpoint.
9292
serviceName := fmt.Sprintf("%s-cockroachdb-public", releaseName)
9393
k8s.WaitUntilServiceAvailable(t, kubectlOptions, serviceName, 30, 2*time.Second)
9494

@@ -123,8 +123,8 @@ func TestCockroachDbHelmInstallWithCAProvided(t *testing.T) {
123123
}
124124

125125
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
126-
// ... and make sure to delete the namespace at the end of the test
127-
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
126+
// ... and make sure to delete the namespace at the end of the test.
127+
defer testutil.DeleteNamespace(t, k8sClient, namespaceName)
128128

129129
certOutput, err := shell.RunCommandAndGetOutputE(t, cmd)
130130
t.Log(certOutput)
@@ -168,7 +168,7 @@ func TestCockroachDbHelmInstallWithCAProvided(t *testing.T) {
168168
},
169169
)
170170

171-
// custom user CA certificate secret should not be deleted by pre-delete job
171+
// custom user CA certificate secret should not be deleted by pre-delete job.
172172
_, err = k8s.GetSecretE(t, kubectlOptions, crdbCluster.CaSecret)
173173
require.NoError(t, err)
174174
}()
@@ -180,7 +180,7 @@ func TestCockroachDbHelmInstallWithCAProvided(t *testing.T) {
180180
}
181181
}()
182182

183-
// Next we wait for the service endpoint
183+
// Next we wait for the service endpoint.
184184
serviceName := fmt.Sprintf("%s-cockroachdb-public", releaseName)
185185
k8s.WaitUntilServiceAvailable(t, kubectlOptions, serviceName, 30, 2*time.Second)
186186

@@ -190,7 +190,7 @@ func TestCockroachDbHelmInstallWithCAProvided(t *testing.T) {
190190
testutil.RequireCRDBToFunction(t, crdbCluster, false)
191191
}
192192

193-
// Test to check migration from Bring your own certificate method to self-sginer cert utility
193+
// Test to check migration from Bring your own certificate method to self-sginer cert utility.
194194
func TestCockroachDbHelmMigration(t *testing.T) {
195195
namespaceName := "cockroach" + strings.ToLower(random.UniqueId())
196196
kubectlOptions := k8s.NewKubectlOptions("", "", namespaceName)
@@ -250,8 +250,8 @@ func TestCockroachDbHelmMigration(t *testing.T) {
250250
}
251251

252252
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
253-
// Make sure to delete the namespace at the end of the test
254-
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
253+
// Make sure to delete the namespace at the end of the test.
254+
defer testutil.DeleteNamespace(t, k8sClient, namespaceName)
255255

256256
cmds := []shell.Command{cmdCa, cmdNode, cmdClient}
257257
for i := range cmds {
@@ -270,7 +270,7 @@ func TestCockroachDbHelmMigration(t *testing.T) {
270270
fmt.Sprintf("--from-file=%s/ca.crt", certsDir))
271271
require.NoError(t, err)
272272

273-
// Setup the args
273+
// Setup the args.
274274
options := &helm.Options{
275275
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
276276
SetValues: patchHelmValues(map[string]string{
@@ -299,12 +299,12 @@ func TestCockroachDbHelmMigration(t *testing.T) {
299299
testutil.RequireClusterToBeReadyEventuallyTimeout(t, crdbCluster, 600*time.Second)
300300
time.Sleep(20 * time.Second)
301301

302-
// Setup the args for upgrade
302+
// Setup the args for upgrade.
303303
crdbCluster.NodeSecret = fmt.Sprintf("%s-cockroachdb-node-secret", releaseName)
304304
crdbCluster.ClientSecret = fmt.Sprintf("%s-cockroachdb-client-secret", releaseName)
305305
crdbCluster.CaSecret = fmt.Sprintf("%s-cockroachdb-ca-secret", releaseName)
306306

307-
// Default method is self-signer so no need to set explicitly
307+
// Default method is self-signer so no need to set explicitly.
308308
options = &helm.Options{
309309
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
310310
SetValues: patchHelmValues(map[string]string{
@@ -319,8 +319,8 @@ func TestCockroachDbHelmMigration(t *testing.T) {
319319
}
320320

321321
// Upgrade the cockroachdb helm chart and checks installation should succeed.
322-
// Upgrade is done in goRoutine to unblock the code flow
323-
// While upgrading statefulset pods need to be deleted manually to consume the new certificate chain
322+
// Upgrade is done in goRoutine to unblock the code flow.
323+
// While upgrading statefulset pods need to be deleted manually to consume the new certificate chain.
324324
wg := sync.WaitGroup{}
325325
wg.Add(1)
326326

@@ -338,7 +338,7 @@ func TestCockroachDbHelmMigration(t *testing.T) {
338338

339339
wg.Wait()
340340

341-
// Wait for the service endpoint
341+
// Wait for the service endpoint.
342342
k8s.WaitUntilServiceAvailable(t, kubectlOptions, publicService, 30, 2*time.Second)
343343

344344
testutil.RequireCertificatesToBeValid(t, crdbCluster)
@@ -360,7 +360,7 @@ func TestCockroachDbWithInsecureMode(t *testing.T) {
360360

361361
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
362362
// ... and make sure to delete the namespace at the end of the test
363-
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
363+
defer testutil.DeleteNamespace(t, k8sClient, namespaceName)
364364

365365
// Setup the args. For this test, we will set the following input values:
366366
options := &helm.Options{
@@ -397,7 +397,7 @@ func TestCockroachDbWithCertManager(t *testing.T) {
397397

398398
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
399399
// ... and make sure to delete the namespace at the end of the test
400-
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
400+
defer testutil.DeleteNamespace(t, k8sClient, namespaceName)
401401

402402
certManagerHelmOptions := &helm.Options{
403403
KubectlOptions: k8s.NewKubectlOptions("", "", "cert-manager"),
@@ -526,7 +526,7 @@ func testWALFailoverExistingCluster(t *testing.T, additionalValues map[string]st
526526
}
527527

528528
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
529-
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
529+
defer testutil.DeleteNamespace(t, k8sClient, namespaceName)
530530

531531
// Print the debug logs in case of test failure.
532532
defer func() {

tests/k3d/dev-cluster.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ REQUIRED_IMAGES=(
2626
"quay.io/jetstack/cert-manager-webhook:v1.11.0"
2727
"quay.io/jetstack/cert-manager-controller:v1.11.0"
2828
"quay.io/jetstack/cert-manager-ctl:v1.11.0"
29-
"cockroachdb/cockroach:v24.3.6"
29+
"cockroachdb/cockroach:v25.1.0"
3030
"${REGISTRY}/${REPOSITORY}:$(bin/yq '.tls.selfSigner.image.tag' ./cockroachdb/values.yaml)"
3131
)
3232

tests/testutil/require.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import (
1111
"testing"
1212
"time"
1313

14+
"github.com/cockroachdb/cockroach-operator/pkg/ptr"
15+
v1 "k8s.io/api/rbac/v1"
16+
1417
"github.com/cockroachdb/cockroach-operator/pkg/database"
1518
"github.com/cockroachdb/cockroach-operator/pkg/kube"
1619
"github.com/gruntwork-io/terratest/modules/k8s"
@@ -37,6 +40,8 @@ type CockroachCluster struct {
3740
IsCaUserProvided bool
3841
}
3942

43+
const role = "crdb-test-cockroachdb-node-reader"
44+
4045
// RequireClusterToBeReadyEventuallyTimeout waits for all the CRDB pods to come into running state.
4146
func RequireClusterToBeReadyEventuallyTimeout(t *testing.T, crdbCluster CockroachCluster, timeout time.Duration) {
4247

@@ -463,3 +468,52 @@ func WaitUntilPodDeleted(
463468
}
464469
log.Println(message)
465470
}
471+
472+
// DeleteNamespace deletes a namespace by removing Finalizers and setting GracePeriodSeconds to 0 for immediate deletion.
473+
// Since we use force deletion, we don't need to wait for the namespace to be fully deleted.
474+
// Namespace will be cleaned up when cluster is deleted post e2e execution
475+
func DeleteNamespace(t *testing.T, k8sClient client.Client, namespace string) {
476+
t.Helper()
477+
478+
crb := &v1.ClusterRoleBinding{}
479+
if err := k8sClient.Get(context.Background(), types.NamespacedName{Name: role}, crb); err != nil {
480+
t.Logf("Error getting ClusterRoleBinding %s: %v", role, err)
481+
}
482+
483+
if err := k8sClient.Delete(context.Background(), crb); err != nil {
484+
t.Logf("Error deleting ClusterRoleBinding %s: %v", role, err)
485+
}
486+
cr := &v1.ClusterRole{}
487+
if err := k8sClient.Get(context.Background(), types.NamespacedName{Name: role}, cr); err != nil {
488+
t.Logf("Error getting ClusterRole %s: %v", role, err)
489+
}
490+
491+
if err := k8sClient.Delete(context.Background(), cr); err != nil {
492+
t.Logf("Error deleting ClusterRole %s: %v", role, err)
493+
}
494+
495+
ns := &corev1.Namespace{}
496+
if err := k8sClient.Get(context.Background(), types.NamespacedName{Name: namespace}, ns); err != nil {
497+
if apierrors.IsNotFound(err) {
498+
return
499+
}
500+
t.Logf("Error getting namespace %s: %v", namespace, err)
501+
return
502+
}
503+
504+
if len(ns.Spec.Finalizers) > 0 {
505+
ns.Spec.Finalizers = nil
506+
if err := k8sClient.Update(context.Background(), ns); err != nil {
507+
t.Logf("Error removing finalizers from namespace %s: %v", namespace, err)
508+
}
509+
}
510+
511+
deleteOptions := metav1.DeleteOptions{
512+
GracePeriodSeconds: ptr.Int64(60),
513+
}
514+
if err := k8sClient.Delete(context.Background(), ns, &client.DeleteOptions{
515+
Raw: &deleteOptions,
516+
}); err != nil && !apierrors.IsNotFound(err) {
517+
t.Logf("Error deleting namespace %s: %v", namespace, err)
518+
}
519+
}

0 commit comments

Comments
 (0)