From b36b1357df5a48d5c7d4c98841050e2fd1dd5253 Mon Sep 17 00:00:00 2001 From: Rajat Chopra Date: Fri, 1 Feb 2019 13:00:25 -0500 Subject: [PATCH] pkg/asset: A new asset called user-manifests that just picks up user defined manifests A new asset called user-manifest is created so that any files that the user wants to get created can be put in a directory and the installer will end up picking it. The iginition asset will depend on this asset which will have 'empty' files by default, unless something is found on-disk which then gets loaded. It helps us to separate manifests asset and user-defined manifests because there will be no entanglement with other dirty assets and the user can always just plant the manifests without running a separate target 'create manifests' as a sub-step to getting stuff added. --- pkg/asset/ignition/bootstrap/bootstrap.go | 8 ++- pkg/asset/manifests/usermanifests.go | 63 +++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 pkg/asset/manifests/usermanifests.go diff --git a/pkg/asset/ignition/bootstrap/bootstrap.go b/pkg/asset/ignition/bootstrap/bootstrap.go index 6b4f6009244..9d61eb968fd 100644 --- a/pkg/asset/ignition/bootstrap/bootstrap.go +++ b/pkg/asset/ignition/bootstrap/bootstrap.go @@ -78,6 +78,7 @@ func (a *Bootstrap) Dependencies() []asset.Asset { &kubeconfig.Kubelet{}, &manifests.Manifests{}, &manifests.Openshift{}, + &manifests.UserManifests{}, } } @@ -334,7 +335,8 @@ func readFile(name string, reader io.Reader, templateData interface{}) (finalNam func (a *Bootstrap) addParentFiles(dependencies asset.Parents) { mfsts := &manifests.Manifests{} openshiftManifests := &manifests.Openshift{} - dependencies.Get(mfsts, openshiftManifests) + userManifests := &manifests.UserManifests{} + dependencies.Get(mfsts, openshiftManifests, userManifests) a.Config.Storage.Files = append( a.Config.Storage.Files, @@ -344,6 +346,10 @@ func (a *Bootstrap) addParentFiles(dependencies asset.Parents) { a.Config.Storage.Files, ignition.FilesFromAsset(rootDir, "root", 0644, openshiftManifests)..., ) + a.Config.Storage.Files = append( + a.Config.Storage.Files, + ignition.FilesFromAsset(rootDir, "root", 0644, userManifests)..., + ) for _, asset := range []asset.WritableAsset{ &kubeconfig.Admin{}, diff --git a/pkg/asset/manifests/usermanifests.go b/pkg/asset/manifests/usermanifests.go new file mode 100644 index 00000000000..da9c1f9253e --- /dev/null +++ b/pkg/asset/manifests/usermanifests.go @@ -0,0 +1,63 @@ +package manifests + +import ( + "path/filepath" + + "github.com/openshift/installer/pkg/asset" +) + +const ( + userManifestsDir = "user-manifests" +) + +// UserManifests picks up any manifests put in by the user +type UserManifests struct { + FileList []*asset.File +} + +var _ asset.WritableAsset = (*UserManifests)(nil) + +// Name returns a human friendly name for the asset. +func (*UserManifests) Name() string { + return "User's Manifests" +} + +// Dependencies returns all of the dependencies directly needed to generate +// the asset. +func (*UserManifests) Dependencies() []asset.Asset { + return []asset.Asset{} +} + +// Generate generates asset data (which is an empty file list) +func (um *UserManifests) Generate(dependencies asset.Parents) error { + um.FileList = []*asset.File{} + return nil +} + +// Files returns the files generated by the asset. +func (um *UserManifests) Files() []*asset.File { + return um.FileList +} + +// Load loads the user supplied manifest files into the 'manifests' directory +func (um *UserManifests) Load(f asset.FileFetcher) (bool, error) { + fileList, err := f.FetchByPattern(filepath.Join(userManifestsDir, "*")) + if err != nil { + return false, err + } + if len(fileList) == 0 { + return false, nil + } + + um.FileList = []*asset.File{} + for _, f := range fileList { + _, fileName := filepath.Split(f.Filename) + fModified := &asset.File{ + Filename: filepath.Join(manifestDir, fileName), + Data: f.Data, + } + um.FileList = append(um.FileList, fModified) + } + + return true, nil +}