Skip to content

Commit

Permalink
Sort order of SA tokens in path collision error message
Browse files Browse the repository at this point in the history
The ServiceAccount token path collision tests were failing inconsistently, due to inconsistent ordering of the SA tokens.
SA tokens are now sorted by name when returning an error involving a path collision.

Signed-off-by: Andrew Obuchowicz <aobuchow@redhat.com>
  • Loading branch information
AObuchow committed May 30, 2023
1 parent a6859af commit cc35471
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/provision/workspace/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,17 @@ func checkSATokenPathCollisions(saTokens []v1alpha1.ServiceAccountToken, mountPa
for _, saToken := range collidingSATokens {
problemNames = append(problemNames, saToken.Name)
}
sort.Slice(problemNames, func(i, j int) bool {
return problemNames[i] < problemNames[j]
})

if len(problemPaths) == 1 {
return fmt.Errorf("the following ServiceAccount tokens have the same path (%s) and mount path (%s): %s", path, mountPath, strings.Join(problemNames, ", "))
}
}
sort.Slice(problemNames, func(i, j int) bool {
return problemNames[i] < problemNames[j]
})
return fmt.Errorf("multiple ServiceAccount tokens share the same path and mount path: %s", strings.Join(problemNames, ", "))
}
return nil
Expand Down

0 comments on commit cc35471

Please sign in to comment.