feat: rollout

This commit is contained in:
2025-10-21 21:02:28 +02:00
parent 9435af0137
commit 9c86e215fe
5 changed files with 883 additions and 7 deletions

View File

@@ -273,6 +273,46 @@ func (c *SporeClient) UpdateFirmware(firmwareData []byte, filename string) (*Fir
return &updateResponse, nil
}
// UpdateNodeLabels updates the labels on a SPORE node
func (c *SporeClient) UpdateNodeLabels(labels map[string]string) error {
targetURL := fmt.Sprintf("%s/api/node/config", c.BaseURL)
// Convert labels to JSON
labelsJSON, err := json.Marshal(labels)
if err != nil {
return fmt.Errorf("failed to marshal labels: %w", err)
}
// Create form data
data := url.Values{}
data.Set("labels", string(labelsJSON))
req, err := http.NewRequest("POST", targetURL, strings.NewReader(data.Encode()))
if err != nil {
return fmt.Errorf("failed to create labels update request: %w", err)
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := c.HTTPClient.Do(req)
if err != nil {
return fmt.Errorf("failed to update node labels: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
return fmt.Errorf("node labels update failed with status %d: %s", resp.StatusCode, string(body))
}
log.WithFields(log.Fields{
"node_ip": c.BaseURL,
"labels": labels,
}).Info("Node labels updated successfully")
return nil
}
// ProxyCall makes a generic HTTP request to a SPORE node endpoint
func (c *SporeClient) ProxyCall(method, uri string, params map[string]interface{}) (*http.Response, error) {
// Build target URL