-
Notifications
You must be signed in to change notification settings - Fork 80
chore: package dependencies debt #656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
First attempt at A What do you think of the current proposal @prestist (sorry for the multiple pings today 🙇) ? I feel like the already existing interface was good enough so I basically copy-pasted it. |
|
@vic1707 No worries on the pings! Looking now. |
prestist
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I am sorry, yes there is an interface but we need it to do more for us. Currently its being used for "translate" only annd because of how its used we cannot use it in a way that enables us to lookup the implementation we need at runtime.
| "github.com/coreos/vcontext/report" | ||
| ) | ||
|
|
||
| type Translator interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is an interface but i think it needs to be expanded.
So im pretty sure what we are hitting a cycle on is validation, and you can see that the translate has already been inverted but we need to do the same for validate I believe.
We might need more then just validate tho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok for validate too, I think the rest will come as I implement it. It's hard to plan that much in advance 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
100% agree'd. I think after we add validate and metadata we should be good atleast to start
translator/registery.go
Outdated
| "github.com/coreos/vcontext/report" | ||
| "gopkg.in/yaml.v3" | ||
| ) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking we would have
a set(register), get, list, then maybe we could add metadata to the interface.
I.e a Translator would have metadata that would be used to lookup the translator/validator you want.
|
|
||
| type Translator interface { | ||
| TranslateBytes(input []byte, options common.TranslateBytesOptions) ([]byte, report.Report, error) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually we prob, want a new type that is used in translator
Metadata
with "variant, version,ignition version, description, and maybe isexperimental"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good, one of my first idea was to re-use
type commonFields struct {
Variant string `yaml:"variant"`
Version semver.Version `yaml:"version"`
}
as the key to the registry, I guess it can/should be the base for the new Metadata type 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that would make sense. Yeah its basically the building block of what we need.
|
Hi @prestist, sorry it took so long, lots of stuff going on right now 😓 I didn't touch much on the registry as I'm not sure I understand what you meant from |
|
@vic1707 No worries, and there is no rush on this. I will take a look today and see what I can do to help :) Sorry I am a bit behind on this, been feeling under the weather today. |
|
@vic1707 I gave it a shot, there is likely something I am overlooking but this is my interpretation of what we need. You can see the registry is basically a map, which we can register all of our implementations on. The next step would be to implement this interface and see where the holes are, I would probably try it with base07_exp config and lets see. |
|
@prestist thanks for your commit, I think I better understand now. Quick question, in the Validate(ctx context.Context, input []byte) (report.Report, error)I wonder if this is the right interface, I would've gone with Validate(ctx context.Context, input interface{}) (report.Report, error)Since the current methods used for validation work on the schema datastruct, not the bytes input 🤔 func (t Tree) Validate(c path.ContextPath) (r report.Report) {
if t.Local == "" {
r.AddOnError(c, common.ErrTreeNoLocal)
}
return
}I feel like having // Parse yml into schema struct
Parse(input []byte) interface{} // Is basically a yaml.UnMarshal wrapper?
// From schema struct to Ignition struct
Translate(input interface{}, options common.TranslateBytesOptions) (interface{}, report.Report, error)
// Validates yml struct
Validate(in interface{}) report.Reportwould make more sense? |
|
@vic1707 Great question! Sorry for the slow reply – holidays had me away. I'm pretty sure we want to keep the proposed signature, but I could be wrong. My thoughts:
Why not expose interface{} in the signature? In doing that, we'd would make the caller have more complex requirements - they would need to know The main goal is to keep the interface simple, maintain encapsulation, and make the registry |
|
Hi, No worries, free time is also hard to find on my end (renovation work + job) 😓 Ok I think I get your point, but it raises one question You expect for all Translators to have func (t *FCOS0.7) Validate(ctx context.Context, input []byte) (report.Report, error) {
yaml, err := yaml.Unmarshal(input)
// Validation steps
return report, nil
}
func (t *FCOS0.7) Translate(ctx context.Context, input []byte, opts Options) (Result, error) {
report, err := t.Validate(ctx, input)
// ...
}
For now I don't have a better interface to submit matching your requirements 🤔 But, if I can cycle back to my edited proposition, // Parse yml into schema struct, basically a yaml.Unmarshal wrapper?
Parse(input []byte, /*opts?*/) (interface{}, error)
// From inner schema struct to Ignition struct
Translate(input interface{}, options common.TranslateBytesOptions) (interface{}, report.Report, error)
// Validates yml inner struct
Validate(in interface{}) (report.Report, error)Wouldn't the func TranslateBytes([]byte input, options common.TranslateBytesOptions) (Result, error) {
t, err := // get the right translator
// Parse into interface{}
// Validate interface{}
// Translate
return res, nil
}This maintains the Consistency, Abstraction (technically) but the encapsulation workflow moves to the registry. |
Oooh, you are absolutely right, yes, the Registry should be the abstraction layer, not the Translator interface itself, I think that approach should work well. Sorry for the initial push back. I was a bit focused on the wrong parts. The double unmarshaling sounds terrible lol. In summary, yeah, I think your edited approach would be correct and should get us there. |
|
happy I pushed back a little 😄 |
PR implementing: #631 (comment) in order to fix the circular dependency of #631.
From @prestist