Skip to content

Commit 33baebc

Browse files
f0sselpull[bot]
authored andcommitted
fix: move experimental flag to server (#4959)
1 parent c502247 commit 33baebc

File tree

11 files changed

+29
-52
lines changed

11 files changed

+29
-52
lines changed

cli/deployment/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,11 @@ func newConfig() *codersdk.DeploymentConfig {
367367
Default: 10 * time.Minute,
368368
},
369369
},
370+
Experimental: &codersdk.DeploymentConfigField[bool]{
371+
Name: "Experimental",
372+
Usage: "Enable experimental features. Experimental features are not ready for production.",
373+
Flag: "experimental",
374+
},
370375
}
371376
}
372377

cli/root.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,10 @@ const (
5050
varNoFeatureWarning = "no-feature-warning"
5151
varForceTty = "force-tty"
5252
varVerbose = "verbose"
53-
varExperimental = "experimental"
5453
notLoggedInMessage = "You are not logged in. Try logging in using 'coder login <url>'."
5554

5655
envNoVersionCheck = "CODER_NO_VERSION_WARNING"
5756
envNoFeatureWarning = "CODER_NO_FEATURE_WARNING"
58-
envExperimental = "CODER_EXPERIMENTAL"
5957
envSessionToken = "CODER_SESSION_TOKEN"
6058
envURL = "CODER_URL"
6159
)
@@ -217,7 +215,6 @@ func Root(subcommands []*cobra.Command) *cobra.Command {
217215
cmd.PersistentFlags().Bool(varNoOpen, false, "Block automatically opening URLs in the browser.")
218216
_ = cmd.PersistentFlags().MarkHidden(varNoOpen)
219217
cliflag.Bool(cmd.PersistentFlags(), varVerbose, "v", "CODER_VERBOSE", false, "Enable verbose output.")
220-
cliflag.Bool(cmd.PersistentFlags(), varExperimental, "", envExperimental, false, "Enable experimental features. Experimental features are not ready for production.")
221218

222219
return cmd
223220
}
@@ -643,19 +640,3 @@ func (h *headerTransport) RoundTrip(req *http.Request) (*http.Response, error) {
643640
}
644641
return h.transport.RoundTrip(req)
645642
}
646-
647-
// ExperimentalEnabled returns if the experimental feature flag is enabled.
648-
func ExperimentalEnabled(cmd *cobra.Command) bool {
649-
enabled, _ := cmd.Flags().GetBool(varExperimental)
650-
return enabled
651-
}
652-
653-
// EnsureExperimental will ensure that the experimental feature flag is set if the given flag is set.
654-
func EnsureExperimental(cmd *cobra.Command, name string) error {
655-
_, set := cliflag.IsSet(cmd, name)
656-
if set && !ExperimentalEnabled(cmd) {
657-
return xerrors.Errorf("flag %s is set but requires flag --experimental or environment variable CODER_EXPERIMENTAL=true.", name)
658-
}
659-
660-
return nil
661-
}

cli/root_test.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717

1818
"github.com/coder/coder/buildinfo"
1919
"github.com/coder/coder/cli"
20-
"github.com/coder/coder/cli/cliflag"
2120
"github.com/coder/coder/cli/clitest"
2221
"github.com/coder/coder/codersdk"
2322
"github.com/coder/coder/testutil"
@@ -230,19 +229,4 @@ func TestRoot(t *testing.T) {
230229
// This won't succeed, because we're using the login cmd to assert requests.
231230
_ = cmd.Execute()
232231
})
233-
234-
t.Run("Experimental", func(t *testing.T) {
235-
t.Parallel()
236-
237-
cmd, _ := clitest.New(t, "--experimental")
238-
err := cmd.Execute()
239-
require.NoError(t, err)
240-
require.True(t, cli.ExperimentalEnabled(cmd))
241-
242-
cmd, _ = clitest.New(t, "help", "--verbose")
243-
_ = cmd.Execute()
244-
_, set := cliflag.IsSet(cmd, "verbose")
245-
require.True(t, set)
246-
require.ErrorContains(t, cli.EnsureExperimental(cmd, "verbose"), "--experimental")
247-
})
248232
}

cli/server.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,6 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
357357
AutoImportTemplates: validatedAutoImportTemplates,
358358
MetricsCacheRefreshInterval: cfg.MetricsCacheRefreshInterval.Value,
359359
AgentStatsRefreshInterval: cfg.AgentStatRefreshInterval.Value,
360-
Experimental: ExperimentalEnabled(cmd),
361360
DeploymentConfig: cfg,
362361
PrometheusRegistry: prometheus.NewRegistry(),
363362
}

cli/testdata/coder_--help.golden

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ Workspace Commands:
4444
update Update a workspace
4545

4646
Flags:
47-
--experimental Enable experimental features. Experimental features are not
48-
ready for production.
49-
Consumes $CODER_EXPERIMENTAL
5047
--global-config coder Path to the global coder config directory.
5148
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
5249
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".

cli/testdata/coder_server_--help.golden

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ Flags:
5252
Consumes
5353
$CODER_DERP_SERVER_STUN_ADDRESSES
5454
(default [stun.l.google.com:19302])
55+
--experimental Enable experimental features.
56+
Experimental features are not ready for
57+
production.
58+
Consumes $CODER_EXPERIMENTAL
5559
-h, --help help for server
5660
--oauth2-github-allow-signups Whether new users can sign up with
5761
GitHub.
@@ -190,9 +194,6 @@ Flags:
190194
Consumes $CODER_WILDCARD_ACCESS_URL
191195

192196
Global Flags:
193-
--experimental Enable experimental features. Experimental features are not
194-
ready for production.
195-
Consumes $CODER_EXPERIMENTAL
196197
--global-config coder Path to the global coder config directory.
197198
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
198199
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".

coderd/coderdtest/coderdtest.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/google/uuid"
3636
"github.com/moby/moby/pkg/namesgenerator"
3737
"github.com/spf13/afero"
38+
"github.com/spf13/pflag"
3839
"github.com/stretchr/testify/assert"
3940
"github.com/stretchr/testify/require"
4041
"golang.org/x/oauth2"
@@ -49,6 +50,8 @@ import (
4950

5051
"cdr.dev/slog"
5152
"cdr.dev/slog/sloggers/slogtest"
53+
"github.com/coder/coder/cli/config"
54+
"github.com/coder/coder/cli/deployment"
5255
"github.com/coder/coder/coderd"
5356
"github.com/coder/coder/coderd/audit"
5457
"github.com/coder/coder/coderd/autobuild/executor"
@@ -159,6 +162,9 @@ func NewOptions(t *testing.T, options *Options) (func(http.Handler), context.Can
159162
if options.Database == nil {
160163
options.Database, options.Pubsub = dbtestutil.NewDB(t)
161164
}
165+
if options.DeploymentConfig == nil {
166+
options.DeploymentConfig = DeploymentConfig(t)
167+
}
162168

163169
ctx, cancelFunc := context.WithCancel(context.Background())
164170
lifecycleExecutor := executor.New(
@@ -236,7 +242,6 @@ func NewOptions(t *testing.T, options *Options) (func(http.Handler), context.Can
236242
CacheDir: t.TempDir(),
237243
Database: options.Database,
238244
Pubsub: options.Pubsub,
239-
Experimental: options.Experimental,
240245
GitAuthConfigs: options.GitAuthConfigs,
241246

242247
Auditor: options.Auditor,
@@ -903,3 +908,13 @@ d8h4Ht09E+f3nhTEc87mODkl7WJZpHL6V2sORfeq/eIkds+H6CJ4hy5w/bSw8tjf
903908
sz9Di8sGIaUbLZI2rd0CQQCzlVwEtRtoNCyMJTTrkgUuNufLP19RZ5FpyXxBO5/u
904909
QastnN77KfUwdj3SJt44U/uh1jAIv4oSLBr8HYUkbnI8
905910
-----END RSA PRIVATE KEY-----`
911+
912+
func DeploymentConfig(t *testing.T) *codersdk.DeploymentConfig {
913+
vip := deployment.NewViper()
914+
fs := pflag.NewFlagSet(randomUsername(), pflag.ContinueOnError)
915+
fs.String(config.FlagName, randomUsername(), randomUsername())
916+
cfg, err := deployment.Config(fs, vip)
917+
require.NoError(t, err)
918+
919+
return cfg
920+
}

coderd/deploymentconfig_test.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ import (
44
"context"
55
"testing"
66

7-
"github.com/spf13/pflag"
87
"github.com/stretchr/testify/require"
98

10-
"github.com/coder/coder/cli/config"
11-
"github.com/coder/coder/cli/deployment"
129
"github.com/coder/coder/coderd/coderdtest"
1310
"github.com/coder/coder/testutil"
1411
)
@@ -18,11 +15,7 @@ func TestDeploymentConfig(t *testing.T) {
1815
hi := "hi"
1916
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
2017
defer cancel()
21-
vip := deployment.NewViper()
22-
fs := pflag.NewFlagSet("test", pflag.ContinueOnError)
23-
fs.String(config.FlagName, hi, "usage")
24-
cfg, err := deployment.Config(fs, vip)
25-
require.NoError(t, err)
18+
cfg := coderdtest.DeploymentConfig(t)
2619
// values should be returned
2720
cfg.AccessURL.Value = hi
2821
// values should not be returned

codersdk/deploymentconfig.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type DeploymentConfig struct {
3939
SCIMAPIKey *DeploymentConfigField[string] `json:"scim_api_key" typescript:",notnull"`
4040
UserWorkspaceQuota *DeploymentConfigField[int] `json:"user_workspace_quota" typescript:",notnull"`
4141
Provisioner *ProvisionerConfig `json:"provisioner" typescript:",notnull"`
42+
Experimental *DeploymentConfigField[bool] `json:"experimental" typescript:",notnull"`
4243
}
4344

4445
type DERP struct {

enterprise/coderd/coderd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func (api *API) updateEntitlements(ctx context.Context) error {
232232
if err != nil {
233233
return err
234234
}
235-
entitlements.Experimental = api.Experimental
235+
entitlements.Experimental = api.DeploymentConfig.Experimental.Value
236236

237237
featureChanged := func(featureName string) (changed bool, enabled bool) {
238238
if api.entitlements.Features == nil {

site/src/api/typesGenerated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ export interface DeploymentConfig {
303303
readonly scim_api_key: DeploymentConfigField<string>
304304
readonly user_workspace_quota: DeploymentConfigField<number>
305305
readonly provisioner: ProvisionerConfig
306+
readonly experimental: DeploymentConfigField<boolean>
306307
}
307308

308309
// From codersdk/deploymentconfig.go

0 commit comments

Comments
 (0)