Skip to content

Commit

Permalink
Merge pull request #273 from alexander-demicev/filesfromsecret
Browse files Browse the repository at this point in the history
Fetch additional files from secrets
  • Loading branch information
alexander-demicev authored Feb 27, 2024
2 parents ae0ecc3 + 7a85e9f commit 0e94e1b
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion bootstrap/internal/controllers/rke2config_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,38 @@ func (r *RKE2ConfigReconciler) generateFileListIncludingRegistries(
Permissions: filePermissions,
}

additionalFiles := []bootstrapv1.File{}

for _, file := range scope.Config.Spec.Files {
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)
}

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 0e94e1b

Please sign in to comment.