Skip to content

[Umbrella issue] Scaffolding enhancements #1218

Closed
@Adirio

Description

@Adirio

Description

The following issue will group together all the different enhancements aimed to obtain a smoother file scaffolding system that improves redability, removes duplicate sections, avoids calling several methods multiple times, and centralizes functionality.

Some of the enhancements will be straight forward and will be directly implemented by a PR while others will have their own issue in order to contain the discussion. Please, keep comments in this issue just related to general topics related this issue or suggestions on which other enhancements to apply and use the respective issues or PR to talk about each of the enhancements.

Motivation

The main scheme followed by kubebuilder is the following:

  1. Create a Cobra command and subcommands
  2. This command creates a scaffolder for the specific command that:
    1. Sets default values
    2. Validates the provided input
    3. Creates the specific files

Issues found

  • Some commands do not have an associated scaffolder and their scaffolding logic is done in the command itself (see cmd/webhook_1.go or cmd/webhook_2.go as examples).
  • Validations are spread all accross the project. Some of them are done by the command and some by the associated scaffolder.
  • Files are scaffolded with multiple non-needed fields (for example, ProjectPath is not required for any file and is provided to all, in pkg/scaffold/v1/crd/doc.go a field called Comments is not used, ...), information about the resource is kept outside the resource (GroupDomain, ResourcePackage), or stored in two places (Resource.Resource vs Plural).
  • Resource is being validated by the scaffolders and by each file. This implies that, for example, for a single kubebuilder create api ... command the resource is validated 13 times.

Proposed solutions:

  • Scaffolders for commands that do not have one should be created to keep the scaffolding logic in pkg/scaffold and not in cmd.
  • Validation, unless directly related to the command, should be delegated to the scaffolder.
  • Design interfaces for both scaffolders and files.
  • Re-design the Resource struct to contain the fields that are outside: GroupDomain, Plural and ResourcePackage.
    • Determine if both Resource.Resource and (Resource.)Plural are needed or keep only one of them.

Related Issues and Pull Requests

Issues:

Pull requests:

More coming soon

/kind feature

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featureCategorizes issue or PR as related to a new feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions