Skip to content

Commit

Permalink
Merge pull request #8842 from ialidzhikov/release-v3.26-cherry-pick-8827
Browse files Browse the repository at this point in the history
[release-v3.26] Manual pick #8827: Improve cni-plugin binary install verification
  • Loading branch information
marvin-tigera authored May 21, 2024
2 parents de7a20f + 7e0ec18 commit 869a515
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions cni-plugin/pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"
"io"
"os"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -182,6 +181,7 @@ func Install(version string) error {
// Place the new binaries if the directory is writeable.
dirs := []string{"/host/opt/cni/bin", "/host/secondary-bin-dir"}
binsWritten := false
calicoBinaryOK := false
for _, d := range dirs {
if err := fileutil.IsDirWriteable(d); err != nil {
logrus.Infof("%s is not writeable, skipping", d)
Expand Down Expand Up @@ -211,24 +211,23 @@ func Install(version string) error {
logrus.WithError(err).Errorf("Failed to install %s", target)
os.Exit(1)
}
// Verify if the binary was installed successfully, exit (to retry) otherwise
binaryOK, err := destinationUptoDate(source, target)
if err != nil || !binaryOK {
logrus.WithError(err).Errorf("Failed to verify installed binary %s", target)
os.Exit(1)
}
if binary.Name() == "calico" || binary.Name() == "calico.exe" {
calicoBinaryOK = true
}
logrus.Infof("Installed %s", target)
}

// Binaries were placed into at least one directory
logrus.Infof("Wrote Calico CNI binaries to %s\n", d)
binsWritten = true

// Instead of executing 'calico -v', check if the calico binary was copied successfully
calicoBinaryName := "calico"
if runtime.GOOS == "windows" {
calicoBinaryName = "calico.exe"
}
calicoBinaryOK, err := destinationUptoDate("/opt/cni/bin/"+calicoBinaryName, d+"/"+calicoBinaryName)
if err != nil {
logrus.WithError(err).Warnf("Failed verifying installed binary, exiting")
return err
}
// Print version number if successful
// Print version number if it was successfully installed
if calicoBinaryOK {
logrus.Infof("CNI plugin version: %s", version)
}
Expand Down

0 comments on commit 869a515

Please sign in to comment.