@@ -2,15 +2,20 @@ package install
2
2
3
3
import (
4
4
"context"
5
+ "errors"
5
6
"fmt"
6
7
"runtime/debug"
7
8
8
9
states "github.com/replicatedhq/embedded-cluster/api/internal/states/install"
9
10
"github.com/replicatedhq/embedded-cluster/api/types"
10
11
)
11
12
13
+ var (
14
+ ErrAppPreflightChecksFailed = errors .New ("app preflight checks failed" )
15
+ )
16
+
12
17
// InstallApp triggers app installation with proper state transitions and panic handling
13
- func (c * InstallController ) InstallApp (ctx context.Context ) (finalErr error ) {
18
+ func (c * InstallController ) InstallApp (ctx context.Context , ignoreAppPreflights bool ) (finalErr error ) {
14
19
lock , err := c .stateMachine .AcquireLock ()
15
20
if err != nil {
16
21
return types .NewConflictError (err )
@@ -25,6 +30,18 @@ func (c *InstallController) InstallApp(ctx context.Context) (finalErr error) {
25
30
}
26
31
}()
27
32
33
+ // Check if app preflights have failed and if we should ignore them
34
+ if c .stateMachine .CurrentState () == states .StateAppPreflightsFailed {
35
+ allowIgnoreAppPreflights := true // TODO: implement once we check for strict app preflights
36
+ if ! ignoreAppPreflights || ! allowIgnoreAppPreflights {
37
+ return types .NewBadRequestError (ErrAppPreflightChecksFailed )
38
+ }
39
+ err = c .stateMachine .Transition (lock , states .StateAppPreflightsFailedBypassed )
40
+ if err != nil {
41
+ return fmt .Errorf ("failed to transition states: %w" , err )
42
+ }
43
+ }
44
+
28
45
if err := c .stateMachine .ValidateTransition (lock , states .StateAppInstalling ); err != nil {
29
46
return types .NewConflictError (err )
30
47
}
@@ -48,21 +65,18 @@ func (c *InstallController) InstallApp(ctx context.Context) (finalErr error) {
48
65
49
66
defer func () {
50
67
if r := recover (); r != nil {
51
- finalErr = fmt .Errorf ("panic installing app : %v: %s" , r , string (debug .Stack ()))
68
+ finalErr = fmt .Errorf ("panic: %v: %s" , r , string (debug .Stack ()))
52
69
}
53
- // Handle errors from app installation
54
70
if finalErr != nil {
55
71
c .logger .Error (finalErr )
56
72
57
73
if err := c .stateMachine .Transition (lock , states .StateAppInstallFailed ); err != nil {
58
74
c .logger .Errorf ("failed to transition states: %w" , err )
59
75
}
60
- return
61
- }
62
-
63
- // Transition to succeeded state on successful app installation
64
- if err := c .stateMachine .Transition (lock , states .StateSucceeded ); err != nil {
65
- c .logger .Errorf ("failed to transition states: %w" , err )
76
+ } else {
77
+ if err := c .stateMachine .Transition (lock , states .StateSucceeded ); err != nil {
78
+ c .logger .Errorf ("failed to transition states: %w" , err )
79
+ }
66
80
}
67
81
}()
68
82
@@ -78,23 +92,6 @@ func (c *InstallController) InstallApp(ctx context.Context) (finalErr error) {
78
92
return nil
79
93
}
80
94
81
- // TODO: remove this once we have endpoints to trigger app installation and report status
82
- // and the app installation is decoupled from the infra installation
83
- func (c * InstallController ) InstallAppNoState (ctx context.Context ) error {
84
- // Get config values for app installation
85
- configValues , err := c .appConfigManager .GetKotsadmConfigValues ()
86
- if err != nil {
87
- return fmt .Errorf ("get kotsadm config values for app install: %w" , err )
88
- }
89
-
90
- // Install the app using the app install manager
91
- if err := c .appInstallManager .Install (ctx , configValues ); err != nil {
92
- return fmt .Errorf ("install app: %w" , err )
93
- }
94
-
95
- return nil
96
- }
97
-
98
95
func (c * InstallController ) GetAppInstallStatus (ctx context.Context ) (types.AppInstall , error ) {
99
96
return c .appInstallManager .GetStatus ()
100
97
}
0 commit comments