Repository: replicatedhq/kots
Pull request #290 (2020-01-29 21:59:09)

app pull test server now returns license yaml where expected


Patch:
diff --git a/integration/replicated/server.go b/integration/replicated/server.go
index 53e0d4719..312dd2df4 100644
--- a/integration/replicated/server.go
+++ b/integration/replicated/server.go
@@ -2,16 +2,26 @@ package replicated
 
 import (
 	"context"
+	"fmt"
 	"net/http"
 )
 
-func StartMockServer(endpoint string, appSlug string, licenseID string, archive []byte) (chan bool, error) {
+func StartMockServer(endpoint string, appSlug string, licenseID string, archive, license []byte) (chan bool, error) {
 	stopCh := make(chan bool)
 
 	srv := &http.Server{Addr: ":3000"}
-	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+	http.HandleFunc("/release/", func(w http.ResponseWriter, r *http.Request) {
+		fmt.Printf("handling URL %s with release tarball\n", r.URL)
 		w.Write(archive)
 	})
+	http.HandleFunc("/license/", func(w http.ResponseWriter, r *http.Request) {
+		fmt.Printf("handling URL %s with license file\n", r.URL)
+		w.Write(license)
+	})
+	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+		fmt.Printf("WARNING! unable to handle url %s", r.URL)
+		w.WriteHeader(501)
+	})
 
 	go func() {
 		srv.ListenAndServe()
diff --git a/pkg/upstream/replicated.go b/pkg/upstream/replicated.go
index 0798abe0e..34b067e29 100644
--- a/pkg/upstream/replicated.go
+++ b/pkg/upstream/replicated.go
@@ -145,6 +145,11 @@ func downloadReplicated(u *url.URL, localPath string, rootDir string, useAppDir
 			return nil, errors.Wrap(err, "failed to download replicated app")
 		}
 
+		license, err = kotslicense.GetLatestLicense(license)
+		if err != nil {
+			return nil, errors.Wrap(err, "failed to get latest license")
+		}
+
 		release = downloadedRelease
 	}
 
@@ -186,13 +191,9 @@ func downloadReplicated(u *url.URL, localPath string, rootDir string, useAppDir
 		release.Manifests["userdata/config.yaml"] = mustMarshalConfigValues(configValues)
 	}
 
-	// Add the license to the upstream, if one was propvided
+	// Add the license to the upstream, if one was provided
 	if license != nil {
-		latestLicense, err := kotslicense.GetLatestLicense(license)
-		if err != nil {
-			return nil, errors.Wrap(err, "failed to get latest license")
-		}
-		release.Manifests["userdata/license.yaml"] = MustMarshalLicense(latestLicense)
+		release.Manifests["userdata/license.yaml"] = MustMarshalLicense(license)
 	}
 
 	files, err := releaseToFiles(release)
diff --git a/support-bundle.yaml b/support-bundle.yaml
index 58854035b..0d57c3c1d 100644
--- a/support-bundle.yaml
+++ b/support-bundle.yaml
@@ -3,33 +3,4 @@ kind: Collector
 metadata:
   name: collector-sample
 spec:
-  collectors:
-    - clusterInfo: {}
-    - clusterResources: {}
-    - exec: 
-        args: 
-          - "-U"
-          - kotsadm
-        collectorName: kotsadm-postgres-db
-        command: 
-          - pg_dump
-        containerName: kotsadm-postgres
-        name: kots/admin_console
-        selector: 
-          - app=kotsadm-postgres
-        timeout: 10s
-    - logs: 
-        collectorName: kotsadm-api
-        name: kots/admin_console
-        selector: 
-          - app=kotsadm-api
-    - logs: 
-        collectorName: kotsadm-operator
-        name: kots/admin_console
-        selector: 
-          - app=kotsadm-operator
-    - secret: 
-        collectorName: kotsadm-replicated-registry
-        includeValue: false
-        key: .dockerconfigjson
-        name: kotsadm-replicated-registry
+  collectors: []


Test patch:
diff --git a/integration/replicated/pull_test.go b/integration/replicated/pull_test.go
index b47b4edec..d9ba82182 100644
--- a/integration/replicated/pull_test.go
+++ b/integration/replicated/pull_test.go
@@ -47,7 +47,11 @@ func Test_PullReplicated(t *testing.T) {
 			archiveData, err := ioutil.ReadFile(path.Join(test.testDir, "archive.tar.gz"))
 			req.NoError(err)
 
-			stopCh, err := StartMockServer(endpoint, "integration", "integration", archiveData)
+			licenseFilepath := path.Join(test.testDir, "license.yaml")
+			licenseFile, err := ioutil.ReadFile(licenseFilepath)
+			req.NoError(err)
+
+			stopCh, err := StartMockServer(endpoint, "integration", "integration", archiveData, licenseFile)
 			req.NoError(err)
 
 			defer func() {
@@ -60,7 +64,7 @@ func Test_PullReplicated(t *testing.T) {
 
 			pullOptions := pull.PullOptions{
 				RootDir:             actualDir,
-				LicenseFile:         path.Join(test.testDir, "license.yaml"),
+				LicenseFile:         licenseFilepath,
 				Namespace:           namespace,
 				ExcludeAdminConsole: true,
 				ExcludeKotsKinds:    true,