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 Oct 30, 2024
2 parents 6ef084b + 46c159d commit 4264d6d
Show file tree
Hide file tree
Showing 26 changed files with 479 additions and 251 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint-conventional-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: Lint PR Title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@47b15d52c5c30e94a17ec87eb8dd51ff5221fed9
- uses: amannn/action-semantic-pull-request@0723387faaf9b38adef4775cd42cfd5155ed6017
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
go-version-file: 'go.mod'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v6.1.0
uses: golangci/golangci-lint-action@v6.1.1
with:
version: v1.60.3
args: --verbose
2 changes: 1 addition & 1 deletion .github/workflows/test-unit-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
with:
path: codebase
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version-file: ${{ github.workspace }}/codebase/go.mod
- name: Run the quality gate verification
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Checkout modulectl
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache-dependency-path: 'go.sum'
Expand Down
24 changes: 18 additions & 6 deletions cmd/modulectl/create/long.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,35 @@ The module config file is a YAML file used to configure the following attributes
- 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
- info:

- defaultCR: a string, optional, reference to a YAML file containing the default CR for the module, must be a relative file name or URL
- 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
- icons: a map with string keys and values, required, icons used for UI
- name: a string, required, the name of the icon
link: a URL, required, the link to the icon
- 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
- resources : a map with string keys and values, optional, additional resources of the ModuleTemplate that may be fetched
- 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
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
16 changes: 13 additions & 3 deletions docs/gen-docs/modulectl_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,31 @@ The module config file is a YAML file used to configure the following attributes
- 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
4 changes: 2 additions & 2 deletions docs/gen-docs/modulectl_scaffold.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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 Expand Up @@ -69,13 +69,13 @@ Generate a scaffold with a manifest file, default CR and security-scanners confi
## Flags

```bash
-c, --config-file string Specifies the name of the generated module configuration file (default "scaffold-module-config.yaml").
-d, --directory string Specifies the target directory where the scaffolding shall be generated (default "./").
--gen-default-cr string Specifies the default CR in the generated module config. A blank default CR file is generated if it doesn't exist (default "default-cr.yaml").
--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-config string Specifies the name of the generated module configuration file (default "scaffold-module-config.yaml").
--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
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ require (
github.com/Masterminds/semver/v3 v3.3.0
github.com/go-git/go-git/v5 v5.12.0
github.com/kyma-project/lifecycle-manager/api v0.0.0-20241016122945-f0ac9bb8aa0c
github.com/mandelsoft/goutils v0.0.0-20240915132328-95975bffaef0
github.com/mandelsoft/vfs v0.4.4
github.com/onsi/ginkgo/v2 v2.20.2
github.com/onsi/gomega v1.34.2
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/apiextensions-apiserver v0.31.1
k8s.io/apimachinery v0.31.1
k8s.io/apiextensions-apiserver v0.31.2
k8s.io/apimachinery v0.31.2
ocm.software/ocm v0.16.2
sigs.k8s.io/yaml v1.4.0
)
Expand Down Expand Up @@ -196,7 +197,6 @@ require (
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mandelsoft/filepath v0.0.0-20240223090642-3e2777258aa3 // indirect
github.com/mandelsoft/goutils v0.0.0-20240915132328-95975bffaef0 // indirect
github.com/mandelsoft/logging v0.0.0-20240618075559-fdca28a87b0a // indirect
github.com/mandelsoft/spiff v1.7.0-beta-5 // indirect
github.com/marstr/guid v1.1.0 // indirect
Expand Down Expand Up @@ -324,9 +324,9 @@ require (
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
helm.sh/helm/v3 v3.16.1 // indirect
k8s.io/api v0.31.1 // indirect
k8s.io/api v0.31.2 // indirect
k8s.io/cli-runtime v0.31.1 // indirect
k8s.io/client-go v0.31.1 // indirect
k8s.io/client-go v0.31.2 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1312,18 +1312,18 @@ helm.sh/helm/v3 v3.16.1 h1:cER6tI/8PgUAsaJaQCVBUg3VI9KN4oVaZJgY60RIc0c=
helm.sh/helm/v3 v3.16.1/go.mod h1:r+xBHHP20qJeEqtvBXMf7W35QDJnzY/eiEBzt+TfHps=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/api v0.31.1 h1:Xe1hX/fPW3PXYYv8BlozYqw63ytA92snr96zMW9gWTU=
k8s.io/api v0.31.1/go.mod h1:sbN1g6eY6XVLeqNsZGLnI5FwVseTrZX7Fv3O26rhAaI=
k8s.io/apiextensions-apiserver v0.31.1 h1:L+hwULvXx+nvTYX/MKM3kKMZyei+UiSXQWciX/N6E40=
k8s.io/apiextensions-apiserver v0.31.1/go.mod h1:tWMPR3sgW+jsl2xm9v7lAyRF1rYEK71i9G5dRtkknoQ=
k8s.io/apimachinery v0.31.1 h1:mhcUBbj7KUjaVhyXILglcVjuS4nYXiwC+KKFBgIVy7U=
k8s.io/apimachinery v0.31.1/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
k8s.io/api v0.31.2 h1:3wLBbL5Uom/8Zy98GRPXpJ254nEFpl+hwndmk9RwmL0=
k8s.io/api v0.31.2/go.mod h1:bWmGvrGPssSK1ljmLzd3pwCQ9MgoTsRCuK35u6SygUk=
k8s.io/apiextensions-apiserver v0.31.2 h1:W8EwUb8+WXBLu56ser5IudT2cOho0gAKeTOnywBLxd0=
k8s.io/apiextensions-apiserver v0.31.2/go.mod h1:i+Geh+nGCJEGiCGR3MlBDkS7koHIIKWVfWeRFiOsUcM=
k8s.io/apimachinery v0.31.2 h1:i4vUt2hPK56W6mlT7Ry+AO8eEsyxMD1U44NR22CLTYw=
k8s.io/apimachinery v0.31.2/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
k8s.io/cli-runtime v0.31.1 h1:/ZmKhmZ6hNqDM+yf9s3Y4KEYakNXUn5sod2LWGGwCuk=
k8s.io/cli-runtime v0.31.1/go.mod h1:pKv1cDIaq7ehWGuXQ+A//1OIF+7DI+xudXtExMCbe9U=
k8s.io/client-go v0.31.1 h1:f0ugtWSbWpxHR7sjVpQwuvw9a3ZKLXX0u0itkFXufb0=
k8s.io/client-go v0.31.1/go.mod h1:sKI8871MJN2OyeqRlmA4W4KM9KBdBUpDLu/43eGemCg=
k8s.io/component-base v0.31.1 h1:UpOepcrX3rQ3ab5NB6g5iP0tvsgJWzxTyAo20sgYSy8=
k8s.io/component-base v0.31.1/go.mod h1:WGeaw7t/kTsqpVTaCoVEtillbqAhF2/JgvO0LDOMa0w=
k8s.io/client-go v0.31.2 h1:Y2F4dxU5d3AQj+ybwSMqQnpZH9F30//1ObxOKlTI9yc=
k8s.io/client-go v0.31.2/go.mod h1:NPa74jSVR/+eez2dFsEIHNa+3o09vtNaWwWwb1qSxSs=
k8s.io/component-base v0.31.2 h1:Z1J1LIaC0AV+nzcPRFqfK09af6bZ4D1nAOpWsy9owlA=
k8s.io/component-base v0.31.2/go.mod h1:9PeyyFN/drHjtJZMCTkSpQJS3U9OXORnHQqMLDz0sUQ=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag=
Expand Down
16 changes: 16 additions & 0 deletions internal/common/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,19 @@ func validateSemanticVersion(version string) error {

return nil
}

func ValidateGvk(group, version, kind string) error {
if kind == "" {
return fmt.Errorf("kind must not be empty: %w", commonerrors.ErrInvalidOption)
}

if group == "" {
return fmt.Errorf("group must not be empty: %w", commonerrors.ErrInvalidOption)
}

if version == "" {
return fmt.Errorf("version must not be empty: %w", commonerrors.ErrInvalidOption)
}

return nil
}
41 changes: 41 additions & 0 deletions internal/common/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,47 @@ func TestValidateNamespace(t *testing.T) {
}
}

func TestValidateGvk(t *testing.T) {
type args struct {
group string
version string
kind string
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "valid GVK",
args: args{group: "kyma-project.io", version: "v1alpha1", kind: "Module"},
wantErr: false,
},
{
name: "invalid GVK when group empty",
args: args{version: "v1alpha1", kind: "Module"},
wantErr: true,
},
{
name: "invalid GVK when version empty",
args: args{group: "kyma-project.io", kind: "Module"},
wantErr: true,
},
{
name: "invalid GVK when kind empty",
args: args{group: "kyma-project.io", version: "v1alpha1"},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := validation.ValidateGvk(tt.args.group, tt.args.version, tt.args.kind); (err != nil) != tt.wantErr {
t.Errorf("ValidateGvk() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

func TestValidateMapEntries(t *testing.T) {
tests := []struct {
name string
Expand Down
Loading

0 comments on commit 4264d6d

Please sign in to comment.