fix: env.json caching, readiness and unique lockerIDs (#3596)

* fix: readiness check

* disable cache for env.json

* always generate unique lockerID

* fix tests
This commit is contained in:
Livio Amstutz
2022-05-04 17:09:49 +02:00
committed by GitHub
parent 929ed8745a
commit 94e420bb24
11 changed files with 8 additions and 276 deletions

View File

@@ -11,7 +11,6 @@ import (
"golang.org/x/text/language"
"github.com/zitadel/zitadel/internal/api/authz"
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/query/projection"
)
@@ -56,14 +55,6 @@ var (
name: projection.InstanceColumnConsoleAppID,
table: instanceTable,
}
InstanceColumnSetupStarted = Column{
name: projection.InstanceColumnSetUpStarted,
table: instanceTable,
}
InstanceColumnSetupDone = Column{
name: projection.InstanceColumnSetUpDone,
table: instanceTable,
}
InstanceColumnDefaultLanguage = Column{
name: projection.InstanceColumnDefaultLanguage,
table: instanceTable,
@@ -82,8 +73,6 @@ type Instance struct {
ConsoleID string
ConsoleAppID string
DefaultLang language.Tag
SetupStarted domain.Step
SetupDone domain.Step
Domains []*InstanceDomain
host string
}
@@ -211,8 +200,6 @@ func prepareInstanceQuery(host string) (sq.SelectBuilder, func(*sql.Row) (*Insta
InstanceColumnProjectID.identifier(),
InstanceColumnConsoleID.identifier(),
InstanceColumnConsoleAppID.identifier(),
InstanceColumnSetupStarted.identifier(),
InstanceColumnSetupDone.identifier(),
InstanceColumnDefaultLanguage.identifier(),
).
From(instanceTable.identifier()).PlaceholderFormat(sq.Dollar),
@@ -228,8 +215,6 @@ func prepareInstanceQuery(host string) (sq.SelectBuilder, func(*sql.Row) (*Insta
&instance.IAMProjectID,
&instance.ConsoleID,
&instance.ConsoleAppID,
&instance.SetupStarted,
&instance.SetupDone,
&lang,
)
if err != nil {
@@ -254,8 +239,6 @@ func prepareInstancesQuery() (sq.SelectBuilder, func(*sql.Rows) (*Instances, err
InstanceColumnProjectID.identifier(),
InstanceColumnConsoleID.identifier(),
InstanceColumnConsoleAppID.identifier(),
InstanceColumnSetupStarted.identifier(),
InstanceColumnSetupDone.identifier(),
InstanceColumnDefaultLanguage.identifier(),
countColumn.identifier(),
).From(instanceTable.identifier()).PlaceholderFormat(sq.Dollar),
@@ -276,8 +259,6 @@ func prepareInstancesQuery() (sq.SelectBuilder, func(*sql.Rows) (*Instances, err
&instance.IAMProjectID,
&instance.ConsoleID,
&instance.ConsoleAppID,
&instance.SetupStarted,
&instance.SetupDone,
&lang,
&count,
)
@@ -312,8 +293,6 @@ func prepareInstanceDomainQuery(host string) (sq.SelectBuilder, func(*sql.Rows)
InstanceColumnProjectID.identifier(),
InstanceColumnConsoleID.identifier(),
InstanceColumnConsoleAppID.identifier(),
InstanceColumnSetupStarted.identifier(),
InstanceColumnSetupDone.identifier(),
InstanceColumnDefaultLanguage.identifier(),
InstanceDomainDomainCol.identifier(),
InstanceDomainIsPrimaryCol.identifier(),
@@ -350,8 +329,6 @@ func prepareInstanceDomainQuery(host string) (sq.SelectBuilder, func(*sql.Rows)
&instance.IAMProjectID,
&instance.ConsoleID,
&instance.ConsoleAppID,
&instance.SetupStarted,
&instance.SetupDone,
&lang,
&domain,
&isPrimary,

View File

@@ -11,7 +11,6 @@ import (
sq "github.com/Masterminds/squirrel"
"golang.org/x/text/language"
"github.com/zitadel/zitadel/internal/domain"
errs "github.com/zitadel/zitadel/internal/errors"
)
@@ -41,8 +40,6 @@ func Test_InstancePrepares(t *testing.T) {
` projections.instances.iam_project_id,`+
` projections.instances.console_client_id,`+
` projections.instances.console_app_id,`+
` projections.instances.setup_started,`+
` projections.instances.setup_done,`+
` projections.instances.default_language`+
` FROM projections.instances`),
nil,
@@ -72,8 +69,6 @@ func Test_InstancePrepares(t *testing.T) {
` projections.instances.iam_project_id,`+
` projections.instances.console_client_id,`+
` projections.instances.console_app_id,`+
` projections.instances.setup_started,`+
` projections.instances.setup_done,`+
` projections.instances.default_language`+
` FROM projections.instances`),
[]string{
@@ -85,8 +80,6 @@ func Test_InstancePrepares(t *testing.T) {
"iam_project_id",
"console_client_id",
"console_app_id",
"setup_started",
"setup_done",
"default_language",
},
[]driver.Value{
@@ -98,8 +91,6 @@ func Test_InstancePrepares(t *testing.T) {
"project-id",
"client-id",
"app-id",
domain.Step2,
domain.Step1,
"en",
},
),
@@ -113,8 +104,6 @@ func Test_InstancePrepares(t *testing.T) {
IAMProjectID: "project-id",
ConsoleID: "client-id",
ConsoleAppID: "app-id",
SetupStarted: domain.Step2,
SetupDone: domain.Step1,
DefaultLang: language.English,
},
},
@@ -133,8 +122,6 @@ func Test_InstancePrepares(t *testing.T) {
` projections.instances.iam_project_id,`+
` projections.instances.console_client_id,`+
` projections.instances.console_app_id,`+
` projections.instances.setup_started,`+
` projections.instances.setup_done,`+
` projections.instances.default_language`+
` FROM projections.instances`),
sql.ErrConnDone,

View File

@@ -22,8 +22,6 @@ const (
InstanceColumnConsoleID = "console_client_id"
InstanceColumnConsoleAppID = "console_app_id"
InstanceColumnSequence = "sequence"
InstanceColumnSetUpStarted = "setup_started"
InstanceColumnSetUpDone = "setup_done"
InstanceColumnDefaultLanguage = "default_language"
)
@@ -46,8 +44,6 @@ func NewInstanceProjection(ctx context.Context, config crdb.StatementHandlerConf
crdb.NewColumn(InstanceColumnConsoleID, crdb.ColumnTypeText, crdb.Default("")),
crdb.NewColumn(InstanceColumnConsoleAppID, crdb.ColumnTypeText, crdb.Default("")),
crdb.NewColumn(InstanceColumnSequence, crdb.ColumnTypeInt64),
crdb.NewColumn(InstanceColumnSetUpStarted, crdb.ColumnTypeInt64, crdb.Default(0)),
crdb.NewColumn(InstanceColumnSetUpDone, crdb.ColumnTypeInt64, crdb.Default(0)),
crdb.NewColumn(InstanceColumnDefaultLanguage, crdb.ColumnTypeText, crdb.Default("")),
},
crdb.NewPrimaryKey(InstanceColumnID),
@@ -82,14 +78,6 @@ func (p *InstanceProjection) reducers() []handler.AggregateReducer {
Event: instance.DefaultLanguageSetEventType,
Reduce: p.reduceDefaultLanguageSet,
},
{
Event: instance.SetupStartedEventType,
Reduce: p.reduceSetupEvent,
},
{
Event: instance.SetupDoneEventType,
Reduce: p.reduceSetupEvent,
},
},
},
}
@@ -184,24 +172,3 @@ func (p *InstanceProjection) reduceDefaultLanguageSet(event eventstore.Event) (*
},
), nil
}
func (p *InstanceProjection) reduceSetupEvent(event eventstore.Event) (*handler.Statement, error) {
e, ok := event.(*instance.SetupStepEvent)
if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-d9nfw", "reduce.wrong.event.type %v", []eventstore.EventType{instance.SetupDoneEventType, instance.SetupStartedEventType})
}
columns := []handler.Column{
handler.NewCol(InstanceColumnID, e.Aggregate().InstanceID),
handler.NewCol(InstanceColumnChangeDate, e.CreationDate()),
handler.NewCol(InstanceColumnSequence, e.Sequence()),
}
if e.EventType == instance.SetupStartedEventType {
columns = append(columns, handler.NewCol(InstanceColumnSetUpStarted, e.Step))
} else {
columns = append(columns, handler.NewCol(InstanceColumnSetUpDone, e.Step))
}
return crdb.NewUpsertStatement(
e,
columns,
), nil
}

View File

@@ -3,7 +3,6 @@ package projection
import (
"testing"
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/handler"
@@ -141,66 +140,6 @@ func TestInstanceProjection_reduces(t *testing.T) {
},
},
},
{
name: "reduceSetupStarted",
args: args{
event: getEvent(testEvent(
repository.EventType(instance.SetupStartedEventType),
instance.AggregateType,
[]byte(`{"Step": 1}`),
), instance.SetupStepMapper),
},
reduce: (&InstanceProjection{}).reduceSetupEvent,
want: wantReduce{
projection: InstanceProjectionTable,
aggregateType: eventstore.AggregateType("instance"),
sequence: 15,
previousSequence: 10,
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPSERT INTO projections.instances (id, change_date, sequence, setup_started) VALUES ($1, $2, $3, $4)",
expectedArgs: []interface{}{
"instance-id",
anyArg{},
uint64(15),
domain.Step1,
},
},
},
},
},
},
{
name: "reduceSetupDone",
args: args{
event: getEvent(testEvent(
repository.EventType(instance.SetupDoneEventType),
instance.AggregateType,
[]byte(`{"Step": 1}`),
), instance.SetupStepMapper),
},
reduce: (&InstanceProjection{}).reduceSetupEvent,
want: wantReduce{
projection: InstanceProjectionTable,
aggregateType: eventstore.AggregateType("instance"),
sequence: 15,
previousSequence: 10,
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPSERT INTO projections.instances (id, change_date, sequence, setup_done) VALUES ($1, $2, $3, $4)",
expectedArgs: []interface{}{
"instance-id",
anyArg{},
uint64(15),
domain.Step1,
},
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {