@@ -27,6 +27,8 @@ import (
27
27
"sync"
28
28
"time"
29
29
30
+ routingutil "github.com/codefresh-io/cli-v2/pkg/util/routing"
31
+
30
32
"github.com/codefresh-io/cli-v2/pkg/log"
31
33
"github.com/codefresh-io/cli-v2/pkg/reporter"
32
34
"github.com/codefresh-io/cli-v2/pkg/runtime"
@@ -69,13 +71,13 @@ type (
69
71
70
72
RuntimeUpgradeOptions struct {
71
73
RuntimeName string
72
- Version * semver.Version
73
74
CloneOpts * apgit.CloneOptions
74
75
CommonConfig * runtime.CommonConfig
75
76
SuggestedSharedConfigRepo string
76
77
DisableTelemetry bool
77
78
runtimeDef string
78
79
80
+ versionStr string
79
81
featuresToInstall []runtime.InstallFeature
80
82
}
81
83
@@ -787,6 +789,11 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
787
789
finalParameters ["Version" ] = versionStr
788
790
}
789
791
792
+ err = validateVersionIfExists (opts .versionStr )
793
+ if err != nil {
794
+ return err
795
+ }
796
+
790
797
err = getApprovalFromUser (ctx , finalParameters , "runtime upgrade" )
791
798
if err != nil {
792
799
return err
@@ -799,13 +806,6 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
799
806
var err error
800
807
ctx := cmd .Context ()
801
808
802
- if versionStr != "" {
803
- opts .Version , err = semver .NewVersion (versionStr )
804
- if err != nil {
805
- return err
806
- }
807
- }
808
-
809
809
opts .CommonConfig = & runtime.CommonConfig {
810
810
CodefreshBaseURL : cfConfig .GetCurrentContext ().URL ,
811
811
}
@@ -816,7 +816,7 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
816
816
},
817
817
}
818
818
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" )
820
820
cmd .Flags ().StringVar (& opts .SuggestedSharedConfigRepo , "shared-config-repo" , "" , "URL to the shared configurations repo. (default: <installation-repo> or the existing one for this account)" )
821
821
cmd .Flags ().BoolVar (& opts .DisableTelemetry , "disable-telemetry" , false , "If true, will disable analytics reporting for the upgrade process" )
822
822
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 {
834
834
835
835
log .G (ctx ).Info ("Downloading runtime definition" )
836
836
837
- runtimeDef := getRuntimeDef (opts .runtimeDef , opts .Version . String () )
837
+ runtimeDef := getRuntimeDef (opts .runtimeDef , opts .versionStr )
838
838
newRt , err := runtime .Download (runtimeDef , opts .RuntimeName , opts .featuresToInstall )
839
839
handleCliStep (reporter .UpgradeStepDownloadRuntimeDefinition , "Downloading runtime definition" , err , true , false )
840
840
if err != nil {
@@ -897,6 +897,21 @@ func runRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
897
897
898
898
handleCliStep (reporter .UpgradeStepInstallNewComponents , "Install new components" , err , false , false )
899
899
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
+
900
915
log .G (ctx ).Infof ("Runtime upgraded to version: v%s" , newRt .Spec .Version )
901
916
902
917
return nil
@@ -922,6 +937,55 @@ func NewRuntimeLogsCommand() *cobra.Command {
922
937
return cmd
923
938
}
924
939
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
+
925
989
func isAllRequiredFlagsForDownloadRuntimeLogs () bool {
926
990
return store .Get ().IsDownloadRuntimeLogs && store .Get ().IngressHost != ""
927
991
}
0 commit comments