@@ -20,8 +20,10 @@ import (
20
20
"fmt"
21
21
"os"
22
22
"path/filepath"
23
+ "runtime"
23
24
"strings"
24
25
26
+ log "github.com/sirupsen/logrus"
25
27
"github.com/spf13/pflag"
26
28
27
29
"sigs.k8s.io/kubebuilder/v3/pkg/config"
@@ -33,6 +35,11 @@ import (
33
35
34
36
var _ plugin.InitSubcommand = & initSubcommand {}
35
37
38
+ // Verify if the local environment is supported by this plugin
39
+ var supportedArchs = []string {"linux/amd64" ,
40
+ "linux/arm64" ,
41
+ "darwin/amd64" }
42
+
36
43
type initSubcommand struct {
37
44
config config.Config
38
45
@@ -43,10 +50,17 @@ type initSubcommand struct {
43
50
}
44
51
45
52
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:
47
54
- a "PROJECT" file that stores project configuration
48
55
- 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
+
50
64
subcmdMeta .Examples = fmt .Sprintf (` # Initialize a common project with your domain and name in copyright
51
65
%[1]s init --plugins common/v3 --domain example.org
52
66
@@ -94,6 +108,37 @@ func (p *initSubcommand) InjectConfig(c config.Config) error {
94
108
return nil
95
109
}
96
110
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
+
97
142
func (p * initSubcommand ) Scaffold (fs machinery.Filesystem ) error {
98
143
scaffolder := scaffolds .NewInitScaffolder (p .config )
99
144
scaffolder .InjectFS (fs )
0 commit comments