mirror of https://github.com/kubernetes/kops.git
add validation interval, cleanup 0 byte log files
This commit is contained in:
parent
40ec87b0f7
commit
3f17147571
|
@ -66,11 +66,13 @@ type ValidateClusterOptions struct {
|
|||
output string
|
||||
wait time.Duration
|
||||
count int
|
||||
interval time.Duration
|
||||
kubeconfig string
|
||||
}
|
||||
|
||||
func (o *ValidateClusterOptions) InitDefaults() {
|
||||
o.output = OutputTable
|
||||
o.interval = 10 * time.Second
|
||||
}
|
||||
|
||||
func NewCmdValidateCluster(f *util.Factory, out io.Writer) *cobra.Command {
|
||||
|
@ -105,6 +107,7 @@ func NewCmdValidateCluster(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
})
|
||||
cmd.Flags().DurationVar(&options.wait, "wait", options.wait, "Amount of time to wait for the cluster to become ready")
|
||||
cmd.Flags().IntVar(&options.count, "count", options.count, "Number of consecutive successful validations required")
|
||||
cmd.Flags().DurationVar(&options.interval, "interval", options.interval, "Time in duration to wait between validation attempts")
|
||||
cmd.Flags().StringVar(&options.kubeconfig, "kubeconfig", "", "Path to the kubeconfig file")
|
||||
|
||||
return cmd
|
||||
|
@ -164,7 +167,6 @@ func RunValidateCluster(ctx context.Context, f *util.Factory, out io.Writer, opt
|
|||
}
|
||||
|
||||
timeout := time.Now().Add(options.wait)
|
||||
pollInterval := 10 * time.Second
|
||||
|
||||
validator, err := validation.NewClusterValidator(cluster, cloud, list, config.Host, k8sClient)
|
||||
if err != nil {
|
||||
|
@ -182,7 +184,7 @@ func RunValidateCluster(ctx context.Context, f *util.Factory, out io.Writer, opt
|
|||
consecutive = 0
|
||||
if options.wait > 0 {
|
||||
klog.Warningf("(will retry): unexpected error during validation: %v", err)
|
||||
time.Sleep(pollInterval)
|
||||
time.Sleep(options.interval)
|
||||
continue
|
||||
} else {
|
||||
return nil, fmt.Errorf("unexpected error during validation: %v", err)
|
||||
|
@ -219,7 +221,7 @@ func RunValidateCluster(ctx context.Context, f *util.Factory, out io.Writer, opt
|
|||
if consecutive < options.count {
|
||||
klog.Infof("(will retry): cluster passed validation %d consecutive times", consecutive)
|
||||
if options.wait > 0 {
|
||||
time.Sleep(pollInterval)
|
||||
time.Sleep(options.interval)
|
||||
continue
|
||||
} else {
|
||||
return nil, fmt.Errorf("cluster passed validation %d consecutive times", consecutive)
|
||||
|
@ -231,7 +233,7 @@ func RunValidateCluster(ctx context.Context, f *util.Factory, out io.Writer, opt
|
|||
if options.wait > 0 {
|
||||
klog.Warningf("(will retry): cluster not yet healthy")
|
||||
consecutive = 0
|
||||
time.Sleep(pollInterval)
|
||||
time.Sleep(options.interval)
|
||||
continue
|
||||
} else {
|
||||
return nil, fmt.Errorf("cluster not yet healthy")
|
||||
|
|
|
@ -31,6 +31,7 @@ kops validate cluster [CLUSTER] [flags]
|
|||
```
|
||||
--count int Number of consecutive successful validations required
|
||||
-h, --help help for cluster
|
||||
--interval duration Time in duration to wait between validation attempts (default 10s)
|
||||
--kubeconfig string Path to the kubeconfig file
|
||||
-o, --output string Output format. One of json|yaml|table. (default "table")
|
||||
--wait duration Amount of time to wait for the cluster to become ready
|
||||
|
|
|
@ -65,7 +65,9 @@ type deployer struct {
|
|||
ControlPlaneIGOverrides []string `flag:"control-plane-instance-group-overrides" desc:"overrides for the control plane instance groups"`
|
||||
NodeIGOverrides []string `flag:"node-instance-group-overrides" desc:"overrides for the node instance groups"`
|
||||
|
||||
ValidationWait time.Duration `flag:"validation-wait" desc:"time to wait for newly created cluster to pass validation"`
|
||||
ValidationWait time.Duration `flag:"validation-wait" desc:"time to wait for newly created cluster to pass validation"`
|
||||
ValidationCount int `flag:"validation-count" desc:"how many times should a validation pass"`
|
||||
ValidationInterval time.Duration `flag:"validation-interval" desc:"time in duration to wait between validation attempts"`
|
||||
|
||||
TemplatePath string `flag:"template-path" desc:"The path to the manifest template used for cluster creation"`
|
||||
|
||||
|
@ -109,13 +111,15 @@ func (d *deployer) Provider() string {
|
|||
|
||||
// New implements deployer.New for kops
|
||||
func New(opts types.Options) (types.Deployer, *pflag.FlagSet) {
|
||||
// create a deployer object and set fields that are not flag controlled
|
||||
// create a deployer object and set fields that are not flag controlled, and default values
|
||||
d := &deployer{
|
||||
commonOptions: opts,
|
||||
BuildOptions: &builder.BuildOptions{
|
||||
BuildKubernetes: false,
|
||||
},
|
||||
boskosHeartbeatClose: make(chan struct{}),
|
||||
ValidationCount: 10,
|
||||
ValidationInterval: 10 * time.Second,
|
||||
}
|
||||
|
||||
dir, err := defaultArtifactsDir()
|
||||
|
|
|
@ -163,7 +163,10 @@ func (d *deployer) dumpClusterInfo() error {
|
|||
"leases",
|
||||
"persistentvolumeclaims",
|
||||
"poddisruptionbudgets",
|
||||
"podmonitors",
|
||||
"statefulsets",
|
||||
"serviceaccounts",
|
||||
"servicemonitors",
|
||||
"rolebindings",
|
||||
"roles",
|
||||
}
|
||||
|
@ -199,6 +202,11 @@ func (d *deployer) dumpClusterInfo() error {
|
|||
}
|
||||
}
|
||||
}
|
||||
// cleanup zero byte files
|
||||
cmd = exec.Command("find", d.ArtifactsDir, "-size", "0", "-print", "-delete", "-o")
|
||||
if err := cmd.Run(); err != nil {
|
||||
dumpErr = errors.Join(dumpErr, err)
|
||||
}
|
||||
return dumpErr
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"fmt"
|
||||
osexec "os/exec"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -290,7 +291,8 @@ func (d *deployer) IsUp() (bool, error) {
|
|||
args := []string{
|
||||
d.KopsBinaryPath, "validate", "cluster",
|
||||
"--name", d.ClusterName,
|
||||
"--count", "10",
|
||||
"--count", strconv.Itoa(d.ValidationCount),
|
||||
"--interval", d.ValidationInterval.String(),
|
||||
"--wait", wait.String(),
|
||||
}
|
||||
klog.Info(strings.Join(args, " "))
|
||||
|
|
Loading…
Reference in New Issue