Skip to content

Commit

Permalink
feat: migrate flagd startup argument to sources flag (#427)
Browse files Browse the repository at this point in the history
Signed-off-by: Kavindu Dodanduwa <kavindudodanduwa@gmail.com>
  • Loading branch information
Kavindu-Dodan authored Mar 31, 2023
1 parent 651c63c commit 1c67f34
Show file tree
Hide file tree
Showing 11 changed files with 346 additions and 161 deletions.
27 changes: 25 additions & 2 deletions apis/core/v1alpha1/flagsourceconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const (
SyncProviderKubernetes SyncProviderType = "kubernetes"
SyncProviderFilepath SyncProviderType = "filepath"
SyncProviderHttp SyncProviderType = "http"
SyncProviderGrpc SyncProviderType = "grpc"
SyncProviderFlagdProxy SyncProviderType = "flagd-proxy"
)

Expand Down Expand Up @@ -124,14 +125,32 @@ type FlagSourceConfigurationSpec struct {
}

type Source struct {
// Source is a URI of the flag sources
Source string `json:"source"`

// Provider type - kubernetes, http, grpc or filepath
// +optional
Provider SyncProviderType `json:"provider"`

// HttpSyncBearerToken is a bearer token. Used by http(s) sync provider only
// +optional
HttpSyncBearerToken string `json:"httpSyncBearerToken"`
// LogFormat allows for the sidecar log format to be overridden, defaults to 'json'

// TLS - Enable/Disable secure TLS connectivity. Currently used only by GRPC sync
// +optional
LogFormat string `json:"logFormat"`
TLS bool `json:"tls"`

// CertPath is a path of a certificate to be used by grpc TLS connection
// +optional
CertPath string `json:"certPath"`

// ProviderID is an identifier to be used in grpc provider
// +optional
ProviderID string `json:"providerID"`

// Selector is a flag configuration selector used by grpc provider
// +optional
Selector string `json:"selector,omitempty"`
}

// FlagSourceConfigurationStatus defines the observed state of FlagSourceConfiguration
Expand Down Expand Up @@ -351,6 +370,10 @@ func (s SyncProviderType) IsFilepath() bool {
return s == SyncProviderFilepath
}

func (s SyncProviderType) IsGrpc() bool {
return s == SyncProviderGrpc
}

func (s SyncProviderType) IsFlagdProxy() bool {
return s == SyncProviderFlagdProxy
}
Expand Down
47 changes: 26 additions & 21 deletions apis/core/v1alpha1/flagsourceconfiguration_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ func Test_FLagSourceConfiguration_SyncProvider(t *testing.T) {
k := SyncProviderKubernetes
f := SyncProviderFilepath
h := SyncProviderHttp
g := SyncProviderGrpc

require.True(t, k.IsKubernetes())
require.True(t, f.IsFilepath())
require.True(t, h.IsHttp())
require.True(t, g.IsGrpc())

require.False(t, f.IsKubernetes())
require.False(t, h.IsFilepath())
require.False(t, k.IsHttp())
require.False(t, k.IsGrpc())
require.False(t, g.IsHttp())
}

func Test_FLagSourceConfiguration_envVarKey(t *testing.T) {
Expand Down Expand Up @@ -103,10 +106,12 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) {
Tag: "tag",
Sources: []Source{
{
Source: "src1",
Provider: SyncProviderKubernetes,
HttpSyncBearerToken: "token1",
LogFormat: "log1",
Source: "src1",
Provider: SyncProviderGrpc,
TLS: true,
CertPath: "etc/cert.ca",
ProviderID: "app",
Selector: "source=database",
},
},
SyncProviderArgs: []string{"arg1", "arg2"},
Expand Down Expand Up @@ -140,10 +145,12 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) {
Tag: "tag",
Sources: []Source{
{
Source: "src1",
Provider: SyncProviderKubernetes,
HttpSyncBearerToken: "token1",
LogFormat: "log1",
Source: "src1",
Provider: SyncProviderGrpc,
TLS: true,
CertPath: "etc/cert.ca",
ProviderID: "app",
Selector: "source=database",
},
},
SyncProviderArgs: []string{"arg1", "arg2"},
Expand Down Expand Up @@ -175,10 +182,8 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) {
Tag: "tag1",
Sources: []Source{
{
Source: "src2",
Provider: SyncProviderFilepath,
HttpSyncBearerToken: "token2",
LogFormat: "log2",
Source: "src2",
Provider: SyncProviderFilepath,
},
},
SyncProviderArgs: []string{"arg3", "arg4"},
Expand Down Expand Up @@ -220,16 +225,16 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) {
Tag: "tag1",
Sources: []Source{
{
Source: "src1",
Provider: SyncProviderKubernetes,
HttpSyncBearerToken: "token1",
LogFormat: "log1",
Source: "src1",
Provider: SyncProviderGrpc,
TLS: true,
CertPath: "etc/cert.ca",
ProviderID: "app",
Selector: "source=database",
},
{
Source: "src2",
Provider: SyncProviderFilepath,
HttpSyncBearerToken: "token2",
LogFormat: "log2",
Source: "src2",
Provider: SyncProviderFilepath,
},
},
SyncProviderArgs: []string{"arg1", "arg2", "arg3", "arg4"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ func TestFlagSourceConfiguration_ConvertFrom(t *testing.T) {
Source: "source",
Provider: "provider",
HttpSyncBearerToken: "token",
LogFormat: "log2",
TLS: false,
CertPath: "/tmp/path",
ProviderID: "myapp",
Selector: "source=database",
},
},
EnvVars: []corev1.EnvVar{
Expand Down
12 changes: 10 additions & 2 deletions apis/core/v1alpha3/flagsourceconfiguration_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ func (src *FlagSourceConfiguration) ConvertTo(dstRaw conversion.Hub) error {
for _, sp := range src.Spec.Sources {
sources = append(sources, v1alpha1.Source{
Source: sp.Source,
HttpSyncBearerToken: sp.HttpSyncBearerToken,
Provider: v1alpha1.SyncProviderType(sp.Provider),
HttpSyncBearerToken: sp.HttpSyncBearerToken,
TLS: sp.TLS,
CertPath: sp.CertPath,
ProviderID: sp.ProviderID,
Selector: sp.Selector,
})
}

Expand Down Expand Up @@ -77,8 +81,12 @@ func (dst *FlagSourceConfiguration) ConvertFrom(srcRaw conversion.Hub) error {
for _, sp := range src.Spec.Sources {
sources = append(sources, Source{
Source: sp.Source,
Provider: string(sp.Provider),
Provider: SyncProviderType(sp.Provider),
HttpSyncBearerToken: sp.HttpSyncBearerToken,
TLS: sp.TLS,
CertPath: sp.CertPath,
ProviderID: sp.ProviderID,
Selector: sp.Selector,
})
}

Expand Down
18 changes: 16 additions & 2 deletions apis/core/v1alpha3/flagsourceconfiguration_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ func TestFlagSourceConfiguration_ConvertFrom(t *testing.T) {
Source: "source",
Provider: "provider",
HttpSyncBearerToken: "token",
LogFormat: "log2",
TLS: true,
CertPath: "etc/cert.ca",
ProviderID: "app",
Selector: "source=database",
},
},
EnvVars: []corev1.EnvVar{
Expand Down Expand Up @@ -79,6 +82,10 @@ func TestFlagSourceConfiguration_ConvertFrom(t *testing.T) {
Source: "source",
Provider: "provider",
HttpSyncBearerToken: "token",
TLS: true,
CertPath: "etc/cert.ca",
ProviderID: "app",
Selector: "source=database",
},
},
EnvVars: []corev1.EnvVar{
Expand Down Expand Up @@ -148,6 +155,10 @@ func TestFlagSourceConfiguration_ConvertTo(t *testing.T) {
Source: "source",
Provider: "provider",
HttpSyncBearerToken: "token",
TLS: false,
CertPath: "etc/cert.ca",
ProviderID: "app",
Selector: "source=database",
},
},
EnvVars: []corev1.EnvVar{
Expand Down Expand Up @@ -184,7 +195,10 @@ func TestFlagSourceConfiguration_ConvertTo(t *testing.T) {
Source: "source",
Provider: "provider",
HttpSyncBearerToken: "token",
LogFormat: "",
TLS: false,
CertPath: "etc/cert.ca",
ProviderID: "app",
Selector: "source=database",
},
},
EnvVars: []corev1.EnvVar{
Expand Down
23 changes: 22 additions & 1 deletion apis/core/v1alpha3/flagsourceconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,32 @@ type FlagSourceConfigurationSpec struct {
}

type Source struct {
// Source is a URI of the flag sources
Source string `json:"source"`

// Provider type - kubernetes, http(s), grpc(s) or filepath
// +optional
Provider string `json:"provider"`
Provider SyncProviderType `json:"provider"`

// HttpSyncBearerToken is a bearer token. Used by http(s) sync provider only
// +optional
HttpSyncBearerToken string `json:"httpSyncBearerToken"`

// TLS - Enable/Disable secure TLS connectivity. Currently used only by GRPC sync
// +optional
TLS bool `json:"tls"`

// CertPath is a path of a certificate to be used by grpc TLS connection
// +optional
CertPath string `json:"certPath"`

// ProviderID is an identifier to be used in grpc provider
// +optional
ProviderID string `json:"providerID"`

// Selector is a flag configuration selector used by grpc provider
// +optional
Selector string `json:"selector,omitempty"`
}

// FlagSourceConfigurationStatus defines the observed state of FlagSourceConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,32 @@ spec:
to be applied to the sidecar
items:
properties:
httpSyncBearerToken:
certPath:
description: CertPath is a path of a certificate to be used
by grpc TLS connection
type: string
logFormat:
description: LogFormat allows for the sidecar log format to
be overridden, defaults to 'json'
httpSyncBearerToken:
description: HttpSyncBearerToken is a bearer token. Used by
http(s) sync provider only
type: string
provider:
description: Provider type - kubernetes, http, grpc or filepath
type: string
providerID:
description: ProviderID is an identifier to be used in grpc
provider
type: string
selector:
description: Selector is a flag configuration selector used
by grpc provider
type: string
source:
description: Source is a URI of the flag sources
type: string
tls:
description: TLS - Enable/Disable secure TLS connectivity. Currently
used only by GRPC sync
type: boolean
required:
- source
type: object
Expand Down Expand Up @@ -480,12 +496,33 @@ spec:
configuration to be applied to the sidecar
items:
properties:
certPath:
description: CertPath is a path of a certificate to be used
by grpc TLS connection
type: string
httpSyncBearerToken:
description: HttpSyncBearerToken is a bearer token. Used by
http(s) sync provider only
type: string
provider:
description: Provider type - kubernetes, http(s), grpc(s) or
filepath
type: string
providerID:
description: ProviderID is an identifier to be used in grpc
provider
type: string
selector:
description: Selector is a flag configuration selector used
by grpc provider
type: string
source:
description: Source is a URI of the flag sources
type: string
tls:
description: TLS - Enable/Disable secure TLS connectivity. Currently
used only by GRPC sync
type: boolean
required:
- source
type: object
Expand Down
14 changes: 9 additions & 5 deletions docs/flag_source_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,15 @@ The relevant `FlagSourceConfigurations` are passed to the operator by setting th

## Source Fields

| Field | Behavior | Type |
|---------------------|---------------------------------------------------------------------------------------------------------------------------------------|-------------------|
| Source | Defines the URI of the flag source, this can be either a `host:port` or the `namespace/name` of a `FeatureFlagConfiguration` | `string` |
| Provider | Defines the provider to be used, can be set to `kubernetes`, `filepath` or `http`. If not provided the default sync provider is used. | optional `string` |
| HttpSyncBearerToken | Defines the bearer token to be used with a `http` sync. Has no effect if `Provider` is not `http` | optional `string` |
| Field | Behavior | Type |
|---------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|-------------------|
| Source | Defines the URI of the flag source, this can be either a `host:port` or the `namespace/name` of a `FeatureFlagConfiguration` | `string` |
| Provider | Defines the provider to be used, can be set to `kubernetes`, `filepath`, `http(s)` or `grpc(s)`. If not provided the default sync provider is used. | optional `string` |
| HttpSyncBearerToken | Defines the bearer token to be used with a `http` sync. Has no effect if `Provider` is not `http` | optional `string` |
| TLS | Enable/Disable secure TLS connectivity. Currently used only by GRPC sync | optional `string` |
| CertPath | Defines the certificate path to be used by grpc TLS connectivity. Has no effect on other `Provider` types | optional `string` |
| ProviderID | Defines the identifier for grpc connection. Has no effect on other `Provider` types | optional `string` |
| Selector | Defines the flag configuration selection criteria for grpc connection. Has no effect on other `Provider` types | optional `string` |

> The flagd-proxy provider type is experimental, documentation can be found [here](./kube_flagd_proxy.md)

Expand Down
4 changes: 2 additions & 2 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ kubectl describe pod busybox-curl-7bd5767999-spf7v
Host Port: 0/TCP
Args:
start
--uri
core.openfeature.dev/default/featureflagconfiguration-sample
--sources
- '[{"uri":"default/featureflagconfiguration-sample","provider":"kubernetes"}]'
Environment:
FLAGD_METRICS_PORT: 8014
```
Expand Down
Loading

0 comments on commit 1c67f34

Please sign in to comment.