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

feat: Add Weave Trace image to wsm #28

Merged
merged 7 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
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
25 changes: 22 additions & 3 deletions cmd/wsm/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,25 @@ func DownloadCmd() *cobra.Command {
Run: func(cmd *cobra.Command, args []string) {
_ = os.RemoveAll("bundle")
// Fetch the latest tag for the controller
latestTag, err := getLatestWandbTag()
operatorTag, err := getMostRecentTag("wandb/controller")
if err != nil {
fmt.Printf("Error fetching the latest operator-wandb controller tag: %v\n", err)
os.Exit(1)
}
// Fetch the latest tag for weave-trace
weaveTraceTag, err := getMostRecentTag("wandb/weave-trace")
if err != nil {
fmt.Printf("Error fetching the latest weave-trace tag: %v\n", err)
os.Exit(1)
}
fmt.Println("Downloading operator helm chart")
operatorImgs, _ := downloadChartImages(
helm.WandbHelmRepoURL,
helm.WandbOperatorChart,
"", // empty version means latest
map[string]interface{}{
"image": map[string]interface{}{
"tag": latestTag,
"tag": operatorTag,
},
},
)
Expand All @@ -74,13 +80,26 @@ func DownloadCmd() *cobra.Command {
if err != nil {
panic(err)
}
// Create a copy of the spec to download additional images without writing changes to the filesystem
dlSpec, err := deployer.GetChannelSpec("")
if err != nil {
panic(err)
}

// Enable weave-trace in the chart values
dlSpec.Values["weave-trace"] = map[string]interface{}{
"install": true,
"image": map[string]interface{}{
"tag": weaveTraceTag,
},
}

fmt.Println("Downloading wandb helm chart")
wandbImgs, _ := downloadChartImages(
spec.Chart.URL,
spec.Chart.Name,
spec.Chart.Version,
spec.Values,
dlSpec.Values,
)

imgs := utils.RemoveDuplicates(append(wandbImgs, operatorImgs...))
Expand Down
49 changes: 31 additions & 18 deletions cmd/wsm/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"sort"

"github.com/Masterminds/semver/v3"
"github.com/charmbracelet/bubbles/spinner"
"github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
Expand Down Expand Up @@ -49,8 +50,8 @@ func (m model) View() string {
}

// Function to fetch the latest tag from Docker Hub API
func getLatestWandbTag() (string, error) {
url := "https://registry.hub.docker.com/v2/repositories/wandb/controller/tags/"
func getMostRecentTag(repository string) (string, error) {
url := fmt.Sprintf("https://registry.hub.docker.com/v2/repositories/%s/tags/", repository)
resp, err := http.Get(url)
if err != nil {
return "", fmt.Errorf("error fetching tags: %v", err)
Expand All @@ -70,25 +71,26 @@ func getLatestWandbTag() (string, error) {
}

// Extract tags and filter out "latest"
var tags []string
var tags []*semver.Version
if results, ok := result["results"].([]interface{}); ok {
for _, r := range results {
if tag, ok := r.(map[string]interface{})["name"].(string); ok && tag != "latest" {
tags = append(tags, tag)
version, err := semver.NewVersion(tag)
if err == nil {
tags = append(tags, version)
}
}
}
}

// Sort tags in natural (version) order
sort.Strings(tags)
// Sort the tags in descending order
sort.Sort(sort.Reverse(semver.Collection(tags)))

// If there are not enough tags, return an error
if len(tags) < 2 {
return "", fmt.Errorf("not enough tags found")
// Return the most recent tag
if len(tags) == 0 {
return "", fmt.Errorf("no valid tags found")
}

// Return the tag just before the last one
return tags[len(tags)-1], nil
return tags[0].String(), nil
}

func ListCmd() *cobra.Command {
Expand Down Expand Up @@ -116,22 +118,25 @@ func ListCmd() *cobra.Command {
}
}()

// Fetch the latest image tag dynamically from Docker Hub
latestTag, err := getLatestWandbTag()
operatorTag, err := getMostRecentTag("wandb/controller")
if err != nil {
fmt.Printf("Error fetching latest tag: %v\n", err)
fmt.Printf("Error fetching the latest operator-wandb controller tag: %v\n", err)
p.Quit()
return
}
weaveTraceTag, err := getMostRecentTag("wandb/weave-trace")
if err != nil {
fmt.Printf("Error fetching the latest weave-trace tag: %v\n", err)
p.Quit()
return
}

// Download and list images
operatorImgs, _ := downloadChartImages(
helm.WandbHelmRepoURL,
helm.WandbOperatorChart,
"", // empty version means latest
map[string]interface{}{
"image": map[string]interface{}{
"tag": latestTag, // Use the dynamically fetched tag
"tag": operatorTag,
},
},
)
Expand All @@ -141,6 +146,14 @@ func ListCmd() *cobra.Command {
panic(err)
}

// Enable weave-trace in the chart values
spec.Values["weave-trace"] = map[string]interface{}{
"install": true,
"image": map[string]interface{}{
"tag": weaveTraceTag,
},
}

wandbImgs, _ := downloadChartImages(
spec.Chart.URL,
spec.Chart.Name,
Expand Down