-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reference Hint Check fixed + alignment of configure function (#672)
## Description Some fixes: - align different configure functions and switch to config context - fix reference hint check for same resource ## What type of PR is this? (check all applicable) - [ ] 🍕 Feature - [x] 🐛 Bug Fix - [ ] 📝 Documentation Update - [ ] 🎨 Style - [ ] 🧑💻 Code Refactor - [ ] 🔥 Performance Improvements - [x] ✅ Test - [ ] 🤖 Build - [ ] 🔁 CI - [ ] 📦 Chore (Release) - [ ] ⏩ Revert ## Related Tickets & Documents <!-- Please use this format link issue numbers: Fixes #123 https://docs.github.com/en/free-pro-team@latest/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword --> - Related Issue # (issue) - Closes # (issue) - Fixes # (issue) > Remove if not applicable ## Screenshots <!-- Visual changes require screenshots --> ## Added tests? - [ ] 👍 yes - [ ] 🙅 no, because they aren't needed - [ ] 🙋 no, because I need help - [ ] Separate ticket for tests # (issue/pr) Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration ## Added to documentation? - [ ] 📜 README.md - [ ] 🙅 no documentation needed ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules
- Loading branch information
1 parent
137c796
commit 929d0ea
Showing
5 changed files
with
56 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
name: chart2 | ||
type: helmChart | ||
input: | ||
type: helm | ||
path: testchart | ||
repository: mandelsoft/testchart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,20 @@ | ||
package configutils | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
_ "github.com/open-component-model/ocm/pkg/contexts/datacontext/config" | ||
|
||
"github.com/mandelsoft/spiff/features" | ||
"github.com/mandelsoft/spiff/spiffing" | ||
"github.com/mandelsoft/vfs/pkg/osfs" | ||
"github.com/mandelsoft/vfs/pkg/vfs" | ||
|
||
"github.com/open-component-model/ocm/pkg/contexts/config" | ||
"github.com/open-component-model/ocm/pkg/errors" | ||
"github.com/open-component-model/ocm/pkg/contexts/ocm/utils" | ||
) | ||
|
||
func Configure(path string) error { | ||
return ConfigureContext(config.DefaultContext(), path) | ||
func Configure(path string, fss ...vfs.FileSystem) error { | ||
_, err := utils.Configure(config.DefaultContext(), path, fss...) | ||
return err | ||
} | ||
|
||
func ConfigureContext(ctxp config.ContextProvider, path string) error { | ||
ctx := config.FromProvider(ctxp) | ||
|
||
h, _ := os.UserHomeDir() | ||
if path == "" { | ||
if h != "" { | ||
cfg := h + "/.ocmconfig" | ||
if ok, err := vfs.FileExists(osfs.New(), cfg); ok && err == nil { | ||
path = cfg | ||
} | ||
} | ||
} | ||
|
||
if path != "" { | ||
if strings.HasPrefix(path, "~"+string(os.PathSeparator)) { | ||
if len(h) == 0 { | ||
return fmt.Errorf("no home directory found for resolving path of ocm config file %q", path) | ||
} | ||
path = h + path[1:] | ||
} | ||
data, err := vfs.ReadFile(osfs.New(), path) | ||
if err != nil { | ||
return errors.Wrapf(err, "cannot read ocm config file %q", path) | ||
} | ||
|
||
sctx := spiffing.New().WithFeatures(features.INTERPOLATION, features.CONTROL) | ||
data, err = spiffing.Process(sctx, spiffing.NewSourceData(path, data)) | ||
if err != nil { | ||
return errors.Wrapf(err, "processing ocm config %q", path) | ||
} | ||
cfg, err := ctx.GetConfigForData(data, nil) | ||
if err != nil { | ||
return errors.Wrapf(err, "invalid ocm config file %q", path) | ||
} | ||
err = ctx.ApplyConfig(cfg, path) | ||
if err != nil { | ||
return errors.Wrapf(err, "cannot apply ocm config %q", path) | ||
} | ||
} | ||
return nil | ||
func ConfigureContext(ctxp config.ContextProvider, path string, fss ...vfs.FileSystem) error { | ||
_, err := utils.Configure(ctxp, path, fss...) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters