You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// GetInput returns the Input for creating a scaffold file
GetInput() (Input, error)
}
The single method is not descriptive enough and does different tasks:
Sets default values
Returns a non-descriptive Input struct which contains:
Two fields needed to prepare the template: Path and TemplateBody
Several other fileds that are not used
Note: the Input struct also works as a parent class for mostly all File-implementing structs so that they can be injected some data from the scaffold. By mostly I mean all except the PROJECT file, which is an special-cased yaml file which doesn't have an embedded Input.
The path is needed in lines 235, 291 and 292. The template body is needed in line 278. The side-effect of setting the default values is important here as the files are used to execute the templates in line 284:
Context
Current situation
The current
File
interface is as follows:kubebuilder/pkg/scaffold/input/input.go
Lines 141 to 145 in 03f70fb
The single method is not descriptive enough and does different tasks:
Input
struct which contains:Path
andTemplateBody
Note: the
Input
struct also works as a parent class for mostly allFile
-implementing structs so that they can be injected some data from the scaffold. By mostly I mean all except thePROJECT
file, which is an special-cased yaml file which doesn't have an embeddedInput
.GetInput
usageI have tracked
GetInput
usages.pkg/scaffold/project.go
Lines 101 and 106 for v1, 192 and 197 for v2:
kubebuilder/pkg/scaffold/project.go
Line 101 in 03f70fb
kubebuilder/pkg/scaffold/project.go
Line 106 in 03f70fb
kubebuilder/pkg/scaffold/project.go
Line 192 in 03f70fb
kubebuilder/pkg/scaffold/project.go
Line 197 in 03f70fb
The created variables are used in lines 113 and 127 for v1, and 204 and 218 for v2:
kubebuilder/pkg/scaffold/project.go
Line 113 in 03f70fb
kubebuilder/pkg/scaffold/project.go
Line 127 in 03f70fb
kubebuilder/pkg/scaffold/project.go
Line 204 in 03f70fb
kubebuilder/pkg/scaffold/project.go
Line 218 in 03f70fb
Only the path is needed. Setting the default values (which is also done by
GetInput
) is not needed here except for the path itself.pkg/scaffold/scaffold.go
Line 229:
kubebuilder/pkg/scaffold/scaffold.go
Line 229 in 03f70fb
Which is later used in line 235 and 238:
kubebuilder/pkg/scaffold/scaffold.go
Line 235 in 03f70fb
kubebuilder/pkg/scaffold/scaffold.go
Line 238 in 03f70fb
The usage in
doTemplate
are in lines 278, 291 and 292:kubebuilder/pkg/scaffold/scaffold.go
Line 278 in 03f70fb
kubebuilder/pkg/scaffold/scaffold.go
Lines 291 to 292 in 03f70fb
The path is needed in lines 235, 291 and 292. The template body is needed in line 278. The side-effect of setting the default values is important here as the files are used to execute the templates in line 284:
kubebuilder/pkg/scaffold/scaffold.go
Line 284 in 03f70fb
pkg/scaffold/project/project_test.go
Line 49:
kubebuilder/pkg/scaffold/project/project_test.go
Lines 48 to 52 in 03f70fb
It is used to set the default values.
Proposal
A new interface is proposed:
Method usage
GetPath
would be used in lines 113, 127, 204 and 218 ofpkg/scaffold/project.go
and in lines 235, 291 and 292 ofpkg/scaffold/scaffold.go
.GetTemplateBody
would be used in line 278 ofpkg/scaffold/scaffold.go
.SetDefaults
would be called before line 284 ofpkg/scaffold/scaffold.go
and in line 49 ofpkg/scaffold/project/project_test.go
.GetInput
calls with their error handlings could be removed.This feature is part of a bigger change tracked in #1218
/kind feature
The text was updated successfully, but these errors were encountered: