Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/flipt-io/flipt
Browse files Browse the repository at this point in the history
* 'main' of https://github.com/flipt-io/flipt:
  feat: default variants (#3271)
  • Loading branch information
markphelps committed Jul 23, 2024
2 parents 147555d + 97b0bc3 commit 24b7946
Show file tree
Hide file tree
Showing 64 changed files with 2,610 additions and 1,030 deletions.
2 changes: 1 addition & 1 deletion build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (f *Flipt) Base(ctx context.Context, source *dagger.Directory) (*Container,
return f.BaseContainer, err
}

// Return container with Flipt binariesin a thinner alpine distribution
// Return container with Flipt binaries in a thinner alpine distribution
func (f *Flipt) Build(ctx context.Context, source *dagger.Directory) (*Container, error) {
base, err := f.Base(ctx, source)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion build/testing/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ segments:
value: buzz
`

expectedYAMLStreamOutput = `version: "1.2"
expectedYAMLStreamOutput = `version: "1.3"
namespace: default
---
namespace: foo
Expand Down
22 changes: 11 additions & 11 deletions build/testing/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func Integration(ctx context.Context, client *dagger.Client, base, flipt *dagger
name := strings.ToLower(replacer.Replace(fmt.Sprintf("flipt-test-%s-config-%s", caseName, config.name)))
flipt = flipt.
WithEnvVariable("CI", os.Getenv("CI")).
WithEnvVariable("FLIPT_LOG_LEVEL", "debug").
WithEnvVariable("FLIPT_LOG_LEVEL", "WARN").
WithExposedPort(config.port)

if exportLogs {
Expand Down Expand Up @@ -344,7 +344,7 @@ func withCockroach(fn testCaseFn) testCaseFn {

func cache(ctx context.Context, _ *dagger.Client, base, flipt *dagger.Container, conf testConfig) func() error {
flipt = flipt.
WithEnvVariable("FLIPT_LOG_LEVEL", "DEBUG").
WithEnvVariable("FLIPT_LOG_LEVEL", "WARN").
WithEnvVariable("FLIPT_CACHE_ENABLED", "true").
WithEnvVariable("FLIPT_CACHE_TTL", "1s")

Expand All @@ -369,7 +369,7 @@ func cacheWithTLS(ctx context.Context, client *dagger.Client, base, flipt *dagge
AsService()

flipt = flipt.
WithEnvVariable("FLIPT_LOG_LEVEL", "DEBUG").
WithEnvVariable("FLIPT_LOG_LEVEL", "WARN").
WithEnvVariable("FLIPT_CACHE_ENABLED", "true").
WithEnvVariable("FLIPT_CACHE_TTL", "1s").
WithEnvVariable("FLIPT_CACHE_BACKEND", "redis").
Expand All @@ -389,7 +389,7 @@ const (
func local(ctx context.Context, client *dagger.Client, base, flipt *dagger.Container, conf testConfig) func() error {
flipt = flipt.
WithDirectory("/tmp/testdata", base.Directory(singleRevisionTestdataDir)).
WithEnvVariable("FLIPT_LOG_LEVEL", "DEBUG").
WithEnvVariable("FLIPT_LOG_LEVEL", "WARN").
WithEnvVariable("FLIPT_STORAGE_TYPE", "local").
WithEnvVariable("FLIPT_STORAGE_LOCAL_PATH", "/tmp/testdata").
WithEnvVariable("UNIQUE", uuid.New().String())
Expand Down Expand Up @@ -454,7 +454,7 @@ func git(ctx context.Context, client *dagger.Client, base, flipt *dagger.Contain

flipt = flipt.
WithServiceBinding("gitea", gitea.AsService()).
WithEnvVariable("FLIPT_LOG_LEVEL", "DEBUG").
WithEnvVariable("FLIPT_LOG_LEVEL", "WARN").
WithEnvVariable("FLIPT_STORAGE_TYPE", "git").
WithEnvVariable("FLIPT_STORAGE_GIT_REPOSITORY", "http://gitea:3000/root/features.git").
WithEnvVariable("FLIPT_STORAGE_GIT_AUTHENTICATION_BASIC_USERNAME", "root").
Expand Down Expand Up @@ -490,7 +490,7 @@ func s3(ctx context.Context, client *dagger.Client, base, flipt *dagger.Containe

flipt = flipt.
WithServiceBinding("minio", minio).
WithEnvVariable("FLIPT_LOG_LEVEL", "DEBUG").
WithEnvVariable("FLIPT_LOG_LEVEL", "WARN").
WithEnvVariable("AWS_ACCESS_KEY_ID", "user").
WithEnvVariable("AWS_SECRET_ACCESS_KEY", "password").
WithEnvVariable("FLIPT_STORAGE_TYPE", "object").
Expand Down Expand Up @@ -554,7 +554,7 @@ func oci(ctx context.Context, client *dagger.Client, base, flipt *dagger.Contain

flipt = flipt.
WithServiceBinding("zot", zot.AsService()).
WithEnvVariable("FLIPT_LOG_LEVEL", "DEBUG").
WithEnvVariable("FLIPT_LOG_LEVEL", "WARN").
WithEnvVariable("FLIPT_STORAGE_TYPE", "oci").
WithEnvVariable("FLIPT_STORAGE_OCI_REPOSITORY", "http://zot:5000/readonly:latest").
WithEnvVariable("FLIPT_STORAGE_OCI_AUTHENTICATION_USERNAME", "username").
Expand Down Expand Up @@ -619,7 +619,7 @@ func importExport(ctx context.Context, _ *dagger.Client, base, flipt *dagger.Con

if ns == "default" {
// replace namespace in expected yaml
expected = strings.ReplaceAll(expected, "version: \"1.2\"\n", fmt.Sprintf("version: \"1.2\"\nnamespace: %s\n", ns))
expected = strings.ReplaceAll(expected, "version: \"1.3\"\n", fmt.Sprintf("version: \"1.3\"\nnamespace: %s\n", ns))
}

if ns != "default" {
Expand Down Expand Up @@ -870,7 +870,7 @@ func azblob(ctx context.Context, client *dagger.Client, base, flipt *dagger.Cont

flipt = flipt.
WithServiceBinding("azurite", azurite).
WithEnvVariable("FLIPT_LOG_LEVEL", "DEBUG").
WithEnvVariable("FLIPT_LOG_LEVEL", "WARN").
WithEnvVariable("FLIPT_STORAGE_TYPE", "object").
WithEnvVariable("FLIPT_STORAGE_OBJECT_TYPE", "azblob").
WithEnvVariable("FLIPT_STORAGE_OBJECT_AZBLOB_ENDPOINT", "http://azurite:10000/devstoreaccount1").
Expand Down Expand Up @@ -902,7 +902,7 @@ func gcs(ctx context.Context, client *dagger.Client, base, flipt *dagger.Contain

flipt = flipt.
WithServiceBinding("gcs", gcs).
WithEnvVariable("FLIPT_LOG_LEVEL", "DEBUG").
WithEnvVariable("FLIPT_LOG_LEVEL", "WARN").
WithEnvVariable("FLIPT_STORAGE_TYPE", "object").
WithEnvVariable("FLIPT_STORAGE_OBJECT_TYPE", "googlecloud").
WithEnvVariable("FLIPT_STORAGE_OBJECT_GOOGLECLOUD_BUCKET", "testdata").
Expand Down Expand Up @@ -1014,7 +1014,7 @@ func serveOIDC(_ context.Context, _ *dagger.Client, base, flipt *dagger.Containe
})

return flipt.
WithEnvVariable("FLIPT_LOG_LEVEL", "debug").
WithEnvVariable("FLIPT_LOG_LEVEL", "WARN").
WithEnvVariable("FLIPT_AUTHENTICATION_METHODS_KUBERNETES_DISCOVERY_URL", "https://discover.svc").
WithServiceBinding("discover.svc", base.
WithNewFile("/server.crt", dagger.ContainerWithNewFileOpts{
Expand Down
25 changes: 24 additions & 1 deletion build/testing/integration/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func API(t *testing.T, ctx context.Context, opts integration.TestOpts) {

assert.Equal(t, "Test 2", updated.Name)

t.Log("List all Flags error with invalid page token")
t.Log("List all flags error with invalid page token")

_, err = client.Flipt().ListFlags(ctx, &flipt.ListFlagRequest{
NamespaceKey: namespace.Key,
Expand Down Expand Up @@ -259,6 +259,29 @@ func API(t *testing.T, ctx context.Context, opts integration.TestOpts) {

assert.Equal(t, "one", updatedVariant.Key)
assert.Equal(t, "One", updatedVariant.Name)

t.Log("Set default variant for flag \"test\".")

_, err = client.Flipt().UpdateFlag(ctx, &flipt.UpdateFlagRequest{
NamespaceKey: namespace.Key,
Key: enabled.Key,
Name: "Test 2",
Description: enabled.Description,
Enabled: true,
DefaultVariantId: updatedVariant.Id,
})

require.NoError(t, err)

flag, err = client.Flipt().GetFlag(ctx, &flipt.GetFlagRequest{
NamespaceKey: namespace.Key,
Key: enabled.Key,
})

require.NoError(t, err)
assert.Equal(t, updatedVariant.Id, flag.DefaultVariant.Id)
assert.Equal(t, updatedVariant.Key, flag.DefaultVariant.Key)
assert.Equal(t, updatedVariant.Name, flag.DefaultVariant.Name)
})

t.Run("Segments and Constraints", func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "1.2"
version: "1.3"
flags:
- key: flag_001
name: FLAG_001
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "1.2"
version: "1.3"
namespace: production
flags:
- key: flag_001
Expand Down
1 change: 1 addition & 0 deletions config/migrations/cockroachdb/11_default_variant.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE flags ADD COLUMN default_variant_id VARCHAR(255) REFERENCES variants(id) ON DELETE SET NULL;
1 change: 1 addition & 0 deletions config/migrations/mysql/13_default_variant.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `flags` ADD COLUMN `default_variant_id` VARCHAR(255) REFERENCES variants(`id`) ON DELETE SET NULL;
1 change: 1 addition & 0 deletions config/migrations/postgres/14_default_variant.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE flags ADD COLUMN default_variant_id VARCHAR(255) REFERENCES variants(id) ON DELETE SET NULL;
1 change: 1 addition & 0 deletions config/migrations/sqlite3/13_default_variant.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `flags` ADD COLUMN `default_variant_id` VARCHAR(255) REFERENCES variants(`id`) ON DELETE SET NULL;
11 changes: 7 additions & 4 deletions core/validation/flipt.cue
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
version: "1.0" | "1.1" | "1.2" | *"1.3"

close({
version: "1.0" | "1.1" | *"1.2"
namespace: string & =~"^[-_,A-Za-z0-9]+$" | *"default"
flags: [...{_version: version} & #Flag]
flags: [...#Flag]
segments: [...#Segment]
})

#Flag: {
_version: string
key: string & =~"^[-_,A-Za-z0-9]+$"
name: string & =~"^.+$"
description?: string
enabled: bool | *false
variants: [...#Variant]
rules: [...#Rule]
if _version == "1.1" || _version == "1.2" {
if version == "1.1" || version == "1.2" || version == "1.3" {
type: "BOOLEAN_FLAG_TYPE" | *"VARIANT_FLAG_TYPE"
#FlagBoolean | *{}
}
Expand All @@ -32,6 +32,9 @@ close({
name?: string & =~"^.+$"
description?: string
attachment: {...} | [...] | *null
if version == "1.3" {
default: bool | *false
}
}

#RuleSegment: {
Expand Down
Loading

0 comments on commit 24b7946

Please sign in to comment.