fix: migration from es v1 (#1462)

* handle old step1

* add migration ES V1 to operator
This commit is contained in:
Livio Amstutz 2021-03-24 09:30:45 +01:00 committed by GitHub
parent d5f54259d6
commit e7c11cb9e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 13 deletions

View File

@ -3,6 +3,7 @@ package iam
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"github.com/caos/zitadel/internal/eventstore" "github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/domain"
@ -34,6 +35,10 @@ func SetupStepMapper(event *repository.Event) (eventstore.EventReader, error) {
step := &SetupStepEvent{ step := &SetupStepEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event), BaseEvent: *eventstore.BaseEventFromRepo(event),
Done: eventstore.EventType(event.Type) == SetupDoneEventType, Done: eventstore.EventType(event.Type) == SetupDoneEventType,
Step: domain.Step1,
}
if len(event.Data) == 0 {
return step, nil
} }
err := json.Unmarshal(event.Data, step) err := json.Unmarshal(event.Data, step)
if err != nil { if err != nil {

View File

@ -3,15 +3,16 @@ package configuration
import "github.com/caos/orbos/pkg/secret" import "github.com/caos/orbos/pkg/secret"
type Configuration struct { type Configuration struct {
Tracing *Tracing `yaml:"tracing,omitempty"` Tracing *Tracing `yaml:"tracing,omitempty"`
Cache *Cache `yaml:"cache,omitempty"` Cache *Cache `yaml:"cache,omitempty"`
Secrets *Secrets `yaml:"secrets,omitempty"` Secrets *Secrets `yaml:"secrets,omitempty"`
Notifications *Notifications `yaml:"notifications,omitempty"` Notifications *Notifications `yaml:"notifications,omitempty"`
Passwords *Passwords `yaml:"passwords,omitempty"` Passwords *Passwords `yaml:"passwords,omitempty"`
DebugMode bool `yaml:"debugMode"` DebugMode bool `yaml:"debugMode"`
LogLevel string `yaml:"logLevel"` LogLevel string `yaml:"logLevel"`
DNS *DNS `yaml:"dns"` MigrateEventStoreV1 bool `yaml:"migrateEventstoreV1"`
ClusterDNS string `yaml:"clusterdns"` DNS *DNS `yaml:"dns"`
ClusterDNS string `yaml:"clusterdns"`
} }
type DNS struct { type DNS struct {

View File

@ -2,10 +2,12 @@ package configuration
import ( import (
"encoding/json" "encoding/json"
"github.com/caos/orbos/pkg/kubernetes"
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/database"
"strconv" "strconv"
"strings" "strings"
"github.com/caos/orbos/pkg/kubernetes"
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/database"
) )
const ( const (
@ -31,6 +33,7 @@ func literalsConfigMap(
"ZITADEL_KEY_PATH": secretPath + "/" + zitadelKeysPath, "ZITADEL_KEY_PATH": secretPath + "/" + zitadelKeysPath,
"ZITADEL_LOG_LEVEL": "info", "ZITADEL_LOG_LEVEL": "info",
"DEBUG_MODE": strconv.FormatBool(desired.DebugMode), "DEBUG_MODE": strconv.FormatBool(desired.DebugMode),
"ZITADEL_MIGRATE_ES_V1": strconv.FormatBool(desired.MigrateEventStoreV1),
"SMTP_TLS": tls, "SMTP_TLS": tls,
"CAOS_OIDC_DEV": "true", "CAOS_OIDC_DEV": "true",
"CR_SSL_MODE": "require", "CR_SSL_MODE": "require",

View File

@ -1,14 +1,16 @@
package configuration package configuration
import ( import (
"testing"
kubernetesmock "github.com/caos/orbos/pkg/kubernetes/mock" kubernetesmock "github.com/caos/orbos/pkg/kubernetes/mock"
"github.com/caos/orbos/pkg/secret" "github.com/caos/orbos/pkg/secret"
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/database"
"github.com/golang/mock/gomock" "github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
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"
"testing"
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/database"
) )
var ( var (
@ -191,6 +193,7 @@ func TestConfiguration_LiteralsConfigMap(t *testing.T) {
"SMTP_HOST": "", "SMTP_HOST": "",
"CAOS_OIDC_DEV": "true", "CAOS_OIDC_DEV": "true",
"DEBUG_MODE": "false", "DEBUG_MODE": "false",
"ZITADEL_MIGRATE_ES_V1": "false",
"CR_AUTH_CERT": "test/client.auth.crt", "CR_AUTH_CERT": "test/client.auth.crt",
"ZITADEL_OIDC_KEYS_ID": "", "ZITADEL_OIDC_KEYS_ID": "",
"CR_MIGRATION_CERT": "test/client.migration.crt", "CR_MIGRATION_CERT": "test/client.migration.crt",
@ -267,6 +270,7 @@ func TestConfiguration_LiteralsConfigMapFull(t *testing.T) {
"ZITADEL_ISSUER": "https://issuer.domain", "ZITADEL_ISSUER": "https://issuer.domain",
"ZITADEL_KEY_PATH": "test/test", "ZITADEL_KEY_PATH": "test/test",
"ZITADEL_LOG_LEVEL": "debug", "ZITADEL_LOG_LEVEL": "debug",
"ZITADEL_MIGRATE_ES_V1": "false",
"ZITADEL_OAUTH": "https://api.domain/oauth/v2", "ZITADEL_OAUTH": "https://api.domain/oauth/v2",
"ZITADEL_OIDC_KEYS_ID": "oidcid", "ZITADEL_OIDC_KEYS_ID": "oidcid",
"ZITADEL_OTP_VERIFICATION_KEY": "otpid", "ZITADEL_OTP_VERIFICATION_KEY": "otpid",