Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/amannn/action-sema…
Browse files Browse the repository at this point in the history
…ntic-pull-request-5.5.3
  • Loading branch information
nesmabadr authored Oct 29, 2024
2 parents 9debc19 + 543128d commit eb20272
Show file tree
Hide file tree
Showing 46 changed files with 1,934 additions and 582 deletions.
16 changes: 14 additions & 2 deletions cmd/modulectl/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/kyma-project/modulectl/internal/service/create"
"github.com/kyma-project/modulectl/internal/service/filegenerator"
"github.com/kyma-project/modulectl/internal/service/filegenerator/reusefilegenerator"
"github.com/kyma-project/modulectl/internal/service/fileresolver"
"github.com/kyma-project/modulectl/internal/service/git"
moduleconfiggenerator "github.com/kyma-project/modulectl/internal/service/moduleconfig/generator"
moduleconfigreader "github.com/kyma-project/modulectl/internal/service/moduleconfig/reader"
Expand Down Expand Up @@ -89,7 +90,17 @@ func buildModuleService() (*create.Service, error) {
fileSystemUtil := &filesystem.Util{}
tmpFileSystem := filesystem.NewTempFileSystem()

moduleConfigService, err := moduleconfigreader.NewService(fileSystemUtil, tmpFileSystem)
manifestFileResolver, err := fileresolver.NewFileResolver("kyma-module-manifest-*.yaml", tmpFileSystem)
if err != nil {
return nil, fmt.Errorf("failed to create manifest file resolver: %w", err)
}

defaultCRFileResolver, err := fileresolver.NewFileResolver("kyma-module-default-cr-*.yaml", tmpFileSystem)
if err != nil {
return nil, fmt.Errorf("failed to create default CR file resolver: %w", err)
}

moduleConfigService, err := moduleconfigreader.NewService(fileSystemUtil)
if err != nil {
return nil, fmt.Errorf("failed to create module config service: %w", err)
}
Expand Down Expand Up @@ -127,7 +138,8 @@ func buildModuleService() (*create.Service, error) {
return nil, fmt.Errorf("failed to create crd parser service: %w", err)
}
moduleService, err := create.NewService(moduleConfigService, gitSourcesService,
securityConfigService, componentArchiveService, registryService, moduleTemplateService, crdParserService)
securityConfigService, componentArchiveService, registryService, moduleTemplateService,
crdParserService, manifestFileResolver, defaultCRFileResolver, fileSystemUtil)
if err != nil {
return nil, fmt.Errorf("failed to create module service: %w", err)
}
Expand Down
15 changes: 9 additions & 6 deletions cmd/modulectl/create/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func Test_Execute_ParsesAllModuleOptions(t *testing.T) {

os.Args = []string{
"create",
"--module-config-file", moduleConfigFile,
"--config-file", moduleConfigFile,
"--git-remote", gitRemote,
"--insecure", insecure,
"--output", templateOutput,
Expand All @@ -74,7 +74,7 @@ func Test_Execute_ParsesAllModuleOptions(t *testing.T) {
insecureFlagSet, err := strconv.ParseBool(insecure)
require.NoError(t, err)

assert.Equal(t, moduleConfigFile, svc.opts.ModuleConfigFile)
assert.Equal(t, moduleConfigFile, svc.opts.ConfigFile)
assert.Equal(t, credentials, svc.opts.Credentials)
assert.Equal(t, gitRemote, svc.opts.GitRemote)
assert.Equal(t, insecureFlagSet, svc.opts.Insecure)
Expand All @@ -84,13 +84,15 @@ func Test_Execute_ParsesAllModuleOptions(t *testing.T) {
}

func Test_Execute_ParsesModuleShortOptions(t *testing.T) {
credentials := testutils.RandomName(10)
configFile := testutils.RandomName(10)
templateOutput := testutils.RandomName(10)
registry := testutils.RandomName(10)

os.Args = []string{
"create",
"-c", credentials,
"-c", configFile,
"-o", templateOutput,
"-r", registry,
}

svc := &moduleServiceStub{}
Expand All @@ -99,8 +101,9 @@ func Test_Execute_ParsesModuleShortOptions(t *testing.T) {
err := cmd.Execute()
require.NoError(t, err)

assert.Equal(t, credentials, svc.opts.Credentials)
assert.Equal(t, configFile, svc.opts.ConfigFile)
assert.Equal(t, templateOutput, svc.opts.TemplateOutput)
assert.Equal(t, registry, svc.opts.RegistryURL)
}

func Test_Execute_ModuleParsesDefaults(t *testing.T) {
Expand All @@ -114,7 +117,7 @@ func Test_Execute_ModuleParsesDefaults(t *testing.T) {
err := cmd.Execute()
require.NoError(t, err)

assert.Equal(t, createcmd.ModuleConfigFileFlagDefault, svc.opts.ModuleConfigFile)
assert.Equal(t, createcmd.ConfigFileFlagDefault, svc.opts.ConfigFile)
assert.Equal(t, createcmd.CredentialsFlagDefault, svc.opts.Credentials)
assert.Equal(t, createcmd.GitRemoteFlagDefault, svc.opts.GitRemote)
assert.Equal(t, createcmd.InsecureFlagDefault, svc.opts.Insecure)
Expand Down
2 changes: 1 addition & 1 deletion cmd/modulectl/create/example.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Build a simple module and push it to a remote registry
modulectl create --module-config-file=/path/to/module-config-file --registry http://localhost:5001/unsigned --insecure
modulectl create --config-file=/path/to/module-config-file --registry http://localhost:5001/unsigned --insecure
14 changes: 7 additions & 7 deletions cmd/modulectl/create/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
)

const (
ModuleConfigFileFlagName = "module-config-file"
ModuleConfigFileFlagDefault = "module-config.yaml"
moduleConfigFileFlagUsage = "Specifies the path to the module configuration file."
ConfigFileFlagName = "config-file"
configFileFlagShort = "c"
ConfigFileFlagDefault = "module-config.yaml"
configFileFlagUsage = "Specifies the path to the module configuration file."

CredentialsFlagName = "registry-credentials" //nolint:gosec // Not hardcoded credentials, rather just flag name
credentialsFlagShort = "c"
CredentialsFlagDefault = ""
credentialsFlagUsage = "Basic authentication credentials for the given repository in the <user:password> format."

Expand Down Expand Up @@ -42,9 +42,9 @@ const (
)

func parseFlags(flags *pflag.FlagSet, opts *create.Options) {
flags.StringVar(&opts.ModuleConfigFile, ModuleConfigFileFlagName, ModuleConfigFileFlagDefault,
moduleConfigFileFlagUsage)
flags.StringVarP(&opts.Credentials, CredentialsFlagName, credentialsFlagShort, CredentialsFlagDefault,
flags.StringVarP(&opts.ConfigFile, ConfigFileFlagName, configFileFlagShort, ConfigFileFlagDefault,
configFileFlagUsage)
flags.StringVar(&opts.Credentials, CredentialsFlagName, CredentialsFlagDefault,
credentialsFlagUsage)
flags.StringVar(&opts.GitRemote, GitRemoteFlagName, GitRemoteFlagDefault, gitRemoteFlagUsage)
flags.BoolVar(&opts.Insecure, InsecureFlagName, InsecureFlagDefault, insecureFlagUsage)
Expand Down
4 changes: 2 additions & 2 deletions cmd/modulectl/create/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ func Test_ScaffoldFlagsDefaults(t *testing.T) {
expected string
}{
{
name: createcmd.ModuleConfigFileFlagName,
value: createcmd.ModuleConfigFileFlagDefault,
name: createcmd.ConfigFileFlagName,
value: createcmd.ConfigFileFlagDefault,
expected: "module-config.yaml",
},
{name: createcmd.CredentialsFlagName, value: createcmd.CredentialsFlagDefault, expected: ""},
Expand Down
17 changes: 14 additions & 3 deletions cmd/modulectl/create/long.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,39 @@ For more information about Kyma modules see the [documentation](https://kyma-pro

### Configuration

Provide the `--module-config-file` flag with a config file path.
Provide the `--config-file` flag with a config file path.
The module config file is a YAML file used to configure the following attributes for the module:

```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 relative file name or URL
- manifest: a string, required, reference to the manifest, must be a URL

- defaultCR: a string, optional, reference to a YAML file containing the default CR for the module, must be a relative file name or URL
- defaultCR: a string, optional, reference to a YAML file containing the default CR for the module, must be a URL
- mandatory: a boolean, optional, default=false, indicates whether the module is mandatory to be installed on all clusters
- resourceName: a string, optional, default={NAME}-{CHANNEL}, the name for the ModuleTemplate CR that will be created
- internal: a boolean, optional, default=false, determines whether the ModuleTemplate CR should have the internal flag or not
- beta: a boolean, optional, default=false, determines whether the ModuleTemplate CR should have the beta flag or not
- security: a string, optional, name of the security scanners config file
- labels: a map with string keys and values, optional, additional labels for the generated ModuleTemplate CR
- annotations: a map with string keys and values, optional, additional annotations for the generated ModuleTemplate CR
- manager: # an object, optional, module resource that indicates the installation readiness of the module
name: a string, required, the name of the module resource
namespace: a string, optional, the namespace of the module resource
group: a string, required, the API group of the module resource
version: a string, required, the API version of the module resource
kind: a string, required, the API kind of the module resource
- associatedResources: a list of Group-Version-Kind(GVK), optional, resources that should be cleaned up with the module deletion
- resources: # a map with string keys and values, optional, additional resources of the module that may be fetched
- name: a string, required, the name of the resource
link: a URL, required, the link to the resource
```

The **manifest** file contains all the module's resources in a single, multi-document YAML file. These resources will be created in the Kyma cluster when the module is activated.
The **defaultCR** file contains a default custom resource for the module that is installed along with the module. It is additionally schema-validated against the Custom Resource Definition.
The CRD used for the validation must exist in the set of the module's resources.
The **resources** are copied to the ModuleTemplate **spec.resources**. If it does not have an entry named 'raw-manifest', the ModuleTemplate **spec.resources** populates this entry from the **manifest** field specified in the module config file.

### Modules as OCI artifacts
Modules are built and distributed as OCI artifacts.
Expand Down
2 changes: 1 addition & 1 deletion cmd/modulectl/create/use.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
create [--module-config-file MODULE_CONFIG_FILE] [--registry MODULE_REGISTRY] [flags]
create [--config-file MODULE_CONFIG_FILE] [--registry MODULE_REGISTRY] [flags]
5 changes: 4 additions & 1 deletion cmd/modulectl/scaffold/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func Test_Execute_ParsesOptions(t *testing.T) {
os.Args = []string{
"scaffold",
"--directory", directory,
"--module-config", moduleConfigFile,
"--config-file", moduleConfigFile,
"--overwrite",
"--gen-manifest", manifestFile,
"--gen-default-cr=" + defaultCRFile,
Expand Down Expand Up @@ -84,8 +84,10 @@ func Test_Execute_ParsesOptions(t *testing.T) {

func Test_Execute_ParsesShortOptions(t *testing.T) {
directory := testutils.RandomName(10)
configFile := testutils.RandomName(10)
os.Args = []string{
"scaffold",
"-c", configFile,
"-d", directory,
"-o",
}
Expand All @@ -95,6 +97,7 @@ func Test_Execute_ParsesShortOptions(t *testing.T) {
err := cmd.Execute()
require.NoError(t, err)

assert.Equal(t, configFile, svc.opts.ModuleConfigFileName)
assert.Equal(t, directory, svc.opts.Directory)
assert.True(t, svc.opts.ModuleConfigFileOverwrite)
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/modulectl/scaffold/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const (
DirectoryFlagDefault = "./"
directoryFlagUsage = `Specifies the target directory where the scaffolding shall be generated (default "./").`

ModuleConfigFileFlagName = "module-config"
ModuleConfigFileFlagName = "config-file"
moduleConfigFileFlagShort = "c"
ModuleConfigFileFlagDefault = "scaffold-module-config.yaml"
moduleConfigFileFlagUsage = `Specifies the name of the generated module configuration file (default "scaffold-module-config.yaml").`

Expand Down Expand Up @@ -50,7 +51,7 @@ const (

func parseFlags(flags *pflag.FlagSet, opts *scaffold.Options) {
flags.StringVarP(&opts.Directory, DirectoryFlagName, directoryFlagShort, DirectoryFlagDefault, directoryFlagUsage)
flags.StringVar(&opts.ModuleConfigFileName, ModuleConfigFileFlagName, ModuleConfigFileFlagDefault, moduleConfigFileFlagUsage)
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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/modulectl/scaffold/long.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ allowing for a tailored scaffolding experience according to the specific needs o
The command generates or uses the following files:
- Module Config:
Enabled: Always
Adjustable with flag: --module-config=VALUE
Adjustable with flag: --config-file=VALUE
Generated when: The file doesn't exist or the --overwrite=true flag is provided
Default file name: scaffold-module-config.yaml
- Manifest:
Expand Down
25 changes: 18 additions & 7 deletions docs/gen-docs/modulectl_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,39 @@ For more information about Kyma modules see the [documentation](https://kyma-pro

### Configuration

Provide the `--module-config-file` flag with a config file path.
Provide the `--config-file` flag with a config file path.
The module config file is a YAML file used to configure the following attributes for the module:

```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 relative file name or URL
- manifest: a string, required, reference to the manifest, must be a URL

- defaultCR: a string, optional, reference to a YAML file containing the default CR for the module, must be a relative file name or URL
- defaultCR: a string, optional, reference to a YAML file containing the default CR for the module, must be a URL
- mandatory: a boolean, optional, default=false, indicates whether the module is mandatory to be installed on all clusters
- resourceName: a string, optional, default={NAME}-{CHANNEL}, the name for the ModuleTemplate CR that will be created
- internal: a boolean, optional, default=false, determines whether the ModuleTemplate CR should have the internal flag or not
- beta: a boolean, optional, default=false, determines whether the ModuleTemplate CR should have the beta flag or not
- security: a string, optional, name of the security scanners config file
- labels: a map with string keys and values, optional, additional labels for the generated ModuleTemplate CR
- annotations: a map with string keys and values, optional, additional annotations for the generated ModuleTemplate CR
- manager: # an object, optional, module resource that indicates the installation readiness of the module
name: a string, required, the name of the module resource
namespace: a string, optional, the namespace of the module resource
group: a string, required, the API group of the module resource
version: a string, required, the API version of the module resource
kind: a string, required, the API kind of the module resource
- associatedResources: a list of Group-Version-Kind(GVK), optional, resources that should be cleaned up with the module deletion
- resources: # a map with string keys and values, optional, additional resources of the module that may be fetched
- name: a string, required, the name of the resource
link: a URL, required, the link to the resource
```
The **manifest** file contains all the module's resources in a single, multi-document YAML file. These resources will be created in the Kyma cluster when the module is activated.
The **defaultCR** file contains a default custom resource for the module that is installed along with the module. It is additionally schema-validated against the Custom Resource Definition.
The CRD used for the validation must exist in the set of the module's resources.
The **resources** are copied to the ModuleTemplate **spec.resources**. If it does not have an entry named 'raw-manifest', the ModuleTemplate **spec.resources** populates this entry from the **manifest** field specified in the module config file.
### Modules as OCI artifacts
Modules are built and distributed as OCI artifacts.
Expand All @@ -47,27 +58,27 @@ If you configured the "--registry" flag, the created module is validated and pus
```bash
modulectl create [--module-config-file MODULE_CONFIG_FILE] [--registry MODULE_REGISTRY] [flags]
modulectl create [--config-file MODULE_CONFIG_FILE] [--registry MODULE_REGISTRY] [flags]
```

## Examples

```bash
Build a simple module and push it to a remote registry
modulectl create --module-config-file=/path/to/module-config-file --registry http://localhost:5001/unsigned --insecure
modulectl create --config-file=/path/to/module-config-file --registry http://localhost:5001/unsigned --insecure
```

## Flags

```bash
-c, --config-file string Specifies the path to the module configuration file.
--git-remote string Specifies the URL of the module's GitHub repository.
-h, --help Provides help for the create command.
--insecure Uses an insecure connection to access the registry.
--module-config-file string Specifies the path to the module configuration file.
-o, --output string Path to write the ModuleTemplate file to, if the module is uploaded to a registry (default "template.yaml").
-r, --registry string Context URL of the repository. The repository URL will be automatically added to the repository contexts in the module descriptor.
--registry-cred-selector string Label selector to identify an externally created Secret of type "kubernetes.io/dockerconfigjson". It allows the image to be accessed in private image registries. It can be used when you push your module to a registry with authenticated access. For example, "label1=value1,label2=value2".
-c, --registry-credentials string Basic authentication credentials for the given repository in the <user:password> format.
--registry-credentials string Basic authentication credentials for the given repository in the <user:password> format.
```
## See also
Expand Down
Loading

0 comments on commit eb20272

Please sign in to comment.