Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨deploy-image/v1-alpha: fix the track of options in PROJECT file #2776

Merged
merged 1 commit into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions pkg/plugins/golang/deploy-image/v1alpha1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,19 @@ func (p *createAPISubcommand) Scaffold(fs machinery.Filesystem) error {
if err != nil && !errors.As(err, &config.PluginKeyNotFoundError{}) {
return err
}
cfg.Resources = append(cfg.Resources, p.resource.GVK)
// Track the options informed
cfg.Image = p.image
cfg.ContainerCommand = p.imageContainerCommand
cfg.ContainerPort = p.imageContainerPort
configDataOptions := options{
Image: p.image,
ContainerCommand: p.imageContainerCommand,
ContainerPort: p.imageContainerPort,
}
cfg.Resources = append(cfg.Resources, resourceData{
Group: p.resource.GVK.Group,
Domain: p.resource.GVK.Domain,
Version: p.resource.GVK.Version,
Kind: p.resource.GVK.Kind,
Options: configDataOptions,
},
)
if err := p.config.EncodePluginConfig(pluginKey, cfg); err != nil {
return err
}
Expand Down
15 changes: 12 additions & 3 deletions pkg/plugins/golang/deploy-image/v1alpha1/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package v1alpha1
import (
"sigs.k8s.io/kubebuilder/v3/pkg/config"
cfgv3 "sigs.k8s.io/kubebuilder/v3/pkg/config/v3"
"sigs.k8s.io/kubebuilder/v3/pkg/model/resource"
"sigs.k8s.io/kubebuilder/v3/pkg/model/stage"
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"
"sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang"
Expand Down Expand Up @@ -53,8 +52,18 @@ func (Plugin) SupportedProjectVersions() []config.Version { return supportedProj
func (p Plugin) GetCreateAPISubcommand() plugin.CreateAPISubcommand { return &p.createAPISubcommand }

type pluginConfig struct {
Resources []resource.GVK `json:"resources,omitempty"`
// image indicates the image that will be used to scaffold the deployment
Resources []resourceData `json:"resources,omitempty"`
}

type resourceData struct {
Group string `json:"group,omitempty"`
Domain string `json:"domain,omitempty"`
Version string `json:"version"`
Kind string `json:"kind"`
Options options `json:"options,omitempty"`
}

type options struct {
Image string `json:"image,omitempty"`
ContainerCommand string `json:"containerCommand,omitempty"`
ContainerPort string `json:"containerPort,omitempty"`
Expand Down
7 changes: 4 additions & 3 deletions testdata/project-v3-with-deploy-image/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ layout:
- go.kubebuilder.io/v3
plugins:
deploy-image.go.kubebuilder.io/v1-alpha:
containerCommand: memcached,-m=64,-o,modern,-v
containerPort: "11211"
image: memcached:1.4.36-alpine
resources:
- domain: testproject.org
group: example.com
kind: Memcached
options:
containerCommand: memcached,-m=64,-o,modern,-v
containerPort: "11211"
image: memcached:1.4.36-alpine
version: v1alpha1
projectName: project-v3-with-deploy-image
repo: sigs.k8s.io/kubebuilder/testdata/project-v3-with-deploy-image
Expand Down