9393 DisableRollback bool
9494 DisableTelemetry bool
9595 FromRepo bool
96- Version * semver.Version
9796 GsCloneOpts * apgit.CloneOptions
9897 InsCloneOpts * apgit.CloneOptions
9998 GitIntegrationCreationOpts * apmodel.AddGitIntegrationArgs
@@ -119,6 +118,7 @@ type (
119118 gitProvider cfgit.Provider
120119 useGatewayAPI bool
121120 featuresToInstall []runtime.InstallFeature
121+ runtimeDef string
122122 }
123123
124124 tunnelServer struct {
@@ -254,6 +254,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
254254 cmd .Flags ().StringToStringVar (& installationOpts .InternalIngressAnnotation , "internal-ingress-annotation" , nil , "Add annotations to the internal ingress" )
255255 cmd .Flags ().StringToStringVar (& installationOpts .ExternalIngressAnnotation , "external-ingress-annotation" , nil , "Add annotations to the external ingress" )
256256 cmd .Flags ().BoolVar (& installationOpts .EnableGitProviders , "enable-git-providers" , false , "Enable git providers (bitbucket|bitbucket-server|gitlab)" )
257+ cmd .Flags ().StringVar (& installationOpts .runtimeDef , "runtime-def" , store .RuntimeDefURL , "Install runtime from a specific manifest" )
257258 cmd .Flags ().StringVar (& accessMode , "access-mode" , string (platmodel .AccessModeIngress ), "The access mode to the cluster, one of: ingress|tunnel" )
258259 cmd .Flags ().StringVar (& installationOpts .TunnelRegisterHost , "tunnel-register-host" , "register-tunnels.cf-cd.com" , "The host name for registering a new tunnel" )
259260 cmd .Flags ().StringVar (& installationOpts .TunnelDomain , "tunnel-domain" , "tunnels.cf-cd.com" , "The base domain for the tunnels" )
@@ -278,6 +279,9 @@ func NewRuntimeInstallCommand() *cobra.Command {
278279 util .Die (cmd .Flags ().MarkHidden ("tunnel-register-host" ))
279280 util .Die (cmd .Flags ().MarkHidden ("tunnel-domain" ))
280281 util .Die (cmd .Flags ().MarkHidden ("ips-allow-list" ))
282+ util .Die (cmd .Flags ().MarkHidden ("runtime-def" ))
283+ cmd .MarkFlagsMutuallyExclusive ("runtime-def" , "version" )
284+ cmd .MarkFlagsMutuallyExclusive ("runtime-def" , "set-default-resources" )
281285
282286 return cmd
283287}
@@ -288,12 +292,8 @@ func runtimeInstallCommandPreRunHandler(cmd *cobra.Command, opts *RuntimeInstall
288292
289293 handleCliStep (reporter .InstallPhasePreCheckStart , "Starting pre checks" , nil , true , false )
290294
291- opts . Version , err = getVersionIfExists (opts .versionStr )
295+ err = validateVersionIfExists (opts .versionStr )
292296 handleCliStep (reporter .InstallStepPreCheckValidateRuntimeVersion , "Validating runtime version" , err , true , false )
293- if err != nil {
294- return err
295- }
296-
297297 if opts .RuntimeName == "" {
298298 if ! store .Get ().Silent {
299299 opts .RuntimeName , err = getRuntimeNameFromUserInput ()
@@ -597,19 +597,14 @@ func createRuntimeOnPlatform(ctx context.Context, opts *RuntimeInstallOptions, r
597597}
598598
599599func runRuntimeInstall (ctx context.Context , opts * RuntimeInstallOptions ) error {
600- err := preInstallationChecks (ctx , opts )
600+ rt , err := preInstallationChecks (ctx , opts )
601601 handleCliStep (reporter .InstallPhaseRunPreCheckFinish , "Pre run installation checks" , err , true , true )
602602 if err != nil {
603603 return fmt .Errorf ("pre installation checks failed: %w" , err )
604604 }
605605
606606 handleCliStep (reporter .InstallPhaseStart , "Runtime installation phase started" , nil , false , true )
607607
608- rt , err := runtimeInstallPreparations (opts )
609- if err != nil {
610- return err
611- }
612-
613608 if opts .FromRepo {
614609 // in case of a runtime recovery, we don't want to clear the repo when failure occures
615610 opts .DisableRollback = true
@@ -781,22 +776,6 @@ To complete the installation:
781776 return nil
782777}
783778
784- func runtimeInstallPreparations (opts * RuntimeInstallOptions ) (* runtime.Runtime , error ) {
785- rt , err := runtime .Download (opts .Version , opts .RuntimeName , opts .featuresToInstall )
786- handleCliStep (reporter .InstallStepDownloadRuntimeDefinition , "Downloading runtime definition" , err , false , true )
787- if err != nil {
788- return nil , fmt .Errorf ("failed to download runtime definition: %w" , err )
789- }
790-
791- rt .Spec .Cluster , err = util .KubeServerByContextName (opts .kubeContext , opts .kubeconfig )
792- handleCliStep (reporter .InstallStepGetServerAddress , "Getting kube server address" , err , false , true )
793- if err != nil {
794- return nil , fmt .Errorf ("failed to get current server address: %w" , err )
795- }
796-
797- return rt , nil
798- }
799-
800779func createRuntimeComponents (ctx context.Context , opts * RuntimeInstallOptions , rt * runtime.Runtime ) error {
801780 var err error
802781
@@ -1104,22 +1083,24 @@ func installComponents(ctx context.Context, opts *RuntimeInstallOptions, rt *run
11041083 return nil
11051084}
11061085
1107- func preInstallationChecks (ctx context.Context , opts * RuntimeInstallOptions ) error {
1086+ func preInstallationChecks (ctx context.Context , opts * RuntimeInstallOptions ) ( * runtime. Runtime , error ) {
11081087 var err error
1088+
11091089 log .G (ctx ).Debug ("running pre-installation checks..." )
11101090
11111091 handleCliStep (reporter .InstallPhaseRunPreCheckStart , "Running pre run installation checks" , nil , true , false )
11121092
11131093 err = checkIscProvider (ctx , opts .InsCloneOpts )
11141094 handleCliStep (reporter .InstallStepRunPreCheckGitProvider , "Checking Account Git Provider" , err , true , true )
11151095 if err != nil {
1116- return err
1096+ return nil , err
11171097 }
11181098
1119- rt , err := runtime .Download (opts .Version , opts .RuntimeName , nil ) // no need to send featuresToInstall, since we only use the runtime to get the DefVersion anyway
1099+ runtimeDef := getRuntimeDef (opts .runtimeDef , opts .versionStr )
1100+ rt , err := runtime .Download (runtimeDef , opts .RuntimeName , nil )
11201101 handleCliStep (reporter .InstallStepRunPreCheckDownloadRuntimeDefinition , "Downloading runtime definition" , err , true , true )
11211102 if err != nil {
1122- return fmt .Errorf ("failed to download runtime definition: %w" , err )
1103+ return nil , fmt .Errorf ("failed to download runtime definition: %w" , err )
11231104 }
11241105
11251106 if rt .Spec .DefVersion .GreaterThan (store .Get ().MaxDefVersion ) {
@@ -1128,38 +1109,47 @@ func preInstallationChecks(ctx context.Context, opts *RuntimeInstallOptions) err
11281109
11291110 handleCliStep (reporter .InstallStepRunPreCheckEnsureCliVersion , "Checking CLI version" , err , true , false )
11301111 if err != nil {
1131- return util .DecorateErrorWithDocsLink (err , store .Get ().DownloadCliLink )
1112+ return nil , util .DecorateErrorWithDocsLink (err , store .Get ().DownloadCliLink )
11321113 }
11331114
11341115 err = checkRuntimeCollisions (ctx , opts .KubeFactory , opts .RuntimeName )
11351116 handleCliStep (reporter .InstallStepRunPreCheckRuntimeCollision , "Checking for runtime collisions" , err , true , false )
11361117 if err != nil {
1137- return fmt .Errorf ("runtime collision check failed: %w" , err )
1118+ return nil , fmt .Errorf ("runtime collision check failed: %w" , err )
1119+ }
1120+
1121+ rt .Spec .Cluster , err = util .KubeServerByContextName (opts .kubeContext , opts .kubeconfig )
1122+ handleCliStep (reporter .InstallStepGetServerAddress , "Getting kube server address" , err , false , true )
1123+ if err != nil {
1124+ return nil , fmt .Errorf ("failed to get current server address: %w" , err )
11381125 }
11391126
11401127 if ! opts .FromRepo {
11411128 err = checkExistingRuntimes (ctx , opts .RuntimeName )
11421129 }
1130+
11431131 handleCliStep (reporter .InstallStepRunPreCheckExisitingRuntimes , "Checking for exisiting runtimes" , err , true , false )
11441132 if err != nil {
1145- return fmt .Errorf ("existing runtime check failed: %w" , err )
1133+ return nil , fmt .Errorf ("existing runtime check failed: %w" , err )
11461134 }
11471135
11481136 if ! opts .SkipClusterChecks {
1149- err = kubeutil .EnsureClusterRequirements (ctx , kubeutil.RuntimeInstallOptions {
1137+ err = kubeutil .EnsureClusterRequirements (ctx , kubeutil.ClusterRequirementsOptions {
11501138 KubeFactory : opts .KubeFactory ,
11511139 Namespace : opts .RuntimeName ,
11521140 ContextUrl : cfConfig .GetCurrentContext ().URL ,
11531141 AccessMode : opts .AccessMode ,
11541142 TunnelRegisterHost : opts .TunnelRegisterHost ,
1143+ IsCustomInstall : opts .IsCustomInstall (),
11551144 })
11561145 }
1146+
11571147 handleCliStep (reporter .InstallStepRunPreCheckValidateClusterRequirements , "Ensuring cluster requirements" , err , true , false )
11581148 if err != nil {
1159- return fmt .Errorf ("validation of minimum cluster requirements failed: %w" , err )
1149+ return nil , fmt .Errorf ("validation of minimum cluster requirements failed: %w" , err )
11601150 }
11611151
1162- return nil
1152+ return rt , nil
11631153}
11641154
11651155func checkIscProvider (ctx context.Context , opts * apgit.CloneOptions ) error {
@@ -2012,13 +2002,14 @@ func printPreviousVsNewConfigsToUser(previousConfigurations map[string]string, n
20122002 fmt .Printf ("%vIngress host:%v %s %v--> %s%v\n " , BOLD , BOLD_RESET , previousConfigurations ["IngressHost" ], GREEN , newConfigurations ["IngressHost" ], COLOR_RESET )
20132003}
20142004
2015- func getVersionIfExists (versionStr string ) (* semver.Version , error ) {
2005+ func validateVersionIfExists (versionStr string ) error {
2006+ var err error
20162007 if versionStr != "" {
20172008 log .G ().Infof ("vesionStr: %s" , versionStr )
2018- return semver .NewVersion (versionStr )
2009+ _ , err = semver .NewVersion (versionStr )
20192010 }
20202011
2021- return nil , nil
2012+ return err
20222013}
20232014
20242015func initializeGitSourceCloneOpts (opts * RuntimeInstallOptions ) {
@@ -2055,3 +2046,28 @@ func (opts *RuntimeInstallOptions) GetValues(name string) (string, error) {
20552046func (opts * RuntimeInstallOptions ) shouldInstallIngress () bool {
20562047 return ! opts .SkipIngress && opts .AccessMode == platmodel .AccessModeIngress
20572048}
2049+
2050+ func (opts * RuntimeInstallOptions ) IsCustomInstall () bool {
2051+ return opts .runtimeDef != store .RuntimeDefURL
2052+ }
2053+
2054+ func getRuntimeDef (runtimeDef , versionStr string ) string {
2055+ if ! strings .HasPrefix (runtimeDef , "http" ) {
2056+ // runtimeDef is some local file
2057+ return runtimeDef
2058+ }
2059+
2060+ if versionStr == "" {
2061+ // no specific version string
2062+ return runtimeDef
2063+ }
2064+
2065+ version , err := semver .NewVersion (versionStr )
2066+ if err != nil {
2067+ // should not arrive here, since we check for validateVersionIfExists earlier
2068+ return runtimeDef
2069+ }
2070+
2071+ // specific version means the runtimeDef is the default value in cli-v2 repo
2072+ return strings .Replace (runtimeDef , "/releases/latest/download" , "/releases/download/v" + version .String (), 1 )
2073+ }
0 commit comments