Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some linter's complaints #556

Merged
merged 4 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading