Skip to content

Commit

Permalink
Merge pull request #82 from replicatedhq/additional-ports
Browse files Browse the repository at this point in the history
Allow for different registry for easier e2e testing
  • Loading branch information
marccampbell authored Oct 7, 2019
2 parents 69ac1a1 + 9f56de8 commit 6cec56e
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 5 deletions.
13 changes: 12 additions & 1 deletion cmd/kots/cli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/k8sutil/portforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kotsadm/api_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
44 changes: 44 additions & 0 deletions pkg/kotsadm/kotsad_version_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
}
26 changes: 26 additions & 0 deletions pkg/kotsadm/kotsadm_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion pkg/kotsadm/operator_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion pkg/kotsadm/schemahero_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion pkg/kotsadm/web_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 6cec56e

Please sign in to comment.