-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OPCT-257: fix status cmd must not required clients to init command (#119
) The command initialization must have minimal to no external dependencies to create the command. Currently OPCT commands have been with some dependencies to initialize the `Run` command, which isn't the best practice. The #118 introduced a new external dependency requiring a live cluster when the cobra is creating and initializing the command (without triggering it), which isn't expected nor desired, as OPCT tool provides many capabilities to operate without access to O/K API, such as `report` command which is affected raising an error after #118: ~~~ $ opct-devel report --save-to res opct_202408131745_9dd0adf1-df49-44fd-ae32-9c2ace0946c9.tar.gz --log-level=debug ERRO[0000] error creating clients: error creating sonobuoy rest helper: could not get api group resources: Get "https://api.opct-base-05.devcluster.openshift.com:6443/api?timeout=32s": dial tcp: lookup api.opct-base-05.devcluster.openshift.com on 192.168.15.1:53: no such host error="error creating sonobuoy rest helper: could not get api group resources: Get \"https://api.opct-base-05.devcluster.openshift.com:6443/api?timeout=32s\": dial tcp: lookup api.opct-base-05.devcluster.openshift.com on 192.168.15.1:53: no such host" ~~~ The changes here creates declares the cmd Status as a var, declaring the `Run` as an external function.
- Loading branch information
Showing
8 changed files
with
204 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package status | ||
|
||
import ( | ||
"github.com/redhat-openshift-ecosystem/provider-certification-tool/pkg/wait" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// cmdStatusArgs is the struct to store the input arguments for the status command. | ||
type cmdInputStatus struct { | ||
Watch bool | ||
IntervalSeconds int | ||
} | ||
|
||
var cmdArgsStatus cmdInputStatus | ||
var cmdStatus = &cobra.Command{ | ||
Use: "status", | ||
Example: "opct status --watch", | ||
Short: "Show the current status of the validation tool", | ||
Long: ``, | ||
RunE: cmdStatusRun, | ||
} | ||
|
||
func init() { | ||
cmdStatus.PersistentFlags().BoolVarP(&cmdArgsStatus.Watch, "watch", "w", false, "Keep watch status after running") | ||
cmdStatus.Flags().IntVarP(&cmdArgsStatus.IntervalSeconds, "watch-interval", "", DefaultStatusIntervalSeconds, "Interval to watch the status and print in the stdout") | ||
} | ||
|
||
func NewCmdStatus() *cobra.Command { | ||
return cmdStatus | ||
} | ||
|
||
func cmdStatusRun(cmd *cobra.Command, args []string) error { | ||
o := NewStatus(&StatusInput{ | ||
Watch: cmdArgsStatus.Watch, | ||
IntervalSeconds: cmdArgsStatus.IntervalSeconds, | ||
}) | ||
// Pre-checks and setup | ||
if err := o.PreRunCheck(); err != nil { | ||
log.WithError(err).Error("error running pre-checks") | ||
return err | ||
} | ||
|
||
// Wait for Sonobuoy to create | ||
if err := wait.WaitForRequiredResources(o.kclient); err != nil { | ||
log.WithError(err).Error("error waiting for sonobuoy pods to become ready") | ||
return err | ||
} | ||
|
||
// Wait for Sononbuoy to start reporting status | ||
if err := o.WaitForStatusReport(cmd.Context()); err != nil { | ||
log.WithError(err).Error("error retrieving current aggregator status") | ||
return err | ||
} | ||
|
||
if err := o.Print(cmd); err != nil { | ||
log.WithError(err).Error("error printing status") | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.