@@ -122,7 +122,9 @@ type (
122122 FastExit bool
123123 DisableTelemetry bool
124124 Managed bool
125- kubeContext string
125+
126+ kubeContext string
127+ skipAutopilotUninstall bool
126128 }
127129
128130 RuntimeUpgradeOptions struct {
@@ -188,8 +190,10 @@ func NewRuntimeCommand() *cobra.Command {
188190
189191func NewRuntimeInstallCommand () * cobra.Command {
190192 var (
193+ gitIntegrationApiURL = ""
191194 gitIntegrationCreationOpts = apmodel.AddGitIntegrationArgs {
192195 SharingPolicy : apmodel .SharingPolicyAllUsersInAccount ,
196+ APIURL : & gitIntegrationApiURL ,
193197 }
194198 installationOpts = RuntimeInstallOptions {
195199 GitIntegrationCreationOpts : & gitIntegrationCreationOpts ,
@@ -269,7 +273,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
269273 cmd .Flags ().BoolVar (& installationOpts .SkipClusterChecks , "skip-cluster-checks" , false , "Skips the cluster's checks" )
270274 cmd .Flags ().BoolVar (& installationOpts .DisableRollback , "disable-rollback" , false , "If true, will not perform installation rollback after a failed installation" )
271275 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" )
273277 cmd .Flags ().BoolVar (& store .Get ().SkipIngress , "skip-ingress" , false , "Skips the creation of ingress resources" )
274278 cmd .Flags ().BoolVar (& store .Get ().BypassIngressClassCheck , "bypass-ingress-class-check" , false , "Disables the ingress class check during pre-installation" )
275279 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
458462 if ! opts .Managed {
459463 kubeconfig := cmd .Flag ("kubeconfig" ).Value .String ()
460464 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+ }
461471 }
462472 handleCliStep (reporter .UninstallStepPreCheckEnsureRuntimeOnKubeContext , "Ensuring runtime is on the kube context" , err , true , false )
463473 if err != nil {
@@ -845,19 +855,24 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
845855 handleCliStep (reporter .InstallStepCreateDefaultGitIntegration , "-skipped-" , err , false , true )
846856 handleCliStep (reporter .InstallStepRegisterToDefaultGitIntegration , "-skipped-" , err , false , true )
847857
858+ var apiURL string
859+ if opts .GitIntegrationCreationOpts .APIURL != nil {
860+ apiURL = fmt .Sprintf ("--api-url %s" , * opts .GitIntegrationCreationOpts .APIURL )
861+ }
862+
848863 skipIngressInfoMsg := util .Doc (fmt .Sprintf (`
849864To complete the installation:
8508651. Configure your cluster's routing service with path to '/%s' and \"%s\"
8518662. Create and register Git integration using the commands:
852867
853- <BIN> integration git add default --runtime %s --api-url %s
868+ <BIN> integration git add default --runtime %s %s
854869
855870<BIN> integration git register default --runtime %s --token <AUTHENTICATION_TOKEN>
856871` ,
857872 store .Get ().AppProxyIngressPath ,
858873 util .GenerateIngressEventSourcePath (opts .RuntimeName ),
859874 opts .RuntimeName ,
860- opts . GitIntegrationCreationOpts . APIURL ,
875+ apiURL ,
861876 opts .RuntimeName ))
862877 summaryArr = append (summaryArr , summaryLog {skipIngressInfoMsg , Info })
863878 } else {
@@ -1064,11 +1079,16 @@ func removeGitIntegrations(ctx context.Context, opts *RuntimeUninstallOptions) e
10641079
10651080func addDefaultGitIntegration (ctx context.Context , appProxyClient codefresh.AppProxyAPI , runtime string , opts * apmodel.AddGitIntegrationArgs ) error {
10661081 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+
10671087 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" ,
10691089 runtime ,
10701090 strings .ToLower (opts .Provider .String ()),
1071- opts . APIURL ,
1091+ apiURL ,
10721092 ))
10731093
10741094 commandRegister := util .Doc (fmt .Sprintf (
@@ -1637,51 +1657,47 @@ func RunRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err
16371657 return fmt .Errorf ("failed to remove runtime isc: %w" , err )
16381658 }
16391659
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
16441682 }
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
16611683 }
1662- handleCliStep (reporter .UninstallStepUninstallRepo , "Uninstalling repo" , err , false , ! opts .Managed )
1684+ handleCliStep (reporter .UninstallStepUninstallRepo , "Uninstalling repo" , err , false , ! opts .Managed && ! opts . skipAutopilotUninstall )
16631685 if err != nil {
16641686 summaryArr = append (summaryArr , summaryLog {"you can attempt to uninstall again with the \" --force\" flag" , Info })
16651687 return err
16661688 }
16671689
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 {
16691694 err = deleteRuntimeFromPlatform (ctx , opts )
16701695 }
16711696 handleCliStep (reporter .UninstallStepDeleteRuntimeFromPlatform , "Deleting runtime from platform" , err , false , ! opts .Managed )
16721697 if err != nil {
16731698 return fmt .Errorf ("failed to delete runtime from the platform: %w" , err )
16741699 }
16751700
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-
16851701 if cfConfig .GetCurrentContext ().DefaultRuntime == opts .RuntimeName {
16861702 cfConfig .GetCurrentContext ().DefaultRuntime = ""
16871703 }
@@ -1806,14 +1822,24 @@ func getApplicationChecklistState(name string, a *argocdv1alpha1.Application, ru
18061822}
18071823
18081824func 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+
18091835 appProxyClient , err := cfConfig .NewClient ().AppProxy (ctx , runtimeName , store .Get ().InsecureIngressHost )
18101836 if err != nil {
18111837 return fmt .Errorf ("failed to build app-proxy client while removing runtime isc: %w" , err )
18121838 }
18131839
18141840 _ , err = appProxyClient .AppProxyIsc ().RemoveRuntimeFromIscRepo (ctx )
18151841 if err == nil {
1816- log .G (ctx ).Info ("Removed runtime from isc repo" )
1842+ log .G (ctx ).Info ("Removed runtime from ISC repo" )
18171843 }
18181844
18191845 return err
@@ -2611,7 +2637,7 @@ func ensureGitIntegrationOpts(opts *RuntimeInstallOptions) error {
26112637 opts .GitIntegrationCreationOpts .Provider = apmodel .GitProviders (strings .ToUpper (opts .InsCloneOpts .Provider ))
26122638 }
26132639
2614- if opts .GitIntegrationCreationOpts .APIURL == "" {
2640+ if opts .GitIntegrationCreationOpts .APIURL == nil || * opts . GitIntegrationCreationOpts . APIURL == "" {
26152641 if opts .GitIntegrationCreationOpts .APIURL , err = inferAPIURLForGitProvider (opts .GitIntegrationCreationOpts .Provider ); err != nil {
26162642 return err
26172643 }
@@ -2637,17 +2663,20 @@ func inferProviderFromCloneURL(cloneURL string) (apmodel.GitProviders, error) {
26372663 return apmodel .GitProviders ("" ), fmt .Errorf ("failed to infer git provider from clone url: %s, %s" , cloneURL , suggest )
26382664}
26392665
2640- func inferAPIURLForGitProvider (provider apmodel.GitProviders ) (string , error ) {
2666+ func inferAPIURLForGitProvider (provider apmodel.GitProviders ) (* string , error ) {
26412667 const suggest = "you can specify a git provider explicitly with --provider-api-url"
2668+ var res string
26422669
26432670 switch provider {
26442671 case apmodel .GitProvidersGithub :
2645- return "https://api.github.com" , nil
2672+ res = "https://api.github.com"
2673+ return & res , nil
26462674 case apmodel .GitProvidersGitlab :
2647- return "https://gitlab.com/api/v4" , nil
2675+ res = "https://gitlab.com/api/v4"
2676+ return & res , nil
26482677 }
26492678
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 )
26512680}
26522681
26532682// display the user the old vs. the new configurations that will be changed upon recovery
0 commit comments