2020-11-01 09:24:13 +00:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
appsv1 "k8s.io/api/apps/v1"
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
|
|
"k8s.io/apimachinery/pkg/api/resource"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
"k8s.io/apimachinery/pkg/types"
|
|
|
|
|
|
|
|
seaweedv1 "github.com/seaweedfs/seaweedfs-operator/api/v1"
|
|
|
|
)
|
|
|
|
|
2020-11-09 07:02:09 +00:00
|
|
|
var (
|
|
|
|
TrueValue = true
|
|
|
|
FalseVallue = false
|
|
|
|
)
|
|
|
|
|
2020-11-01 09:24:13 +00:00
|
|
|
var _ = Describe("Seaweed Controller", func() {
|
|
|
|
Context("Basic Functionality", func() {
|
|
|
|
It("Should create StatefulSets", func() {
|
|
|
|
By("By creating a new Seaweed", func() {
|
|
|
|
const (
|
|
|
|
namespace = "default"
|
|
|
|
name = "test-seaweed"
|
|
|
|
|
2020-11-01 09:32:43 +00:00
|
|
|
timeout = time.Second * 30
|
2020-11-01 09:24:13 +00:00
|
|
|
interval = time.Millisecond * 250
|
|
|
|
)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
seaweed := &seaweedv1.Seaweed{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Namespace: namespace,
|
|
|
|
Name: name,
|
|
|
|
},
|
|
|
|
Spec: seaweedv1.SeaweedSpec{
|
2021-12-25 09:27:48 +00:00
|
|
|
Image: "chrislusf/seaweedfs:2.83",
|
2020-11-01 09:24:13 +00:00
|
|
|
VolumeServerDiskCount: 1,
|
|
|
|
Master: &seaweedv1.MasterSpec{
|
2020-11-09 07:02:09 +00:00
|
|
|
Replicas: 3,
|
|
|
|
ConcurrentStart: &TrueValue,
|
2020-11-01 09:24:13 +00:00
|
|
|
},
|
|
|
|
Volume: &seaweedv1.VolumeSpec{
|
|
|
|
Replicas: 1,
|
|
|
|
ResourceRequirements: corev1.ResourceRequirements{
|
|
|
|
Requests: corev1.ResourceList{
|
|
|
|
corev1.ResourceStorage: resource.MustParse("1Gi"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Filer: &seaweedv1.FilerSpec{
|
|
|
|
Replicas: 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
Expect(k8sClient.Create(ctx, seaweed)).Should(Succeed())
|
|
|
|
|
|
|
|
masterKey := types.NamespacedName{Name: name + "-master", Namespace: namespace}
|
|
|
|
volumeKey := types.NamespacedName{Name: name + "-volume", Namespace: namespace}
|
|
|
|
filerKey := types.NamespacedName{Name: name + "-filer", Namespace: namespace}
|
|
|
|
|
|
|
|
masterSts := &appsv1.StatefulSet{}
|
|
|
|
volumeSts := &appsv1.StatefulSet{}
|
|
|
|
filerSts := &appsv1.StatefulSet{}
|
|
|
|
|
|
|
|
Eventually(func() bool {
|
|
|
|
err := k8sClient.Get(ctx, masterKey, masterSts)
|
2020-11-01 09:34:52 +00:00
|
|
|
return err == nil
|
2020-11-01 09:24:13 +00:00
|
|
|
}, timeout, interval).Should(BeTrue())
|
2020-11-01 09:32:43 +00:00
|
|
|
Expect(masterSts.Spec.Replicas).ShouldNot(BeNil())
|
2020-11-01 09:24:13 +00:00
|
|
|
Expect(*masterSts.Spec.Replicas).Should(Equal(seaweed.Spec.Master.Replicas))
|
|
|
|
|
|
|
|
Eventually(func() bool {
|
|
|
|
err := k8sClient.Get(ctx, volumeKey, volumeSts)
|
2020-11-01 09:34:52 +00:00
|
|
|
return err == nil
|
2020-11-01 09:24:13 +00:00
|
|
|
}, timeout, interval).Should(BeTrue())
|
2020-11-01 09:32:43 +00:00
|
|
|
Expect(volumeSts.Spec.Replicas).ShouldNot(BeNil())
|
2020-11-01 09:24:13 +00:00
|
|
|
Expect(*volumeSts.Spec.Replicas).Should(Equal(seaweed.Spec.Volume.Replicas))
|
|
|
|
|
|
|
|
Eventually(func() bool {
|
|
|
|
err := k8sClient.Get(ctx, filerKey, filerSts)
|
2020-11-01 09:34:52 +00:00
|
|
|
return err == nil
|
2020-11-01 09:24:13 +00:00
|
|
|
}, timeout, interval).Should(BeTrue())
|
2020-11-01 09:32:43 +00:00
|
|
|
Expect(filerSts.Spec.Replicas).ShouldNot(BeNil())
|
2020-11-01 09:24:13 +00:00
|
|
|
Expect(*filerSts.Spec.Replicas).Should(Equal(seaweed.Spec.Filer.Replicas))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|