93
93
DisableRollback bool
94
94
DisableTelemetry bool
95
95
FromRepo bool
96
- Version * semver.Version
97
96
GsCloneOpts * apgit.CloneOptions
98
97
InsCloneOpts * apgit.CloneOptions
99
98
GitIntegrationCreationOpts * apmodel.AddGitIntegrationArgs
@@ -119,6 +118,7 @@ type (
119
118
gitProvider cfgit.Provider
120
119
useGatewayAPI bool
121
120
featuresToInstall []runtime.InstallFeature
121
+ runtimeDef string
122
122
}
123
123
124
124
tunnelServer struct {
@@ -254,6 +254,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
254
254
cmd .Flags ().StringToStringVar (& installationOpts .InternalIngressAnnotation , "internal-ingress-annotation" , nil , "Add annotations to the internal ingress" )
255
255
cmd .Flags ().StringToStringVar (& installationOpts .ExternalIngressAnnotation , "external-ingress-annotation" , nil , "Add annotations to the external ingress" )
256
256
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" )
257
258
cmd .Flags ().StringVar (& accessMode , "access-mode" , string (platmodel .AccessModeIngress ), "The access mode to the cluster, one of: ingress|tunnel" )
258
259
cmd .Flags ().StringVar (& installationOpts .TunnelRegisterHost , "tunnel-register-host" , "register-tunnels.cf-cd.com" , "The host name for registering a new tunnel" )
259
260
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 {
278
279
util .Die (cmd .Flags ().MarkHidden ("tunnel-register-host" ))
279
280
util .Die (cmd .Flags ().MarkHidden ("tunnel-domain" ))
280
281
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" )
281
285
282
286
return cmd
283
287
}
@@ -288,12 +292,8 @@ func runtimeInstallCommandPreRunHandler(cmd *cobra.Command, opts *RuntimeInstall
288
292
289
293
handleCliStep (reporter .InstallPhasePreCheckStart , "Starting pre checks" , nil , true , false )
290
294
291
- opts . Version , err = getVersionIfExists (opts .versionStr )
295
+ err = validateVersionIfExists (opts .versionStr )
292
296
handleCliStep (reporter .InstallStepPreCheckValidateRuntimeVersion , "Validating runtime version" , err , true , false )
293
- if err != nil {
294
- return err
295
- }
296
-
297
297
if opts .RuntimeName == "" {
298
298
if ! store .Get ().Silent {
299
299
opts .RuntimeName , err = getRuntimeNameFromUserInput ()
@@ -597,19 +597,14 @@ func createRuntimeOnPlatform(ctx context.Context, opts *RuntimeInstallOptions, r
597
597
}
598
598
599
599
func runRuntimeInstall (ctx context.Context , opts * RuntimeInstallOptions ) error {
600
- err := preInstallationChecks (ctx , opts )
600
+ rt , err := preInstallationChecks (ctx , opts )
601
601
handleCliStep (reporter .InstallPhaseRunPreCheckFinish , "Pre run installation checks" , err , true , true )
602
602
if err != nil {
603
603
return fmt .Errorf ("pre installation checks failed: %w" , err )
604
604
}
605
605
606
606
handleCliStep (reporter .InstallPhaseStart , "Runtime installation phase started" , nil , false , true )
607
607
608
- rt , err := runtimeInstallPreparations (opts )
609
- if err != nil {
610
- return err
611
- }
612
-
613
608
if opts .FromRepo {
614
609
// in case of a runtime recovery, we don't want to clear the repo when failure occures
615
610
opts .DisableRollback = true
@@ -781,22 +776,6 @@ To complete the installation:
781
776
return nil
782
777
}
783
778
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
-
800
779
func createRuntimeComponents (ctx context.Context , opts * RuntimeInstallOptions , rt * runtime.Runtime ) error {
801
780
var err error
802
781
@@ -1104,22 +1083,24 @@ func installComponents(ctx context.Context, opts *RuntimeInstallOptions, rt *run
1104
1083
return nil
1105
1084
}
1106
1085
1107
- func preInstallationChecks (ctx context.Context , opts * RuntimeInstallOptions ) error {
1086
+ func preInstallationChecks (ctx context.Context , opts * RuntimeInstallOptions ) ( * runtime. Runtime , error ) {
1108
1087
var err error
1088
+
1109
1089
log .G (ctx ).Debug ("running pre-installation checks..." )
1110
1090
1111
1091
handleCliStep (reporter .InstallPhaseRunPreCheckStart , "Running pre run installation checks" , nil , true , false )
1112
1092
1113
1093
err = checkIscProvider (ctx , opts .InsCloneOpts )
1114
1094
handleCliStep (reporter .InstallStepRunPreCheckGitProvider , "Checking Account Git Provider" , err , true , true )
1115
1095
if err != nil {
1116
- return err
1096
+ return nil , err
1117
1097
}
1118
1098
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 )
1120
1101
handleCliStep (reporter .InstallStepRunPreCheckDownloadRuntimeDefinition , "Downloading runtime definition" , err , true , true )
1121
1102
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 )
1123
1104
}
1124
1105
1125
1106
if rt .Spec .DefVersion .GreaterThan (store .Get ().MaxDefVersion ) {
@@ -1128,38 +1109,47 @@ func preInstallationChecks(ctx context.Context, opts *RuntimeInstallOptions) err
1128
1109
1129
1110
handleCliStep (reporter .InstallStepRunPreCheckEnsureCliVersion , "Checking CLI version" , err , true , false )
1130
1111
if err != nil {
1131
- return util .DecorateErrorWithDocsLink (err , store .Get ().DownloadCliLink )
1112
+ return nil , util .DecorateErrorWithDocsLink (err , store .Get ().DownloadCliLink )
1132
1113
}
1133
1114
1134
1115
err = checkRuntimeCollisions (ctx , opts .KubeFactory , opts .RuntimeName )
1135
1116
handleCliStep (reporter .InstallStepRunPreCheckRuntimeCollision , "Checking for runtime collisions" , err , true , false )
1136
1117
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 )
1138
1125
}
1139
1126
1140
1127
if ! opts .FromRepo {
1141
1128
err = checkExistingRuntimes (ctx , opts .RuntimeName )
1142
1129
}
1130
+
1143
1131
handleCliStep (reporter .InstallStepRunPreCheckExisitingRuntimes , "Checking for exisiting runtimes" , err , true , false )
1144
1132
if err != nil {
1145
- return fmt .Errorf ("existing runtime check failed: %w" , err )
1133
+ return nil , fmt .Errorf ("existing runtime check failed: %w" , err )
1146
1134
}
1147
1135
1148
1136
if ! opts .SkipClusterChecks {
1149
- err = kubeutil .EnsureClusterRequirements (ctx , kubeutil.RuntimeInstallOptions {
1137
+ err = kubeutil .EnsureClusterRequirements (ctx , kubeutil.ClusterRequirementsOptions {
1150
1138
KubeFactory : opts .KubeFactory ,
1151
1139
Namespace : opts .RuntimeName ,
1152
1140
ContextUrl : cfConfig .GetCurrentContext ().URL ,
1153
1141
AccessMode : opts .AccessMode ,
1154
1142
TunnelRegisterHost : opts .TunnelRegisterHost ,
1143
+ IsCustomInstall : opts .IsCustomInstall (),
1155
1144
})
1156
1145
}
1146
+
1157
1147
handleCliStep (reporter .InstallStepRunPreCheckValidateClusterRequirements , "Ensuring cluster requirements" , err , true , false )
1158
1148
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 )
1160
1150
}
1161
1151
1162
- return nil
1152
+ return rt , nil
1163
1153
}
1164
1154
1165
1155
func checkIscProvider (ctx context.Context , opts * apgit.CloneOptions ) error {
@@ -2012,13 +2002,14 @@ func printPreviousVsNewConfigsToUser(previousConfigurations map[string]string, n
2012
2002
fmt .Printf ("%vIngress host:%v %s %v--> %s%v\n " , BOLD , BOLD_RESET , previousConfigurations ["IngressHost" ], GREEN , newConfigurations ["IngressHost" ], COLOR_RESET )
2013
2003
}
2014
2004
2015
- func getVersionIfExists (versionStr string ) (* semver.Version , error ) {
2005
+ func validateVersionIfExists (versionStr string ) error {
2006
+ var err error
2016
2007
if versionStr != "" {
2017
2008
log .G ().Infof ("vesionStr: %s" , versionStr )
2018
- return semver .NewVersion (versionStr )
2009
+ _ , err = semver .NewVersion (versionStr )
2019
2010
}
2020
2011
2021
- return nil , nil
2012
+ return err
2022
2013
}
2023
2014
2024
2015
func initializeGitSourceCloneOpts (opts * RuntimeInstallOptions ) {
@@ -2055,3 +2046,28 @@ func (opts *RuntimeInstallOptions) GetValues(name string) (string, error) {
2055
2046
func (opts * RuntimeInstallOptions ) shouldInstallIngress () bool {
2056
2047
return ! opts .SkipIngress && opts .AccessMode == platmodel .AccessModeIngress
2057
2048
}
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