BackupConfiguration initial test suite
This commit is contained in:
parent
1dfd0d472b
commit
393465300a
@ -5,7 +5,7 @@ import (
|
|||||||
//"k8s.io/apimachinery/pkg/types"
|
//"k8s.io/apimachinery/pkg/types"
|
||||||
//"reflect"
|
//"reflect"
|
||||||
//"fmt"
|
//"fmt"
|
||||||
"time"
|
//"time"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
@ -19,86 +19,24 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("Setup the environment", func() {
|
var _ = Describe("Testing BackupConf controller", func() {
|
||||||
const (
|
const (
|
||||||
BackupConfName = "test-backupconf"
|
BackupConfName = "test-backupconf"
|
||||||
BackupConfNamespace = "test-backupconf-namespace"
|
|
||||||
RepoName = "test-repo"
|
|
||||||
DeploymentName = "test-deployment"
|
|
||||||
timeout = time.Second * 10
|
|
||||||
interval = time.Millisecond * 250
|
|
||||||
)
|
)
|
||||||
var (
|
var (
|
||||||
key = types.NamespacedName{
|
key = types.NamespacedName{
|
||||||
Name: BackupConfName,
|
Name: BackupConfName,
|
||||||
Namespace: BackupConfNamespace,
|
Namespace: TestNamespace,
|
||||||
}
|
}
|
||||||
ctx = context.Background()
|
ctx = context.Background()
|
||||||
namespace = &corev1.Namespace{
|
backupConf = &formolv1alpha1.BackupConfiguration{}
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
)
|
||||||
Name: BackupConfNamespace,
|
|
||||||
},
|
BeforeEach(func() {
|
||||||
}
|
|
||||||
deployment = &appsv1.Deployment{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: DeploymentName,
|
|
||||||
Namespace: BackupConfNamespace,
|
|
||||||
},
|
|
||||||
Spec: appsv1.DeploymentSpec{
|
|
||||||
Selector: &metav1.LabelSelector{
|
|
||||||
MatchLabels: map[string]string{"app": "test-deployment"},
|
|
||||||
},
|
|
||||||
Template: corev1.PodTemplateSpec{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Labels: map[string]string{"app": "test-deployment"},
|
|
||||||
},
|
|
||||||
Spec: corev1.PodSpec{
|
|
||||||
Containers: []corev1.Container{
|
|
||||||
corev1.Container{
|
|
||||||
Name: "test-container",
|
|
||||||
Image: "test-image",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
sa = &corev1.ServiceAccount{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: "default",
|
|
||||||
Namespace: BackupConfNamespace,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
secret = &corev1.Secret{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: "test-secret",
|
|
||||||
Namespace: BackupConfNamespace,
|
|
||||||
},
|
|
||||||
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: RepoName,
|
|
||||||
Namespace: BackupConfNamespace,
|
|
||||||
},
|
|
||||||
Spec: formolv1alpha1.RepoSpec{
|
|
||||||
Backend: formolv1alpha1.Backend{
|
|
||||||
S3: formolv1alpha1.S3{
|
|
||||||
Server: "raid5.desmojim.fr:9000",
|
|
||||||
Bucket: "testbucket2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
RepositorySecrets: "test-secret",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
backupConf = &formolv1alpha1.BackupConfiguration{
|
backupConf = &formolv1alpha1.BackupConfiguration{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: BackupConfName,
|
Name: BackupConfName,
|
||||||
Namespace: BackupConfNamespace,
|
Namespace: TestNamespace,
|
||||||
},
|
},
|
||||||
Spec: formolv1alpha1.BackupConfigurationSpec{
|
Spec: formolv1alpha1.BackupConfigurationSpec{
|
||||||
Repository: RepoName,
|
Repository: RepoName,
|
||||||
@ -108,27 +46,36 @@ var _ = Describe("Setup the environment", func() {
|
|||||||
Kind: "Deployment",
|
Kind: "Deployment",
|
||||||
Name: DeploymentName,
|
Name: DeploymentName,
|
||||||
},
|
},
|
||||||
|
formolv1alpha1.Target{
|
||||||
|
Kind: "Task",
|
||||||
|
Name: BackupFuncName,
|
||||||
|
Steps: []formolv1alpha1.Step{
|
||||||
|
formolv1alpha1.Step{
|
||||||
|
Name: BackupFuncName,
|
||||||
|
Namespace: TestNamespace,
|
||||||
|
Env: []corev1.EnvVar{
|
||||||
|
corev1.EnvVar{
|
||||||
|
Name: "foo",
|
||||||
|
Value: "bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
})
|
||||||
|
Context("There is a backupconf", func() {
|
||||||
BeforeEach(func() {
|
JustBeforeEach(func() {
|
||||||
|
Eventually(func() error {
|
||||||
|
return k8sClient.Create(ctx, backupConf)
|
||||||
|
}, timeout, interval).Should(Succeed())
|
||||||
})
|
})
|
||||||
AfterEach(func() {
|
AfterEach(func() {
|
||||||
|
Expect(k8sClient.Delete(ctx, backupConf)).Should(Succeed())
|
||||||
})
|
})
|
||||||
|
It("Has a schedule", func() {
|
||||||
Context("Testing backupconf", func() {
|
|
||||||
It("Requires initialisation", func() {
|
|
||||||
Expect(k8sClient.Create(ctx, namespace)).Should(Succeed())
|
|
||||||
Expect(k8sClient.Create(ctx, sa)).Should(Succeed())
|
|
||||||
Expect(k8sClient.Create(ctx, secret)).Should(Succeed())
|
|
||||||
Expect(k8sClient.Create(ctx, repo)).Should(Succeed())
|
|
||||||
Expect(k8sClient.Create(ctx, deployment)).Should(Succeed())
|
|
||||||
})
|
|
||||||
Context("Creating a backupconf", func() {
|
|
||||||
It("Requires initialisation", func() {
|
|
||||||
Expect(k8sClient.Create(ctx, backupConf)).Should(Succeed())
|
|
||||||
realBackupConf := &formolv1alpha1.BackupConfiguration{}
|
realBackupConf := &formolv1alpha1.BackupConfiguration{}
|
||||||
Eventually(func() bool {
|
Eventually(func() bool {
|
||||||
err := k8sClient.Get(ctx, key, realBackupConf)
|
err := k8sClient.Get(ctx, key, realBackupConf)
|
||||||
@ -144,7 +91,7 @@ var _ = Describe("Setup the environment", func() {
|
|||||||
Eventually(func() bool {
|
Eventually(func() bool {
|
||||||
err := k8sClient.Get(ctx, types.NamespacedName{
|
err := k8sClient.Get(ctx, types.NamespacedName{
|
||||||
Name: "backup-" + BackupConfName,
|
Name: "backup-" + BackupConfName,
|
||||||
Namespace: BackupConfNamespace,
|
Namespace: TestNamespace,
|
||||||
}, cronJob)
|
}, cronJob)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
@ -158,7 +105,7 @@ var _ = Describe("Setup the environment", func() {
|
|||||||
Eventually(func() (int, error) {
|
Eventually(func() (int, error) {
|
||||||
err := k8sClient.Get(ctx, types.NamespacedName{
|
err := k8sClient.Get(ctx, types.NamespacedName{
|
||||||
Name: DeploymentName,
|
Name: DeploymentName,
|
||||||
Namespace: BackupConfNamespace,
|
Namespace: TestNamespace,
|
||||||
}, realDeployment)
|
}, realDeployment)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
@ -166,11 +113,15 @@ var _ = Describe("Setup the environment", func() {
|
|||||||
return len(realDeployment.Spec.Template.Spec.Containers), nil
|
return len(realDeployment.Spec.Template.Spec.Containers), nil
|
||||||
}, timeout, interval).Should(Equal(2))
|
}, timeout, interval).Should(Equal(2))
|
||||||
})
|
})
|
||||||
})
|
|
||||||
Context("Updating a backupconf", func() {
|
|
||||||
It("Should also update the CronJob", func() {
|
It("Should also update the CronJob", func() {
|
||||||
realBackupConf := &formolv1alpha1.BackupConfiguration{}
|
realBackupConf := &formolv1alpha1.BackupConfiguration{}
|
||||||
Expect(k8sClient.Get(ctx, key, realBackupConf)).Should(Succeed())
|
Eventually(func() bool {
|
||||||
|
err := k8sClient.Get(ctx, key, realBackupConf)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}, timeout, interval).Should(BeTrue())
|
||||||
realBackupConf.Spec.Schedule = "1 0 * * *"
|
realBackupConf.Spec.Schedule = "1 0 * * *"
|
||||||
suspend := true
|
suspend := true
|
||||||
realBackupConf.Spec.Suspend = &suspend
|
realBackupConf.Spec.Suspend = &suspend
|
||||||
@ -179,7 +130,7 @@ var _ = Describe("Setup the environment", func() {
|
|||||||
Eventually(func() (string, error) {
|
Eventually(func() (string, error) {
|
||||||
err := k8sClient.Get(ctx, types.NamespacedName{
|
err := k8sClient.Get(ctx, types.NamespacedName{
|
||||||
Name: "backup-" + BackupConfName,
|
Name: "backup-" + BackupConfName,
|
||||||
Namespace: BackupConfNamespace,
|
Namespace: TestNamespace,
|
||||||
}, cronJob)
|
}, cronJob)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -189,7 +140,7 @@ var _ = Describe("Setup the environment", func() {
|
|||||||
Eventually(func() (bool, error) {
|
Eventually(func() (bool, error) {
|
||||||
err := k8sClient.Get(ctx, types.NamespacedName{
|
err := k8sClient.Get(ctx, types.NamespacedName{
|
||||||
Name: "backup-" + BackupConfName,
|
Name: "backup-" + BackupConfName,
|
||||||
Namespace: BackupConfNamespace,
|
Namespace: TestNamespace,
|
||||||
}, cronJob)
|
}, cronJob)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@ -199,13 +150,18 @@ var _ = Describe("Setup the environment", func() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
Context("Deleting a backupconf", func() {
|
Context("Deleting a backupconf", func() {
|
||||||
|
JustBeforeEach(func() {
|
||||||
|
Eventually(func() error {
|
||||||
|
return k8sClient.Create(ctx, backupConf)
|
||||||
|
}, timeout, interval).Should(Succeed())
|
||||||
|
})
|
||||||
It("Should also delete the sidecar container", func() {
|
It("Should also delete the sidecar container", func() {
|
||||||
Expect(k8sClient.Delete(ctx, backupConf)).Should(Succeed())
|
Expect(k8sClient.Delete(ctx, backupConf)).Should(Succeed())
|
||||||
realDeployment := &appsv1.Deployment{}
|
realDeployment := &appsv1.Deployment{}
|
||||||
Eventually(func() (int, error) {
|
Eventually(func() (int, error) {
|
||||||
err := k8sClient.Get(ctx, types.NamespacedName{
|
err := k8sClient.Get(ctx, types.NamespacedName{
|
||||||
Name: DeploymentName,
|
Name: DeploymentName,
|
||||||
Namespace: BackupConfNamespace,
|
Namespace: TestNamespace,
|
||||||
}, realDeployment)
|
}, realDeployment)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
@ -215,6 +171,5 @@ var _ = Describe("Setup the environment", func() {
|
|||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
@ -17,12 +17,17 @@ limitations under the License.
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
appsv1 "k8s.io/api/apps/v1"
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/client-go/kubernetes/scheme"
|
"k8s.io/client-go/kubernetes/scheme"
|
||||||
"k8s.io/client-go/rest"
|
"k8s.io/client-go/rest"
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
@ -38,11 +43,94 @@ import (
|
|||||||
|
|
||||||
// These tests use Ginkgo (BDD-style Go testing framework). Refer to
|
// These tests use Ginkgo (BDD-style Go testing framework). Refer to
|
||||||
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
|
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
|
||||||
|
const (
|
||||||
|
BackupFuncName = "test-backup-func"
|
||||||
|
TestNamespace = "test-namespace"
|
||||||
|
RepoName = "test-repo"
|
||||||
|
DeploymentName = "test-deployment"
|
||||||
|
timeout = time.Second * 10
|
||||||
|
interval = time.Millisecond * 250
|
||||||
|
)
|
||||||
|
|
||||||
var cfg *rest.Config
|
var cfg *rest.Config
|
||||||
var k8sClient client.Client
|
var k8sClient client.Client
|
||||||
var testEnv *envtest.Environment
|
var testEnv *envtest.Environment
|
||||||
|
|
||||||
|
var (
|
||||||
|
namespace = &corev1.Namespace{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: TestNamespace,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
deployment = &appsv1.Deployment{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: DeploymentName,
|
||||||
|
Namespace: TestNamespace,
|
||||||
|
},
|
||||||
|
Spec: appsv1.DeploymentSpec{
|
||||||
|
Selector: &metav1.LabelSelector{
|
||||||
|
MatchLabels: map[string]string{"app": "test-deployment"},
|
||||||
|
},
|
||||||
|
Template: corev1.PodTemplateSpec{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Labels: map[string]string{"app": "test-deployment"},
|
||||||
|
},
|
||||||
|
Spec: corev1.PodSpec{
|
||||||
|
Containers: []corev1.Container{
|
||||||
|
corev1.Container{
|
||||||
|
Name: "test-container",
|
||||||
|
Image: "test-image",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
sa = &corev1.ServiceAccount{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "default",
|
||||||
|
Namespace: TestNamespace,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
secret = &corev1.Secret{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "test-secret",
|
||||||
|
Namespace: TestNamespace,
|
||||||
|
},
|
||||||
|
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: RepoName,
|
||||||
|
Namespace: TestNamespace,
|
||||||
|
},
|
||||||
|
Spec: formolv1alpha1.RepoSpec{
|
||||||
|
Backend: formolv1alpha1.Backend{
|
||||||
|
S3: formolv1alpha1.S3{
|
||||||
|
Server: "raid5.desmojim.fr:9000",
|
||||||
|
Bucket: "testbucket2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RepositorySecrets: "test-secret",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
function = &formolv1alpha1.Function{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: BackupFuncName,
|
||||||
|
Namespace: TestNamespace,
|
||||||
|
},
|
||||||
|
Spec: corev1.Container{
|
||||||
|
Name: "backup-func",
|
||||||
|
Image: "myimage",
|
||||||
|
Args: []string{"a", "set", "of", "args"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
func TestAPIs(t *testing.T) {
|
func TestAPIs(t *testing.T) {
|
||||||
RegisterFailHandler(Fail)
|
RegisterFailHandler(Fail)
|
||||||
|
|
||||||
@ -86,7 +174,14 @@ var _ = BeforeSuite(func() {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
k8sClient = k8sManager.GetClient()
|
k8sClient = k8sManager.GetClient()
|
||||||
|
ctx := context.Background()
|
||||||
Expect(k8sClient).ToNot(BeNil())
|
Expect(k8sClient).ToNot(BeNil())
|
||||||
|
Expect(k8sClient.Create(ctx, namespace)).Should(Succeed())
|
||||||
|
Expect(k8sClient.Create(ctx, sa)).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, function)).Should(Succeed())
|
||||||
}, 60)
|
}, 60)
|
||||||
|
|
||||||
var _ = AfterSuite(func() {
|
var _ = AfterSuite(func() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user