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
|
output string
|
||||||
wait time.Duration
|
wait time.Duration
|
||||||
count int
|
count int
|
||||||
|
interval time.Duration
|
||||||
kubeconfig string
|
kubeconfig string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *ValidateClusterOptions) InitDefaults() {
|
func (o *ValidateClusterOptions) InitDefaults() {
|
||||||
o.output = OutputTable
|
o.output = OutputTable
|
||||||
|
o.interval = 10 * time.Second
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCmdValidateCluster(f *util.Factory, out io.Writer) *cobra.Command {
|
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().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().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")
|
cmd.Flags().StringVar(&options.kubeconfig, "kubeconfig", "", "Path to the kubeconfig file")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
@ -164,7 +167,6 @@ func RunValidateCluster(ctx context.Context, f *util.Factory, out io.Writer, opt
|
||||||
}
|
}
|
||||||
|
|
||||||
timeout := time.Now().Add(options.wait)
|
timeout := time.Now().Add(options.wait)
|
||||||
pollInterval := 10 * time.Second
|
|
||||||
|
|
||||||
validator, err := validation.NewClusterValidator(cluster, cloud, list, config.Host, k8sClient)
|
validator, err := validation.NewClusterValidator(cluster, cloud, list, config.Host, k8sClient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -182,7 +184,7 @@ func RunValidateCluster(ctx context.Context, f *util.Factory, out io.Writer, opt
|
||||||
consecutive = 0
|
consecutive = 0
|
||||||
if options.wait > 0 {
|
if options.wait > 0 {
|
||||||
klog.Warningf("(will retry): unexpected error during validation: %v", err)
|
klog.Warningf("(will retry): unexpected error during validation: %v", err)
|
||||||
time.Sleep(pollInterval)
|
time.Sleep(options.interval)
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("unexpected error during validation: %v", err)
|
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 {
|
if consecutive < options.count {
|
||||||
klog.Infof("(will retry): cluster passed validation %d consecutive times", consecutive)
|
klog.Infof("(will retry): cluster passed validation %d consecutive times", consecutive)
|
||||||
if options.wait > 0 {
|
if options.wait > 0 {
|
||||||
time.Sleep(pollInterval)
|
time.Sleep(options.interval)
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("cluster passed validation %d consecutive times", consecutive)
|
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 {
|
if options.wait > 0 {
|
||||||
klog.Warningf("(will retry): cluster not yet healthy")
|
klog.Warningf("(will retry): cluster not yet healthy")
|
||||||
consecutive = 0
|
consecutive = 0
|
||||||
time.Sleep(pollInterval)
|
time.Sleep(options.interval)
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("cluster not yet healthy")
|
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
|
--count int Number of consecutive successful validations required
|
||||||
-h, --help help for cluster
|
-h, --help help for cluster
|
||||||
|
--interval duration Time in duration to wait between validation attempts (default 10s)
|
||||||
--kubeconfig string Path to the kubeconfig file
|
--kubeconfig string Path to the kubeconfig file
|
||||||
-o, --output string Output format. One of json|yaml|table. (default "table")
|
-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
|
--wait duration Amount of time to wait for the cluster to become ready
|
||||||
|
|
|
@ -66,6 +66,8 @@ type deployer struct {
|
||||||
NodeIGOverrides []string `flag:"node-instance-group-overrides" desc:"overrides for the node 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"`
|
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
|
// New implements deployer.New for kops
|
||||||
func New(opts types.Options) (types.Deployer, *pflag.FlagSet) {
|
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{
|
d := &deployer{
|
||||||
commonOptions: opts,
|
commonOptions: opts,
|
||||||
BuildOptions: &builder.BuildOptions{
|
BuildOptions: &builder.BuildOptions{
|
||||||
BuildKubernetes: false,
|
BuildKubernetes: false,
|
||||||
},
|
},
|
||||||
boskosHeartbeatClose: make(chan struct{}),
|
boskosHeartbeatClose: make(chan struct{}),
|
||||||
|
ValidationCount: 10,
|
||||||
|
ValidationInterval: 10 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, err := defaultArtifactsDir()
|
dir, err := defaultArtifactsDir()
|
||||||
|
|
|
@ -163,7 +163,10 @@ func (d *deployer) dumpClusterInfo() error {
|
||||||
"leases",
|
"leases",
|
||||||
"persistentvolumeclaims",
|
"persistentvolumeclaims",
|
||||||
"poddisruptionbudgets",
|
"poddisruptionbudgets",
|
||||||
|
"podmonitors",
|
||||||
|
"statefulsets",
|
||||||
"serviceaccounts",
|
"serviceaccounts",
|
||||||
|
"servicemonitors",
|
||||||
"rolebindings",
|
"rolebindings",
|
||||||
"roles",
|
"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
|
return dumpErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
osexec "os/exec"
|
osexec "os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -290,7 +291,8 @@ func (d *deployer) IsUp() (bool, error) {
|
||||||
args := []string{
|
args := []string{
|
||||||
d.KopsBinaryPath, "validate", "cluster",
|
d.KopsBinaryPath, "validate", "cluster",
|
||||||
"--name", d.ClusterName,
|
"--name", d.ClusterName,
|
||||||
"--count", "10",
|
"--count", strconv.Itoa(d.ValidationCount),
|
||||||
|
"--interval", d.ValidationInterval.String(),
|
||||||
"--wait", wait.String(),
|
"--wait", wait.String(),
|
||||||
}
|
}
|
||||||
klog.Info(strings.Join(args, " "))
|
klog.Info(strings.Join(args, " "))
|
||||||
|
|
Loading…
Reference in New Issue