@@ -122,7 +122,9 @@ type (
122
122
FastExit bool
123
123
DisableTelemetry bool
124
124
Managed bool
125
- kubeContext string
125
+
126
+ kubeContext string
127
+ skipAutopilotUninstall bool
126
128
}
127
129
128
130
RuntimeUpgradeOptions struct {
@@ -188,8 +190,10 @@ func NewRuntimeCommand() *cobra.Command {
188
190
189
191
func NewRuntimeInstallCommand () * cobra.Command {
190
192
var (
193
+ gitIntegrationApiURL = ""
191
194
gitIntegrationCreationOpts = apmodel.AddGitIntegrationArgs {
192
195
SharingPolicy : apmodel .SharingPolicyAllUsersInAccount ,
196
+ APIURL : & gitIntegrationApiURL ,
193
197
}
194
198
installationOpts = RuntimeInstallOptions {
195
199
GitIntegrationCreationOpts : & gitIntegrationCreationOpts ,
@@ -269,7 +273,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
269
273
cmd .Flags ().BoolVar (& installationOpts .SkipClusterChecks , "skip-cluster-checks" , false , "Skips the cluster's checks" )
270
274
cmd .Flags ().BoolVar (& installationOpts .DisableRollback , "disable-rollback" , false , "If true, will not perform installation rollback after a failed installation" )
271
275
cmd .Flags ().DurationVar (& store .Get ().WaitTimeout , "wait-timeout" , store .Get ().WaitTimeout , "How long to wait for the runtime components to be ready" )
272
- cmd .Flags ().StringVar (& gitIntegrationCreationOpts . APIURL , "provider-api-url" , "" , "Git provider API url" )
276
+ cmd .Flags ().StringVar (& gitIntegrationApiURL , "provider-api-url" , "" , "Git provider API url" )
273
277
cmd .Flags ().BoolVar (& store .Get ().SkipIngress , "skip-ingress" , false , "Skips the creation of ingress resources" )
274
278
cmd .Flags ().BoolVar (& store .Get ().BypassIngressClassCheck , "bypass-ingress-class-check" , false , "Disables the ingress class check during pre-installation" )
275
279
cmd .Flags ().BoolVar (& installationOpts .DisableTelemetry , "disable-telemetry" , false , "If true, will disable the analytics reporting for the installation process" )
@@ -458,6 +462,12 @@ func runtimeUninstallCommandPreRunHandler(cmd *cobra.Command, args []string, opt
458
462
if ! opts .Managed {
459
463
kubeconfig := cmd .Flag ("kubeconfig" ).Value .String ()
460
464
err = ensureRuntimeOnKubeContext (cmd .Context (), kubeconfig , opts .RuntimeName , opts .kubeContext )
465
+
466
+ if err != nil && opts .Force {
467
+ log .G (cmd .Context ()).Warn ("Failed to verify runtime is installed on the selected kubernetes context, installation repository will not be cleaned" )
468
+ err = nil
469
+ opts .skipAutopilotUninstall = true // will not touch the cluster and repo
470
+ }
461
471
}
462
472
handleCliStep (reporter .UninstallStepPreCheckEnsureRuntimeOnKubeContext , "Ensuring runtime is on the kube context" , err , true , false )
463
473
if err != nil {
@@ -845,19 +855,24 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
845
855
handleCliStep (reporter .InstallStepCreateDefaultGitIntegration , "-skipped-" , err , false , true )
846
856
handleCliStep (reporter .InstallStepRegisterToDefaultGitIntegration , "-skipped-" , err , false , true )
847
857
858
+ var apiURL string
859
+ if opts .GitIntegrationCreationOpts .APIURL != nil {
860
+ apiURL = fmt .Sprintf ("--api-url %s" , * opts .GitIntegrationCreationOpts .APIURL )
861
+ }
862
+
848
863
skipIngressInfoMsg := util .Doc (fmt .Sprintf (`
849
864
To complete the installation:
850
865
1. Configure your cluster's routing service with path to '/%s' and \"%s\"
851
866
2. Create and register Git integration using the commands:
852
867
853
- <BIN> integration git add default --runtime %s --api-url %s
868
+ <BIN> integration git add default --runtime %s %s
854
869
855
870
<BIN> integration git register default --runtime %s --token <AUTHENTICATION_TOKEN>
856
871
` ,
857
872
store .Get ().AppProxyIngressPath ,
858
873
util .GenerateIngressEventSourcePath (opts .RuntimeName ),
859
874
opts .RuntimeName ,
860
- opts . GitIntegrationCreationOpts . APIURL ,
875
+ apiURL ,
861
876
opts .RuntimeName ))
862
877
summaryArr = append (summaryArr , summaryLog {skipIngressInfoMsg , Info })
863
878
} else {
@@ -1064,11 +1079,16 @@ func removeGitIntegrations(ctx context.Context, opts *RuntimeUninstallOptions) e
1064
1079
1065
1080
func addDefaultGitIntegration (ctx context.Context , appProxyClient codefresh.AppProxyAPI , runtime string , opts * apmodel.AddGitIntegrationArgs ) error {
1066
1081
if err := RunGitIntegrationAddCommand (ctx , appProxyClient , opts ); err != nil {
1082
+ var apiURL string
1083
+ if opts .APIURL != nil {
1084
+ apiURL = fmt .Sprintf ("--api-url %s" , * opts .APIURL )
1085
+ }
1086
+
1067
1087
commandAdd := util .Doc (fmt .Sprintf (
1068
- "\t <BIN> integration git add default --runtime %s --provider %s --api-url %s" ,
1088
+ "\t <BIN> integration git add default --runtime %s --provider %s %s" ,
1069
1089
runtime ,
1070
1090
strings .ToLower (opts .Provider .String ()),
1071
- opts . APIURL ,
1091
+ apiURL ,
1072
1092
))
1073
1093
1074
1094
commandRegister := util .Doc (fmt .Sprintf (
@@ -1637,51 +1657,47 @@ func RunRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err
1637
1657
return fmt .Errorf ("failed to remove runtime isc: %w" , err )
1638
1658
}
1639
1659
1640
- subCtx , cancel := context .WithCancel (ctx )
1641
- go func () {
1642
- if err := printApplicationsState (subCtx , opts .RuntimeName , opts .KubeFactory , opts .Managed ); err != nil {
1643
- log .G (ctx ).WithError (err ).Debug ("failed to print uninstallation progress" )
1660
+ if ! opts .skipAutopilotUninstall {
1661
+ subCtx , cancel := context .WithCancel (ctx )
1662
+ go func () {
1663
+ if err := printApplicationsState (subCtx , opts .RuntimeName , opts .KubeFactory , opts .Managed ); err != nil {
1664
+ log .G (ctx ).WithError (err ).Debug ("failed to print uninstallation progress" )
1665
+ }
1666
+ }()
1667
+
1668
+ if ! opts .Managed {
1669
+ err = apcmd .RunRepoUninstall (ctx , & apcmd.RepoUninstallOptions {
1670
+ Namespace : opts .RuntimeName ,
1671
+ KubeContextName : opts .kubeContext ,
1672
+ Timeout : opts .Timeout ,
1673
+ CloneOptions : opts .CloneOpts ,
1674
+ KubeFactory : opts .KubeFactory ,
1675
+ Force : opts .Force ,
1676
+ FastExit : opts .FastExit ,
1677
+ })
1678
+ }
1679
+ cancel () // to tell the progress to stop displaying even if it's not finished
1680
+ if opts .Force {
1681
+ err = nil
1644
1682
}
1645
- }()
1646
-
1647
- if ! opts .Managed {
1648
- err = apcmd .RunRepoUninstall (ctx , & apcmd.RepoUninstallOptions {
1649
- Namespace : opts .RuntimeName ,
1650
- KubeContextName : opts .kubeContext ,
1651
- Timeout : opts .Timeout ,
1652
- CloneOptions : opts .CloneOpts ,
1653
- KubeFactory : opts .KubeFactory ,
1654
- Force : opts .Force ,
1655
- FastExit : opts .FastExit ,
1656
- })
1657
- }
1658
- cancel () // to tell the progress to stop displaying even if it's not finished
1659
- if opts .Force {
1660
- err = nil
1661
1683
}
1662
- handleCliStep (reporter .UninstallStepUninstallRepo , "Uninstalling repo" , err , false , ! opts .Managed )
1684
+ handleCliStep (reporter .UninstallStepUninstallRepo , "Uninstalling repo" , err , false , ! opts .Managed && ! opts . skipAutopilotUninstall )
1663
1685
if err != nil {
1664
1686
summaryArr = append (summaryArr , summaryLog {"you can attempt to uninstall again with the \" --force\" flag" , Info })
1665
1687
return err
1666
1688
}
1667
1689
1668
- if ! opts .Managed {
1690
+ log .G (ctx ).Infof ("Deleting runtime '%s' from platform" , opts .RuntimeName )
1691
+ if opts .Managed {
1692
+ _ , err = cfConfig .NewClient ().V2 ().Runtime ().DeleteManaged (ctx , opts .RuntimeName )
1693
+ } else {
1669
1694
err = deleteRuntimeFromPlatform (ctx , opts )
1670
1695
}
1671
1696
handleCliStep (reporter .UninstallStepDeleteRuntimeFromPlatform , "Deleting runtime from platform" , err , false , ! opts .Managed )
1672
1697
if err != nil {
1673
1698
return fmt .Errorf ("failed to delete runtime from the platform: %w" , err )
1674
1699
}
1675
1700
1676
- if opts .Managed {
1677
- log .G (ctx ).Infof ("Deleting runtime '%s' from platform" , opts .RuntimeName )
1678
- _ , err = cfConfig .NewClient ().V2 ().Runtime ().DeleteManaged (ctx , opts .RuntimeName )
1679
- }
1680
- handleCliStep (reporter .UninstallStepDeleteManagedRuntimeFromPlatform , "Deleting hosted runtime from platform" , err , false , opts .Managed )
1681
- if err != nil {
1682
- return fmt .Errorf ("failed to delete hosted runtime from the platform: %w" , err )
1683
- }
1684
-
1685
1701
if cfConfig .GetCurrentContext ().DefaultRuntime == opts .RuntimeName {
1686
1702
cfConfig .GetCurrentContext ().DefaultRuntime = ""
1687
1703
}
@@ -1806,14 +1822,24 @@ func getApplicationChecklistState(name string, a *argocdv1alpha1.Application, ru
1806
1822
}
1807
1823
1808
1824
func removeRuntimeIsc (ctx context.Context , runtimeName string ) error {
1825
+ me , err := cfConfig .NewClient ().V2 ().UsersV2 ().GetCurrent (ctx )
1826
+ if err != nil {
1827
+ return fmt .Errorf ("failed to get current user information: %w" , err )
1828
+ }
1829
+
1830
+ if me .ActiveAccount .SharedConfigRepo == nil || * me .ActiveAccount .SharedConfigRepo == "" {
1831
+ log .G (ctx ).Info ("Skipped removing runtime from ISC repo. ISC repo not defined" )
1832
+ return nil
1833
+ }
1834
+
1809
1835
appProxyClient , err := cfConfig .NewClient ().AppProxy (ctx , runtimeName , store .Get ().InsecureIngressHost )
1810
1836
if err != nil {
1811
1837
return fmt .Errorf ("failed to build app-proxy client while removing runtime isc: %w" , err )
1812
1838
}
1813
1839
1814
1840
_ , err = appProxyClient .AppProxyIsc ().RemoveRuntimeFromIscRepo (ctx )
1815
1841
if err == nil {
1816
- log .G (ctx ).Info ("Removed runtime from isc repo" )
1842
+ log .G (ctx ).Info ("Removed runtime from ISC repo" )
1817
1843
}
1818
1844
1819
1845
return err
@@ -2611,7 +2637,7 @@ func ensureGitIntegrationOpts(opts *RuntimeInstallOptions) error {
2611
2637
opts .GitIntegrationCreationOpts .Provider = apmodel .GitProviders (strings .ToUpper (opts .InsCloneOpts .Provider ))
2612
2638
}
2613
2639
2614
- if opts .GitIntegrationCreationOpts .APIURL == "" {
2640
+ if opts .GitIntegrationCreationOpts .APIURL == nil || * opts . GitIntegrationCreationOpts . APIURL == "" {
2615
2641
if opts .GitIntegrationCreationOpts .APIURL , err = inferAPIURLForGitProvider (opts .GitIntegrationCreationOpts .Provider ); err != nil {
2616
2642
return err
2617
2643
}
@@ -2637,17 +2663,20 @@ func inferProviderFromCloneURL(cloneURL string) (apmodel.GitProviders, error) {
2637
2663
return apmodel .GitProviders ("" ), fmt .Errorf ("failed to infer git provider from clone url: %s, %s" , cloneURL , suggest )
2638
2664
}
2639
2665
2640
- func inferAPIURLForGitProvider (provider apmodel.GitProviders ) (string , error ) {
2666
+ func inferAPIURLForGitProvider (provider apmodel.GitProviders ) (* string , error ) {
2641
2667
const suggest = "you can specify a git provider explicitly with --provider-api-url"
2668
+ var res string
2642
2669
2643
2670
switch provider {
2644
2671
case apmodel .GitProvidersGithub :
2645
- return "https://api.github.com" , nil
2672
+ res = "https://api.github.com"
2673
+ return & res , nil
2646
2674
case apmodel .GitProvidersGitlab :
2647
- return "https://gitlab.com/api/v4" , nil
2675
+ res = "https://gitlab.com/api/v4"
2676
+ return & res , nil
2648
2677
}
2649
2678
2650
- return "" , fmt .Errorf ("cannot infer api-url for git provider %s, %s" , provider , suggest )
2679
+ return nil , fmt .Errorf ("cannot infer api-url for git provider %s, %s" , provider , suggest )
2651
2680
}
2652
2681
2653
2682
// display the user the old vs. the new configurations that will be changed upon recovery
0 commit comments