Skip to content
Closed
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
17 changes: 13 additions & 4 deletions pkg/cmd/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var (
encoder = runtimejson.NewYAMLSerializer(runtimejson.DefaultMetaFactory, scheme.Scheme, scheme.Scheme)
)

func onboardingPath(clusterName, mirror, image, version string) string {
func onboardingPath(clusterName, mirror, image, version, namespace string) string {
path := "/v1/onboarding/k8s.yaml"
params := url.Values{}
if clusterName != "" {
Expand All @@ -63,19 +63,28 @@ func onboardingPath(clusterName, mirror, image, version string) string {
if version != "" {
params.Set("version", version)
}
if namespace != "" {
// Tell cosmos which namespace the controller is installed into so the
// generated manifest stamps it into every namespaced object, the
// ClusterRoleBinding subject, and the controller's runtime config.
// Without this the server defaults to "apoxy" and a non-default
// install namespace leaves the SA unbound and the controller pointed
// at the wrong namespace.
params.Set("namespace", namespace)
}
if len(params) == 0 {
return path
}
return path + "?" + params.Encode()
}

func getYAML(clusterName, mirror, image, version string) ([]byte, error) {
func getYAML(clusterName, mirror, image, version, namespace string) ([]byte, error) {
c, err := config.DefaultAPIClient()
if err != nil {
return nil, err
}

resp, err := c.SendRequest(http.MethodGet, onboardingPath(clusterName, mirror, image, version), nil)
resp, err := c.SendRequest(http.MethodGet, onboardingPath(clusterName, mirror, image, version, namespace), nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1113,7 +1122,7 @@ will automatically connect to the Apoxy API and begin managing your in-cluster A
}
}

yamlz, err := getYAML(clusterName, mirror, image, version)
yamlz, err := getYAML(clusterName, mirror, image, version, namespace)
if err != nil {
return fmt.Errorf("failed to get YAML: %w", err)
}
Expand Down
14 changes: 11 additions & 3 deletions pkg/cmd/k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,31 @@ import (
)

func TestOnboardingPath(t *testing.T) {
got := onboardingPath("silent-hill", "gateway", "docker.io/apoxy/apoxy:v0.1.6-dev-849f400", "")
got := onboardingPath("silent-hill", "gateway", "docker.io/apoxy/apoxy:v0.1.6-dev-849f400", "", "")
want := "/v1/onboarding/k8s.yaml?cluster_name=silent-hill&image=docker.io%2Fapoxy%2Fapoxy%3Av0.1.6-dev-849f400&mirror=gateway"
if got != want {
t.Fatalf("onboardingPath() = %q, want %q", got, want)
}
}

func TestOnboardingPathWithVersion(t *testing.T) {
got := onboardingPath("silent-hill", "gateway", "", "v0.3.0")
got := onboardingPath("silent-hill", "gateway", "", "v0.3.0", "")
want := "/v1/onboarding/k8s.yaml?cluster_name=silent-hill&mirror=gateway&version=v0.3.0"
if got != want {
t.Fatalf("onboardingPath() = %q, want %q", got, want)
}
}

func TestOnboardingPathWithNamespace(t *testing.T) {
got := onboardingPath("silent-hill", "gateway", "", "", "platform")
want := "/v1/onboarding/k8s.yaml?cluster_name=silent-hill&mirror=gateway&namespace=platform"
if got != want {
t.Fatalf("onboardingPath() = %q, want %q", got, want)
}
}

func TestOnboardingPathWithoutParams(t *testing.T) {
got := onboardingPath("", "", "", "")
got := onboardingPath("", "", "", "", "")
want := "/v1/onboarding/k8s.yaml"
if got != want {
t.Fatalf("onboardingPath() = %q, want %q", got, want)
Expand Down
Loading