Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add silent flag and fix dry run with prerequisites #767

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading