From e690232793a2dacf6be61f0ccf6a46acf340ee3a Mon Sep 17 00:00:00 2001 From: Jeremy Harisch <48282931+jeremyharisch@users.noreply.github.com> Date: Mon, 24 Apr 2023 11:01:53 +0200 Subject: [PATCH] Fix 2.13.0 (#1641) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add label to descriptor (#1625) * Remove helm chart bundling of `KubeBuilder` projects (#1581) * remove helm chart bundling of kubebuilder projectss * update golang-ci version to latets * go fmt * rm unused code * rm commented code * go fmt * fix error caps * fix failing tests * refactor project build signature * fix linting * fix linting * fix linting ii * fix linting iii * fix linting * fix linting * fix linting * fix linting * fix linting * Remove envtest logs for verbose mode (#1629) * Support the installation of specific Garden Linux version for Gardener (#1630) * Add gardenlinux flag for Gardener provisioning * generate docs * fix test * fix test * Add missing comment Co-authored-by: Małgorzata Świeca * Fix indentation --------- Co-authored-by: Małgorzata Świeca * Replace key parsing logic with ocm signing (#1633) * replace public key parsing logic with what offered by ocm * replace private key parsing logic with what offered by ocm * change signature name and issuer * Upgrade hydroform version (#1635) * Configure creds for empty auth (#1634) * Debug * Fix for credentials * Cleanup --------- Co-authored-by: Xin Ruan Co-authored-by: Ali Khlifi <46890720+khlifi411@users.noreply.github.com> Co-authored-by: Nesma Badr Co-authored-by: Małgorzata Świeca Co-authored-by: Tomasz Smelcerz --- .gitignore | 3 + cmd/kyma/alpha/create/module/module.go | 2 +- cmd/kyma/provision/cmd.go | 1 + cmd/kyma/provision/gardener/aws/cmd.go | 4 ++ cmd/kyma/provision/gardener/aws/cmd_test.go | 15 +++-- cmd/kyma/provision/gardener/aws/opts.go | 1 + cmd/kyma/provision/gardener/aws/template.go | 2 +- cmd/kyma/provision/gardener/az/cmd.go | 4 ++ cmd/kyma/provision/gardener/az/cmd_test.go | 6 +- cmd/kyma/provision/gardener/az/opts.go | 1 + cmd/kyma/provision/gardener/az/template.go | 2 +- cmd/kyma/provision/gardener/gcp/cmd.go | 4 ++ cmd/kyma/provision/gardener/gcp/cmd_test.go | 5 +- cmd/kyma/provision/gardener/gcp/opts.go | 1 + cmd/kyma/provision/gardener/gcp/template.go | 2 +- docs/gen-docs/kyma_provision_gardener_aws.md | 1 + docs/gen-docs/kyma_provision_gardener_az.md | 1 + docs/gen-docs/kyma_provision_gardener_gcp.md | 1 + go.mod | 15 ++--- go.sum | 30 +++++---- internal/cli/setup/envtest/setup.go | 19 +----- pkg/module/kubebuilder/chart.go | 42 ------------ pkg/module/kubebuilder/project.go | 48 +++---------- pkg/module/layer.go | 7 +- pkg/module/remote.go | 16 ++++- pkg/module/resources.go | 12 ++-- pkg/module/sign.go | 20 ++---- pkg/module/template.go | 4 ++ pkg/module/validation.go | 71 ++++++++++---------- pkg/module/validation_test.go | 6 +- 30 files changed, 148 insertions(+), 198 deletions(-) delete mode 100644 pkg/module/kubebuilder/chart.go diff --git a/.gitignore b/.gitignore index 35d80a207..0c29451de 100755 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ bin workspace kyma.crt mod + +# Generated template files (generate by alpha module create) +/template.yaml diff --git a/cmd/kyma/alpha/create/module/module.go b/cmd/kyma/alpha/create/module/module.go index 7dd10402c..2dc5da8e8 100644 --- a/cmd/kyma/alpha/create/module/module.go +++ b/cmd/kyma/alpha/create/module/module.go @@ -288,7 +288,7 @@ func (cmd *command) validateDefaultCR(ctx context.Context, modDef *module.Defini return err } - if err := crValidator.Run(ctx, cmd.CurrentStep, cmd.opts.Verbose, l); err != nil { + if err := crValidator.Run(ctx, l); err != nil { if errors.Is(err, module.ErrEmptyCR) { cmd.CurrentStep.Successf("Default CR validation skipped - no default CR") return nil diff --git a/cmd/kyma/provision/cmd.go b/cmd/kyma/provision/cmd.go index 792a6d13b..5373d1202 100644 --- a/cmd/kyma/provision/cmd.go +++ b/cmd/kyma/provision/cmd.go @@ -6,6 +6,7 @@ import ( const DefaultK8sShortVersion = "1.25" //default Kubernetes version for provisioning clusters on hyperscalers const DefaultK8sFullVersion = DefaultK8sShortVersion + ".6" //default Kubernetes version with the "patch" component (mainly for K3d/K3s) +const DefaultGardenLinuxVersion = "934.6.0" //default Garden Linux version // NewCmd creates a new provision command func NewCmd() *cobra.Command { diff --git a/cmd/kyma/provision/gardener/aws/cmd.go b/cmd/kyma/provision/gardener/aws/cmd.go index 1d4774fbb..2470caee9 100644 --- a/cmd/kyma/provision/gardener/aws/cmd.go +++ b/cmd/kyma/provision/gardener/aws/cmd.go @@ -59,6 +59,10 @@ Use service account details to create a Secret and import it in Gardener.`, &o.HibernationLocation, "hibernation-location", "Europe/Berlin", "Timezone in which the hibernation schedule should be applied.", ) + cmd.Flags().StringVarP( + &o.GardenLinuxVersion, "gardenlinux-version", "g", provision.DefaultGardenLinuxVersion, + "Garden Linux version of the cluster.", + ) return cmd } diff --git a/cmd/kyma/provision/gardener/aws/cmd_test.go b/cmd/kyma/provision/gardener/aws/cmd_test.go index 60488a8f3..4533f894d 100644 --- a/cmd/kyma/provision/gardener/aws/cmd_test.go +++ b/cmd/kyma/provision/gardener/aws/cmd_test.go @@ -91,12 +91,13 @@ func TestProvisionGardenerAWSSubcommands(t *testing.T) { func TestNewCluster(t *testing.T) { t.Parallel() o := &Options{ - Name: "mega-cluster", - KubernetesVersion: "1.19.0", - Region: "north-pole", - MachineType: "HAL", - DiskSizeGB: 9000, - ScalerMax: 3, + Name: "mega-cluster", + KubernetesVersion: "1.19.0", + Region: "north-pole", + MachineType: "HAL", + DiskSizeGB: 9000, + ScalerMax: 3, + GardenLinuxVersion: "576.7.0", } cmd := newAwsCmd(o) c := cmd.NewCluster() @@ -145,7 +146,7 @@ func TestNewProvider(t *testing.T) { custom["workercidr"] = "10.250.0.0/16" custom["networking_type"] = "calico" custom["machine_image_name"] = "gardenlinux" - custom["machine_image_version"] = "934.6.0" + custom["machine_image_version"] = o.GardenLinuxVersion custom["hibernation_start"] = "00 18 * * 1,2,3,4,5" custom["hibernation_end"] = "" custom["hibernation_location"] = "Europe/Berlin" diff --git a/cmd/kyma/provision/gardener/aws/opts.go b/cmd/kyma/provision/gardener/aws/opts.go index 6be4f246d..fb805f131 100644 --- a/cmd/kyma/provision/gardener/aws/opts.go +++ b/cmd/kyma/provision/gardener/aws/opts.go @@ -10,6 +10,7 @@ type Options struct { CredentialsFile string Secret string KubernetesVersion string + GardenLinuxVersion string Region string Zones []string MachineType string diff --git a/cmd/kyma/provision/gardener/aws/template.go b/cmd/kyma/provision/gardener/aws/template.go index a594c1548..5df444383 100644 --- a/cmd/kyma/provision/gardener/aws/template.go +++ b/cmd/kyma/provision/gardener/aws/template.go @@ -59,7 +59,7 @@ func (c *awsCmd) NewProvider() (*types.Provider, error) { p.CustomConfigurations["workercidr"] = "10.250.0.0/16" p.CustomConfigurations["networking_type"] = "calico" p.CustomConfigurations["machine_image_name"] = "gardenlinux" - p.CustomConfigurations["machine_image_version"] = "934.6.0" + p.CustomConfigurations["machine_image_version"] = c.opts.GardenLinuxVersion p.CustomConfigurations["zones"] = c.opts.Zones p.CustomConfigurations["hibernation_start"] = c.opts.HibernationStart p.CustomConfigurations["hibernation_end"] = c.opts.HibernationEnd diff --git a/cmd/kyma/provision/gardener/az/cmd.go b/cmd/kyma/provision/gardener/az/cmd.go index 3d34ad25d..bae6a941a 100644 --- a/cmd/kyma/provision/gardener/az/cmd.go +++ b/cmd/kyma/provision/gardener/az/cmd.go @@ -61,6 +61,10 @@ Create a service account with the ` + "`contributor`" + ` role. Use service acco &o.HibernationLocation, "hibernation-location", "Europe/Berlin", "Timezone in which the hibernation schedule should be applied.", ) + cmd.Flags().StringVarP( + &o.GardenLinuxVersion, "gardenlinux-version", "g", provision.DefaultGardenLinuxVersion, + "Garden Linux version of the cluster.", + ) return cmd } diff --git a/cmd/kyma/provision/gardener/az/cmd_test.go b/cmd/kyma/provision/gardener/az/cmd_test.go index 8c3516e1d..8b423b5ee 100644 --- a/cmd/kyma/provision/gardener/az/cmd_test.go +++ b/cmd/kyma/provision/gardener/az/cmd_test.go @@ -36,6 +36,10 @@ func TestProvisionGardenerAzureFlags(t *testing.T) { require.Equal(t, "00 18 * * 1,2,3,4,5", o.HibernationStart, "Default value for the project flag not as expected.") require.Equal(t, "", o.HibernationEnd, "Default value for the project flag not as expected.") require.Equal(t, "Europe/Berlin", o.HibernationLocation, "Default value for the project flag not as expected.") + require.Equal( + t, provision.DefaultGardenLinuxVersion, o.GardenLinuxVersion, + "Default value for the gardenlinux-version flag not as expected.", + ) // test passing flags err := c.ParseFlags( @@ -145,7 +149,7 @@ func TestNewProvider(t *testing.T) { custom["workercidr"] = "10.250.0.0/16" custom["networking_type"] = "calico" custom["machine_image_name"] = "gardenlinux" - custom["machine_image_version"] = "934.6.0" + custom["machine_image_version"] = o.GardenLinuxVersion custom["hibernation_start"] = "00 18 * * 1,2,3,4,5" custom["hibernation_end"] = "" custom["hibernation_location"] = "Europe/Berlin" diff --git a/cmd/kyma/provision/gardener/az/opts.go b/cmd/kyma/provision/gardener/az/opts.go index f8fb3711b..ea5b92e48 100644 --- a/cmd/kyma/provision/gardener/az/opts.go +++ b/cmd/kyma/provision/gardener/az/opts.go @@ -10,6 +10,7 @@ type Options struct { CredentialsFile string Secret string KubernetesVersion string + GardenLinuxVersion string Region string Zones []string MachineType string diff --git a/cmd/kyma/provision/gardener/az/template.go b/cmd/kyma/provision/gardener/az/template.go index 344a417dd..84a1b50b1 100644 --- a/cmd/kyma/provision/gardener/az/template.go +++ b/cmd/kyma/provision/gardener/az/template.go @@ -59,7 +59,7 @@ func (c *azCmd) NewProvider() (*types.Provider, error) { p.CustomConfigurations["workercidr"] = "10.250.0.0/16" p.CustomConfigurations["networking_type"] = "calico" p.CustomConfigurations["machine_image_name"] = "gardenlinux" - p.CustomConfigurations["machine_image_version"] = "934.6.0" + p.CustomConfigurations["machine_image_version"] = c.opts.GardenLinuxVersion p.CustomConfigurations["zones"] = c.opts.Zones p.CustomConfigurations["hibernation_start"] = c.opts.HibernationStart p.CustomConfigurations["hibernation_end"] = c.opts.HibernationEnd diff --git a/cmd/kyma/provision/gardener/gcp/cmd.go b/cmd/kyma/provision/gardener/gcp/cmd.go index 560583396..4cb45dc31 100644 --- a/cmd/kyma/provision/gardener/gcp/cmd.go +++ b/cmd/kyma/provision/gardener/gcp/cmd.go @@ -60,6 +60,10 @@ Use service account details to create a Secret and import it in Gardener.`, &o.HibernationLocation, "hibernation-location", "Europe/Berlin", "Timezone in which the hibernation schedule should be applied.", ) + cmd.Flags().StringVarP( + &o.GardenLinuxVersion, "gardenlinux-version", "g", provision.DefaultGardenLinuxVersion, + "Garden Linux version of the cluster.", + ) return cmd } diff --git a/cmd/kyma/provision/gardener/gcp/cmd_test.go b/cmd/kyma/provision/gardener/gcp/cmd_test.go index c528d9df5..e131648a8 100644 --- a/cmd/kyma/provision/gardener/gcp/cmd_test.go +++ b/cmd/kyma/provision/gardener/gcp/cmd_test.go @@ -54,6 +54,7 @@ func TestProvisionGardenerGCPFlags(t *testing.T) { "--scaler-max", "99", "--extra", "VAR1=VALUE1,VAR2=VALUE2", "--attempts", "2", + "--gardenlinux-version", "934.7", }, ) @@ -72,6 +73,7 @@ func TestProvisionGardenerGCPFlags(t *testing.T) { require.Equal(t, "a big one", o.DiskType, "The parsed value for the disk-type flag not as expected.") require.Equal(t, 88, o.ScalerMin, "The parsed value for the scaler-min flag not as expected.") require.Equal(t, 99, o.ScalerMax, "The parsed value for the scaler-max flag not as expected.") + require.Equal(t, "934.7", o.GardenLinuxVersion, "The parsed value for the gardenlinux-version flag not as expected.") require.Equal( t, []string{"VAR1=VALUE1", "VAR2=VALUE2"}, o.Extra, "The parsed value for the extra flag not as expected.", ) @@ -120,6 +122,7 @@ func TestNewProvider(t *testing.T) { HibernationStart: "00 18 * * 1,2,3,4,5", HibernationLocation: "Europe/Berlin", Extra: []string{"VAR1=VALUE1", "VAR2=VALUE2"}, + GardenLinuxVersion: "934.7", } cmd := newGcpCmd(o) p, err := cmd.NewProvider() @@ -145,7 +148,7 @@ func TestNewProvider(t *testing.T) { custom["workercidr"] = "10.250.0.0/16" custom["networking_type"] = "calico" custom["machine_image_name"] = "gardenlinux" - custom["machine_image_version"] = "934.6.0" + custom["machine_image_version"] = o.GardenLinuxVersion custom["hibernation_start"] = "00 18 * * 1,2,3,4,5" custom["hibernation_end"] = "" custom["hibernation_location"] = "Europe/Berlin" diff --git a/cmd/kyma/provision/gardener/gcp/opts.go b/cmd/kyma/provision/gardener/gcp/opts.go index 53e48ebd5..74b0c78df 100644 --- a/cmd/kyma/provision/gardener/gcp/opts.go +++ b/cmd/kyma/provision/gardener/gcp/opts.go @@ -10,6 +10,7 @@ type Options struct { CredentialsFile string Secret string KubernetesVersion string + GardenLinuxVersion string Region string Zones []string MachineType string diff --git a/cmd/kyma/provision/gardener/gcp/template.go b/cmd/kyma/provision/gardener/gcp/template.go index d0c0d2bf1..8d74cd5c8 100644 --- a/cmd/kyma/provision/gardener/gcp/template.go +++ b/cmd/kyma/provision/gardener/gcp/template.go @@ -60,7 +60,7 @@ func (c *gcpCmd) NewProvider() (*types.Provider, error) { p.CustomConfigurations["workercidr"] = "10.250.0.0/16" p.CustomConfigurations["networking_type"] = "calico" p.CustomConfigurations["machine_image_name"] = "gardenlinux" - p.CustomConfigurations["machine_image_version"] = "934.6.0" + p.CustomConfigurations["machine_image_version"] = c.opts.GardenLinuxVersion p.CustomConfigurations["zones"] = c.opts.Zones p.CustomConfigurations["hibernation_start"] = c.opts.HibernationStart p.CustomConfigurations["hibernation_end"] = c.opts.HibernationEnd diff --git a/docs/gen-docs/kyma_provision_gardener_aws.md b/docs/gen-docs/kyma_provision_gardener_aws.md index 34e5257dd..89e5129ad 100644 --- a/docs/gen-docs/kyma_provision_gardener_aws.md +++ b/docs/gen-docs/kyma_provision_gardener_aws.md @@ -23,6 +23,7 @@ kyma provision gardener aws [flags] --disk-size int Disk size (in GB) of the cluster. (default 50) --disk-type string Type of disk to use on AWS. (default "gp2") -e, --extra NAME=VALUE One or more arguments provided as the NAME=VALUE key-value pairs to configure additional cluster settings. You can use this flag multiple times or enter the key-value pairs as a comma-separated list. + -g, --gardenlinux-version string Garden Linux version of the cluster. (default "934.6.0") --hibernation-end string Cron expression to configure when the cluster should stop hibernating --hibernation-location string Timezone in which the hibernation schedule should be applied. (default "Europe/Berlin") --hibernation-start string Cron expression to configure when the cluster should start hibernating (default "00 18 * * 1,2,3,4,5") diff --git a/docs/gen-docs/kyma_provision_gardener_az.md b/docs/gen-docs/kyma_provision_gardener_az.md index b883f5fd0..20a6f180b 100644 --- a/docs/gen-docs/kyma_provision_gardener_az.md +++ b/docs/gen-docs/kyma_provision_gardener_az.md @@ -22,6 +22,7 @@ kyma provision gardener az [flags] --disk-size int Disk size (in GB) of the cluster. (default 50) --disk-type string Type of disk to use on Azure. (default "Standard_LRS") -e, --extra NAME=VALUE One or more arguments provided as the NAME=VALUE key-value pairs to configure additional cluster settings. You can use this flag multiple times or enter the key-value pairs as a comma-separated list. + -g, --gardenlinux-version string Garden Linux version of the cluster. (default "934.6.0") --hibernation-end string Cron expression to configure when the cluster should stop hibernating --hibernation-location string Timezone in which the hibernation schedule should be applied. (default "Europe/Berlin") --hibernation-start string Cron expression to configure when the cluster should start hibernating (default "00 18 * * 1,2,3,4,5") diff --git a/docs/gen-docs/kyma_provision_gardener_gcp.md b/docs/gen-docs/kyma_provision_gardener_gcp.md index 7b2eff162..d51d6d4ed 100644 --- a/docs/gen-docs/kyma_provision_gardener_gcp.md +++ b/docs/gen-docs/kyma_provision_gardener_gcp.md @@ -23,6 +23,7 @@ kyma provision gardener gcp [flags] --disk-size int Disk size (in GB) of the cluster. (default 50) --disk-type string Type of disk to use on GCP. (default "pd-standard") -e, --extra NAME=VALUE One or more arguments provided as the NAME=VALUE key-value pairs to configure additional cluster settings. You can use this flag multiple times or enter the key-value pairs as a comma-separated list. + -g, --gardenlinux-version string Garden Linux version of the cluster. (default "934.6.0") --hibernation-end string Cron expression to configure when the cluster should stop hibernating --hibernation-location string Timezone in which the hibernation schedule should be applied. (default "Europe/Berlin") --hibernation-start string Cron expression to configure when the cluster should start hibernating (default "00 18 * * 1,2,3,4,5") diff --git a/go.mod b/go.mod index fb6289f7d..1967c486d 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,7 @@ require ( github.com/imdario/mergo v0.3.13 github.com/kyma-incubator/reconciler v0.0.0-20230414081633-01086c789985 github.com/kyma-project/hydroform/function v0.0.0-20230307104736-fc661e702543 - github.com/kyma-project/hydroform/provision v0.0.0-20230127124234-b67611c40868 + github.com/kyma-project/hydroform/provision v0.0.0-20230418133637-1ea26b368bb6 github.com/kyma-project/lifecycle-manager v0.0.0-20230228084539-adc0e4a5f93a github.com/mandelsoft/vfs v0.0.0-20220805210647-bf14a11bfe31 github.com/open-component-model/ocm v0.3.0-rc.1 @@ -112,7 +112,6 @@ require ( github.com/docker/go-metrics v0.0.1 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect - github.com/elazarl/goproxy v0.0.0-20191011121108-aa519ddbe484 // indirect github.com/emicklei/go-restful/v3 v3.10.1 // indirect github.com/emirpasic/gods v1.18.1 // indirect github.com/evanphx/json-patch v5.6.0+incompatible // indirect @@ -122,7 +121,7 @@ require ( github.com/fatih/structs v1.1.0 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/fvbommel/sortorder v1.0.2 // indirect - github.com/gardener/gardener v1.53.2 // indirect + github.com/gardener/gardener v1.67.0 // indirect github.com/ghodss/yaml v1.0.0 // indirect github.com/go-cmd/cmd v1.4.1 // indirect github.com/go-errors/errors v1.4.2 // indirect @@ -251,14 +250,14 @@ require ( go.starlark.net v0.0.0-20230128213706-3f75dec8e403 // indirect go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.9.0 // indirect - golang.org/x/crypto v0.5.0 // indirect + golang.org/x/crypto v0.6.0 // indirect golang.org/x/mod v0.8.0 // indirect - golang.org/x/net v0.7.0 // indirect + golang.org/x/net v0.8.0 // indirect golang.org/x/oauth2 v0.4.0 // indirect golang.org/x/sync v0.1.0 // indirect - golang.org/x/sys v0.5.0 // indirect - golang.org/x/term v0.5.0 // indirect - golang.org/x/text v0.7.0 // indirect + golang.org/x/sys v0.6.0 // indirect + golang.org/x/term v0.6.0 // indirect + golang.org/x/text v0.8.0 // indirect golang.org/x/time v0.3.0 // indirect golang.org/x/tools v0.6.0 // indirect gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect diff --git a/go.sum b/go.sum index b0fc838cb..1b7f52373 100644 --- a/go.sum +++ b/go.sum @@ -570,8 +570,6 @@ github.com/dvsekhvalnov/jose2go v0.0.0-20170216131308-f21a8cedbbae/go.mod h1:7Bv github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= github.com/elazarl/goproxy v0.0.0-20191011121108-aa519ddbe484 h1:pEtiCjIXx3RvGjlUJuCNxNOw0MNblyR9Wi+vJGBFh+8= -github.com/elazarl/goproxy v0.0.0-20191011121108-aa519ddbe484/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM= -github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8= github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= github.com/emicklei/go-restful/v3 v3.8.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= @@ -624,8 +622,8 @@ github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoD github.com/form3tech-oss/jwt-go v3.2.3+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= github.com/form3tech-oss/jwt-go v3.2.5+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= -github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= +github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= @@ -636,8 +634,8 @@ github.com/fvbommel/sortorder v1.0.2 h1:mV4o8B2hKboCdkJm+a7uX/SIpZob4JzUpc5GGnM4 github.com/fvbommel/sortorder v1.0.2/go.mod h1:uk88iVf1ovNn1iLfgUVU2F9o5eO30ui720w+kxuqRs0= github.com/gabriel-vasile/mimetype v1.3.1/go.mod h1:fA8fi6KUiG7MgQQ+mEWotXoEOvmxRtOJlERCzSmRvr8= github.com/gabriel-vasile/mimetype v1.4.0/go.mod h1:fA8fi6KUiG7MgQQ+mEWotXoEOvmxRtOJlERCzSmRvr8= -github.com/gardener/gardener v1.53.2 h1:X7NuzKuTRiyrc4YHFuXN6QBAOnXEOSxUSDHi4Qcr8zg= -github.com/gardener/gardener v1.53.2/go.mod h1:O+59kTQavqxX5nr5jyHqD6o4JxIukHMaW2t5BLiXqmc= +github.com/gardener/gardener v1.67.0 h1:biGI++snKisq4xu7Relgv9p9FwVZ8CsiR+U2dvNFgsU= +github.com/gardener/gardener v1.67.0/go.mod h1:LOelF1QZM+flQ9qbEBOY73JJJSnyLd8fuZ2pQfreGxU= github.com/garyburd/redigo v0.0.0-20150301180006-535138d7bcd7/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY= github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ= github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= @@ -754,7 +752,7 @@ github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LB github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= -github.com/go-test/deep v1.0.7 h1:/VSMRlnY/JSyqxQUzQLKVMAskpY/NZKFA5j2P+0pP2M= +github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg= github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY= github.com/gobuffalo/depgen v0.1.0/go.mod h1:+ifsuy7fhi15RWncXQQKjWS9JPkdah5sZvtHc2RXGlg= @@ -1178,8 +1176,8 @@ github.com/kyma-incubator/reconciler v0.0.0-20230414081633-01086c789985 h1:P7dPx github.com/kyma-incubator/reconciler v0.0.0-20230414081633-01086c789985/go.mod h1:Xgvl68xt2qKPKrzh73UbeHjmT4VdSNJPKXpozkMPUN0= github.com/kyma-project/hydroform/function v0.0.0-20230307104736-fc661e702543 h1:7xCxCkLYwwcl1zrhu65YQ5LkHzZYiCcM1tYhC/vNQ00= github.com/kyma-project/hydroform/function v0.0.0-20230307104736-fc661e702543/go.mod h1:h6psCfFtd9Lo4AjiV2a9EYnG0yeNCR5TvSPbkZHL4qg= -github.com/kyma-project/hydroform/provision v0.0.0-20230127124234-b67611c40868 h1:RV2QLbL7Za94O62CvDlrdcLRK5GFI2Zq0GNUe0mCMZk= -github.com/kyma-project/hydroform/provision v0.0.0-20230127124234-b67611c40868/go.mod h1:ttfW/oPcTIMMtAqY9qpocdAaQ2A+5nN8ZQl2L+1rIac= +github.com/kyma-project/hydroform/provision v0.0.0-20230418133637-1ea26b368bb6 h1:k8TsRKhbYr+uQ1Glpbwii9kBqMPSFEZdMSov9KJjgiA= +github.com/kyma-project/hydroform/provision v0.0.0-20230418133637-1ea26b368bb6/go.mod h1:eXIZaENQU/Y4sq20z3AgiFg6hSZUP4DmQ2JTMtFt+A8= github.com/kyma-project/istio/operator v0.0.0-20221129102055-d37c5c8e6add h1:ohTtnIlNXSQPHB/nMZvBXs+uBnTqQ6HRSgAvptyWzlc= github.com/kyma-project/istio/operator v0.0.0-20221129102055-d37c5c8e6add/go.mod h1:K5jDoHdqW8EI2vXX+7J+RnEmk4YQRnd6fTmuuSyQ3Qg= github.com/kyma-project/lifecycle-manager v0.0.0-20230228084539-adc0e4a5f93a h1:I72FDYpnBAR5NhuN1ZR7Eaiyf+yKhlcWp1w5/rnnyiM= @@ -1565,7 +1563,6 @@ github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw= github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= -github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc= github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= @@ -1889,8 +1886,9 @@ golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= -golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE= golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= +golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc= +golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -2024,8 +2022,9 @@ golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfS golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/oauth2 v0.0.0-20180227000427-d7d64896b5ff/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -2198,8 +2197,9 @@ golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -2209,8 +2209,9 @@ golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= -golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw= +golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -2223,8 +2224,9 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/internal/cli/setup/envtest/setup.go b/internal/cli/setup/envtest/setup.go index 6f3245c7c..bd124cc7e 100644 --- a/internal/cli/setup/envtest/setup.go +++ b/internal/cli/setup/envtest/setup.go @@ -11,7 +11,6 @@ import ( "github.com/kyma-project/cli/internal/envtest" "github.com/kyma-project/cli/internal/files" - "github.com/kyma-project/cli/pkg/step" ) const ( @@ -23,7 +22,7 @@ const ( // based on "kubernetes-sigs/controller-runtime/tools/setup-envtest/versions/parse.go", but more strict var envtestVersionRegexp = regexp.MustCompile(`^(0|[1-9]\d{0,2})\.(0|[1-9]\d{0,2})\.(0|[1-9]\d{0,3})$`) -func EnvTest(step step.Step, verbose bool) (*envtest.Runner, error) { +func EnvTest() (*envtest.Runner, error) { p, err := files.KymaHome() if err != nil { return nil, err @@ -40,8 +39,6 @@ func EnvTest(step step.Step, verbose bool) (*envtest.Runner, error) { out, err := envtestSetupCmd.CombinedOutput() if err != nil { return nil, fmt.Errorf("error installing setup-envtest: %w. Details: %s", err, string(out)) - } else if verbose { - step.LogInfof("Installed setup-envtest in: %q", p) } } @@ -65,15 +62,6 @@ func EnvTest(step step.Step, verbose bool) (*envtest.Runner, error) { return nil, fmt.Errorf("error installing envtest binaries: %w", err) } - if verbose { - version, err := extractVersion(string(out)) - if err == nil { - step.LogInfof("Installed envtest binaries in version %s, path: %q", version, envtestBinariesPath) - } else { - step.LogInfof("Installed envtest binaries in: %q", envtestBinariesPath) - } - } - return envtest.NewRunner(envtestBinariesPath, nil, nil), nil } @@ -98,11 +86,6 @@ func extractPath(envtestSetupMsg string) (string, error) { } -// extractVersion extracts the envtest binaries version from the "setup-envtest" command output -func extractVersion(envtestSetupMsg string) (string, error) { - return parseEnvtestSetupMsg(envtestSetupMsg, `[vV]ersion:(.+)`, "envtest version") -} - func parseEnvtestSetupMsg(envtestSetupMsg, rgxp, objName string) (string, error) { r, err := regexp.Compile(rgxp) if err != nil { diff --git a/pkg/module/kubebuilder/chart.go b/pkg/module/kubebuilder/chart.go deleted file mode 100644 index 66fbfad4f..000000000 --- a/pkg/module/kubebuilder/chart.go +++ /dev/null @@ -1,42 +0,0 @@ -package kubebuilder - -import ( - "bytes" - "os" - "path/filepath" - "text/template" -) - -const ( - chartFile = "Chart.yaml" - chartTemplate = `apiVersion: v2 -name: {{ .Name }} -description: A Helm chart for the Operator in a Cluster based on a Kustomize Manifest -type: application -version: {{ .Version }} -appVersion: "{{ .Version }}" -` -) - -// Add chart generates a Chart.yaml file with the given name and version and saves it to the chartFolder. -func addChart(name, version, chartFolder string) error { - t, err := template.New("Chart").Parse(chartTemplate) - if err != nil { - return err - } - - data := struct { - Name string - Version string - }{ - Name: name, - Version: version, - } - - w := &bytes.Buffer{} - if err := t.Execute(w, data); err != nil { - return err - } - - return os.WriteFile(filepath.Join(chartFolder, chartFile), w.Bytes(), os.ModePerm) -} diff --git a/pkg/module/kubebuilder/project.go b/pkg/module/kubebuilder/project.go index b1f273738..11bf057da 100644 --- a/pkg/module/kubebuilder/project.go +++ b/pkg/module/kubebuilder/project.go @@ -2,7 +2,6 @@ package kubebuilder import ( "fmt" - "io/fs" "os" "path/filepath" "strconv" @@ -22,11 +21,7 @@ const ( configFile = "config.yaml" defaultKustomization = "config/default" samplesPath = "config/samples/" - - crdFileIdentifier = "customresourcedefinition" - chartsFolder = "charts/%s" - templatesFolder = "templates" - crdsFolder = "crds" + OutputPath = "manifests" ) type Project struct { @@ -60,7 +55,7 @@ func (p *Project) FullName() string { } // Build builds the kubebuilder project default kustomization following the given definition. -func (p *Project) Build(name, version string) (string, error) { +func (p *Project) Build(name string) (string, error) { // check layout if !(slices.Contains(p.Layout, V3) || slices.Contains(p.Layout, V4alpha)) { return "", fmt.Errorf("project layout %v is not supported", p.Layout) @@ -73,49 +68,24 @@ func (p *Project) Build(name, version string) (string, error) { // create output folders pieces := strings.Split(name, "/") - chartName := pieces[len(pieces)-1] // always return the last part of the path - chartsPath := filepath.Join(p.path, fmt.Sprintf(chartsFolder, chartName)) - outPath := filepath.Join(chartsPath, templatesFolder) - crdsPath := filepath.Join(chartsPath, crdsFolder) + moduleName := pieces[len(pieces)-1] // always return the last part of the path + manifestsPath := filepath.Join(p.path, OutputPath, moduleName) - if err := os.MkdirAll(outPath, os.ModePerm); err != nil { + if err := os.MkdirAll(manifestsPath, os.ModePerm); err != nil { return "", fmt.Errorf("could not create chart templates output dir: %w", err) } - if err := os.MkdirAll(crdsPath, os.ModePerm); err != nil { - return "", fmt.Errorf("could not create chart CRDs output dir: %w", err) - } // do build yml, err := kustomize.Build(k) if err != nil { return "", err } - - if err := os.WriteFile(filepath.Join(outPath, "rendered.yaml"), yml, os.ModePerm); err != nil { - return "", fmt.Errorf("could not write rendered kustomization as yml to %s: %w", outPath, err) - } - - // move CRDs to their folder - mvFn := func(path string, d fs.DirEntry, err error) error { - fileName := filepath.Base(path) - if strings.Contains(fileName, crdFileIdentifier) { - if err := os.Rename(path, filepath.Join(crdsPath, fileName)); err != nil { - return fmt.Errorf("could not move CRD file from %q to %q: %w", path, crdsPath, err) - } - } - return nil - } - - if err := filepath.WalkDir(outPath, mvFn); err != nil { - return "", err - } - - // generate Chart.yaml file - if err := addChart(chartName, version, chartsPath); err != nil { - return "", fmt.Errorf("could not generate Chart.yaml file: %w", err) + renderedManifestPath := filepath.Join(manifestsPath, "rendered.yaml") + if err := os.WriteFile(renderedManifestPath, yml, os.ModePerm); err != nil { + return "", fmt.Errorf("could not write rendered kustomization as yml to %s: %w", manifestsPath, err) } - return chartsPath, nil + return renderedManifestPath, nil } func (p *Project) Config() (string, error) { diff --git a/pkg/module/layer.go b/pkg/module/layer.go index 551c43a7f..51d646b18 100644 --- a/pkg/module/layer.go +++ b/pkg/module/layer.go @@ -7,9 +7,10 @@ import ( ) const ( - configLayerName = "config" - typeHelmChart = "helm-chart" - typeYaml = "yaml" + configLayerName = "config" + rawManifestLayerName = "raw-manifest" + typeHelmChart = "helm-chart" + typeYaml = "yaml" ) // Layer encapsulates all necessary data to create an OCI layer diff --git a/pkg/module/remote.go b/pkg/module/remote.go index b72e49e15..3793ec03e 100644 --- a/pkg/module/remote.go +++ b/pkg/module/remote.go @@ -89,8 +89,9 @@ func (r *Remote) getCredentials(ctx cpi.Context) credentials.Credentials { } } } + // if no creds are set, try to use username and password that are provided. - if creds == nil { + if creds == nil || isEmptyAuth(creds) { u, p := r.userPass() if p == "" { p = r.Token @@ -103,6 +104,19 @@ func (r *Remote) getCredentials(ctx cpi.Context) credentials.Credentials { return creds } +// See: github.com/open-component-model/ocm/pkg/contexts/credentials/repositories/dockerconfig/repository.go#IsEmptyAuthConfig() +func isEmptyAuth(creds credentials.Credentials) bool { + + if len(creds.GetProperty("auth")) != 0 { + return false + } + if len(creds.GetProperty("username")) != 0 { + return false + } + + return true +} + // userPass splits the credentials string into user and password. // If the string is empty or can't be split, it returns 2 empty strings. func (r *Remote) userPass() (string, string) { diff --git a/pkg/module/resources.go b/pkg/module/resources.go index 51d970884..27040302b 100644 --- a/pkg/module/resources.go +++ b/pkg/module/resources.go @@ -161,10 +161,8 @@ func inspectProject(def *Definition, p *kubebuilder.Project, layers []Layer, s s return err } - // generated chart -> layer 1 - chartPath, err := p.Build( - def.Name, def.Version, - ) // TODO switch from charts to pure manifests when mod-mngr is ready + // generated raw manifest -> layer 1 + renderedManifestPath, err := p.Build(def.Name) if err != nil { return err } @@ -199,9 +197,9 @@ func inspectProject(def *Definition, p *kubebuilder.Project, layers []Layer, s s def.Repo = p.Repo def.DefaultCR = cr def.Layers = append(def.Layers, Layer{ - name: filepath.Base(chartPath), - resourceType: typeHelmChart, - path: chartPath, + name: rawManifestLayerName, + resourceType: typeYaml, + path: renderedManifestPath, }) def.Layers = append(def.Layers, layers...) diff --git a/pkg/module/sign.go b/pkg/module/sign.go index cb7564cbc..403c3638c 100644 --- a/pkg/module/sign.go +++ b/pkg/module/sign.go @@ -1,8 +1,6 @@ package module import ( - "crypto/x509" - "encoding/pem" "fmt" "os" @@ -22,8 +20,8 @@ type ComponentSignConfig struct { } const ( - SignatureName = "kyma-project.io/module-signature" - Issuer = "kyma-project.io/cli" + SignatureName = "kyma-module-signature" + Issuer = "kyma-cli" ) func Sign(cfg *ComponentSignConfig, remote *Remote) error { @@ -109,16 +107,12 @@ func (cfg *ComponentSignConfig) validate() error { } func privateKey(pathToPrivateKey string) (interface{}, error) { - privKeyFile, err := os.ReadFile(pathToPrivateKey) + privateKeyFile, err := os.ReadFile(pathToPrivateKey) if err != nil { return nil, fmt.Errorf("unable to open key file: %w", err) } - block, _ := pem.Decode(privKeyFile) - if block == nil { - return nil, fmt.Errorf("unable to decode pem formatted block in key: %w", err) - } - key, err := x509.ParsePKCS1PrivateKey(block.Bytes) + key, err := signing.ParsePrivateKey(privateKeyFile) if err != nil { return nil, fmt.Errorf("unable to parse private key: %w", err) } @@ -131,11 +125,7 @@ func publicKey(pathToPublicKey string) (interface{}, error) { return nil, fmt.Errorf("unable to open key file: %w", err) } - block, _ := pem.Decode(publicKeyFile) - if block == nil { - return nil, fmt.Errorf("unable to decode pem formatted block in key: %w", err) - } - key, err := x509.ParsePKIXPublicKey(block.Bytes) + key, err := signing.ParsePublicKey(publicKeyFile) if err != nil { return nil, fmt.Errorf("unable to parse public key: %w", err) } diff --git a/pkg/module/template.go b/pkg/module/template.go index 6625e1cef..45ff1b0b0 100644 --- a/pkg/module/template.go +++ b/pkg/module/template.go @@ -51,6 +51,10 @@ func Template( if err != nil { return nil, err } + descriptor.SetLabels([]ocmv1.Label{{ + Name: OCIRegistryCredLabel, + Value: matchLabels, + }}) for i := range descriptor.Resources { resource := &descriptor.Resources[i] resource.SetLabels( diff --git a/pkg/module/validation.go b/pkg/module/validation.go index f2b7794a9..c3e21b483 100644 --- a/pkg/module/validation.go +++ b/pkg/module/validation.go @@ -10,9 +10,10 @@ import ( "strings" "time" + "github.com/kyma-project/cli/pkg/module/kubebuilder" + setup "github.com/kyma-project/cli/internal/cli/setup/envtest" "github.com/kyma-project/cli/internal/kube" - "github.com/kyma-project/cli/pkg/step" "go.uber.org/zap" "gopkg.in/yaml.v3" amv "k8s.io/apimachinery/pkg/util/validation" @@ -21,32 +22,33 @@ import ( var ErrEmptyCR = errors.New("provided CR is empty") type DefaultCRValidator struct { - modulePath string - crData []byte + crdSearchDir string + crData []byte } func NewDefaultCRValidator(cr []byte, modulePath string) (*DefaultCRValidator, error) { + crdSearchDir := filepath.Join(modulePath, kubebuilder.OutputPath) return &DefaultCRValidator{ - modulePath: modulePath, - crData: cr, + crdSearchDir: crdSearchDir, + crData: cr, }, nil } -func (v *DefaultCRValidator) Run(ctx context.Context, s step.Step, verbose bool, log *zap.SugaredLogger) error { +func (v *DefaultCRValidator) Run(ctx context.Context, log *zap.SugaredLogger) error { // skip validation if no CR detected if len(v.crData) == 0 { return nil } // setup test env - runner, err := setup.EnvTest(s, verbose) + runner, err := setup.EnvTest() if err != nil { return err } crMap, err := parseYamlToMap(v.crData) if err != nil { - return fmt.Errorf("Error parsing default CR: %w", err) + return fmt.Errorf("error parsing default CR: %w", err) } group, kind, err := readGroupKind(crMap) @@ -54,18 +56,17 @@ func (v *DefaultCRValidator) Run(ctx context.Context, s step.Step, verbose bool, return err } - searchDirPath := filepath.Join(v.modulePath, "charts") - crdFound, crdFilePath, err := findCRDFileFor(group, kind, searchDirPath) + crdFound, crdFilePath, err := findCRDFileFor(group, kind, v.crdSearchDir) if err != nil { - return fmt.Errorf("Error finding CRD file in the %q directory: %w", searchDirPath, err) + return fmt.Errorf("error finding CRD file in the %q directory: %w", v.crdSearchDir, err) } if !crdFound { - return fmt.Errorf("Can't find the CRD for (group: %q, kind %q)", group, kind) + return fmt.Errorf("can't find the CRD for (group: %q, kind %q)", group, kind) } err = ensureDefaultNamespace(crMap) if err != nil { - return err + return fmt.Errorf("error parsing default CR: %w", err) } properCR, err := renderYamlFromMap(crMap) @@ -79,7 +80,7 @@ func (v *DefaultCRValidator) Run(ctx context.Context, s step.Step, verbose bool, defer func() { if err := runner.Stop(); err != nil { //TODO: This doesn't seem to print anything... - log.Error(fmt.Errorf("Error stopping envTest: %w", err)) + log.Error(fmt.Errorf("error stopping envTest: %w", err)) //THIS does: fmt.Println(fmt.Errorf("Error stopping envTest: %w", stopErr)) } }() @@ -95,18 +96,18 @@ func (v *DefaultCRValidator) Run(ctx context.Context, s step.Step, verbose bool, } if err := kc.Apply(ctx, false, objs...); err != nil { - return fmt.Errorf("Error applying the default CR: %w", err) + return fmt.Errorf("error applying the default CR: %w", err) } return nil } -// ensureDefaultNamespace ensures that the metadata.namespace attribute exists and its value is "default". This is because of how we use the envtest to validate the CR. +// ensureDefaultNamespace ensures that the metadata.namespace attribute exists, and its value is "default". This is because of how we use the envtest to validate the CR. func ensureDefaultNamespace(modelMap map[string]interface{}) error { //Traverse the Map to look for "metadata.namespace" metadataMap, err := mustReadMap(modelMap, "metadata") if err != nil { - return fmt.Errorf("Error parsing default CR: %w", err) + return err } namespaceVal, ok := metadataMap["namespace"] @@ -117,7 +118,7 @@ func ensureDefaultNamespace(modelMap map[string]interface{}) error { //Set the "metadata.namespace" if different than "default" existing, ok := namespaceVal.(string) if !ok { - return errors.New("Error parsing default CR: Attribute \"metadata.namespace\" is not a string") + return errors.New("attribute \"metadata.namespace\" is not a string") } if existing != "default" { metadataMap["namespace"] = "default" @@ -130,14 +131,14 @@ func ensureDefaultNamespace(modelMap map[string]interface{}) error { func readGroupKind(crMap map[string]interface{}) (group, kind string, retErr error) { apiVersion, err := mustReadString(crMap, "apiVersion") if err != nil { - retErr = fmt.Errorf("Can't parse default CR data: %w", err) + retErr = fmt.Errorf("can't parse default CR data: %w", err) return } group = strings.Split(apiVersion, "/")[0] //e.g: apiVersion: example.org/v1 kind, err = mustReadString(crMap, "kind") if err != nil { - retErr = fmt.Errorf("Can't parse default CR data: %w", err) + retErr = fmt.Errorf("can't parse default CR data: %w", err) return } @@ -148,12 +149,12 @@ func readGroupKind(crMap map[string]interface{}) (group, kind string, retErr err func mustReadMap(input map[string]interface{}, key string) (map[string]interface{}, error) { attrVal, ok := input[key] if !ok { - return nil, fmt.Errorf("Attribute %q not found", key) + return nil, fmt.Errorf("attribute %q not found", key) } asMap, ok := attrVal.(map[string]interface{}) if !ok { - return nil, fmt.Errorf("Attribute %q is not a Map", key) + return nil, fmt.Errorf("attribute %q is not a Map", key) } return asMap, nil @@ -163,12 +164,12 @@ func mustReadMap(input map[string]interface{}, key string) (map[string]interface func mustReadString(input map[string]interface{}, key string) (string, error) { attrVal, ok := input[key] if !ok { - return "", fmt.Errorf("Attribute %q not found", key) + return "", fmt.Errorf("attribute %q not found", key) } asString, ok := attrVal.(string) if !ok { - return "", fmt.Errorf("Attribute %q is not a string", key) + return "", fmt.Errorf("attribute %q is not a string", key) } return asString, nil @@ -176,9 +177,9 @@ func mustReadString(input map[string]interface{}, key string) (string, error) { func parseYamlToMap(crData []byte) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) - err := yaml.Unmarshal([]byte(crData), &modelMap) + err := yaml.Unmarshal(crData, &modelMap) if err != nil { - return nil, fmt.Errorf("Error parsing default CR: %w", err) + return nil, fmt.Errorf("error parsing default CR: %w", err) } return modelMap, nil @@ -188,25 +189,25 @@ func renderYamlFromMap(modelMap map[string]interface{}) ([]byte, error) { output, err := yaml.Marshal(modelMap) if err != nil { - return nil, fmt.Errorf("Error processing default CR data: %w", err) + return nil, fmt.Errorf("error processing default CR data: %w", err) } return output, nil } -// findCRDFileFor returns path to the file with a CRD definition for the given group and kind, if exists. It looks in the dirPath directory and all of it's subdirectories, recursively. The first parameter is true if the file is found, it's false otherwise. +// findCRDFileFor returns path to the file with a CRD definition for the given group and kind, if exists. +// It looks in the dirPath directory and all of its subdirectories, recursively. The first parameter is true if the file is found, it's false otherwise. func findCRDFileFor(group, kind, dirPath string) (bool, string, error) { //list all files in the dirPath and all it's subdirectories, recursively files, err := listFiles(dirPath) if err != nil { - return false, "", fmt.Errorf("Error listing files in %q directory: %w", dirPath, err) + return false, "", fmt.Errorf("error listing files in %q directory: %w", dirPath, err) } var found string for _, f := range files { - //fmt.Printf("- Checking file: %q\n", f) ok, err := isCRDFileFor(group, kind, f) if err != nil { //Error is expected. Either the file is not YAML, or it's not a CRD, or it's a CRD but not the one we're looking for. @@ -230,7 +231,7 @@ func isCRDFileFor(group, kind, filePath string) (bool, error) { { f, err := os.Open(filePath) if err != nil { - return false, fmt.Errorf("Error reading \"%q\": %w", filePath, err) + return false, fmt.Errorf("error reading \"%q\": %w", filePath, err) } defer f.Close() @@ -310,7 +311,7 @@ func listFiles(dirPath string) ([]string, error) { err := filepath.Walk(dirPath, walkFunc) if err != nil { - return nil, fmt.Errorf("Error reading directory \"%q\": %w", dirPath, err) + return nil, fmt.Errorf("error reading directory \"%q\": %w", dirPath, err) } return res, nil @@ -319,16 +320,16 @@ func listFiles(dirPath string) ([]string, error) { // ValidateName checks if the name is at least three characters long and if it conforms to the "RFC 1035 Label Names" specification (K8s compatibility requirement) func ValidateName(name string) error { if len(name) < 3 { - return errors.New("Invalid module name: name must be at least three characters long") + return errors.New("invalid module name: name must be at least three characters long") } violations := amv.IsDNS1035Label(name) if len(violations) == 1 { - return fmt.Errorf("Invalid module name: %s", violations[0]) + return fmt.Errorf("invalid module name: %s", violations[0]) } if len(violations) > 1 { vl := "\n - " + strings.Join(violations, "\n - ") - return fmt.Errorf("Invalid module name: %s", vl) + return fmt.Errorf("invalid module name: %s", vl) } return nil diff --git a/pkg/module/validation_test.go b/pkg/module/validation_test.go index 47643c6d7..27b5ca10e 100644 --- a/pkg/module/validation_test.go +++ b/pkg/module/validation_test.go @@ -103,20 +103,20 @@ spec: noMetadataYaml = `abc: def foo: bar ` - noMetadataError = `Attribute "metadata" not found` + noMetadataError = `attribute "metadata" not found` invalidMetadataTypeYaml = ` abc: def metadata: 2 ` - invalidMetadataTypeError = `Attribute "metadata" is not a Map` + invalidMetadataTypeError = `attribute "metadata" is not a Map` invalidNamespaceTypeYaml = ` abc: def metadata: namespace: 2 ` - invalidNamespaceTypeError = `Attribute "metadata.namespace" is not a string` + invalidNamespaceTypeError = `attribute "metadata.namespace" is not a string` missingNamespaceYaml = `abc: def metadata: name: foobar