-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
command to check dataplane api (#63)
Signed-off-by: Matt Siwiec <[email protected]>
- Loading branch information
Showing
5 changed files
with
107 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"go.infratographer.com/x/viperx" | ||
|
||
"go.infratographer.com/loadbalancer-manager-haproxy/internal/dataplaneapi" | ||
) | ||
|
||
// checkDataplaneCmd checks the connection to the dataplaneapi | ||
var checkDataplaneCmd = &cobra.Command{ | ||
Use: "check_dataplane", | ||
Short: "checks the connection to the dataplaneapi", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return checkDataPlane(cmd.Context(), viper.GetViper()) | ||
}, | ||
} | ||
|
||
const ( | ||
defaultRetryLimit = 3 | ||
defaultRetryInterval = 1 * time.Second | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(checkDataplaneCmd) | ||
|
||
checkDataplaneCmd.PersistentFlags().String("dataplane-user-name", "haproxy", "DataplaneAPI user name") | ||
viperx.MustBindFlag(viper.GetViper(), "dataplane.user.name", checkDataplaneCmd.PersistentFlags().Lookup("dataplane-user-name")) | ||
|
||
checkDataplaneCmd.PersistentFlags().String("dataplane-user-pwd", "adminpwd", "DataplaneAPI user password") | ||
viperx.MustBindFlag(viper.GetViper(), "dataplane.user.pwd", checkDataplaneCmd.PersistentFlags().Lookup("dataplane-user-pwd")) | ||
|
||
checkDataplaneCmd.PersistentFlags().String("dataplane-url", "http://127.0.0.1:5555/v2/", "DataplaneAPI base url") | ||
viperx.MustBindFlag(viper.GetViper(), "dataplane.url", checkDataplaneCmd.PersistentFlags().Lookup("dataplane-url")) | ||
|
||
checkDataplaneCmd.PersistentFlags().Int("retries", defaultRetryLimit, "Number of attempts to verify connection to DataplaneAPI") | ||
viperx.MustBindFlag(viper.GetViper(), "retries", checkDataplaneCmd.PersistentFlags().Lookup("retries")) | ||
|
||
checkDataplaneCmd.PersistentFlags().Duration("retry-interval", defaultRetryInterval, "Interval between checks") | ||
viperx.MustBindFlag(viper.GetViper(), "retry-interval", checkDataplaneCmd.PersistentFlags().Lookup("retry-interval")) | ||
} | ||
|
||
func checkDataPlane(ctx context.Context, viper *viper.Viper) error { | ||
client := dataplaneapi.NewClient(viper.GetString("dataplane.url")) | ||
|
||
if err := client.WaitForDataPlaneReady( | ||
ctx, | ||
viper.GetInt("retries"), | ||
viper.GetDuration("retry-interval"), | ||
); err != nil { | ||
logger.Fatalw("dataplane api is not ready", "error", 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
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