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

Bug 1997347: pkg/cmd/verify: bug fixes and improvements #657

Merged
merged 5 commits into from
Sep 2, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion bindata/etcd/cluster-backup-pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ spec:
volumeMounts:
- mountPath: /etc/kubernetes/cluster-backup
name: etc-kubernetes-cluster-backup
- mountPath: /var/run/secrets/etcd-client
name: etcd-client
- mountPath: /var/run/configmaps/etcd-ca
name: etcd-ca
containers:
- name: cluster-backup
imagePullPolicy: IfNotPresent
Expand Down Expand Up @@ -73,4 +77,9 @@ spec:
- hostPath:
path: /etc/kubernetes/static-pod-resources/etcd-certs
name: cert-dir

- name: etcd-client
secret:
secretName: etcd-client
- name: etcd-ca
configMap:
name: etcd-ca-bundle
2 changes: 1 addition & 1 deletion cmd/cluster-etcd-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func NewSSCSCommand() *cobra.Command {
cmd.AddCommand(certsyncpod.NewCertSyncControllerCommand(operator.CertConfigMaps, operator.CertSecrets))
cmd.AddCommand(waitforceo.NewWaitForCeoCommand(os.Stderr))
cmd.AddCommand(monitor.NewMonitorCommand(os.Stderr))
cmd.AddCommand(verify.NewVerifyCommand())
cmd.AddCommand(verify.NewVerifyCommand(os.Stderr))

return cmd
}
26 changes: 18 additions & 8 deletions pkg/cmd/verify/backupstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package verify
import (
"context"
"fmt"
"io"
"os"
"os/signal"
"syscall"
Expand All @@ -23,8 +24,8 @@ import (
)

const (
defaultEndpoint = "https://127.0.0.1:2370"
defaultBackupPath = "/var/lib/cluster-backup"
defaultEndpoint = "https://localhost:2379"
defaultBackupPath = "/etc/kubernetes/cluster-backup"
defaultCertFilePath = "/var/run/secrets/etcd-client/tls.crt"
defaultKeyFilePath = "/var/run/secrets/etcd-client/tls.key"
defaultCaCertFilePath = "/var/run/configmaps/etcd-ca/ca-bundle.crt"
Expand All @@ -35,6 +36,8 @@ const (
)

type verifyBackupStorage struct {
errOut io.Writer

endpoints string
backupPath string
clientCertFile string
Expand All @@ -44,13 +47,20 @@ type verifyBackupStorage struct {

// NewVerifyBackupStorage perform checks against the local filesystem and compares the available storage bytes with the
// estimated size as reported by EndpointStatus.
func NewVerifyBackupStorage() *cobra.Command {
verifyBackupStorage := &verifyBackupStorage{}
func NewVerifyBackupStorage(errOut io.Writer) *cobra.Command {
verifyBackupStorage := &verifyBackupStorage{
errOut: errOut,
}
cmd := &cobra.Command{
Use: "backup-storage",
Short: "performs checks to ensure storage is adequate for backup state",
Run: func(cmd *cobra.Command, args []string) {
must := func(fn func(ctx context.Context) error) {}
must := func(fn func(ctx context.Context) error) {
if err := fn(context.Background()); err != nil {
fmt.Fprint(verifyBackupStorage.errOut, err.Error())
os.Exit(1)
}
}
must(verifyBackupStorage.Run)
},
}
Expand Down Expand Up @@ -139,10 +149,10 @@ func (v *verifyBackupStorage) isStorageAdequate(ctx context.Context) (bool, erro

requiredBytes := 2 * dbSizeBytes
if requiredBytes > fsAvailableBytes {
return false, fmt.Errorf("available storage is not adequate for path: %q, required bytes: %d, available bytes %d", v.backupPath, requiredBytes, fsAvailableBytes)
return false, fmt.Errorf("available storage is not adequate for path: %q, required bytes: %d, available bytes %d\n", v.backupPath, requiredBytes, fsAvailableBytes)
}

klog.Infof("Path %s, required storage bytes: %d, available %d", v.backupPath, requiredBytes, fsAvailableBytes)
klog.Infof("Path %s, required storage bytes: %d, available %d\n", v.backupPath, requiredBytes, fsAvailableBytes)
return true, nil
}

Expand Down Expand Up @@ -218,7 +228,7 @@ func getPathAvailableSpaceBytes(path string) (int64, error) {
return 0, fmt.Errorf("filesystem status: %w", err)
}

available := int64(stat.Bavail) * stat.Bsize
available := int64(stat.Bavail) * int64(stat.Bsize)
if available == 0 {
return 0, fmt.Errorf("filesystem status: no available bytes")
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/cmd/verify/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ import (
)

type verifyStorageOpts struct {
errOut io.Writer
kubeconfig string
errOut io.Writer
}

// NewVerifyCommand checks to verify preconditions and exit 0 on success.
func NewVerifyCommand() *cobra.Command {
func NewVerifyCommand(errOut io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "verify",
Short: "performs checks to verify preconditions and exit 0 on success",
Run: func(cmd *cobra.Command, args []string) {},
}
cmd.AddCommand(NewVerifyBackupStorage())
cmd.AddCommand(NewVerifyBackupStorage(errOut))
return cmd
}
11 changes: 10 additions & 1 deletion pkg/operator/etcd_assets/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.