-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ab17d7
commit a98a90a
Showing
5 changed files
with
220 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package druid | ||
|
||
import ( | ||
"time" | ||
|
||
druidv1alpha1 "github.com/datainfrahq/druid-operator/apis/druid/v1alpha1" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
// +kubebuilder:docs-gen:collapse=Imports | ||
|
||
/* | ||
finalizers_test | ||
*/ | ||
var _ = Describe("Test finalizers logic", func() { | ||
const ( | ||
filePath = "testdata/finalizers.yaml" | ||
timeout = time.Second * 45 | ||
interval = time.Millisecond * 250 | ||
) | ||
|
||
var ( | ||
druid = &druidv1alpha1.Druid{} | ||
) | ||
|
||
Context("When creating a druid cluster", func() { | ||
It("Should create the druid object", func() { | ||
By("Creating a new druid") | ||
druidCR, err := readDruidClusterSpecFromFile(filePath) | ||
Expect(err).Should(BeNil()) | ||
Expect(k8sClient.Create(ctx, druidCR)).To(Succeed()) | ||
|
||
By("Getting a newly created druid") | ||
Eventually(func() bool { | ||
err := k8sClient.Get(ctx, types.NamespacedName{Name: druidCR.Name, Namespace: druidCR.Namespace}, druid) | ||
return err == nil | ||
}, timeout, interval).Should(BeTrue()) | ||
}) | ||
It("Should add the delete PVC finalizer", func() { | ||
By("Waiting for the finalizer to be created") | ||
Eventually(func() bool { | ||
err := k8sClient.Get(ctx, types.NamespacedName{Name: druid.Name, Namespace: druid.Namespace}, druid) | ||
if err == nil && ContainsString(druid.GetFinalizers(), deletePVCFinalizerName) { | ||
return true | ||
} | ||
return false | ||
}, timeout, interval).Should(BeTrue()) | ||
}) | ||
It("Should delete druid successfully", func() { | ||
By("Waiting for the druid cluster to be deleted") | ||
Expect(k8sClient.Delete(ctx, druid)).To(Succeed()) | ||
Eventually(func() bool { | ||
err := k8sClient.Get(ctx, types.NamespacedName{Name: druid.Name, Namespace: druid.Namespace}, druid) | ||
return err != nil | ||
}, timeout, interval).Should(BeTrue()) | ||
}) | ||
}) | ||
|
||
Context("When creating a druid cluster with disablePVCDeletion", func() { | ||
It("Should create the druid object", func() { | ||
By("Creating a new druid") | ||
druidCR, err := readDruidClusterSpecFromFile(filePath) | ||
druidCR.Spec.DisablePVCDeletionFinalizer = true | ||
Expect(err).Should(BeNil()) | ||
Expect(k8sClient.Create(ctx, druidCR)).To(Succeed()) | ||
|
||
By("Getting a newly created druid") | ||
Eventually(func() bool { | ||
err := k8sClient.Get(ctx, types.NamespacedName{Name: druidCR.Name, Namespace: druidCR.Namespace}, druid) | ||
return err == nil | ||
}, timeout, interval).Should(BeTrue()) | ||
}) | ||
It("Should not add the delete PVC finalizer", func() { | ||
By("Call for the update finalizer function") | ||
Expect(updateFinalizers(ctx, k8sClient, druid, emitEvent)).Should(BeNil()) | ||
|
||
By("Getting a updated druid") | ||
Eventually(func() bool { | ||
err := k8sClient.Get(ctx, types.NamespacedName{Name: druid.Name, Namespace: druid.Namespace}, druid) | ||
return err == nil | ||
}, timeout, interval).Should(BeTrue()) | ||
|
||
By("Checking the absence of the finalizer") | ||
Expect(ContainsString(druid.GetFinalizers(), deletePVCFinalizerName)).Should(BeFalse()) | ||
}) | ||
It("Should delete druid successfully", func() { | ||
Expect(k8sClient.Delete(ctx, druid)).To(Succeed()) | ||
Eventually(func() bool { | ||
err := k8sClient.Get(ctx, types.NamespacedName{Name: druid.Name, Namespace: druid.Namespace}, druid) | ||
return err != nil | ||
}, timeout, interval).Should(BeTrue()) | ||
}) | ||
}) | ||
|
||
Context("When creating a druid cluster", func() { | ||
It("Should create the druid object", func() { | ||
By("Creating a new druid") | ||
druidCR, err := readDruidClusterSpecFromFile(filePath) | ||
Expect(err).Should(BeNil()) | ||
Expect(k8sClient.Create(ctx, druidCR)).To(Succeed()) | ||
|
||
By("Getting the CR") | ||
Eventually(func() bool { | ||
err := k8sClient.Get(ctx, types.NamespacedName{Name: druidCR.Name, Namespace: druidCR.Namespace}, druid) | ||
return err == nil | ||
}, timeout, interval).Should(BeTrue()) | ||
}) | ||
It("Should add the delete PVC finalizer", func() { | ||
By("Waiting for the finalizer to be created") | ||
Eventually(func() bool { | ||
err := k8sClient.Get(ctx, types.NamespacedName{Name: druid.Name, Namespace: druid.Namespace}, druid) | ||
if err == nil && ContainsString(druid.GetFinalizers(), deletePVCFinalizerName) { | ||
return true | ||
} | ||
return false | ||
}, timeout, interval).Should(BeTrue()) | ||
}) | ||
It("Should remove the delete PVC finalizer", func() { | ||
By("Disabling the deletePVC finalizer") | ||
druid.Spec.DisablePVCDeletionFinalizer = true | ||
Expect(k8sClient.Update(ctx, druid)).To(BeNil()) | ||
By("Waiting for the finalizer to be deleted") | ||
Eventually(func() bool { | ||
err := k8sClient.Get(ctx, types.NamespacedName{Name: druid.Name, Namespace: druid.Namespace}, druid) | ||
if err == nil && !ContainsString(druid.GetFinalizers(), deletePVCFinalizerName) { | ||
return true | ||
} | ||
return false | ||
}, timeout, interval).Should(BeTrue()) | ||
}) | ||
It("Should delete druid successfully", func() { | ||
Expect(k8sClient.Delete(ctx, druid)).To(Succeed()) | ||
Eventually(func() bool { | ||
err := k8sClient.Get(ctx, types.NamespacedName{Name: druid.Name, Namespace: druid.Namespace}, druid) | ||
return err != nil | ||
}, timeout, interval).Should(BeTrue()) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
apiVersion: druid.apache.org/v1alpha1 | ||
kind: Druid | ||
metadata: | ||
name: finalizers | ||
namespace: default | ||
spec: | ||
image: apache/druid:25.0.0 | ||
startScript: /druid.sh | ||
rollingDeploy: false | ||
securityContext: | ||
fsGroup: 1000 | ||
runAsUser: 1000 | ||
runAsGroup: 1000 | ||
services: | ||
- spec: | ||
type: ClusterIP | ||
commonConfigMountPath: "/opt/druid/conf/druid/cluster/_common" | ||
jvm.options: |- | ||
-server | ||
-XX:MaxDirectMemorySize=10240g | ||
-Duser.timezone=UTC | ||
-Dfile.encoding=UTF-8 | ||
-Djava.io.tmpdir=/druid/data | ||
common.runtime.properties: |- | ||
# Metadata Store | ||
druid.metadata.storage.type=derby | ||
druid.metadata.storage.connector.connectURI=jdbc:derby://localhost:1527/druid/data/derbydb/metadata.db;create=true | ||
druid.metadata.storage.connector.host=localhost | ||
druid.metadata.storage.connector.port=1527 | ||
druid.metadata.storage.connector.createTables=true | ||
# Deep Storage | ||
druid.storage.type=local | ||
druid.storage.storageDirectory=/druid/deepstorage | ||
# Service discovery | ||
druid.selectors.indexing.serviceName=druid/overlord | ||
druid.selectors.coordinator.serviceName=druid/coordinator | ||
nodes: | ||
brokers: | ||
nodeType: "broker" | ||
kind: "Deployment" | ||
druid.port: 8088 | ||
nodeConfigMountPath: "/opt/druid/conf/druid/cluster/query/broker" | ||
replicas: 1 | ||
runtime.properties: |- | ||
druid.service=druid/broker | ||
additionalContainer: | ||
- command: | ||
- /bin/sh echo hello | ||
containerName: node-level | ||
image: hello-world | ||
coordinators: | ||
nodeType: "coordinator" | ||
druid.port: 8080 | ||
nodeConfigMountPath: "/opt/druid/conf/druid/cluster/master/coordinator-overlord" | ||
replicas: 1 | ||
runtime.properties: |- | ||
druid.service=druid/coordinator | ||
druid.coordinator.asOverlord.enabled=true | ||
druid.coordinator.asOverlord.overlordService=druid/overlord | ||
historicals: | ||
nodeType: "historical" | ||
druid.port: 8080 | ||
nodeConfigMountPath: "/opt/druid/conf/druid/cluster/data/historical" | ||
replicas: 1 | ||
runtime.properties: |- | ||
druid.service=druid/historical | ||
druid.segmentCache.locations=[{\"path\":\"/druid/data/segments\",\"maxSize\":10737418240}] | ||
druid.server.maxSize=10737418240 |