feat: enable running ZITADEL offline (#1894)

* feat: enable running ZITADEL offline

* refactor: move operator image to common images

* test: remove empty test
This commit is contained in:
Elio Bischof
2021-06-25 08:56:22 +00:00
committed by GitHub
parent c6c60d1d2a
commit b2b53ae9e1
44 changed files with 408 additions and 127 deletions
@@ -19,7 +19,6 @@ const (
secretPath = "/secrets/sa.json"
jobPrefix = "backup-"
jobSuffix = "-restore"
image = "ghcr.io/caos/zitadel-crbackup"
internalSecretName = "client-certs"
rootSecretName = "cockroachdb.client.root"
timeout = 15 * time.Minute
@@ -38,7 +37,7 @@ func AdaptFunc(
checkDBReady operator.EnsureFunc,
secretName string,
secretKey string,
version string,
image string,
) (
queryFunc operator.QueryFunc,
destroyFunc operator.DestroyFunc,
@@ -60,8 +59,8 @@ func AdaptFunc(
tolerations,
secretName,
secretKey,
version,
command)
command,
image)
destroyJ, err := job.AdaptFuncToDestroy(jobName, namespace)
if err != nil {
@@ -26,7 +26,7 @@ func TestBackup_Adapt1(t *testing.T) {
timestamp := "testTs"
backupName := "testName2"
bucketName := "testBucket2"
version := "testVersion"
image := "testImage2"
secretKey := "testKey"
secretName := "testSecretName"
jobName := GetJobName(backupName)
@@ -44,13 +44,13 @@ func TestBackup_Adapt1(t *testing.T) {
tolerations,
secretName,
secretKey,
version,
getCommand(
timestamp,
databases,
bucketName,
backupName,
),
image,
)
client.EXPECT().ApplyJob(jobDef).Times(1).Return(nil)
@@ -69,7 +69,7 @@ func TestBackup_Adapt1(t *testing.T) {
checkDBReady,
secretName,
secretKey,
version,
image,
)
assert.NoError(t, err)
@@ -91,7 +91,7 @@ func TestBackup_Adapt2(t *testing.T) {
timestamp := "testTs"
backupName := "testName2"
bucketName := "testBucket2"
version := "testVersion2"
image := "testImage2"
secretKey := "testKey2"
secretName := "testSecretName2"
jobName := GetJobName(backupName)
@@ -109,13 +109,13 @@ func TestBackup_Adapt2(t *testing.T) {
tolerations,
secretName,
secretKey,
version,
getCommand(
timestamp,
databases,
bucketName,
backupName,
),
image,
)
client.EXPECT().ApplyJob(jobDef).Times(1).Return(nil)
@@ -134,7 +134,7 @@ func TestBackup_Adapt2(t *testing.T) {
checkDBReady,
secretName,
secretKey,
version,
image,
)
assert.NoError(t, err)
@@ -15,9 +15,8 @@ func getJob(
tolerations []corev1.Toleration,
secretName string,
secretKey string,
version string,
command string,
image string,
) *batchv1.Job {
return &batchv1.Job{
ObjectMeta: v1.ObjectMeta{
@@ -33,7 +32,7 @@ func getJob(
RestartPolicy: corev1.RestartPolicyNever,
Containers: []corev1.Container{{
Name: nameLabels.Name(),
Image: image + ":" + version,
Image: image,
Command: []string{
"/bin/bash",
"-c",
@@ -1,25 +1,26 @@
package restore
import (
"testing"
"github.com/caos/orbos/pkg/labels"
"github.com/caos/zitadel/operator/helpers"
"github.com/stretchr/testify/assert"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"testing"
)
func TestBackup_Job1(t *testing.T) {
nodeselector := map[string]string{"test": "test"}
tolerations := []corev1.Toleration{
{Key: "testKey", Operator: "testOp"}}
version := "testVersion"
command := "test"
secretKey := "testKey"
secretName := "testSecretName"
jobName := "testJob"
namespace := "testNs"
image := "testImage"
k8sLabels := map[string]string{
"app.kubernetes.io/component": "testComponent",
"app.kubernetes.io/managed-by": "testOp",
@@ -46,7 +47,7 @@ func TestBackup_Job1(t *testing.T) {
Tolerations: tolerations,
Containers: []corev1.Container{{
Name: jobName,
Image: image + ":" + version,
Image: image,
Command: []string{
"/bin/bash",
"-c",
@@ -83,19 +84,19 @@ func TestBackup_Job1(t *testing.T) {
},
}
assert.Equal(t, equals, getJob(namespace, nameLabels, nodeselector, tolerations, secretName, secretKey, version, command))
assert.Equal(t, equals, getJob(namespace, nameLabels, nodeselector, tolerations, secretName, secretKey, command, image))
}
func TestBackup_Job2(t *testing.T) {
nodeselector := map[string]string{"test2": "test2"}
tolerations := []corev1.Toleration{
{Key: "testKey2", Operator: "testOp2"}}
version := "testVersion2"
command := "test2"
secretKey := "testKey2"
secretName := "testSecretName2"
jobName := "testJob2"
namespace := "testNs2"
testImage := "testImage2"
k8sLabels := map[string]string{
"app.kubernetes.io/component": "testComponent2",
"app.kubernetes.io/managed-by": "testOp2",
@@ -122,7 +123,7 @@ func TestBackup_Job2(t *testing.T) {
Tolerations: tolerations,
Containers: []corev1.Container{{
Name: jobName,
Image: image + ":" + version,
Image: testImage,
Command: []string{
"/bin/bash",
"-c",
@@ -159,5 +160,5 @@ func TestBackup_Job2(t *testing.T) {
},
}
assert.Equal(t, equals, getJob(namespace, nameLabels, nodeselector, tolerations, secretName, secretKey, version, command))
assert.Equal(t, equals, getJob(namespace, nameLabels, nodeselector, tolerations, secretName, secretKey, command, testImage))
}