Repository: replicatedhq/kots
Pull request #82 (2019-10-04 16:37:18)

Allow for different registry for easier e2e testing


Patch:
diff --git a/cmd/kots/cli/install.go b/cmd/kots/cli/install.go
index 54cf982d4..9218df126 100644
--- a/cmd/kots/cli/install.go
+++ b/cmd/kots/cli/install.go
@@ -60,6 +60,10 @@ func InstallCmd() *cobra.Command {
 				namespace = enteredNamespace
 			}
 
+			kotsadm.OverrideVersion = v.GetString("kotsadm-tag")
+			kotsadm.OverrideRegistry = v.GetString("kotsadm-registry")
+			kotsadm.OverrideNamespace = v.GetString("kotsadm-namespace")
+
 			pullOptions := pull.PullOptions{
 				HelmRepoURI: v.GetString("repo"),
 				RootDir:     rootDir,
@@ -121,11 +125,11 @@ func InstallCmd() *cobra.Command {
 				if err != nil {
 					return err
 				}
-				defer close(stopCh)
 
 				if err := upload.Upload(rootDir, uploadOptions); err != nil {
 					return err
 				}
+				close(stopCh)
 			}
 
 			// port forward
@@ -174,6 +178,13 @@ func InstallCmd() *cobra.Command {
 	cmd.Flags().String("repo", "", "repo uri to use when installing a helm chart")
 	cmd.Flags().StringSlice("set", []string{}, "values to pass to helm when running helm template")
 
+	cmd.Flags().String("kotsadm-tag", "", "set to override the tag of kotsadm. this may create an incompatible deployment because the version of kots and kotsadm are designed to work together")
+	cmd.Flags().String("kotsadm-registry", "", "set to override the registry of kotsadm image. this may create an incompatible deployment because the version of kots and kotsadm are designed to work together")
+	cmd.Flags().String("kotsadm-namespace", "", "set to override the namespace of kotsadm image. this may create an incompatible deployment because the version of kots and kotsadm are designed to work together")
+	cmd.Flags().MarkHidden("kotsadm-tag")
+	cmd.Flags().MarkHidden("kotsadm-registry")
+	cmd.Flags().MarkHidden("kotsadm-namespace")
+
 	return cmd
 }
 
diff --git a/pkg/k8sutil/portforward.go b/pkg/k8sutil/portforward.go
index 585216265..b43bfcd02 100644
--- a/pkg/k8sutil/portforward.go
+++ b/pkg/k8sutil/portforward.go
@@ -12,6 +12,7 @@ import (
 	"time"
 
 	"github.com/pkg/errors"
+	"github.com/replicatedhq/kots/pkg/logger"
 	corev1 "k8s.io/api/core/v1"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/labels"
@@ -168,6 +169,8 @@ func PortForward(kubeContext string, localPort int, remotePort int, namespace st
 					}
 
 					forwardedAdditionalPorts[desiredAdditionalPort] = serviceStopCh
+					log := logger.NewLogger()
+					log.Info("Go to http://localhost:%d to access the application", desiredAdditionalPort.LocalPort)
 				}
 				time.Sleep(time.Second * 5)
 			}
diff --git a/pkg/kotsadm/api_objects.go b/pkg/kotsadm/api_objects.go
index 799d0a7f6..e8cb8a24a 100644
--- a/pkg/kotsadm/api_objects.go
+++ b/pkg/kotsadm/api_objects.go
@@ -102,7 +102,7 @@ func apiDeployment(namespace string) *appsv1.Deployment {
 					RestartPolicy:      corev1.RestartPolicyAlways,
 					Containers: []corev1.Container{
 						{
-							Image:           fmt.Sprintf("kotsadm/kotsadm-api:%s", kotsadmTag()),
+							Image:           fmt.Sprintf("%s/kotsadm-api:%s", kotsadmRegistry(), kotsadmTag()),
 							ImagePullPolicy: corev1.PullAlways,
 							Name:            "kotsadm-api",
 							Ports: []corev1.ContainerPort{
diff --git a/pkg/kotsadm/kotsadm_version.go b/pkg/kotsadm/kotsadm_version.go
index 52d6c2e9a..713597474 100644
--- a/pkg/kotsadm/kotsadm_version.go
+++ b/pkg/kotsadm/kotsadm_version.go
@@ -7,9 +7,19 @@ import (
 	"github.com/replicatedhq/kots/pkg/version"
 )
 
+var (
+	OverrideVersion   = ""
+	OverrideRegistry  = ""
+	OverrideNamespace = ""
+)
+
 // return "alpha" for all prerelease or invalid versions of kots,
 // kotsadm tag that matches this version for others
 func kotsadmTag() string {
+	if OverrideVersion != "" {
+		return OverrideVersion
+	}
+
 	kotsVersion := version.Version()
 	parsed, err := semver.NewVersion(kotsVersion)
 	if err != nil {
@@ -22,3 +32,19 @@ func kotsadmTag() string {
 
 	return fmt.Sprintf("v%s", kotsVersion)
 }
+
+func kotsadmRegistry() string {
+	if OverrideRegistry == "" {
+		if OverrideNamespace == "" {
+			return "kotsadm"
+		} else {
+			return OverrideNamespace
+		}
+	}
+
+	if OverrideNamespace == "" {
+		return fmt.Sprintf("%s/kotsadm", OverrideRegistry)
+	}
+
+	return fmt.Sprintf("%s/%s", OverrideRegistry, OverrideNamespace)
+}
diff --git a/pkg/kotsadm/operator_objects.go b/pkg/kotsadm/operator_objects.go
index 123926ef6..d84bc3736 100644
--- a/pkg/kotsadm/operator_objects.go
+++ b/pkg/kotsadm/operator_objects.go
@@ -100,7 +100,7 @@ func operatorDeployment(namespace string) *appsv1.Deployment {
 					RestartPolicy:      corev1.RestartPolicyAlways,
 					Containers: []corev1.Container{
 						{
-							Image:           fmt.Sprintf("kotsadm/kotsadm-operator:%s", kotsadmTag()),
+							Image:           fmt.Sprintf("%s/kotsadm-operator:%s", kotsadmRegistry(), kotsadmTag()),
 							ImagePullPolicy: corev1.PullAlways,
 							Name:            "kotsadm-operator",
 							Env: []corev1.EnvVar{
diff --git a/pkg/kotsadm/schemahero_objects.go b/pkg/kotsadm/schemahero_objects.go
index 41aa52de5..2a5cc5471 100644
--- a/pkg/kotsadm/schemahero_objects.go
+++ b/pkg/kotsadm/schemahero_objects.go
@@ -24,7 +24,7 @@ func migrationsPod(deployOptions DeployOptions) *corev1.Pod {
 			RestartPolicy: corev1.RestartPolicyOnFailure,
 			Containers: []corev1.Container{
 				{
-					Image:           fmt.Sprintf("kotsadm/kotsadm-migrations:%s", kotsadmTag()),
+					Image:           fmt.Sprintf("%s/kotsadm-migrations:%s", kotsadmRegistry(), kotsadmTag()),
 					ImagePullPolicy: corev1.PullAlways,
 					Name:            name,
 					Env: []corev1.EnvVar{
diff --git a/pkg/kotsadm/web_objects.go b/pkg/kotsadm/web_objects.go
index 72d79ab1d..f94ae46ca 100644
--- a/pkg/kotsadm/web_objects.go
+++ b/pkg/kotsadm/web_objects.go
@@ -79,7 +79,7 @@ func webDeployment(namespace string) *appsv1.Deployment {
 					},
 					Containers: []corev1.Container{
 						{
-							Image:           fmt.Sprintf("kotsadm/kotsadm-web:%s", kotsadmTag()),
+							Image:           fmt.Sprintf("%s/kotsadm-web:%s", kotsadmRegistry(), kotsadmTag()),
 							ImagePullPolicy: corev1.PullAlways,
 							Name:            "kotsadm-web",
 							Args: []string{


Test patch:
diff --git a/pkg/kotsadm/kotsad_version_test.go b/pkg/kotsadm/kotsad_version_test.go
new file mode 100644
index 000000000..de3dec6e4
--- /dev/null
+++ b/pkg/kotsadm/kotsad_version_test.go
@@ -0,0 +1,44 @@
+package kotsadm
+
+import (
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func Test_kotsadmRegistry(t *testing.T) {
+	tests := []struct {
+		name              string
+		overrideVersion   string
+		overrideRegistry  string
+		overrideNamespace string
+		expected          string
+	}{
+		{
+			name:     "no overrides",
+			expected: "kotsadm",
+		},
+		{
+			name:             "local registry",
+			overrideRegistry: "localhost:32000",
+			expected:         "localhost:32000/kotsadm",
+		},
+		{
+			name:              "local registry, custom namespace",
+			overrideRegistry:  "registry.somebigbank.com",
+			overrideNamespace: "my-namespace",
+			expected:          "registry.somebigbank.com/my-namespace",
+		},
+	}
+
+	for _, test := range tests {
+		t.Run(test.name, func(t *testing.T) {
+			OverrideVersion = test.overrideVersion
+			OverrideRegistry = test.overrideRegistry
+			OverrideNamespace = test.overrideNamespace
+
+			actual := kotsadmRegistry()
+			assert.Equal(t, test.expected, actual)
+		})
+	}
+}