From bcf3890e379e232039265550c485eaeefe3cda3b Mon Sep 17 00:00:00 2001 From: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> Date: Mon, 22 Apr 2024 13:25:47 +0200 Subject: [PATCH 1/2] fix: remove all personal information from tests (#740) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Fixes https://github.com/open-component-model/ocm-project/issues/43 ## What type of PR is this? (check all applicable) - [ ] 🍕 Feature - [ ] 🐛 Bug Fix - [ ] 📝 Documentation Update - [ ] 🎨 Style - [ ] 🧑‍💻 Code Refactor - [ ] 🔥 Performance Improvements - [ ] ✅ Test - [ ] 🤖 Build - [ ] 🔁 CI - [ ] 📦 Chore (Release) - [ ] ⏩ Revert ## Related Tickets & Documents - Related Issue # (issue) - Closes # (issue) - Fixes # (issue) > Remove if not applicable ## Screenshots ## Added tests? - [ ] 👍 yes - [ ] 🙅 no, because they aren't needed - [ ] 🙋 no, because I need help - [ ] Separate ticket for tests # (issue/pr) Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration ## Added to documentation? - [ ] 📜 README.md - [ ] 🙅 no documentation needed ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --- pkg/env/builder/ocm_version_test.go | 4 ++-- pkg/toi/install/credentials_test.go | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/env/builder/ocm_version_test.go b/pkg/env/builder/ocm_version_test.go index 73e5beceeb..25509b2b88 100644 --- a/pkg/env/builder/ocm_version_test.go +++ b/pkg/env/builder/ocm_version_test.go @@ -21,9 +21,9 @@ import ( const ARCH = "/tmp/ctf" const ARCH2 = "/tmp/ctf2" -const PROVIDER = "mandelsoft" +const PROVIDER = "open-component-model" const VERSION = "v1" -const COMPONENT = "github.com/mandelsoft/test" +const COMPONENT = "github.com/open-component-model/test" const OUT = "/tmp/res" var _ = Describe("Transfer handler", func() { diff --git a/pkg/toi/install/credentials_test.go b/pkg/toi/install/credentials_test.go index 4dc34251e0..6b4c33432e 100644 --- a/pkg/toi/install/credentials_test.go +++ b/pkg/toi/install/credentials_test.go @@ -21,14 +21,14 @@ import ( ) var _ = Describe("credential mapping", func() { - consumerid := credentials.NewConsumerIdentity("CT", identity.ID_HOSTNAME, "github.com", identity.ID_PATHPREFIX, "mandelsoft") + consumerid := credentials.NewConsumerIdentity("CT", identity.ID_HOSTNAME, "github.com", identity.ID_PATHPREFIX, "open-component-model") ccreds := common.Properties{ - "user": "mandelsoft", + "user": "open-component-model", "pass": "mypass", } memspec := memory.NewRepositorySpec("default") memcred := credentials.DirectCredentials{ - "username": "mandelsoft", + "username": "open-component-model", "password": "secret", } cfgdata := ` @@ -36,7 +36,7 @@ configurations: - credentials: - credentials: password: secret - username: mandelsoft + username: open-component-model credentialsName: other - credentials: token: XXX @@ -55,11 +55,11 @@ configurations: - credentialsName: Credentials properties: pass: mypass - user: mandelsoft + user: open-component-model type: Credentials identity: hostname: github.com - pathprefix: mandelsoft/testrepo + pathprefix: open-component-model/testrepo type: CT type: credentials.config.ocm.software type: generic.config.ocm.software @@ -99,7 +99,7 @@ forwardedConsumers: - consumerId: type: CT hostname: github.com - pathprefix: mandelsoft/testrepo + pathprefix: open-component-model/testrepo consumerType: hostpath ` spec, err := install.ParseCredentialSpecification([]byte(input), "settings") @@ -126,7 +126,7 @@ forwardedConsumers: Expect(mem.LookupCredentials("other")).To(Equal(memcred)) creq := consumerid.Copy() - creq[identity.ID_PATHPREFIX] = "mandelsoft/testrepo/bla" + creq[identity.ID_PATHPREFIX] = "open-component-model/testrepo/bla" props := Must(credentials.CredentialsForConsumer(ctx, creq, hostpath.Matcher)) Expect(props.Properties()).To(Equal(ccreds)) }) From 0da176504ec64a42b6530be7457eeb6f6fa94081 Mon Sep 17 00:00:00 2001 From: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> Date: Tue, 23 Apr 2024 08:49:05 +0200 Subject: [PATCH 2/2] fix: do not create a new resource manager client (#742) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Fixes https://github.com/open-component-model/ocm-project/issues/178 ## What type of PR is this? (check all applicable) - [ ] 🍕 Feature - [ ] 🐛 Bug Fix - [ ] 📝 Documentation Update - [ ] 🎨 Style - [ ] 🧑‍💻 Code Refactor - [ ] 🔥 Performance Improvements - [ ] ✅ Test - [ ] 🤖 Build - [ ] 🔁 CI - [ ] 📦 Chore (Release) - [ ] ⏩ Revert ## Related Tickets & Documents - Related Issue # (issue) - Closes # (issue) - Fixes # (issue) > Remove if not applicable ## Screenshots ## Added tests? - [ ] 👍 yes - [ ] 🙅 no, because they aren't needed - [ ] 🙋 no, because I need help - [ ] Separate ticket for tests # (issue/pr) Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration ## Added to documentation? - [ ] 📜 README.md - [ ] 🙅 no documentation needed ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --- .../commands/controllercmds/install/cmd.go | 19 +++++++++++-------- .../install/install_cert_manager.go | 13 ++----------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/cmds/ocm/commands/controllercmds/install/cmd.go b/cmds/ocm/commands/controllercmds/install/cmd.go index e17d8379fb..f79063131b 100644 --- a/cmds/ocm/commands/controllercmds/install/cmd.go +++ b/cmds/ocm/commands/controllercmds/install/cmd.go @@ -50,6 +50,7 @@ type Command struct { DryRun bool SkipPreFlightCheck bool InstallPrerequisites bool + SM *ssa.ResourceManager } var _ utils.OCMCommand = (*Command)(nil) @@ -86,6 +87,14 @@ func (o *Command) Complete(args []string) error { } func (o *Command) Run() error { + kubeconfigArgs := genericclioptions.NewConfigFlags(false) + sm, err := NewResourceManager(kubeconfigArgs) + if err != nil { + return fmt.Errorf("✗ failed to create resource manager: %w", err) + } + + o.SM = sm + ctx := context.Background() if !o.SkipPreFlightCheck { out.Outf(o.Context, "► running pre-install check\n") @@ -163,23 +172,17 @@ func (o *Command) installManifest(ctx context.Context, releaseURL, baseURL, mani } out.Outf(o.Context, "► applying to cluster...\n") - kubeconfigArgs := genericclioptions.NewConfigFlags(false) - sm, err := NewResourceManager(kubeconfigArgs) - if err != nil { - return fmt.Errorf("✗ failed to create resource manager: %w", err) - } - objects, err := readObjects(path) if err != nil { return fmt.Errorf("✗ failed to construct objects to apply: %w", err) } - if _, err := sm.ApplyAllStaged(context.Background(), objects, ssa.DefaultApplyOptions()); err != nil { + if _, err := o.SM.ApplyAllStaged(context.Background(), objects, ssa.DefaultApplyOptions()); err != nil { return fmt.Errorf("✗ failed to apply manifests: %w", err) } out.Outf(o.Context, "► waiting for ocm deployment to be ready\n") - if err = sm.Wait(objects, ssa.DefaultWaitOptions()); err != nil { + if err = o.SM.Wait(objects, ssa.DefaultWaitOptions()); err != nil { return fmt.Errorf("✗ failed to wait for objects to be ready: %w", err) } diff --git a/cmds/ocm/commands/controllercmds/install/install_cert_manager.go b/cmds/ocm/commands/controllercmds/install/install_cert_manager.go index 8dcde14dd5..e24766d770 100644 --- a/cmds/ocm/commands/controllercmds/install/install_cert_manager.go +++ b/cmds/ocm/commands/controllercmds/install/install_cert_manager.go @@ -2,15 +2,12 @@ package install import ( "context" + _ "embed" "fmt" "os" - _ "embed" - "github.com/fluxcd/pkg/ssa" "github.com/mandelsoft/filepath/pkg/filepath" - "k8s.io/cli-runtime/pkg/genericclioptions" - "github.com/open-component-model/ocm/pkg/out" ) @@ -54,18 +51,12 @@ func (o *Command) createRegistryCertificate() error { return fmt.Errorf("failed to write issuer.yaml file at location: %w", err) } - kubeconfigArgs := genericclioptions.NewConfigFlags(false) - sm, err := NewResourceManager(kubeconfigArgs) - if err != nil { - return fmt.Errorf("failed to create resource manager: %w", err) - } - objects, err := readObjects(path) if err != nil { return fmt.Errorf("failed to construct objects to apply: %w", err) } - if _, err := sm.ApplyAllStaged(context.Background(), objects, ssa.DefaultApplyOptions()); err != nil { + if _, err := o.SM.ApplyAllStaged(context.Background(), objects, ssa.DefaultApplyOptions()); err != nil { return fmt.Errorf("failed to apply manifests: %w", err) }