2525 BuildTime = "unknown"
2626)
2727
28+ // Unbootstrap command flags
29+ var cleanupMode string
30+
2831// NewAgentCommand creates a new agent command
2932func NewAgentCommand () * cobra.Command {
3033 cmd := & cobra.Command {
@@ -44,12 +47,19 @@ func NewUnbootstrapCommand() *cobra.Command {
4447 cmd := & cobra.Command {
4548 Use : "unbootstrap" ,
4649 Short : "Remove AKS node configuration and Arc connection" ,
47- Long : "Clean up and remove all AKS node components and Arc registration from this machine" ,
50+ Long : `Clean up and remove all AKS node components and Arc registration from this machine.
51+
52+ For private clusters (config has private: true), this also handles VPN cleanup:
53+ --cleanup-mode=local Remove node and local VPN config, keep Gateway (default)
54+ --cleanup-mode=full Remove everything including Gateway VM and Azure resources` ,
4855 RunE : func (cmd * cobra.Command , args []string ) error {
4956 return runUnbootstrap (cmd .Context ())
5057 },
5158 }
5259
60+ cmd .Flags ().StringVar (& cleanupMode , "cleanup-mode" , "local" ,
61+ "[private cluster only] Cleanup mode: 'local' (keep Gateway) or 'full' (remove all Azure resources)" )
62+
5363 return cmd
5464}
5565
@@ -76,7 +86,7 @@ func runAgent(ctx context.Context) error {
7686 return fmt .Errorf ("failed to load config from %s: %w" , configPath , err )
7787 }
7888
79- bootstrapExecutor := bootstrapper .New (cfg , logger )
89+ bootstrapExecutor := bootstrapper .New (logger )
8090 result , err := bootstrapExecutor .Bootstrap (ctx )
8191 if err != nil {
8292 return err
@@ -87,6 +97,13 @@ func runAgent(ctx context.Context) error {
8797 return err
8898 }
8999
100+ // Print visible success message
101+ fmt .Println ()
102+ fmt .Println ("========================================" )
103+ fmt .Println (" Join process finished successfully!" )
104+ fmt .Println ("========================================" )
105+ fmt .Println ()
106+
90107 // After successful bootstrap, transition to daemon mode
91108 logger .Info ("Bootstrap completed successfully, transitioning to daemon mode..." )
92109 return runDaemonLoop (ctx , cfg )
@@ -101,14 +118,27 @@ func runUnbootstrap(ctx context.Context) error {
101118 return fmt .Errorf ("failed to load config from %s: %w" , configPath , err )
102119 }
103120
104- bootstrapExecutor := bootstrapper .New (cfg , logger )
121+ // Pass cleanup mode to config so the PrivateClusterUninstall step can read it
122+ if cfg .Azure .TargetCluster != nil {
123+ cfg .Azure .TargetCluster .CleanupMode = cleanupMode
124+ }
125+
126+ bootstrapExecutor := bootstrapper .New (logger )
105127 result , err := bootstrapExecutor .Unbootstrap (ctx )
106128 if err != nil {
107129 return err
108130 }
109131
110132 // Handle and log the result (unbootstrap is more lenient with failures)
111- return handleExecutionResult (result , "unbootstrap" , logger )
133+ if err := handleExecutionResult (result , "unbootstrap" , logger ); err != nil {
134+ return err
135+ }
136+
137+ // Print final success message
138+ fmt .Println ()
139+ fmt .Println ("\033 [0;32mSUCCESS:\033 [0m Unbootstrap completed successfully!" )
140+
141+ return nil
112142}
113143
114144// runVersion displays version information
@@ -214,7 +244,7 @@ func checkAndBootstrap(ctx context.Context, cfg *config.Config) error {
214244 logger .Info ("Node requires re-bootstrapping, initiating auto-bootstrap..." )
215245
216246 // Perform bootstrap
217- bootstrapExecutor := bootstrapper .New (cfg , logger )
247+ bootstrapExecutor := bootstrapper .New (logger )
218248 result , err := bootstrapExecutor .Bootstrap (ctx )
219249 if err != nil {
220250 // Bootstrap failed - remove status file so next check will detect the problem
0 commit comments