diff --git a/cli/cmd/prepare.go b/cli/cmd/prepare.go index c7de6e131b..d614c182af 100644 --- a/cli/cmd/prepare.go +++ b/cli/cmd/prepare.go @@ -44,6 +44,7 @@ var prepareTransformGitLinks = &cobra.Command{ // Overwrite the file err = ioutil.WriteFile(fileName, []byte(processedText), 0640) if err != nil { + log.Logger.Debug(err) log.Logger.Fatal("Unable to write the changes back to the file") } } @@ -59,6 +60,7 @@ var prepareComputeFileSha256sum = &cobra.Command{ fileName := args[0] hash, err := utils.GetSha256Sum(fileName) if err != nil { + log.Logger.Debug(err) log.Logger.Fatal("Unable to compute the hash") } else { fmt.Println(hash) diff --git a/cli/config/config.go b/cli/config/config.go index cf7aa46bd2..d66531ce0a 100644 --- a/cli/config/config.go +++ b/cli/config/config.go @@ -54,11 +54,13 @@ func Load(path string) { file, err := ioutil.ReadFile(path) if err != nil { + logContext.Debug(err) logContext.Fatal("Unable to load the config file") } err = yaml.Unmarshal(file, &config) if err != nil { + logContext.Debug(err) logContext.Fatal("Unable to parse the config file") } } @@ -88,11 +90,13 @@ func WriteConfig(path string) { // Save the parsed output to the config path given content, err := yaml.Marshal(config) if err != nil { + logContext.Debug(err) logContext.Fatal("Unable to process the config data") } err = ioutil.WriteFile(path, content, 0400) if err != nil { + logContext.Debug(err) logContext.Fatal("Unable to write the config file") } } diff --git a/cli/internal/git/checkout.go b/cli/internal/git/checkout.go index 222b80e892..ed865c37a8 100644 --- a/cli/internal/git/checkout.go +++ b/cli/internal/git/checkout.go @@ -17,6 +17,7 @@ func CheckoutTag(path string, tag string) { // Open the given repo repo, err := git.PlainOpen(path) if err != nil { + logContext.Debug(err) logContext.Fatal("Not a valid git repo or unable to open") return } @@ -24,6 +25,7 @@ func CheckoutTag(path string, tag string) { // Get the working tree so we can change refs tree, err := repo.Worktree() if err != nil { + logContext.Debug(err) logContext.Fatal("Unable to load the git repo") } @@ -32,6 +34,7 @@ func CheckoutTag(path string, tag string) { Branch: plumbing.ReferenceName("refs/tags/" + tag), }) if err != nil { + logContext.Debug(err) logContext.Fatal("Unable to checkout the given tag") } } diff --git a/cli/internal/git/pull.go b/cli/internal/git/pull.go index e08b31135c..6afed6883a 100644 --- a/cli/internal/git/pull.go +++ b/cli/internal/git/pull.go @@ -47,6 +47,7 @@ func pull(gitUrl string, targetFolder string) { if err == git.ErrRepositoryAlreadyExists { logContext.Info("Repo already cloned") } else if err != nil { + logContext.Debug(err) logContext.Fatal("Not a valid git repo or unable to clone") } diff --git a/cli/internal/git/utils.go b/cli/internal/git/utils.go index 6aae75e08e..2e65ff0cd3 100644 --- a/cli/internal/git/utils.go +++ b/cli/internal/git/utils.go @@ -122,6 +122,7 @@ func CredentialsGenerator() string { credentialsFile, err := os.OpenFile(credentialsPath, os.O_CREATE|os.O_WRONLY, 0600) if err != nil { + log.Logger.Debug(err) log.Logger.Fatal("Unable to access the git credentials file") } defer credentialsFile.Close() @@ -138,12 +139,14 @@ func CredentialsGenerator() string { // Write the entry to the file _, err = credentialsFile.WriteString(credentialsText) if err != nil { + log.Logger.Debug(err) log.Logger.Fatal("Unable to update the git credentials file") } // Save the change err = credentialsFile.Sync() if err != nil { + log.Logger.Debug(err) log.Logger.Fatal("Unable to update the git credentials file") } diff --git a/cli/internal/helm/charts.go b/cli/internal/helm/charts.go index 2224e256c9..935251919a 100644 --- a/cli/internal/helm/charts.go +++ b/cli/internal/helm/charts.go @@ -67,12 +67,14 @@ func DownloadPublishedChart(chart config.ZarfChart, destination string) { // Perform simple chart download chartURL, err := repo.FindChartInRepoURL(chart.Url, chart.Name, chart.Version, pull.CertFile, pull.KeyFile, pull.CaFile, getter.All(pull.Settings)) if err != nil { + logContext.Debug(err) logContext.Fatal("Unable to pull the helm chart") } // Download the file (we don't control what name helm creates here) saved, _, err := downloader.DownloadTo(chartURL, pull.Version, destination) if err != nil { + logContext.Debug(err) logContext.Fatal("Unable to download the helm chart") } diff --git a/cli/internal/images/pull.go b/cli/internal/images/pull.go index d2da3cc30c..e724fc7216 100644 --- a/cli/internal/images/pull.go +++ b/cli/internal/images/pull.go @@ -27,6 +27,7 @@ func PullAll(buildImageList []string, imageTarballPath string) { log.Logger.Info("Creating image tarball (this will take a while)") if err := crane.MultiSave(imageMap, imageTarballPath); err != nil { + log.Logger.Debug(err) log.Logger.Fatal("Unable to save the tarball") } } diff --git a/cli/internal/images/push.go b/cli/internal/images/push.go index 9811ed6d96..17c638c247 100644 --- a/cli/internal/images/push.go +++ b/cli/internal/images/push.go @@ -19,12 +19,14 @@ func PushAll(imageTarballPath string, buildImageList []string) { logContext.Info("Updating image") img, err := crane.LoadTag(imageTarballPath, src, cranePlatformOptions) if err != nil { + logContext.Debug(err) logContext.Warn("Unable to load the image from the update package") return } onlineName, err := docker.ParseNormalizedNamed(src) if err != nil { + logContext.Debug(err) logContext.Warn("Unable to parse the image domain") return } @@ -33,6 +35,7 @@ func PushAll(imageTarballPath string, buildImageList []string) { log.Logger.Info(offlineName) err = crane.Push(img, offlineName, cranePlatformOptions) if err != nil { + logContext.Debug(err) logContext.Warn("Unable to push the image to the registry") } } diff --git a/cli/internal/k3s/install.go b/cli/internal/k3s/install.go index 272ca22e5f..76f677eab7 100644 --- a/cli/internal/k3s/install.go +++ b/cli/internal/k3s/install.go @@ -52,6 +52,7 @@ func createK3sSymlinks() { // Make the k3s kubeconfig available to other standard K8s tools that bind to the default ~/.kube/config err := utils.CreateDirectory("/root/.kube", 0700) if err != nil { + log.Logger.Debug(err) log.Logger.Warn("Unable to create the root kube config directory") } else { // Dont log an error for now since re-runs throw an invalid error @@ -71,11 +72,13 @@ func createService() { _, err := utils.ExecCommand(nil, "systemctl", "daemon-reload") if err != nil { + log.Logger.Debug(err) log.Logger.Warn("Unable to reload systemd") } _, err = utils.ExecCommand(nil, "systemctl", "enable", "--now", "k3s") if err != nil { + log.Logger.Debug(err) log.Logger.Warn("Unable to enable or start k3s via systemd") } } diff --git a/cli/internal/k3s/rhel.go b/cli/internal/k3s/rhel.go index 167dc4bcad..6837245607 100644 --- a/cli/internal/k3s/rhel.go +++ b/cli/internal/k3s/rhel.go @@ -9,6 +9,7 @@ func configureRHEL() { // @todo: k3s docs recommend disabling this, but we should look at just tuning it appropriately _, err := utils.ExecCommand(nil, "systemctl", "disable", "firewalld", "--now") if err != nil { + log.Logger.Debug(err) log.Logger.Warn("Unable to disable the firewall") } } diff --git a/cli/internal/k8s/common.go b/cli/internal/k8s/common.go index 59059577e8..2cfd3317d0 100644 --- a/cli/internal/k8s/common.go +++ b/cli/internal/k8s/common.go @@ -31,6 +31,7 @@ func connect() *kubernetes.Clientset { func readFile(file string) ([]byte, error) { b, err := ioutil.ReadFile(file) if err != nil { + log.Logger.Debug(err) return []byte{}, fmt.Errorf("cannot read file %v, %v", file, err) } return b, nil diff --git a/cli/internal/k8s/secrets.go b/cli/internal/k8s/secrets.go index 4033ffd091..cf61b352fc 100644 --- a/cli/internal/k8s/secrets.go +++ b/cli/internal/k8s/secrets.go @@ -25,18 +25,22 @@ func ReplaceTLSSecret(namespace string, name string, certPath string, keyPath st err := namespaceSecrets.Delete(context.TODO(), name, metav1.DeleteOptions{}) if err != nil && !errors.IsNotFound(err) { + logContext.Debug(err) logContext.Warn("Error deleting the secret") } tlsCert, err := readFile(certPath) if err != nil { + logContext.Debug(err) logContext.Fatal("Unable to read the TLS public certificate") } tlsKey, err := readFile(keyPath) if err != nil { + logContext.Debug(err) logContext.Fatal("Unable to read the TLS private key") } if _, err := tls.X509KeyPair(tlsCert, tlsKey); err != nil { + logContext.Debug(err) logContext.Fatal("Unable to create the TLS keypair") } @@ -58,6 +62,7 @@ func ReplaceTLSSecret(namespace string, name string, certPath string, keyPath st _, err = namespaceSecrets.Create(context.TODO(), secretTLS, metav1.CreateOptions{}) if err != nil { + logContext.Debug(err) logContext.Fatal("Unable to create the secret", err) } } diff --git a/cli/internal/packager/create.go b/cli/internal/packager/create.go index af9bfeea5d..625ee381ee 100644 --- a/cli/internal/packager/create.go +++ b/cli/internal/packager/create.go @@ -57,6 +57,7 @@ func Create(confirm bool) { _ = os.RemoveAll(packageName) err := archiver.Archive([]string{tempPath.base + "/"}, packageName) if err != nil { + log.Logger.Debug(err) log.Logger.Fatal("Unable to create the package archive") } diff --git a/cli/internal/packager/deploy.go b/cli/internal/packager/deploy.go index 73031de51f..2c4c4580a0 100644 --- a/cli/internal/packager/deploy.go +++ b/cli/internal/packager/deploy.go @@ -31,6 +31,7 @@ func Deploy(packageName string, confirm bool, componentRequest string) { // Extract the archive err := archiver.Unarchive(packageName, tempPath.base) if err != nil { + log.Logger.Debug(err) log.Logger.Fatal("Unable to extract the package contents") } @@ -124,6 +125,7 @@ func deployComponents(tempPath componentPaths, assets config.ZarfComponent) { } err := copy.Copy(sourceFile, file.Target) if err != nil { + log.Logger.Debug(err) log.Logger.WithField("file", file.Target).Fatal("Unable to copy the contents of the asset") } // Cleanup now to reduce disk pressure diff --git a/cli/internal/utils/io.go b/cli/internal/utils/io.go index c1894c34b6..17ac05552f 100644 --- a/cli/internal/utils/io.go +++ b/cli/internal/utils/io.go @@ -21,6 +21,7 @@ func MakeTempDir() string { logContext.Info("Creating temp path") if err != nil { + logContext.Debug(err) logContext.Fatal("Unable to create temp directory") } return tmp @@ -51,6 +52,7 @@ func ListDirectories(directory string) []string { var directories []string paths, err := os.ReadDir(directory) if err != nil { + log.Logger.Debug(err) log.Logger.WithField("path", directory).Fatal("Unable to load the directory") } @@ -69,17 +71,20 @@ func WriteFile(path string, data []byte) { f, err := os.Create(path) if err != nil { + logContext.Debug(err) logContext.Fatal("Unable to create the file to write the contents") } _, err = f.Write(data) if err != nil { - logContext.Fatal("Unable to write the file contents") _ = f.Close() + logContext.Debug(err) + logContext.Fatal("Unable to write the file contents") } err = f.Close() if err != nil { + logContext.Debug(err) logContext.Fatal("Error saving file") } @@ -89,12 +94,14 @@ func ReplaceText(path string, old string, new string) { logContext := log.Logger.WithField("path", path) input, err := ioutil.ReadFile(path) if err != nil { + logContext.Debug(err) logContext.Fatal("Unable to load the given file") } output := bytes.Replace(input, []byte(old), []byte(new), -1) if err = ioutil.WriteFile(path, output, 0600); err != nil { + logContext.Debug(err) logContext.Fatal("Unable to update the given file") } } @@ -114,6 +121,7 @@ func RecursiveFileList(root string) []string { }) if err != nil { + log.Logger.Debug(err) log.Logger.WithField("path", root).Fatal("Unable to complete directory walking") } @@ -124,6 +132,7 @@ func CreateFilePath(destination string) { parentDest := path.Dir(destination) err := CreateDirectory(parentDest, 0700) if err != nil { + log.Logger.Debug(err) log.Logger.WithField("path", parentDest).Fatal("Unable to create the destination path") } } @@ -141,6 +150,7 @@ func CreatePathAndCopy(source string, destination string) { // Copy the asset err := copy.Copy(source, destination) if err != nil { + logContext.Debug(err) logContext.Fatal("Unable to copy the contents of the asset") } } diff --git a/cli/internal/utils/network.go b/cli/internal/utils/network.go index 5e6ba0e588..197e948240 100644 --- a/cli/internal/utils/network.go +++ b/cli/internal/utils/network.go @@ -63,6 +63,7 @@ func DownloadToFile(url string, target string) { // Create the file destinationFile, err := os.Create(target) if err != nil { + logContext.Debug(err) logContext.Fatal("Unable to create the destination file") } defer destinationFile.Close() @@ -70,6 +71,7 @@ func DownloadToFile(url string, target string) { // Get the data resp, err := http.Get(url) if err != nil { + logContext.Debug(err) logContext.Fatal("Unable to download the file", err) } defer resp.Body.Close() @@ -82,6 +84,7 @@ func DownloadToFile(url string, target string) { // Writer the body to file _, err = io.Copy(destinationFile, resp.Body) if err != nil { + logContext.Debug(err) logContext.Fatal("Unable to save the file", err) } } diff --git a/cli/internal/utils/pki.go b/cli/internal/utils/pki.go index 146cd343c0..69adb91673 100644 --- a/cli/internal/utils/pki.go +++ b/cli/internal/utils/pki.go @@ -42,6 +42,7 @@ func RandomString(length int) string { bytes := make([]byte, length) if _, err := rand.Read(bytes); err != nil { + log.Logger.Debug(err) log.Logger.Fatal("unable to generate a random secret") } @@ -112,12 +113,14 @@ func addCAToTrustStore(caFilePath string) { CreatePathAndCopy(caFilePath, "/etc/pki/ca-trust/source/anchors/zarf-ca.crt") _, err := ExecCommand(nil, rhelBinary, "extract") if err != nil { + log.Logger.Debug(err) log.Logger.Warn("Error adding the ephemeral CA to the RHEL root trust") } } else if VerifyBinary(debianBinary) { CreatePathAndCopy(caFilePath, "/usr/local/share/ca-certificates/extra/zarf-ca.crt") _, err := ExecCommand(nil, debianBinary) if err != nil { + log.Logger.Debug(err) log.Logger.Warn("Error adding the ephemeral CA to the trust store") } }