Skip to content

Commit

Permalink
chore: add cnpg plugin for kubectl
Browse files Browse the repository at this point in the history
Add the cnpg plugin for kubectl to be used with CloudNativePG operator

Signed-off-by: Jonathan Gonzalez V <[email protected]>
  • Loading branch information
sxd committed Mar 5, 2023
1 parent a06dab2 commit 3a44a23
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
58 changes: 58 additions & 0 deletions pkg/get/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5687,3 +5687,61 @@ func Test_DownloaCroc(t *testing.T) {
}
}
}

func Test_DownloadKubectlcnpg(t *testing.T) {
tools := MakeTools()
name := "kubectl-cnpg"

tool := getTool(name, tools)

const toolVersion = "v1.19.0"

tests := []test{
{
os: "linux",
arch: arch64bit,
version: toolVersion,
url: `https://github.com/cloudnative-pg/cloudnative-pg/releases/download/v1.19.0/kubectl-cnpg_1.19.0_linux_x86_64.tar.gz`,
},
{
os: "darwin",
arch: arch64bit,
version: toolVersion,
url: `https://github.com/cloudnative-pg/cloudnative-pg/releases/download/v1.19.0/kubectl-cnpg_1.19.0_darwin_x86_64.tar.gz`,
},
{
os: "linux",
arch: archARM64,
version: toolVersion,
url: `https://github.com/cloudnative-pg/cloudnative-pg/releases/download/v1.19.0/kubectl-cnpg_1.19.0_linux_arm64.tar.gz`,
},
{
os: "darwin",
arch: archDarwinARM64,
version: toolVersion,
url: `https://github.com/cloudnative-pg/cloudnative-pg/releases/download/v1.19.0/kubectl-cnpg_1.19.0_darwin_arm64.tar.gz`,
},
{
os: "linux",
arch: archARM7,
version: toolVersion,
url: `https://github.com/cloudnative-pg/cloudnative-pg/releases/download/v1.19.0/kubectl-cnpg_1.19.0_linux_armv7.tar.gz`,
},
{
os: "ming",
arch: arch64bit,
version: toolVersion,
url: `https://github.com/cloudnative-pg/cloudnative-pg/releases/download/v1.19.0/kubectl-cnpg_1.19.0_windows_x86_64.tar.gz`,
},
}

for _, tc := range tests {
got, err := tool.GetURL(tc.os, tc.arch, tc.version, false)
if err != nil {
t.Fatal(err)
}
if got != tc.url {
t.Errorf("want: %s, got: %s", tc.url, got)
}
}
}
26 changes: 26 additions & 0 deletions pkg/get/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -3243,5 +3243,31 @@ https://github.com/{{.Owner}}/{{.Repo}}/releases/download/{{.Version}}/{{.Name}}
croc_{{.VersionNumber}}_{{$os}}-{{$arch}}.{{$ext}}
`,
})

tools = append(tools,
Tool{
Owner: "cloudnative-pg",
Repo: "cloudnative-pg",
Name: "kubectl-cnpg",
Description: "This plugin provides multiple commands to help you manage your CloudNativePG clusters.",
BinaryTemplate: `
{{ $os := .OS }}
{{ $arch := .Arch }}
{{- if eq .Arch "aarch64" -}}
{{ $arch = "arm64" }}
{{- else if eq .Arch "arm64" -}}
{{ $arch = "arm64" }}
{{- else if eq .Arch "armv7l" -}}
{{ $arch = "armv7" }}
{{- end -}}
{{ if HasPrefix .OS "ming" -}}
{{$os = "windows"}}
{{- end -}}
kubectl-cnpg_{{ .VersionNumber }}_{{ $os }}_{{ $arch }}.tar.gz
`,
})
return tools
}

0 comments on commit 3a44a23

Please sign in to comment.