@@ -27,6 +27,8 @@ import (
2727 "sync"
2828 "time"
2929
30+ routingutil "github.com/codefresh-io/cli-v2/pkg/util/routing"
31+
3032 "github.com/codefresh-io/cli-v2/pkg/log"
3133 "github.com/codefresh-io/cli-v2/pkg/reporter"
3234 "github.com/codefresh-io/cli-v2/pkg/runtime"
@@ -69,13 +71,13 @@ type (
6971
7072 RuntimeUpgradeOptions struct {
7173 RuntimeName string
72- Version * semver.Version
7374 CloneOpts * apgit.CloneOptions
7475 CommonConfig * runtime.CommonConfig
7576 SuggestedSharedConfigRepo string
7677 DisableTelemetry bool
7778 runtimeDef string
7879
80+ versionStr string
7981 featuresToInstall []runtime.InstallFeature
8082 }
8183
@@ -787,6 +789,11 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
787789 finalParameters ["Version" ] = versionStr
788790 }
789791
792+ err = validateVersionIfExists (opts .versionStr )
793+ if err != nil {
794+ return err
795+ }
796+
790797 err = getApprovalFromUser (ctx , finalParameters , "runtime upgrade" )
791798 if err != nil {
792799 return err
@@ -799,13 +806,6 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
799806 var err error
800807 ctx := cmd .Context ()
801808
802- if versionStr != "" {
803- opts .Version , err = semver .NewVersion (versionStr )
804- if err != nil {
805- return err
806- }
807- }
808-
809809 opts .CommonConfig = & runtime.CommonConfig {
810810 CodefreshBaseURL : cfConfig .GetCurrentContext ().URL ,
811811 }
@@ -816,7 +816,7 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
816816 },
817817 }
818818
819- cmd .Flags ().StringVar (& versionStr , "version" , "" , "The runtime version to upgrade to, defaults to latest" )
819+ cmd .Flags ().StringVar (& opts . versionStr , "version" , "" , "The runtime version to upgrade to, defaults to latest" )
820820 cmd .Flags ().StringVar (& opts .SuggestedSharedConfigRepo , "shared-config-repo" , "" , "URL to the shared configurations repo. (default: <installation-repo> or the existing one for this account)" )
821821 cmd .Flags ().BoolVar (& opts .DisableTelemetry , "disable-telemetry" , false , "If true, will disable analytics reporting for the upgrade process" )
822822 cmd .Flags ().BoolVar (& store .Get ().SetDefaultResources , "set-default-resources" , false , "If true, will set default requests and limits on all of the runtime components" )
@@ -834,7 +834,7 @@ func runRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
834834
835835 log .G (ctx ).Info ("Downloading runtime definition" )
836836
837- runtimeDef := getRuntimeDef (opts .runtimeDef , opts .Version . String () )
837+ runtimeDef := getRuntimeDef (opts .runtimeDef , opts .versionStr )
838838 newRt , err := runtime .Download (runtimeDef , opts .RuntimeName , opts .featuresToInstall )
839839 handleCliStep (reporter .UpgradeStepDownloadRuntimeDefinition , "Downloading runtime definition" , err , true , false )
840840 if err != nil {
@@ -897,6 +897,21 @@ func runRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
897897
898898 handleCliStep (reporter .UpgradeStepInstallNewComponents , "Install new components" , err , false , false )
899899
900+ needsInternalRouter := curRt .Spec .Version .LessThan (semver .MustParse ("v0.0.542" ))
901+ isIngress := curRt .Spec .AccessMode == platmodel .AccessModeIngress
902+ isNotAlb := curRt .Spec .IngressController != string (routingutil .IngressControllerALB )
903+
904+ if needsInternalRouter && isIngress && isNotAlb {
905+ log .G (ctx ).Info ("Migrating to Internal Router " )
906+
907+ err = migrateInternalRouter (ctx , opts , newRt )
908+ if err != nil {
909+ return fmt .Errorf ("failed to migrate internal router: %w" , err )
910+ }
911+
912+ handleCliStep (reporter .UpgradeStepMigrateInternalRouter , "Migrate internal router" , err , false , false )
913+ }
914+
900915 log .G (ctx ).Infof ("Runtime upgraded to version: v%s" , newRt .Spec .Version )
901916
902917 return nil
@@ -922,6 +937,55 @@ func NewRuntimeLogsCommand() *cobra.Command {
922937 return cmd
923938}
924939
940+ func migrateInternalRouter (ctx context.Context , opts * RuntimeUpgradeOptions , newRt * runtime.Runtime ) error {
941+ dbRuntime , err := getRuntime (ctx , opts .RuntimeName )
942+ if err != nil {
943+ return fmt .Errorf ("failed to get runtime: %s. Error: %w" , opts .RuntimeName , err )
944+ }
945+
946+ gatewayName := ""
947+ gatewaysNamespace := ""
948+
949+ if dbRuntime .GatewayName != nil {
950+ gatewayName = * dbRuntime .GatewayName
951+ }
952+
953+ if dbRuntime .GatewayNamespace != nil {
954+ gatewaysNamespace = * dbRuntime .GatewayNamespace
955+ }
956+
957+ createOpts := & CreateIngressOptions {
958+ IngressHost : newRt .Spec .IngressHost ,
959+ IngressClass : newRt .Spec .IngressClass ,
960+ InternalIngressHost : newRt .Spec .InternalIngressHost ,
961+ IngressController : routingutil .GetIngressController (newRt .Spec .IngressController ),
962+ InsCloneOpts : opts .CloneOpts ,
963+ useGatewayAPI : gatewayName != "" ,
964+ GatewayName : gatewayName ,
965+ GatewayNamespace : gatewaysNamespace ,
966+ }
967+
968+ if err = parseHostName (newRt .Spec .IngressHost , & createOpts .HostName ); err != nil {
969+ return err
970+ }
971+
972+ if createOpts .InternalIngressHost != "" {
973+ if err := parseHostName (newRt .Spec .InternalIngressHost , & createOpts .InternalHostName ); err != nil {
974+ return err
975+ }
976+ }
977+
978+ if err := util .Retry (ctx , & util.RetryOptions {
979+ Func : func () error {
980+ return CreateInternalRouterIngress (ctx , createOpts , newRt )
981+ },
982+ }); err != nil {
983+ return fmt .Errorf ("failed to patch Internal Router ingress: %w" , err )
984+ }
985+
986+ return nil
987+ }
988+
925989func isAllRequiredFlagsForDownloadRuntimeLogs () bool {
926990 return store .Get ().IsDownloadRuntimeLogs && store .Get ().IngressHost != ""
927991}
0 commit comments