Skip to content

Commit

Permalink
fix broken logging lines
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMHD committed Jun 12, 2024
1 parent ddc49ad commit 694658d
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions controllers/namespace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (r *NamespaceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
defer r.mu.Unlock()

logger := log.FromContext(ctx)
logger.Info("Reconciling Namespace: ", fmt.Sprint(req.NamespacedName))
logger.Info("Reconciling Namespace", "Namespace", fmt.Sprint(req.NamespacedName))

err := safeNsCache.InitOrPass(r, ctx)
if err != nil {
Expand All @@ -158,16 +158,16 @@ func (r *NamespaceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
err = r.Get(ctx, req.NamespacedName, ns)
if err != nil {
if errors.IsNotFound(err) {
logger.Info("Namespace not found. Ignoring since object must be deleted")
logger.Info("Namespace not found. Ignoring since object must be deleted", "Namespace", fmt.Sprint(req.NamespacedName))

oldTeams := safeNsCache.GetProjects(req.Name)
if len(oldTeams) > 0 {
for t := range oldTeams {
err := r.reconcileAppProject(ctx, logger, t)
if err != nil {
logger.Info("Failed to reconcile AppProject [", t, "] for not found resource error recovery: ", err.Error())
logger.Error(err, "Failed to reconcile AppProject for not found resource error recovery", "AppProj.Name", fmt.Sprint(t))
} else {
logger.Info("Successfully reconciled AppProject [", t, "] for not found resource error recovery")
logger.Info("Successfully reconciled AppProject for not found resource error recovery", "AppProj.Name", fmt.Sprint(t))
}
}
}
Expand All @@ -177,7 +177,7 @@ func (r *NamespaceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
return ctrl.Result{}, nil
}
// Error reading the object - requeue the request.
logger.Error(err, "Failed to get Namespace Resource, Requeuing the request")
logger.Error(err, "Failed to get Namespace Resource, Requeuing the request", "Namespace", fmt.Sprint(req.NamespacedName))
return ctrl.Result{}, err
}

Expand All @@ -190,34 +190,34 @@ func (r *NamespaceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
for t := range oldProjects {
if _, ok := projectsToAdd[t]; !ok {
projectsToRemove = append(projectsToRemove, t)
logger.Info("Updating Cache: Removing NS:", req.Name, " to AppProject:", t)
logger.Info("Updating Cache: Removing NS from AppProject", "Namespace", req.Name, "AppProj.Name", t)
safeNsCache.LeaveProject(req.Name, t)
} else {
delete(projectsToAdd, t)
logger.Info("Updating Cache: Adding NS:", req.Name, " to AppProject:", t)
logger.Info("Updating Cache: Adding NS to AppProject:", "Namespace", req.Name, "AppProj.Name", t)
safeNsCache.JoinProject(req.Name, t)
}
}

var reconciliationErrors *multierror.Error
// add ns to new app-projects
logger.Info("Reconciling New Teams")
logger.Info("Reconciling New Teams", "len", len(projectsToAdd))
for t := range projectsToAdd {
logger.Info("Reconciling AppProject: ", t)
logger.Info("Reconciling AppProject to add new namespaces", "AppProj.Name", t)
err = r.reconcileAppProject(ctx, logger, t)
if err != nil {
logger.Info("Error while Reconciling AppProject ", t, " : ", err.Error())
logger.Error(err, "Error while Reconciling AppProject", "AppProj.Name", t)
reconciliationErrors = multierror.Append(reconciliationErrors, err)
}
}

// removing ns from old projects
logger.Info("Reconciling Old Teams")
for _, t := range projectsToRemove {
logger.Info("Reconciling AppProject:", t)
logger.Info("Reconciling AppProject as on old member", "AppProj.Name", t)
err = r.reconcileAppProject(ctx, logger, t)
if err != nil {
logger.Info("Error while Reconciling AppProject ", t, " : ", err.Error())
logger.Error(err, "Error while Reconciling AppProject", "AppProj.Name", t)
reconciliationErrors = multierror.Append(reconciliationErrors, err)
}
}
Expand Down Expand Up @@ -260,16 +260,6 @@ func (r *NamespaceReconciler) reconcileAppProject(ctx context.Context, logger lo

func (r *NamespaceReconciler) createAppProj(team string) (*argov1alpha1.AppProject, error) {
fmt.Println("run reconcile on ", team)
// listOpts := []client.ListOption{
// client.MatchingLabels(map[string]string{
// teamLabel: team,
// }),
// }
// nsList := &corev1.NamespaceList{}
// err := r.List(ctx, nsList, listOpts...)
// if err != nil {
// return nil, err
// }
desiredNamespaces := safeNsCache.GetNamespaces(team)

destList := []argov1alpha1.ApplicationDestination{}
Expand Down

0 comments on commit 694658d

Please sign in to comment.