Skip to content

Commit

Permalink
Merge pull request #2776 from NikhilSharmaWe/trackOptions
Browse files Browse the repository at this point in the history
✨deploy-image/v1-alpha: fix the track of options in PROJECT file
  • Loading branch information
k8s-ci-robot committed Jun 28, 2022
2 parents ade165e + c9d4180 commit 78ad658
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
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

0 comments on commit 78ad658

Please sign in to comment.