Skip to content

common: create common functions and way to embed for rest of them #1100

@klaskosk

Description

@klaskosk

The current implementation of EmbeddableBuilder only supports the minimal methods that every builder must support. Some builders, such as HFCBuilder in pkg/bmh/hfc.go only support these. Some builders which only support these methods do so for good reason, as it makes no sense to have some resources deletable. A similar issue is that force is only a parameter for some Update methods.

We need to figure out a way to embed these methods for only some builders then. Some current ideas to do so:

  • worst solution but also easiest is to just define the functions in pkg/internal/common then require builders to create short methods that tail call the common function
  • maybe we create embeddable builders which compose each other to offer more functions. the more idiomatic version is to have something like struct { EmbeddableBuilder; EmbeddableDeleter; EmbeddableUpdater } but this would result in fields referencing other fields in the same struct and other weirdness
  • an alternative to having adjacent builders is a hierarchy of builders. this is just weaponizing composition to create inheritance but seems more viable. GetGVK and SetGVK may be a concern
  • another bad but easy solution is to just implement the methods anyway. it's generally good to prevent users from doing things they shouldn't at compile time and this goes against that. also doesn't handle different signatures very well

Metadata

Metadata

Assignees

Labels

common-builderMigration to use a common builder struct and interface

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions