@@ -303,13 +303,9 @@ argocd admin settings rbac validate --namespace argocd
303303// Load user policy file if requested or use Kubernetes client to get the
304304// appropriate ConfigMap from the current context
305305func getPolicy (ctx context.Context , policyFile string , kubeClient kubernetes.Interface , namespace string ) (userPolicy string , defaultRole string , matchMode string ) {
306- var err error
307306 if policyFile != "" {
308307 // load from file
309- userPolicy , defaultRole , matchMode , err = getPolicyFromFile (policyFile )
310- if err != nil {
311- log .Fatalf ("could not read policy file: %v" , err )
312- }
308+ userPolicy , defaultRole , matchMode = getPolicyFromFile (policyFile )
313309 } else {
314310 cm , err := getPolicyConfigMap (ctx , kubeClient , namespace )
315311 if err != nil {
@@ -321,9 +317,10 @@ func getPolicy(ctx context.Context, policyFile string, kubeClient kubernetes.Int
321317 return userPolicy , defaultRole , matchMode
322318}
323319
324- // getPolicyFromFile loads a RBAC policy from given path
325- // nolint:unparam // complains about the error being always nil which is false-positive
326- func getPolicyFromFile (policyFile string ) (string , string , string , error ) {
320+ // getPolicyFromFile loads an RBAC policy from the given path. The file may be
321+ // raw policy text or a serialized ConfigMap. If [os.ReadFile] fails, it calls
322+ // log.Fatalf (which exits the process) and does not return to the caller.
323+ func getPolicyFromFile (policyFile string ) (string , string , string ) {
327324 var (
328325 userPolicy string
329326 defaultRole string
@@ -333,7 +330,6 @@ func getPolicyFromFile(policyFile string) (string, string, string, error) {
333330 upol , err := os .ReadFile (policyFile )
334331 if err != nil {
335332 log .Fatalf ("error opening policy file: %v" , err )
336- return "" , "" , "" , err
337333 }
338334
339335 // Try to unmarshal the input file as ConfigMap first. If it succeeds, we
@@ -346,7 +342,7 @@ func getPolicyFromFile(policyFile string) (string, string, string, error) {
346342 userPolicy , defaultRole , matchMode = getPolicyFromConfigMap (upolCM )
347343 }
348344
349- return userPolicy , defaultRole , matchMode , nil
345+ return userPolicy , defaultRole , matchMode
350346}
351347
352348// Retrieve policy information from a ConfigMap
0 commit comments