Skip to content

Commit

Permalink
Fetch additional files from secrets
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandr Demicev <alexandr.demicev@suse.com>
  • Loading branch information
alexander-demicev committed Feb 27, 2024
1 parent 357bbb4 commit a32a97c
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion bootstrap/internal/controllers/rke2config_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,36 @@ func (r *RKE2ConfigReconciler) generateFileListIncludingRegistries(
Permissions: filePermissions,
}

additionalFiles := []bootstrapv1.File{}
for _, file := range scope.Config.Spec.Files {

Check failure on line 493 in bootstrap/internal/controllers/rke2config_controller.go

View workflow job for this annotation

GitHub Actions / lint

ranges should only be cuddled with assignments used in the iteration (wsl)

Check failure on line 493 in bootstrap/internal/controllers/rke2config_controller.go

View workflow job for this annotation

GitHub Actions / lint

ranges should only be cuddled with assignments used in the iteration (wsl)

Check failure on line 493 in bootstrap/internal/controllers/rke2config_controller.go

View workflow job for this annotation

GitHub Actions / lint

ranges should only be cuddled with assignments used in the iteration (wsl)

Check failure on line 493 in bootstrap/internal/controllers/rke2config_controller.go

View workflow job for this annotation

GitHub Actions / lint

ranges should only be cuddled with assignments used in the iteration (wsl)
if file.ContentFrom != nil {
scope.Logger.V(5).Info("File content is coming from a Secret, getting the content...")

fileContentSecret := &corev1.Secret{}

if err := r.Client.Get(ctx, types.NamespacedName{
Name: file.ContentFrom.Secret.Name,
Namespace: scope.Config.Namespace,
}, fileContentSecret); err != nil {
return nil, fmt.Errorf("unable to get secret %s/%s: %w", scope.Config.Namespace, file.ContentFrom.Secret.Name, err)
}

fileContent := fileContentSecret.Data[file.ContentFrom.Secret.Key]
if fileContent == nil {
return nil, fmt.Errorf("file content is empty for secret %s/%s, secret key %s", scope.Config.Namespace, file.ContentFrom.Secret.Name, file.ContentFrom.Secret.Key)

Check failure on line 508 in bootstrap/internal/controllers/rke2config_controller.go

View workflow job for this annotation

GitHub Actions / lint

line is 166 characters (lll)

Check failure on line 508 in bootstrap/internal/controllers/rke2config_controller.go

View workflow job for this annotation

GitHub Actions / lint

line is 166 characters (lll)
}

file.Content = string(fileContent)
file.ContentFrom = nil
}

additionalFiles = append(additionalFiles, file)
}

files := configFiles
files = append(files, registryFiles...)
files = append(files, initRegistriesFile)
files = append(files, scope.Config.Spec.Files...)
files = append(files, additionalFiles...)

return files, nil
}
Expand Down

0 comments on commit a32a97c

Please sign in to comment.