mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add --experiments flag to replace --experimental (#5767)
- Deprecates the --experimental flag - Adds a new flag --experiments which supports passing multiple comma-separated values or a wildcard value. - Exposes a new endpoint /api/v2/experiments that returns the list of enabled experiments. - Deprecates the field Features.Experimental in favour of this new API. - Updates apidocgen to support type aliases (shoutout to @mtojek). - Modifies apitypings to support generating slice types. - Updates develop.sh to pass additional args after -- to $CODERD_SHIM.
This commit is contained in:
@@ -446,10 +446,19 @@ func newConfig() *codersdk.DeploymentConfig {
|
||||
Default: 512,
|
||||
},
|
||||
},
|
||||
// DEPRECATED: use Experiments instead.
|
||||
Experimental: &codersdk.DeploymentConfigField[bool]{
|
||||
Name: "Experimental",
|
||||
Usage: "Enable experimental features. Experimental features are not ready for production.",
|
||||
Flag: "experimental",
|
||||
Name: "Experimental",
|
||||
Usage: "Enable experimental features. Experimental features are not ready for production.",
|
||||
Flag: "experimental",
|
||||
Default: false,
|
||||
Hidden: true,
|
||||
},
|
||||
Experiments: &codersdk.DeploymentConfigField[[]string]{
|
||||
Name: "Experiments",
|
||||
Usage: "Enable one or more experiments. These are not ready for production. Separate multiple experiments with commas, or enter '*' to opt-in to all available experiments.",
|
||||
Flag: "experiments",
|
||||
Default: []string{},
|
||||
},
|
||||
UpdateCheck: &codersdk.DeploymentConfigField[bool]{
|
||||
Name: "Update Check",
|
||||
@@ -557,12 +566,12 @@ func setConfig(prefix string, vip *viper.Viper, target interface{}) {
|
||||
// with a comma, but Viper only supports with a space. This
|
||||
// is a small hack around it!
|
||||
rawSlice := reflect.ValueOf(vip.GetStringSlice(prefix)).Interface()
|
||||
slice, ok := rawSlice.([]string)
|
||||
stringSlice, ok := rawSlice.([]string)
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("string slice is of type %T", rawSlice))
|
||||
}
|
||||
value := make([]string, 0, len(slice))
|
||||
for _, entry := range slice {
|
||||
value := make([]string, 0, len(stringSlice))
|
||||
for _, entry := range stringSlice {
|
||||
value = append(value, strings.Split(entry, ",")...)
|
||||
}
|
||||
val.FieldByName("Value").Set(reflect.ValueOf(value))
|
||||
|
||||
@@ -232,6 +232,23 @@ func TestConfig(t *testing.T) {
|
||||
require.Equal(t, config.Prometheus.Enable.Value, true)
|
||||
require.Equal(t, config.Prometheus.Address.Value, config.Prometheus.Address.Default)
|
||||
},
|
||||
}, {
|
||||
Name: "Experiments - no features",
|
||||
Env: map[string]string{
|
||||
"CODER_EXPERIMENTS": "",
|
||||
},
|
||||
Valid: func(config *codersdk.DeploymentConfig) {
|
||||
require.Empty(t, config.Experiments.Value)
|
||||
},
|
||||
}, {
|
||||
Name: "Experiments - multiple features",
|
||||
Env: map[string]string{
|
||||
"CODER_EXPERIMENTS": "foo,bar",
|
||||
},
|
||||
Valid: func(config *codersdk.DeploymentConfig) {
|
||||
expected := []string{"foo", "bar"}
|
||||
require.ElementsMatch(t, expected, config.Experiments.Value)
|
||||
},
|
||||
}} {
|
||||
tc := tc
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
|
||||
+6
-4
@@ -61,10 +61,12 @@ Flags:
|
||||
Consumes
|
||||
$CODER_DERP_SERVER_STUN_ADDRESSES
|
||||
(default [stun.l.google.com:19302])
|
||||
--experimental Enable experimental features.
|
||||
Experimental features are not ready for
|
||||
production.
|
||||
Consumes $CODER_EXPERIMENTAL
|
||||
--experiments strings Enable one or more experiments. These are
|
||||
not ready for production. Separate
|
||||
multiple experiments with commas, or
|
||||
enter '*' to opt-in to all available
|
||||
experiments.
|
||||
Consumes $CODER_EXPERIMENTS
|
||||
-h, --help help for server
|
||||
--http-address string HTTP bind address of the server. Unset to
|
||||
disable the HTTP endpoint.
|
||||
|
||||
Reference in New Issue
Block a user