Skip to content

Commit

Permalink
fix: Fixes #49, inject resource info to update PROJECT file
Browse files Browse the repository at this point in the history
This commit addresses and issue where not all information for all components are
properly injected into the PROJECT file post-generation.  To fix this, we use
the underlying kubebuilder methods to update a resource, within the scaffold
loop so that the information gets properly propogated to the PROJECT file.  This
will allow us to create webhooks at a later time.

Signed-off-by: Dustin Scott <dustin.scott18@gmail.com>
  • Loading branch information
scottd018 committed Jul 22, 2022
1 parent 61d21ea commit 8818d63
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions internal/plugins/workload/v1/scaffolds/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ func (s *apiScaffolder) scaffoldWorkload(
scaffold *machinery.Scaffold,
workload kinds.WorkloadBuilder,
) error {
componentResource := workload.GetComponentResource(
s.config.GetDomain(),
s.config.GetRepository(),
workload.IsClusterScoped(),
)

// override the scaffold if we have a component. this will allow the Resource
// attribute of the scaffolder to be set appropriately so that things like Group,
// Version, and Kind are passed from the child component and not the parent
Expand All @@ -119,14 +125,16 @@ func (s *apiScaffolder) scaffoldWorkload(
scaffold = machinery.NewScaffold(s.fs,
machinery.WithConfig(s.config),
machinery.WithBoilerplate(s.boilerplate),
machinery.WithResource(workload.GetComponentResource(
s.config.GetDomain(),
s.config.GetRepository(),
workload.IsClusterScoped(),
)),
machinery.WithResource(componentResource),
)
}

// inject the resource as this resource so that our PROJECT file is up to date for each
// resource that we loop through
if err := s.config.UpdateResource(*componentResource); err != nil {
return fmt.Errorf("%w; error updating resource", err)
}

// scaffold the workload api. this generates files within the apis/ folder to include
// items such as common resource methods, api type definitions and child resource typed
// object definitions.
Expand Down

0 comments on commit 8818d63

Please sign in to comment.