Skip to content

Commit eecccc9

Browse files
authored
Ensure git clone base directory exists on startup (#111)
1 parent f579732 commit eecccc9

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

cmd/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,18 @@ func main() {
348348
}
349349
setupLog.Info("Func CLI is ready")
350350

351+
gitManager, err := git.NewManager()
352+
if err != nil {
353+
setupLog.Error(err, "failed to initialize git manager")
354+
os.Exit(1)
355+
}
356+
351357
if err := (&controller.FunctionReconciler{
352358
Client: mgr.GetClient(),
353359
Scheme: mgr.GetScheme(),
354360
Recorder: mgr.GetEventRecorder("functions-controller"),
355361
FuncCliManager: funcCLIManager,
356-
GitManager: git.NewManager(),
362+
GitManager: gitManager,
357363
OperatorNamespace: operatorNamespace,
358364
}).SetupWithManager(mgr); err != nil {
359365
setupLog.Error(err, "unable to create controller", "controller", "Function")

internal/git/manager.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ type Manager interface {
2323
CloneRepository(ctx context.Context, url, subPath, reference string, auth map[string][]byte) (*Repository, error)
2424
}
2525

26-
func NewManager() Manager {
27-
return &managerImpl{}
26+
func NewManager() (Manager, error) {
27+
if err := os.MkdirAll(cloneBaseDir, 0755); err != nil {
28+
return nil, fmt.Errorf("failed to create git clone base directory: %w", err)
29+
}
30+
return &managerImpl{}, nil
2831
}
2932

3033
type managerImpl struct{}

0 commit comments

Comments
 (0)