Skip to content

Commit

Permalink
implement shutdown
Browse files Browse the repository at this point in the history
Signed-off-by: Manabu Mccloskey <[email protected]>
  • Loading branch information
nabuskey committed Nov 21, 2023
1 parent a2a8208 commit 6dd8cda
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
25 changes: 22 additions & 3 deletions pkg/controllers/localbuild/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,13 @@ func (r *LocalbuildReconciler) ReconcileArgoAppsWithGitea(ctx context.Context, r
}
}

// TODO: this needs to be removed for local file syncs.
r.shouldShutdown = true
return ctrl.Result{}, nil
shutdown, err := r.shouldShutDown(ctx, resource)
if err != nil {
return ctrl.Result{Requeue: true}, err
}
r.shouldShutdown = shutdown

return ctrl.Result{RequeueAfter: time.Second * 30}, nil
}

func (r *LocalbuildReconciler) reconcileEmbeddedApp(ctx context.Context, appName string, resource *v1alpha1.Localbuild) (ctrl.Result, error) {
Expand Down Expand Up @@ -366,6 +370,21 @@ func (r *LocalbuildReconciler) reconcileEmbeddedApp(ctx context.Context, appName
return ctrl.Result{}, nil
}

func (r *LocalbuildReconciler) shouldShutDown(ctx context.Context, resource *v1alpha1.Localbuild) (bool, error) {
repos := &v1alpha1.GitRepositoryList{}
err := r.Client.List(ctx, repos, client.InNamespace(resource.Namespace))
if err != nil {
return false, fmt.Errorf("getting repo list %w", err)
}
for i := range repos.Items {
repo := repos.Items[i]
if !repo.Status.Synced {
return false, nil
}
}
return true, nil
}

func GetEmbeddedRawInstallResources(name string) ([][]byte, error) {
switch name {
case "argocd":
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/localbuild/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (e *EmbeddedInstallation) Install(ctx context.Context, req ctrl.Request, re
_ = appsv1.AddToScheme(sch)
if gvkObj, err := sch.New(gvk); err == nil {
if gotObj, ok := gvkObj.(client.Object); ok {
if err := cli.Get(ctx, types.NamespacedName{Namespace: obj.GetNamespace(), Name: obj.GetName()}, gotObj); err != nil {
if err := cli.Get(ctx, types.NamespacedName{Namespace: e.namespace, Name: obj.GetName()}, gotObj); err != nil {
if err = controllerutil.SetControllerReference(resource, obj, sc); err != nil {
log.Error(err, "Setting controller reference for deployment", obj.GetName(), obj)
return ctrl.Result{}, err
Expand Down Expand Up @@ -132,7 +132,7 @@ func (e *EmbeddedInstallation) Install(ctx context.Context, req ctrl.Request, re

for {
if gotObj, ok := gvkObj.(client.Object); ok {
if err := cli.Get(ctx, types.NamespacedName{Namespace: obj.GetNamespace(), Name: obj.GetName()}, gotObj); err != nil {
if err := cli.Get(ctx, types.NamespacedName{Namespace: e.namespace, Name: obj.GetName()}, gotObj); err != nil {
errCh <- err
return
}
Expand Down

0 comments on commit 6dd8cda

Please sign in to comment.