Skip to content

Commit

Permalink
feat: controller image as an input parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Andriy Kalashnykov <AndriyKalashnykov@gmail.com>
  • Loading branch information
AndriyKalashnykov committed Jun 27, 2022
1 parent 2ed532b commit 42a7942
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ endif
INIT_OPTS=init \
--workload-config .workloadConfig/workload.yaml \
--repo github.com/acme/acme-cnp-mgr \
--skip-go-version-check
--skip-go-version-check \
--controller-image controller:latest
CREATE_OPTS=create api \
--workload-config .workloadConfig/workload.yaml \
--controller \
Expand Down
3 changes: 3 additions & 0 deletions internal/plugins/config/v1/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ import (

type initSubcommand struct {
workloadConfigPath string
controllerImage string
}

var _ plugin.InitSubcommand = &initSubcommand{}

func (p *initSubcommand) BindFlags(fs *pflag.FlagSet) {
fs.StringVar(&p.workloadConfigPath, "workload-config", "", "path to workload config file")
fs.StringVar(&p.controllerImage, "controller-image", "controller:latest", "controller image")
}

func (p *initSubcommand) InjectConfig(c config.Config) error {
Expand All @@ -33,6 +35,7 @@ func (p *initSubcommand) InjectConfig(c config.Config) error {
pluginConfig := workloadconfig.Plugin{
WorkloadConfigPath: p.workloadConfigPath,
CliRootCommandName: processor.Workload.GetRootCommand().Name,
ControllerImg: p.controllerImage,
}

if err := c.EncodePluginConfig(workloadconfig.PluginKey, pluginConfig); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions internal/plugins/workload/v1/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type initSubcommand struct {

workloadConfigPath string
cliRootCommandName string
controllerImg string

workload kinds.WorkloadBuilder
}
Expand Down Expand Up @@ -53,6 +54,7 @@ func (p *initSubcommand) InjectConfig(c config.Config) error {

p.workloadConfigPath = pluginConfig.WorkloadConfigPath
p.cliRootCommandName = pluginConfig.CliRootCommandName
p.controllerImg = pluginConfig.ControllerImg

return nil
}
Expand All @@ -77,6 +79,7 @@ func (p *initSubcommand) Scaffold(fs machinery.Filesystem) error {
p.config,
p.workload,
p.cliRootCommandName,
p.controllerImg,
)
scaffolder.InjectFS(fs)

Expand Down
5 changes: 4 additions & 1 deletion internal/plugins/workload/v1/scaffolds/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type initScaffolder struct {
boilerplatePath string
workload kinds.WorkloadBuilder
cliRootCommandName string
controllerImg string

fs machinery.Filesystem
}
Expand All @@ -34,12 +35,14 @@ func NewInitScaffolder(
cfg config.Config,
workload kinds.WorkloadBuilder,
cliRootCommandName string,
controllerImg string,
) plugins.Scaffolder {
return &initScaffolder{
config: cfg,
boilerplatePath: "hack/boilerplate.go.txt",
workload: workload,
cliRootCommandName: cliRootCommandName,
controllerImg: controllerImg,
}
}

Expand Down Expand Up @@ -79,7 +82,7 @@ func (s *initScaffolder) Scaffold() error {
&templates.Main{},
&templates.GoMod{},
&templates.Dockerfile{},
&templates.Makefile{RootCmdName: s.cliRootCommandName},
&templates.Makefile{RootCmdName: s.cliRootCommandName, ControllerImg: s.controllerImg},
&templates.Readme{RootCmdName: s.cliRootCommandName},
&e2e.Test{},
); err != nil {
Expand Down
7 changes: 4 additions & 3 deletions internal/plugins/workload/v1/scaffolds/templates/makefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ type Makefile struct {
machinery.TemplateMixin
machinery.RepositoryMixin

RootCmdName string
CrdOptions string
RootCmdName string
CrdOptions string
ControllerImg string
}

func (f *Makefile) SetTemplateDefaults() error {
Expand All @@ -36,7 +37,7 @@ func (f *Makefile) SetTemplateDefaults() error {
//nolint: lll
const makefileTemplate = `
# Image URL to use all building/pushing image targets
IMG ?= controller:latest
IMG ?= "{{ .ControllerImg }}"
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "{{ .CrdOptions }}"
Expand Down
1 change: 1 addition & 0 deletions internal/workload/v1/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ const PluginKey = "operatorBuilder"
type Plugin struct {
WorkloadConfigPath string `json:"workloadConfigPath" yaml:"workloadConfigPath"`
CliRootCommandName string `json:"cliRootCommandName" yaml:"cliRootCommandName"`
ControllerImg string `json:"controllerImg" yaml:"controllerImg"`
}

0 comments on commit 42a7942

Please sign in to comment.