Skip to content

Commit

Permalink
debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Elbehery committed Oct 10, 2024
1 parent 414da71 commit 3b86c6a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/cmd/backuprestore/backupserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type backupRunner interface {
type backupRunnerImpl struct{}

func (b backupRunnerImpl) runBackup(backupOpts *backupOptions, pruneOpts *prune.PruneOpts) error {
klog.Infof("@Mustafa: being runBackup() - backupOpts are [%v] - pruneOpts are [%v] ", backupOpts, pruneOpts)
dateString := time.Now().Format("2006-01-02_150405")
backupOpts.backupDir = path.Join(backupVolume, dateString)
err := backup(backupOpts)
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/backuprestore/backuputils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var backupResourcePodList = []string{
}

func archiveLatestResources(configDir, backupFile string) error {
klog.Infof("@Mustafa: being archiveLatestResources() - configDir are [%v] - backupFile are [%v]", configDir, backupFile)
klog.Info("Static Pod Resources are being stored in: ", backupFile)

paths := []string{}
Expand All @@ -38,6 +39,7 @@ func archiveLatestResources(configDir, backupFile string) error {
}

func backup(r *backupOptions) error {
klog.Infof("@Mustafa: being backup() - backupOpts are [%v] - endpoints are [%v]", r, r.endpoints)
cli, err := getEtcdClient(r.endpoints)
if err != nil {
return fmt.Errorf("backup: failed to get etcd client: %w", err)
Expand Down
8 changes: 8 additions & 0 deletions pkg/cmd/backuprestore/etcdclientutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@ import (
)

func getEtcdClient(endpoints []string) (*clientv3.Client, error) {
klog.Infof("@Mustafa: being getEtcdClient() - endpoints are [%v]", endpoints)
grpclog.SetLoggerV2(grpclog.NewLoggerV2(ioutil.Discard, ioutil.Discard, os.Stderr))
dialOptions := []grpc.DialOption{
grpc.WithBlock(), // block until the underlying connection is up
}

klog.Infof("@Mustafa: before tlsInfo in getEtcdClient()")
tlsInfo := transport.TLSInfo{
CertFile: os.Getenv("ETCDCTL_CERT"),
KeyFile: os.Getenv("ETCDCTL_KEY"),
TrustedCAFile: os.Getenv("ETCDCTL_CACERT"),
}
tlsConfig, err := tlsInfo.ClientConfig()
if err != nil {
klog.Infof("@Mustafa: before tlsInfo in getEtcdClient() - tlsConfig are [%v]", tlsConfig)
klog.Infof("@Mustafa: before tlsInfo in getEtcdClient() - err is [%v]", err)
return nil, fmt.Errorf("failed to generate tls client config endpoints %v and env %v: %w", endpoints, os.Environ(), err)
}

Expand All @@ -38,14 +42,18 @@ func getEtcdClient(endpoints []string) (*clientv3.Client, error) {
TLS: tlsConfig,
}

klog.Infof("@Mustafa: after tlsInfo in getEtcdClient()")
cli, err := clientv3.New(*cfg)
if err != nil {
klog.Infof("@Mustafa: after tlsInfo in getEtcdClient() - cli are [%v]", cli)
klog.Infof("@Mustafa: after tlsInfo in getEtcdClient() - err is [%v]", err)
return nil, fmt.Errorf("failed to make etcd client for endpoints %v and env %v: %w", endpoints, os.Environ(), err)
}
return cli, nil
}

func saveSnapshot(cli *clientv3.Client, dbPath string) error {
klog.Infof("@Mustafa: being saveSnapshot() - cli are [%v] - dbPath are [%v]", cli, dbPath)
partpath := dbPath + ".part"
defer os.RemoveAll(partpath)

Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/backuprestore/fileioutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"io/ioutil"
"k8s.io/klog/v2"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -71,12 +72,15 @@ func findTheLatestRevision(dir, filePrefix string, isDir bool) (string, error) {
}

func checkAndCreateDir(dirName string) error {
klog.Infof("@Mustafa: being checkAndCreateDir() - dirName are [%v]", dirName)
_, err := os.Stat(dirName)
if err != nil && !os.IsNotExist(err) {
klog.Infof("@Mustafa: being checkAndCreateDir() - err are [%v]", err)
return fmt.Errorf("checkAndCreateDir failed: %w", err)
}
// If dirName already exists, remove it
if err == nil {
klog.Infof("@Mustafa: being checkAndCreateDir() - err are [%v]", err)
if err := os.RemoveAll(dirName); err != nil {
return fmt.Errorf("checkAndCreateDir failed to remove %s: %w", dirName, err)
}
Expand Down

0 comments on commit 3b86c6a

Please sign in to comment.