Skip to content

Commit

Permalink
providers: Only check if the user-data / vendor-data has data inside …
Browse files Browse the repository at this point in the history
…of it instead of verifying that it contains valid JSON data.
  • Loading branch information
jdoss committed Feb 27, 2025
1 parent f60d7f9 commit 3ce4656
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions internal/providers/proxmoxve/proxmoxve.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package proxmoxve
import (
"bytes"
"context"
"encoding/json"
"fmt"
"os"
"os/exec"
Expand Down Expand Up @@ -130,34 +129,33 @@ func fetchConfigFromDevice(logger *log.Logger, ctx context.Context, path string)
header := []byte("#cloud-config\n")

for _, path := range paths {
fullPath := filepath.Join(mnt, path)
if !fileExists(fullPath) {
continue
}
fullPath := filepath.Join(mnt, path)
if !fileExists(fullPath) {
continue
}

contents, err := os.ReadFile(fullPath)
if err != nil {
// Log the error but continue to next file
logger.Debug("failed to read %q: %v", fullPath, err)
continue
}
contents, err := os.ReadFile(fullPath)
if err != nil {
// Log the error but continue to next file
logger.Debug("failed to read %q: %v", fullPath, err)
continue
}

// Skip if it's a cloud-config file
if bytes.HasPrefix(contents, header) {
logger.Debug("config drive (%q) contains a cloud-config configuration, ignoring", fullPath)
continue
}

// Try to validate if it's JSON
if json.Valid(contents) {
// Since paths are ordered with ciuserdataPath first,
// we'll automatically get the right precedence
// user-data should always be chosen over vendor-data
logger.Debug("config drive (%q) contains an ignition configuration", fullPath)
return contents, nil
}
// Skip if it's a cloud-config file
if bytes.HasPrefix(contents, header) {
logger.Debug("config drive (%q) contains a cloud-config configuration, ignoring", fullPath)
continue
}

// Check if there's actual content in the file
if len(contents) > 0 {
logger.Debug("config drive (%q) contains data", fullPath)
return contents, nil
}

logger.Debug("config drive (%q) is empty, ignoring", fullPath)
}

// No valid JSON found in any of the files
// No valid configuration found in any of the files
return nil, nil
}

0 comments on commit 3ce4656

Please sign in to comment.