Răsfoiți Sursa

feat: support checking updates for non porter charts

Soham Parekh 3 ani în urmă
părinte
comite
dd7b85e22f
1 a modificat fișierele cu 27 adăugiri și 7 ștergeri
  1. 27 7
      api/server/handlers/release/get.go

+ 27 - 7
api/server/handlers/release/get.go

@@ -95,15 +95,35 @@ func (c *ReleaseGetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		res.PorterRelease = &types.PorterRelease{}
 	}
 
-	// detect if Porter application chart and attempt to get the latest version
-	// from chart repo
-	cache := c.Config().URLCache
-	chartRepoURL, foundFirst := cache.GetURL(helmRelease.Chart.Metadata.Name)
+	chartRepoURL := ""
 
-	if !foundFirst {
-		cache.Update()
+	// First try to find the chart from the release's chart metadata
+	sources := helmRelease.Chart.Metadata.Sources
 
-		chartRepoURL, _ = cache.GetURL(helmRelease.Chart.Metadata.Name)
+	if len(sources) != 0 {
+		chartRepoURL = sources[0]
+
+		// Try to fetch the repo index to see if the URL is a valid repo
+		_, err := loader.LoadRepoIndexPublic(chartRepoURL)
+
+		if err != nil {
+			// If we have an error, reset the chartRepoURL to empty
+			chartRepoURL = ""
+		}
+	}
+
+	// If chartRepoURL was not set, try to find the chart from the cache
+	if chartRepoURL == "" {
+		cache := c.Config().URLCache
+		chartRepoURLFromCache, foundFirst := cache.GetURL(helmRelease.Chart.Metadata.Name)
+
+		if foundFirst {
+			chartRepoURL = chartRepoURLFromCache
+		} else {
+			cache.Update()
+
+			chartRepoURL, _ = cache.GetURL(helmRelease.Chart.Metadata.Name)
+		}
 	}
 
 	if chartRepoURL != "" {