Skip to content

Commit 24e2ecd

Browse files
authored
Skip admin email prompt when using new platform activation flow (#3385)
* Skip admin email prompt when using new platform activation flow
1 parent 8d3daf7 commit 24e2ecd

File tree

2 files changed

+85
-3
lines changed

2 files changed

+85
-3
lines changed

cmd/vclusterctl/cmd/platform/start.go

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ before running this command:
8686
}
8787

8888
func (cmd *StartCmd) Run(ctx context.Context) error {
89-
// get version to deploy
89+
// get the version to deploy
9090
if cmd.Version == "latest" || cmd.Version == "" {
9191
cmd.Version = platform.MinimumVersionTag
9292
latestVersion, err := platform.LatestCompatibleVersion(ctx)
@@ -154,8 +154,10 @@ func (cmd *StartCmd) Run(ctx context.Context) error {
154154
}
155155
}
156156

157-
if err := cmd.ensureEmailWithDisclaimer(ctx, cmd.KubeClient, cmd.Namespace); err != nil {
158-
return err
157+
if !cmd.platformUsesNewActivationFlow(cmd.Version) {
158+
if err := cmd.ensureEmailWithDisclaimer(ctx, cmd.KubeClient, cmd.Namespace); err != nil {
159+
return err
160+
}
159161
}
160162

161163
return start.NewLoftStarter(cmd.StartOptions).Start(ctx)
@@ -192,6 +194,39 @@ Privacy Statement: https://www.loft.sh/legal/privacy
192194
return nil
193195
}
194196

197+
// platformUsesNewActivationFlow checks if the platform version supports the new platform activation flow.
198+
//
199+
// The new platform activation flow is supported for the following platform versions:
200+
// 1. GA version >= 4.6.0,
201+
// 2. Preview version 4.6.0-next.internal.X, where X >= 1.
202+
func (cmd *StartCmd) platformUsesNewActivationFlow(platformVersion string) bool {
203+
platformSemVerVersion, err := semver.ParseTolerant(platformVersion)
204+
if err != nil {
205+
cmd.Log.Warnf("Failed to parse platform version %s, falling back to the old platform activation flow with the admin email prompt", platformVersion)
206+
return false
207+
}
208+
209+
const minGAVersion = "4.6.0"
210+
if platformSemVerVersion.GTE(semver.MustParse(minGAVersion)) {
211+
cmd.Log.Debugf("Platform version %s is greater than or equal to %s, platform is using the new activation flow, so skipping admin email prompt", platformVersion, minGAVersion)
212+
return true
213+
}
214+
215+
if platformSemVerVersion.Major == 4 &&
216+
platformSemVerVersion.Minor == 6 &&
217+
platformSemVerVersion.Patch == 0 &&
218+
len(platformSemVerVersion.Pre) == 3 &&
219+
platformSemVerVersion.Pre[0].VersionStr == "next" &&
220+
platformSemVerVersion.Pre[1].VersionStr == "internal" &&
221+
platformSemVerVersion.Pre[2].VersionNum >= 1 {
222+
cmd.Log.Debugf("Platform version %s is the development version that is using the new activation flow, so skipping admin email prompt", platformVersion)
223+
return true
224+
}
225+
226+
cmd.Log.Debugf("Platform version %s is not using the new activation flow, so admin email is required", platformVersion)
227+
return false
228+
}
229+
195230
func promptForEmail(emailAddress string) (string, error) {
196231
if err := validateEmail(emailAddress); err != nil {
197232
return survey.NewSurvey().Question(&survey.QuestionOptions{
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package platform
2+
3+
import (
4+
"testing"
5+
6+
"github.com/loft-sh/log"
7+
"github.com/loft-sh/vcluster/pkg/cli/flags"
8+
"github.com/loft-sh/vcluster/pkg/cli/start"
9+
)
10+
11+
func TestPlatformUsesNewActivationFlow(t *testing.T) {
12+
testCases := []struct {
13+
version string
14+
expected bool
15+
}{
16+
{"", false},
17+
{"dev", false},
18+
{"4.5.0", false},
19+
{"v4.5.0", false},
20+
{"4.5.1", false},
21+
{"4.6.0-alpha.5", false},
22+
{"4.6.0-next.2", false},
23+
{"4.6.0-next.internal.0", false},
24+
{"4.6.0-next.internal.1", true},
25+
{"4.6.0-next.internal.2", true},
26+
{"4.6.0", true},
27+
{"v4.6.0", true},
28+
}
29+
30+
globalFlags := &flags.GlobalFlags{}
31+
startCmd := &StartCmd{
32+
StartOptions: start.StartOptions{
33+
Options: start.Options{
34+
CommandName: "start",
35+
GlobalFlags: globalFlags,
36+
Log: log.GetInstance(),
37+
},
38+
},
39+
}
40+
41+
for _, testCase := range testCases {
42+
result := startCmd.platformUsesNewActivationFlow(testCase.version)
43+
if result != testCase.expected {
44+
t.Errorf("Expected %v, got %v for platform version %s", testCase.expected, result, testCase.version)
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)