Sidecar tests
This commit is contained in:
parent
c75de6e609
commit
517a6c7324
@ -23,7 +23,7 @@ import (
|
|||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
batchv1 "k8s.io/api/batch/v1"
|
batchv1 "k8s.io/api/batch/v1"
|
||||||
//"time"
|
//"time"
|
||||||
//appsv1 "k8s.io/api/apps/v1"
|
appsv1 "k8s.io/api/apps/v1"
|
||||||
//corev1 "k8s.io/api/core/v1"
|
//corev1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
@ -130,6 +130,24 @@ var _ = Describe("BackupConfiguration controller", func() {
|
|||||||
}, timeout, interval).Should(Equal("1 0 * * *"))
|
}, timeout, interval).Should(Equal("1 0 * * *"))
|
||||||
Expect(*cronJob.Spec.Suspend).Should(BeTrue())
|
Expect(*cronJob.Spec.Suspend).Should(BeTrue())
|
||||||
})
|
})
|
||||||
|
When("The BackupType is an OnlineKind", func() {
|
||||||
|
It("Should create a sidecar container", func() {
|
||||||
|
deployment := &appsv1.Deployment{}
|
||||||
|
Eventually(func() bool {
|
||||||
|
if err := k8sClient.Get(ctx, types.NamespacedName{
|
||||||
|
Name: DEPLOYMENT_NAME,
|
||||||
|
Namespace: NAMESPACE_NAME,
|
||||||
|
}, deployment); err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return len(deployment.Spec.Template.Spec.Containers) == 2
|
||||||
|
}, timeout, interval).Should(BeTrue())
|
||||||
|
|
||||||
|
By("Should add Env labels")
|
||||||
|
Expect(deployment.Spec.Template.Spec.Containers[0].Env[0].Name).Should(Equal(formolv1alpha1.TARGETCONTAINER_TAG))
|
||||||
|
Expect(deployment.Spec.Template.Spec.Containers[1].Name).Should(Equal(formolv1alpha1.SIDECARCONTAINER_NAME))
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
Context("Deleting a BackupConf", func() {
|
Context("Deleting a BackupConf", func() {
|
||||||
JustBeforeEach(func() {
|
JustBeforeEach(func() {
|
||||||
@ -161,5 +179,33 @@ var _ = Describe("BackupConfiguration controller", func() {
|
|||||||
}, timeout, interval).Should(BeFalse())
|
}, timeout, interval).Should(BeFalse())
|
||||||
|
|
||||||
})
|
})
|
||||||
|
When("The BackupType is an OnlineKind", func() {
|
||||||
|
It("Should delete the sidecar container", func() {
|
||||||
|
deployment := &appsv1.Deployment{}
|
||||||
|
Eventually(func() bool {
|
||||||
|
if err := k8sClient.Get(ctx, types.NamespacedName{
|
||||||
|
Name: DEPLOYMENT_NAME,
|
||||||
|
Namespace: NAMESPACE_NAME,
|
||||||
|
}, deployment); err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return len(deployment.Spec.Template.Spec.Containers) == 2
|
||||||
|
}, timeout, interval).Should(BeTrue())
|
||||||
|
Expect(deployment.Spec.Template.Spec.Containers[0].Env[0].Name).Should(Equal(formolv1alpha1.TARGETCONTAINER_TAG))
|
||||||
|
Expect(deployment.Spec.Template.Spec.Containers[1].Name).Should(Equal(formolv1alpha1.SIDECARCONTAINER_NAME))
|
||||||
|
By("The sidecar container has been created. Now deleting the BackupConfiguration")
|
||||||
|
Expect(k8sClient.Delete(ctx, backupConf)).Should(Succeed())
|
||||||
|
Eventually(func() bool {
|
||||||
|
if err := k8sClient.Get(ctx, types.NamespacedName{
|
||||||
|
Name: DEPLOYMENT_NAME,
|
||||||
|
Namespace: NAMESPACE_NAME,
|
||||||
|
}, deployment); err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return len(deployment.Spec.Template.Spec.Containers) == 1
|
||||||
|
}, timeout, interval).Should(BeTrue())
|
||||||
|
Expect(len(deployment.Spec.Template.Spec.Containers[0].Env)).Should(Equal(0))
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -50,6 +50,7 @@ const (
|
|||||||
DEPLOYMENT_NAME = "test-deployment"
|
DEPLOYMENT_NAME = "test-deployment"
|
||||||
CONTAINER_NAME = "test-container"
|
CONTAINER_NAME = "test-container"
|
||||||
DATAVOLUME_NAME = "data"
|
DATAVOLUME_NAME = "data"
|
||||||
|
SECRET_NAME = "test-secret"
|
||||||
timeout = time.Second * 10
|
timeout = time.Second * 10
|
||||||
interval = time.Millisecond * 250
|
interval = time.Millisecond * 250
|
||||||
)
|
)
|
||||||
@ -89,6 +90,32 @@ var (
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
secret = &corev1.Secret{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: SECRET_NAME,
|
||||||
|
Namespace: NAMESPACE_NAME,
|
||||||
|
},
|
||||||
|
Data: map[string][]byte{
|
||||||
|
"RESTIC_PASSWORD": []byte("toto"),
|
||||||
|
"AWS_ACCESS_KEY_ID": []byte("titi"),
|
||||||
|
"AWS_SECRET_ACCESS_KEY": []byte("tata"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
repo = &formolv1alpha1.Repo{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: REPO_NAME,
|
||||||
|
Namespace: NAMESPACE_NAME,
|
||||||
|
},
|
||||||
|
Spec: formolv1alpha1.RepoSpec{
|
||||||
|
Backend: formolv1alpha1.Backend{
|
||||||
|
S3: &formolv1alpha1.S3{
|
||||||
|
Server: "raid5.desmojim.fr:9000",
|
||||||
|
Bucket: "testbucket2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RepositorySecrets: "test-secret",
|
||||||
|
},
|
||||||
|
}
|
||||||
cfg *rest.Config
|
cfg *rest.Config
|
||||||
k8sClient client.Client
|
k8sClient client.Client
|
||||||
testEnv *envtest.Environment
|
testEnv *envtest.Environment
|
||||||
@ -127,6 +154,8 @@ var _ = BeforeSuite(func() {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(k8sClient).NotTo(BeNil())
|
Expect(k8sClient).NotTo(BeNil())
|
||||||
Expect(k8sClient.Create(ctx, namespace)).Should(Succeed())
|
Expect(k8sClient.Create(ctx, namespace)).Should(Succeed())
|
||||||
|
Expect(k8sClient.Create(ctx, secret)).Should(Succeed())
|
||||||
|
Expect(k8sClient.Create(ctx, repo)).Should(Succeed())
|
||||||
Expect(k8sClient.Create(ctx, deployment)).Should(Succeed())
|
Expect(k8sClient.Create(ctx, deployment)).Should(Succeed())
|
||||||
|
|
||||||
k8sManager, err := ctrl.NewManager(cfg, ctrl.Options{
|
k8sManager, err := ctrl.NewManager(cfg, ctrl.Options{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user