Skip to content

Commit

Permalink
fix some linter's complaints (#556)
Browse files Browse the repository at this point in the history
* fix some linter complaints

Signed-off-by: Francesco Ilario <filario@redhat.com>

* Update controllers/idler/idler_controller.go

Co-authored-by: Alexey Kazakov <alkazako@redhat.com>

* Update controllers/nstemplateset/space_roles.go

Co-authored-by: Francisc Munteanu <fmuntean@redhat.com>

---------

Signed-off-by: Francesco Ilario <filario@redhat.com>
Co-authored-by: Alexey Kazakov <alkazako@redhat.com>
Co-authored-by: Francisc Munteanu <fmuntean@redhat.com>
  • Loading branch information
3 people authored Apr 8, 2024
1 parent 77aa3d4 commit 5a3ab8e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion controllers/idler/idler_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func (r *Reconciler) ensureIdling(ctx context.Context, idler *toolchainv1alpha1.
}
newStatusPods := make([]toolchainv1alpha1.Pod, 0, 10)
for _, pod := range podList.Items {
pod := pod // TODO We won't need it after upgrading to go 1.22: https://go.dev/blog/loopvar-preview
logger := log.FromContext(ctx)
podLogger := logger.WithValues("pod_name", pod.Name, "pod_phase", pod.Status.Phase)
if trackedPod := findPodByName(idler, pod.Name); trackedPod != nil {
Expand All @@ -154,7 +155,7 @@ func (r *Reconciler) ensureIdling(ctx context.Context, idler *toolchainv1alpha1.
}
if !deletedByController { // Pod not managed by a controller. We can just delete the pod.
logger.Info("Deleting pod without controller")
if err := r.AllNamespacesClient.Delete(ctx, &pod); err != nil { // nolint:gosec
if err := r.AllNamespacesClient.Delete(ctx, &pod); err != nil {
return err
}
podLogger.Info("Pod deleted")
Expand Down
7 changes: 4 additions & 3 deletions controllers/nstemplateset/space_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (r *spaceRolesManager) ensure(ctx context.Context, nsTmplSet *toolchainv1al
}
logger.Info("ensuring space roles", "namespace_count", len(nss), "role_count", len(nsTmplSet.Spec.SpaceRoles))
for _, ns := range nss {
ns := ns // TODO We won't need it after upgrading to go 1.22: https://go.dev/blog/loopvar-preview
// space roles previously applied
// read annotation to see what was applied last time, so we can compare with the new SpaceRoles and remove all obsolete resources (based on their kind/names)
var lastAppliedSpaceRoles []toolchainv1alpha1.NSTemplateSetSpaceRole
Expand All @@ -47,12 +48,12 @@ func (r *spaceRolesManager) ensure(ctx context.Context, nsTmplSet *toolchainv1al
return false, err
}
}
lastAppliedSpaceRoleObjs, err := r.getSpaceRolesObjects(lctx, &ns, lastAppliedSpaceRoles) // nolint:gosec
lastAppliedSpaceRoleObjs, err := r.getSpaceRolesObjects(lctx, &ns, lastAppliedSpaceRoles)
if err != nil {
return false, r.wrapErrorWithStatusUpdateForSpaceRolesFailure(lctx, nsTmplSet, err, "failed to retrieve last applied space roles")
}
// space roles to apply now
spaceRoleObjs, err := r.getSpaceRolesObjects(lctx, &ns, nsTmplSet.Spec.SpaceRoles) // nolint:gosec
spaceRoleObjs, err := r.getSpaceRolesObjects(lctx, &ns, nsTmplSet.Spec.SpaceRoles)
if err != nil {
return false, r.wrapErrorWithStatusUpdateForSpaceRolesFailure(lctx, nsTmplSet, err, "failed to retrieve space roles to apply")
}
Expand Down Expand Up @@ -84,7 +85,7 @@ func (r *spaceRolesManager) ensure(ctx context.Context, nsTmplSet *toolchainv1al
ns.Annotations = map[string]string{}
}
ns.Annotations[toolchainv1alpha1.LastAppliedSpaceRolesAnnotationKey] = string(sr)
if err := r.Client.Update(ctx, &ns); err != nil { // nolint:gosec
if err := r.Client.Update(ctx, &ns); err != nil {
return false, r.wrapErrorWithStatusUpdate(lctx, nsTmplSet, r.setStatusProvisionFailed, err,
fmt.Sprintf("failed to update namespace with '%s' annotation", toolchainv1alpha1.LastAppliedSpaceRolesAnnotationKey))
}
Expand Down

0 comments on commit 5a3ab8e

Please sign in to comment.