Skip to content

Commit af901a0

Browse files
committed
Wait for func cli manager to be ready before starting controllers
1 parent 9c9bfba commit af901a0

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

cmd/main.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package main
1818

1919
import (
20+
"context"
2021
"crypto/tls"
2122
"flag"
2223
"os"
@@ -210,13 +211,22 @@ func main() {
210211
os.Exit(1)
211212
}
212213

213-
// Initialize and add func CLI manager
214+
// Initialize func CLI manager
214215
funcCLIManager, err := funccli.NewManager(ctrl.Log, funcCLIPath, funcCLICheckInterval)
215216
if err != nil {
216217
setupLog.Error(err, "unable to create func CLI manager")
217218
os.Exit(1)
218219
}
219220

221+
// Ensure func CLI is ready before controllers start
222+
setupLog.Info("Downloading func CLI before starting controllers")
223+
ctx := context.Background()
224+
if err := funcCLIManager.EnsureReady(ctx); err != nil {
225+
setupLog.Error(err, "failed to ensure func CLI is ready")
226+
os.Exit(1)
227+
}
228+
setupLog.Info("Func CLI is ready")
229+
220230
if err := (&controller.FunctionReconciler{
221231
Client: mgr.GetClient(),
222232
Scheme: mgr.GetScheme(),

internal/funccli/manager.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ func (m *Manager) GetCurrentVersion(ctx context.Context) (string, error) {
123123
return version, nil
124124
}
125125

126+
// EnsureReady ensures the func CLI is downloaded and ready to use.
127+
// This should be called before controllers start processing resources.
128+
func (m *Manager) EnsureReady(ctx context.Context) error {
129+
m.logger.Info("Ensuring func CLI is ready")
130+
return m.checkAndUpdate(ctx)
131+
}
132+
126133
// checkAndUpdate checks for a new version and downloads it if available
127134
func (m *Manager) checkAndUpdate(ctx context.Context) error {
128135
// Lock to ensure only one update happens at a time

0 commit comments

Comments
 (0)