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

[release-v3.28] Manual pick #8827: Improve cni-plugin binary install verification #8844

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions cni-plugin/pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func Install(version string) error {
// Place the new binaries if the directory is writeable.
dirs := []string{winutils.GetHostPath("/host/opt/cni/bin"), winutils.GetHostPath("/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 @@ -215,24 +216,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(containerBinDir+"/"+calicoBinaryName, d+"/"+calicoBinaryName)
if err != nil {
logrus.WithError(err).Warnf("Failed verifying installed binary, exiting")
return err
}
// Print version number successful
// Print version number if it was successfully installed
if calicoBinaryOK {
logrus.Infof("CNI plugin version: %s", version)
}
Expand Down