Skip to content

Commit

Permalink
Merge branch 'main' into spec-info
Browse files Browse the repository at this point in the history
  • Loading branch information
lindnerby committed Nov 4, 2024
2 parents 38d4c4c + 5bd654a commit d6f69d8
Show file tree
Hide file tree
Showing 50 changed files with 436 additions and 697 deletions.
1 change: 0 additions & 1 deletion cmd/modulectl/create/long.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ The module config file is a YAML file used to configure the following attributes
```yaml
- name: a string, required, the name of the module
- version: a string, required, the version of the module
- channel: a string, required, channel that should be used in the ModuleTemplate CR
- manifest: a string, required, reference to the manifest, must be a URL
- repository: a string, required, reference to the repository, must be a URL
- documentation: a string, required, reference to the documentation, must be a URL
Expand Down
4 changes: 0 additions & 4 deletions cmd/modulectl/scaffold/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func Test_Execute_ParsesOptions(t *testing.T) {
securityConfigFile := testutils.RandomName(10)
moduleName := testutils.RandomName(10)
moduleVersion := "1.1.1"
moduleChannel := testutils.RandomName(10)
os.Args = []string{
"scaffold",
"--directory", directory,
Expand All @@ -63,7 +62,6 @@ func Test_Execute_ParsesOptions(t *testing.T) {
"--gen-security-config=" + securityConfigFile,
"--module-name", moduleName,
"--module-version", moduleVersion,
"--module-channel", moduleChannel,
}
svc := &scaffoldServiceStub{}
cmd, _ := scaffoldcmd.NewCmd(svc)
Expand All @@ -79,7 +77,6 @@ func Test_Execute_ParsesOptions(t *testing.T) {
assert.Equal(t, defaultCRFile, svc.opts.DefaultCRFileName)
assert.Equal(t, securityConfigFile, svc.opts.SecurityConfigFileName)
assert.Equal(t, moduleVersion, svc.opts.ModuleVersion)
assert.Equal(t, moduleChannel, svc.opts.ModuleChannel)
}

func Test_Execute_ParsesShortOptions(t *testing.T) {
Expand Down Expand Up @@ -120,7 +117,6 @@ func Test_Execute_ParsesDefaults(t *testing.T) {
assert.Equal(t, scaffoldcmd.DefaultCRFlagDefault, svc.opts.DefaultCRFileName)
assert.Equal(t, scaffoldcmd.SecurityConfigFileFlagDefault, svc.opts.SecurityConfigFileName)
assert.Equal(t, scaffoldcmd.ModuleVersionFlagDefault, svc.opts.ModuleVersion)
assert.Equal(t, scaffoldcmd.ModuleChannelFlagDefault, svc.opts.ModuleChannel)
}

func Test_Execute_ParsesNoOptDefaults(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/modulectl/scaffold/example.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Generate a minimal scaffold for a module - only a blank manifest file and module config file is generated using defaults
modulectl scaffold
Generate a scaffold providing required values explicitly
modulectl scaffold --module-name="kyma-project.io/module/testmodule" --module-version="0.1.1" --module-channel=fast
modulectl scaffold --module-name="kyma-project.io/module/testmodule" --module-version="0.1.1"
Generate a scaffold with a manifest file, default CR and security-scanners config for a module
modulectl scaffold --gen-default-cr --gen-security-config
Generate a scaffold with a manifest file, default CR and security-scanners config for a module, overriding default values
Expand Down
14 changes: 6 additions & 8 deletions cmd/modulectl/scaffold/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,20 @@ const (
ModuleVersionFlagName = "module-version"
ModuleVersionFlagDefault = "0.0.1"
moduleVersionFlagUsage = `Specifies the module version in the generated module config file (default "0.0.1").`

ModuleChannelFlagName = "module-channel"
ModuleChannelFlagDefault = "regular"
moduleChannelFlagUsage = `Specifies the module channel in the generated module config file (default "regular").`
)

func parseFlags(flags *pflag.FlagSet, opts *scaffold.Options) {
flags.StringVarP(&opts.Directory, DirectoryFlagName, directoryFlagShort, DirectoryFlagDefault, directoryFlagUsage)
flags.StringVarP(&opts.ModuleConfigFileName, ModuleConfigFileFlagName, moduleConfigFileFlagShort, ModuleConfigFileFlagDefault, moduleConfigFileFlagUsage)
flags.BoolVarP(&opts.ModuleConfigFileOverwrite, ModuleConfigFileOverwriteFlagName, moduleConfigFileOverwriteFlagShort, ModuleConfigFileOverwriteFlagDefault, moduleConfigFileOverwriteFlagUsage)
flags.StringVarP(&opts.ModuleConfigFileName, ModuleConfigFileFlagName, moduleConfigFileFlagShort,
ModuleConfigFileFlagDefault, moduleConfigFileFlagUsage)
flags.BoolVarP(&opts.ModuleConfigFileOverwrite, ModuleConfigFileOverwriteFlagName,
moduleConfigFileOverwriteFlagShort, ModuleConfigFileOverwriteFlagDefault, moduleConfigFileOverwriteFlagUsage)
flags.StringVar(&opts.ManifestFileName, ManifestFileFlagName, ManifestFileFlagDefault, manifestFileFlagUsage)
flags.StringVar(&opts.DefaultCRFileName, DefaultCRFlagName, DefaultCRFlagDefault, defaultCRFlagUsage)
flags.StringVar(&opts.SecurityConfigFileName, SecurityConfigFileFlagName, SecurityConfigFileFlagDefault, securityConfigFileFlagUsage)
flags.StringVar(&opts.SecurityConfigFileName, SecurityConfigFileFlagName, SecurityConfigFileFlagDefault,
securityConfigFileFlagUsage)
flags.StringVar(&opts.ModuleName, ModuleNameFlagName, ModuleNameFlagDefault, moduleNameFlagUsage)
flags.StringVar(&opts.ModuleVersion, ModuleVersionFlagName, ModuleVersionFlagDefault, moduleVersionFlagUsage)
flags.StringVar(&opts.ModuleChannel, ModuleChannelFlagName, ModuleChannelFlagDefault, moduleChannelFlagUsage)

flags.Lookup(SecurityConfigFileFlagName).NoOptDefVal = SecurityConfigFileFlagNoOptDefault
flags.Lookup(DefaultCRFlagName).NoOptDefVal = DefaultCRFlagNoOptDefault
Expand Down
31 changes: 25 additions & 6 deletions cmd/modulectl/scaffold/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,35 @@ func Test_ScaffoldFlagsDefaults(t *testing.T) {
expected string
}{
{name: scaffoldcmd.DirectoryFlagName, value: scaffoldcmd.DirectoryFlagDefault, expected: "./"},
{name: scaffoldcmd.ModuleConfigFileFlagName, value: scaffoldcmd.ModuleConfigFileFlagDefault, expected: "scaffold-module-config.yaml"},
{name: scaffoldcmd.ModuleConfigFileOverwriteFlagName, value: strconv.FormatBool(scaffoldcmd.ModuleConfigFileOverwriteFlagDefault), expected: "false"},
{
name: scaffoldcmd.ModuleConfigFileFlagName,
value: scaffoldcmd.ModuleConfigFileFlagDefault,
expected: "scaffold-module-config.yaml",
},
{
name: scaffoldcmd.ModuleConfigFileOverwriteFlagName,
value: strconv.FormatBool(scaffoldcmd.ModuleConfigFileOverwriteFlagDefault),
expected: "false",
},
{name: scaffoldcmd.ManifestFileFlagName, value: scaffoldcmd.ManifestFileFlagDefault, expected: "manifest.yaml"},
{name: scaffoldcmd.DefaultCRFlagName, value: scaffoldcmd.DefaultCRFlagDefault, expected: ""},
{name: scaffoldcmd.DefaultCRFlagName, value: scaffoldcmd.DefaultCRFlagNoOptDefault, expected: "default-cr.yaml"},
{
name: scaffoldcmd.DefaultCRFlagName,
value: scaffoldcmd.DefaultCRFlagNoOptDefault,
expected: "default-cr.yaml",
},
{name: scaffoldcmd.SecurityConfigFileFlagName, value: scaffoldcmd.SecurityConfigFileFlagDefault, expected: ""},
{name: scaffoldcmd.SecurityConfigFileFlagName, value: scaffoldcmd.SecurityConfigFileFlagNoOptDefault, expected: "sec-scanners-config.yaml"},
{name: scaffoldcmd.ModuleNameFlagName, value: scaffoldcmd.ModuleNameFlagDefault, expected: "kyma-project.io/module/mymodule"},
{
name: scaffoldcmd.SecurityConfigFileFlagName,
value: scaffoldcmd.SecurityConfigFileFlagNoOptDefault,
expected: "sec-scanners-config.yaml",
},
{
name: scaffoldcmd.ModuleNameFlagName,
value: scaffoldcmd.ModuleNameFlagDefault,
expected: "kyma-project.io/module/mymodule",
},
{name: scaffoldcmd.ModuleVersionFlagName, value: scaffoldcmd.ModuleVersionFlagDefault, expected: "0.0.1"},
{name: scaffoldcmd.ModuleChannelFlagName, value: scaffoldcmd.ModuleChannelFlagDefault, expected: "regular"},
}

for _, testcase := range tests {
Expand Down
1 change: 0 additions & 1 deletion cmd/modulectl/scaffold/long.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Only the module config file may be force-overwritten when the --overwrite=true f
You can specify the required fields of the module config using the following CLI flags:
--module-name=NAME
--module-version=VERSION
--module-channel=CHANNEL

**NOTE:** If the required fields aren't provided, the defaults are applied and the module-config.yaml is not ready to be used. You must manually edit the file to make it usable.
Also, edit the sec-scanners-config.yaml to be able to use it.
2 changes: 1 addition & 1 deletion cmd/modulectl/scaffold/use.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
scaffold [--module-name MODULE_NAME --module-version MODULE_VERSION --module-channel CHANNEL] [--directory MODULE_DIRECTORY] [flags]
scaffold [--module-name MODULE_NAME --module-version MODULE_VERSION] [--directory MODULE_DIRECTORY] [flags]
1 change: 0 additions & 1 deletion docs/gen-docs/modulectl_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ The module config file is a YAML file used to configure the following attributes
```yaml
- name: a string, required, the name of the module
- version: a string, required, the version of the module
- channel: a string, required, channel that should be used in the ModuleTemplate CR
- manifest: a string, required, reference to the manifest, must be a URL
- repository: a string, required, reference to the repository, must be a URL
- documentation: a string, required, reference to the documentation, must be a URL
Expand Down
6 changes: 2 additions & 4 deletions docs/gen-docs/modulectl_scaffold.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ Only the module config file may be force-overwritten when the --overwrite=true f
You can specify the required fields of the module config using the following CLI flags:
--module-name=NAME
--module-version=VERSION
--module-channel=CHANNEL

**NOTE:** If the required fields aren't provided, the defaults are applied and the module-config.yaml is not ready to be used. You must manually edit the file to make it usable.
Also, edit the sec-scanners-config.yaml to be able to use it.


```bash
modulectl scaffold [--module-name MODULE_NAME --module-version MODULE_VERSION --module-channel CHANNEL] [--directory MODULE_DIRECTORY] [flags]
modulectl scaffold [--module-name MODULE_NAME --module-version MODULE_VERSION] [--directory MODULE_DIRECTORY] [flags]
```

## Examples
Expand All @@ -58,7 +57,7 @@ modulectl scaffold [--module-name MODULE_NAME --module-version MODULE_VERSION --
Generate a minimal scaffold for a module - only a blank manifest file and module config file is generated using defaults
modulectl scaffold
Generate a scaffold providing required values explicitly
modulectl scaffold --module-name="kyma-project.io/module/testmodule" --module-version="0.1.1" --module-channel=fast
modulectl scaffold --module-name="kyma-project.io/module/testmodule" --module-version="0.1.1"
Generate a scaffold with a manifest file, default CR and security-scanners config for a module
modulectl scaffold --gen-default-cr --gen-security-config
Generate a scaffold with a manifest file, default CR and security-scanners config for a module, overriding default values
Expand All @@ -75,7 +74,6 @@ Generate a scaffold with a manifest file, default CR and security-scanners confi
--gen-manifest string Specifies the manifest in the generated module config. A blank manifest file is generated if it doesn't exist (default "manifest.yaml").
--gen-security-config string Specifies the security file in the generated module config. A scaffold security config file is generated if it doesn't exist (default "sec-scanners-config.yaml").
-h, --help Provides help for the scaffold command.
--module-channel string Specifies the module channel in the generated module config file (default "regular").
--module-name string Specifies the module name in the generated config file (default "kyma-project.io/module/mymodule").
--module-version string Specifies the module version in the generated module config file (default "0.0.1").
-o, --overwrite Specifies if the command overwrites an existing module configuration file.
Expand Down
Loading

0 comments on commit d6f69d8

Please sign in to comment.