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

Add warning messages to magefile for version mismatches in beats #3580

Merged
16 changes: 13 additions & 3 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -979,10 +979,10 @@ func packageAgent(platforms []string, packagingFn func()) {
panic(err)
}

packagesMissing := false
packagesCopied := 0

if !requiredPackagesPresent(pwd, b, packageVersion, requiredPackages) {
fmt.Printf("--- Package %s\n", pwd)
cmd := exec.Command("mage", "package")
cmd.Dir = pwd
cmd.Stdout = os.Stdout
Expand All @@ -1008,6 +1008,15 @@ func packageAgent(platforms []string, packagingFn func()) {
targetPath := filepath.Join(archivePath, rp)
os.MkdirAll(targetPath, 0755)
for _, f := range files {
// safety check; if the user has an older version of the beats repo,
// for example right after a relase where you've `git pulled` from on repo and not the other,
fearful-symmetry marked this conversation as resolved.
Show resolved Hide resolved
// they might end up with a mishmash of packages from different versions.
// check to see if we have mismatched versions.
if !strings.Contains(f, packageVersion) {
// if this panic hits weird edge cases where we don't want actual failures, revert to a printf statement.
panic(fmt.Sprintf("the file %s doesn't match agent version %s, beats might be out of date", f, packageVersion))
fearful-symmetry marked this conversation as resolved.
Show resolved Hide resolved
}

targetFile := filepath.Join(targetPath, filepath.Base(f))
packagesCopied += 1
if err := sh.Copy(targetFile, f); err != nil {
Expand All @@ -1017,8 +1026,8 @@ func packageAgent(platforms []string, packagingFn func()) {
}
// a very basic footcannon protector; if packages are missing and we need to rebuild them, check to see if those files were copied
// if we needed to repackage beats but still somehow copied nothing, could indicate an issue. Usually due to beats and agent being at different versions.
if packagesMissing && packagesCopied == 0 {
fmt.Printf(">>> WARNING: no packages were copied, but we repackaged beats anyway. Check binary to see if intended beats are there.")
if packagesCopied == 0 {
fmt.Printf(">>> WARNING: no packages were copied, but we repackaged beats anyway. Check binary to see if intended beats are there.\n")
fearful-symmetry marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down Expand Up @@ -1153,6 +1162,7 @@ func copyComponentSpecs(componentName, versionedDropPath string) (string, error)
targetPath := filepath.Join(versionedDropPath, specFileName)

if _, err := os.Stat(targetPath); err != nil {
fmt.Printf(">> File %s does not exist, reverting to local specfile\n", targetPath)
// spec not present copy from local
sourceSpecFile := filepath.Join("specs", specFileName)
if mg.Verbose() {
Expand Down
Loading