Skip to content

Commit c7d57aa

Browse files
✨ (kustomize/v1) add validation to let users know when the architecture used to run the plugin is not supported (#2698)
Co-authored-by: Bryce Palmer <[email protected]> Co-authored-by: Bryce Palmer <[email protected]>
1 parent 800fdee commit c7d57aa

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

docs/book/src/plugins/kustomize-v1.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ The kustomize plugin allows you to scaffold all kustomize manifests used to work
44
By using the kustomize plugin, you can create your own language plugins and ensure that you will have the same configurations
55
and features provided by it.
66

7+
<aside class="note">
8+
<h1>Supportability</h1>
9+
10+
This plugin uses [kubernetes-sigs/kustomize](https://github.com/kubernetes-sigs/kustomize) v3 and the architectures supported are:
11+
- linux/amd64
12+
- linux/arm64
13+
- darwin/amd64
14+
15+
You might want to consider using [kustomize/v2-alpha](./kustomize-v2-alpha.md) if you are looking to scaffold projects in
16+
other architecture environments. (i.e. if you are looking to scaffold projects with Apple Silicon/M1 (`darwin/arm64`) this plugin
17+
will not work, more info: [kubernetes-sigs/kustomize#4612](https://github.com/kubernetes-sigs/kustomize/issues/4612)).
18+
</aside>
19+
720
Note that projects such as [Operator-sdk][sdk] consume the Kubebuilder project as a lib and provide options to work with other languages
821
like Ansible and Helm. The kustomize plugin allows them to easily keep a maintained configuration and ensure that all languages have
922
the same configuration. It is also helpful if you are looking to provide nice plugins which will perform changes on top of

pkg/plugins/common/kustomize/v1/init.go

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import (
2020
"fmt"
2121
"os"
2222
"path/filepath"
23+
"runtime"
2324
"strings"
2425

26+
log "github.com/sirupsen/logrus"
2527
"github.com/spf13/pflag"
2628

2729
"sigs.k8s.io/kubebuilder/v3/pkg/config"
@@ -33,6 +35,11 @@ import (
3335

3436
var _ plugin.InitSubcommand = &initSubcommand{}
3537

38+
// Verify if the local environment is supported by this plugin
39+
var supportedArchs = []string{"linux/amd64",
40+
"linux/arm64",
41+
"darwin/amd64"}
42+
3643
type initSubcommand struct {
3744
config config.Config
3845

@@ -43,10 +50,17 @@ type initSubcommand struct {
4350
}
4451

4552
func (p *initSubcommand) UpdateMetadata(cliMeta plugin.CLIMetadata, subcmdMeta *plugin.SubcommandMetadata) {
46-
subcmdMeta.Description = `Initialize a common project including the following files:
53+
subcmdMeta.Description = fmt.Sprintf(`Initialize a common project including the following files:
4754
- a "PROJECT" file that stores project configuration
4855
- several YAML files for project deployment under the "config" directory
49-
`
56+
57+
NOTE: The kustomize/v1 plugin used to do this scaffold uses the v3 release (%s).
58+
Therefore, darwin/arm64 is not supported since Kustomize does not provide v3
59+
binaries for this architecture. The currently supported architectures are %q.
60+
More info: https://github.com/kubernetes-sigs/kustomize/issues/4612.
61+
62+
`, KustomizeVersion, supportedArchs)
63+
5064
subcmdMeta.Examples = fmt.Sprintf(` # Initialize a common project with your domain and name in copyright
5165
%[1]s init --plugins common/v3 --domain example.org
5266
@@ -94,6 +108,37 @@ func (p *initSubcommand) InjectConfig(c config.Config) error {
94108
return nil
95109
}
96110

111+
func (p *initSubcommand) PreScaffold(machinery.Filesystem) error {
112+
arch := runtime.GOARCH
113+
// It probably will never return x86_64. However, we are here checking the support for the binaries
114+
// So that, x86_64 means getting the Linux/amd64 binary. Then, we just keep this line to ensure
115+
// that it complies with the same code implementation that we have in the targets. In case someone
116+
// call the command inform the GOARCH=x86_64 then, we will properly handle the scenario
117+
// since it will work successfully and will instal the Linux/amd64 binary via the Makefile target.
118+
arch = strings.Replace(arch, "x86_64", "amd64", -1)
119+
localPlatform := fmt.Sprintf("%s/%s", strings.TrimSpace(runtime.GOOS), strings.TrimSpace(arch))
120+
121+
if !hasSupportFor(localPlatform) {
122+
log.Warnf("the platform of this environment (%s) is not suppported by kustomize v3 (%s) which is "+
123+
"used in this scaffold. You will be unable to download a binary for the kustomize version supported "+
124+
"and used by this plugin. The currently supported platforms are: %q",
125+
localPlatform,
126+
KustomizeVersion,
127+
supportedArchs)
128+
}
129+
130+
return nil
131+
}
132+
133+
func hasSupportFor(localPlatform string) bool {
134+
for _, value := range supportedArchs {
135+
if value == localPlatform {
136+
return true
137+
}
138+
}
139+
return false
140+
}
141+
97142
func (p *initSubcommand) Scaffold(fs machinery.Filesystem) error {
98143
scaffolder := scaffolds.NewInitScaffolder(p.config)
99144
scaffolder.InjectFS(fs)

0 commit comments

Comments
 (0)