Skip to content

Commit 8e9d8a1

Browse files
dilyevskyclaude
andcommitted
[k8s] add --version flag to install command
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d128d38 commit 8e9d8a1

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

pkg/cmd/k8s.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var (
4545
encoder = runtimejson.NewYAMLSerializer(runtimejson.DefaultMetaFactory, scheme.Scheme, scheme.Scheme)
4646
)
4747

48-
func onboardingPath(clusterName, mirror, image string) string {
48+
func onboardingPath(clusterName, mirror, image, version string) string {
4949
path := "/v1/onboarding/k8s.yaml"
5050
params := url.Values{}
5151
if clusterName != "" {
@@ -57,19 +57,22 @@ func onboardingPath(clusterName, mirror, image string) string {
5757
if image != "" {
5858
params.Set("image", image)
5959
}
60+
if version != "" {
61+
params.Set("version", version)
62+
}
6063
if len(params) == 0 {
6164
return path
6265
}
6366
return path + "?" + params.Encode()
6467
}
6568

66-
func getYAML(clusterName, mirror, image string) ([]byte, error) {
69+
func getYAML(clusterName, mirror, image, version string) ([]byte, error) {
6770
c, err := config.DefaultAPIClient()
6871
if err != nil {
6972
return nil, err
7073
}
7174

72-
resp, err := c.SendRequest(http.MethodGet, onboardingPath(clusterName, mirror, image), nil)
75+
resp, err := c.SendRequest(http.MethodGet, onboardingPath(clusterName, mirror, image, version), nil)
7376
if err != nil {
7477
return nil, err
7578
}
@@ -1030,6 +1033,10 @@ will automatically connect to the Apoxy API and begin managing your in-cluster A
10301033
if err != nil {
10311034
return err
10321035
}
1036+
version, err := cmd.Flags().GetString("version")
1037+
if err != nil {
1038+
return err
1039+
}
10331040
yes, err := cmd.Flags().GetBool("yes")
10341041
if err != nil {
10351042
return err
@@ -1064,7 +1071,7 @@ will automatically connect to the Apoxy API and begin managing your in-cluster A
10641071
}
10651072
}
10661073

1067-
yamlz, err := getYAML(clusterName, mirror, image)
1074+
yamlz, err := getYAML(clusterName, mirror, image, version)
10681075
if err != nil {
10691076
return fmt.Errorf("failed to get YAML: %w", err)
10701077
}
@@ -1092,6 +1099,7 @@ func init() {
10921099
installK8sCmd.Flags().String("cluster-name", "", "Cluster name identifier (defaults to kube context name)")
10931100
installK8sCmd.Flags().String("mirror", "", "Mirror mode (gateway, ingress, all)")
10941101
installK8sCmd.Flags().String("image", "", "Controller image override to pass to the onboarding manifest generator")
1102+
installK8sCmd.Flags().String("version", "", "Controller version override (e.g. v0.3.0)")
10951103
installK8sCmd.Flags().BoolP("yes", "y", false, "Skip confirmation and apply changes immediately")
10961104
k8sCmd.AddCommand(installK8sCmd)
10971105

pkg/cmd/k8s_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,23 @@ import (
77
)
88

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

17+
func TestOnboardingPathWithVersion(t *testing.T) {
18+
got := onboardingPath("silent-hill", "gateway", "", "v0.3.0")
19+
want := "/v1/onboarding/k8s.yaml?cluster_name=silent-hill&mirror=gateway&version=v0.3.0"
20+
if got != want {
21+
t.Fatalf("onboardingPath() = %q, want %q", got, want)
22+
}
23+
}
24+
1725
func TestOnboardingPathWithoutParams(t *testing.T) {
18-
got := onboardingPath("", "", "")
26+
got := onboardingPath("", "", "", "")
1927
want := "/v1/onboarding/k8s.yaml"
2028
if got != want {
2129
t.Fatalf("onboardingPath() = %q, want %q", got, want)

0 commit comments

Comments
 (0)