Skip to content

Commit

Permalink
Merge pull request #274 from alexander-demicev/cherrypickfiles
Browse files Browse the repository at this point in the history
[release-0.2] Fetch additional files from secrets
  • Loading branch information
alexander-demicev authored Feb 27, 2024
2 parents 9b5aa51 + 88b4c7a commit 6e921c2
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 6e921c2

Please sign in to comment.