Skip to content

Commit

Permalink
feat: add silent flag and fix dry run with prerequisites (#767)
Browse files Browse the repository at this point in the history
## Description

Closes open-component-model/ocm-project#37


## What type of PR is this? (check all applicable)

- [ ] 🍕 Feature
- [ ] 🎇 Restructuring
- [ ] 🐛 Bug Fix
- [ ] 📝 Documentation Update
- [ ] 🎨 Style
- [ ] 🧑‍💻 Code Refactor
- [ ] 🔥 Performance Improvements
- [ ] ✅ Test
- [ ] 🤖 Build
- [ ] 🔁 CI
- [ ] 📦 Chore (Release)
- [ ] ⏩ Revert

## Related Tickets & Documents

<!-- 
Please use this format link issue numbers: Fixes #123

https://docs.github.com/en/free-pro-team@latest/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword
-->
- Related Issue # (issue)
- Closes # (issue)
- Fixes # (issue)
> Remove if not applicable

## Screenshots

<!-- Visual changes require 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

Co-authored-by: Hilmar Falkenberg <hilmar.falkenberg@sap.com>
  • Loading branch information
Skarlso and hilmarf authored May 8, 2024
1 parent b44a489 commit 850b785
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmds/ocm/commands/controllercmds/common/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func fetchObjects(ctx context.Context, octx clictx.Context, releaseURL, baseURL,
}

out.Outf(octx, string(content))

return nil, nil
}
out.Outf(octx, "► applying to cluster...\n")
Expand Down
11 changes: 10 additions & 1 deletion cmds/ocm/commands/controllercmds/install/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Command struct {
DryRun bool
SkipPreFlightCheck bool
InstallPrerequisites bool
Silent bool
SM *ssa.ResourceManager
}

Expand Down Expand Up @@ -71,13 +72,21 @@ func (o *Command) AddFlags(set *pflag.FlagSet) {
set.BoolVarP(&o.DryRun, "dry-run", "d", false, "if enabled, prints the downloaded manifest file")
set.BoolVarP(&o.SkipPreFlightCheck, "skip-pre-flight-check", "s", false, "skip the pre-flight check for clusters")
set.BoolVarP(&o.InstallPrerequisites, "install-prerequisites", "i", true, "install prerequisites required by ocm-controller")
set.BoolVarP(&o.Silent, "silent", "l", false, "don't fail on error")
}

func (o *Command) Complete(args []string) error {
return nil
}

func (o *Command) Run() error {
func (o *Command) Run() (err error) {
defer func() {
// don't return any errors
if o.Silent {
err = nil
}
}()

kubeconfigArgs := genericclioptions.NewConfigFlags(false)
sm, err := NewResourceManager(kubeconfigArgs)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func (o *Command) installPrerequisites(ctx context.Context) error {
}

out.Outf(o.Context, "✔ cert-manager successfully installed\n")

if o.DryRun {
return nil
}

out.Outf(o.Context, "► creating certificate for internal registry\n")

if err := o.createRegistryCertificate(); err != nil {
Expand Down
11 changes: 10 additions & 1 deletion cmds/ocm/commands/controllercmds/uninstall/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Command struct {
CertManagerVersion string
SM *ssa.ResourceManager
UninstallPrerequisites bool
Silent bool
DryRun bool
}

Expand Down Expand Up @@ -65,13 +66,21 @@ func (o *Command) AddFlags(set *pflag.FlagSet) {
set.DurationVarP(&o.Timeout, "timeout", "t", 1*time.Minute, "maximum time to wait for deployment to be ready")
set.BoolVarP(&o.UninstallPrerequisites, "uninstall-prerequisites", "p", false, "uninstall prerequisites required by ocm-controller")
set.BoolVarP(&o.DryRun, "dry-run", "d", false, "if enabled, prints the downloaded manifest file")
set.BoolVarP(&o.Silent, "silent", "l", false, "don't fail on error")
}

func (o *Command) Complete(args []string) error {
return nil
}

func (o *Command) Run() error {
func (o *Command) Run() (err error) {
defer func() {
// don't return any errors
if o.Silent {
err = nil
}
}()

kubeconfigArgs := genericclioptions.NewConfigFlags(false)
sm, err := NewResourceManager(kubeconfigArgs)
if err != nil {
Expand Down

0 comments on commit 850b785

Please sign in to comment.