8
8
"os"
9
9
"path/filepath"
10
10
"strings"
11
+ "sync"
11
12
"time"
12
13
13
14
"github.com/openshift/library-go/pkg/assets/create"
@@ -23,6 +24,8 @@ import (
23
24
const (
24
25
// how long we wait until the bootstrap pods to be running
25
26
bootstrapPodsRunningTimeout = 20 * time .Minute
27
+ // how long we wait until the assets must all be created
28
+ assetsCreatedTimeout = 60 * time .Minute
26
29
)
27
30
28
31
type Config struct {
@@ -63,8 +66,8 @@ func (b *startCommand) Run() error {
63
66
64
67
bcp := newBootstrapControlPlane (b .assetDir , b .podManifestPath )
65
68
69
+ // Always tear down the bootstrap control plane and clean up manifests and secrets.
66
70
defer func () {
67
- // Always tear down the bootstrap control plane and clean up manifests and secrets.
68
71
if err := bcp .Teardown (); err != nil {
69
72
UserOutput ("Error tearing down temporary bootstrap control plane: %v\n " , err )
70
73
}
@@ -81,9 +84,6 @@ func (b *startCommand) Run() error {
81
84
return err
82
85
}
83
86
84
- ctx , cancel := context .WithTimeout (context .TODO (), bootstrapPodsRunningTimeout )
85
- defer cancel ()
86
-
87
87
// We don't want the client contact the API servers via load-balancer, but only talk to the local API server.
88
88
// This will speed up the initial "where is working API server" process.
89
89
localClientConfig := rest .CopyConfig (restConfig )
@@ -98,23 +98,46 @@ func (b *startCommand) Run() error {
98
98
return err
99
99
}
100
100
101
- if err := create .EnsureManifestsCreated (ctx , filepath .Join (b .assetDir , assetPathManifests ), localClientConfig , create.CreateOptions {
102
- Verbose : true ,
103
- StdErr : os .Stderr ,
104
- }); err != nil {
105
- return err
101
+ // create assets against localhost apiserver (in the background) and wait for control plane to be up
102
+ createAssetsInBackground := func (ctx context.Context , cancel func (), client * rest.Config ) * sync.WaitGroup {
103
+ done := sync.WaitGroup {}
104
+ done .Add (1 )
105
+ go func () {
106
+ defer done .Done ()
107
+ if err := create .EnsureManifestsCreated (ctx , filepath .Join (b .assetDir , assetPathManifests ), client , create.CreateOptions {
108
+ Verbose : true ,
109
+ StdErr : os .Stderr ,
110
+ }); err != nil {
111
+ select {
112
+ case <- ctx .Done ():
113
+ default :
114
+ UserOutput ("Assert creation failed: %v\n " , err )
115
+ cancel ()
116
+ }
117
+ }
118
+ }()
119
+ return & done
106
120
}
107
-
108
- if err = waitUntilPodsRunning (client , b .requiredPodPrefixes , bootstrapPodsRunningTimeout ); err != nil {
121
+ ctx , cancel := context .WithTimeout (context .TODO (), bootstrapPodsRunningTimeout )
122
+ defer cancel ()
123
+ assetsDone := createAssetsInBackground (ctx , cancel , localClientConfig )
124
+ if err = waitUntilPodsRunning (ctx , client , b .requiredPodPrefixes ); err != nil {
109
125
return err
110
126
}
127
+ cancel ()
128
+ assetsDone .Wait ()
111
129
112
130
// notify installer that we are ready to tear down the temporary bootstrap control plane
113
131
UserOutput ("Sending bootstrap-success event." )
114
132
if _ , err := client .CoreV1 ().Events ("kube-system" ).Create (makeBootstrapSuccessEvent ("kube-system" , "bootstrap-success" )); err != nil && ! apierrors .IsAlreadyExists (err ) {
115
133
return err
116
134
}
117
135
136
+ // switch over to ELB client and continue with the assets
137
+ ctx , cancel = context .WithTimeout (context .Background (), assetsCreatedTimeout )
138
+ defer cancel ()
139
+ assetsDone = createAssetsInBackground (ctx , cancel , restConfig )
140
+
118
141
// optionally wait for tear down event coming from the installer. This is necessary to
119
142
// remove the bootstrap node from the AWS load balancer.
120
143
if len (b .waitForTearDownEvent ) != 0 {
@@ -129,6 +152,17 @@ func (b *startCommand) Run() error {
129
152
UserOutput ("Got %s event." , b .waitForTearDownEvent )
130
153
}
131
154
155
+ // tear down the bootstrap control plane. Set bcp to nil to avoid a second tear down in the defer func.
156
+ err = bcp .Teardown ()
157
+ bcp = nil
158
+ if err != nil {
159
+ UserOutput ("Error tearing down temporary bootstrap control plane: %v\n " , err )
160
+ }
161
+
162
+ // wait for the tail of assets to be created after tear down
163
+ UserOutput ("Waiting for remaining assets to be created.\n " )
164
+ assetsDone .Wait ()
165
+
132
166
return nil
133
167
}
134
168
0 commit comments