Skip to content
Merged
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
14 changes: 10 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@ jobs:

steps:
- name: Checkout Repo
uses: actions/checkout@v3
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3

- name: Set up Go
uses: actions/setup-go@v5
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
with:
go-version-file: go.mod
cache: false

# https://github.com/golang/go/issues/75031
- name: Set toolchain version
run: go env -w GOTOOLCHAIN=go1.25.4+auto

- name: Lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
with:
version: v2.7.2
Comment thread
pmatseykanets marked this conversation as resolved.

- name: Validate Go modules
run: ./scripts/validate
Expand Down Expand Up @@ -51,7 +57,7 @@ jobs:
echo "VERSION=$VERSION" >> $GITHUB_ENV

- name: Docker Build
uses: docker/build-push-action@v5
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5
with:
push: false
context: package
Expand Down
16 changes: 11 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

steps:
- name: Checkout Repo
uses: actions/checkout@v3
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3

- name: Load Secrets from Vault
uses: rancher-eio/read-vault-secrets@main
Expand All @@ -36,13 +36,19 @@ jobs:
credentials_json: "${{ env.GOOGLE_AUTH }}"

- name: Set up Go
uses: actions/setup-go@v5
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
with:
go-version-file: go.mod
cache: false

# https://github.com/golang/go/issues/75031
- name: Set toolchain version
run: go env -w GOTOOLCHAIN=go1.25.4+auto

- name: Lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
with:
version: v2.7.2
Comment thread
pmatseykanets marked this conversation as resolved.

- name: Validate Go modules
run: ./scripts/validate
Expand Down Expand Up @@ -82,7 +88,7 @@ jobs:
gh release upload $VERSION *.txt *.xz *.gz *.zip

- name: Upload Release assets to Google Cloud
uses: google-github-actions/upload-cloud-storage@v2
uses: google-github-actions/upload-cloud-storage@c0f6160ff80057923ff50e5e567695cea181ec23 # v2
with:
path: dist/artifacts/${{ env.VERSION }}
destination: releases.rancher.com/cli2/${{ env.VERSION }}
Expand All @@ -93,7 +99,7 @@ jobs:
cache-control: public,max-age=3600

- name: Docker Build
uses: docker/build-push-action@v5
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5
with:
push: true
context: package
Expand Down
25 changes: 16 additions & 9 deletions .golangci.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
{
"linters": {
"enable": [
"gofmt"
]
},
"run": {
"timeout": "10m"
}
}
"formatters": {
"enable": [
"gofmt"
]
},
"linters": {
"default": "none",
"enable": [
"govet",
"ineffassign",
"staticcheck",
"unused"
]
},
"version": "2"
}
6 changes: 3 additions & 3 deletions cliclient/cliclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ func (mc *MasterClient) newCAPIClient() error {
func (mc *MasterClient) ByID(resource *ntypes.Resource, respObject interface{}) error {
if strings.HasPrefix(resource.Type, "cluster.x-k8s.io") {
return mc.CAPIClient.ByID(resource.Type, resource.ID, &respObject)
} else if _, ok := mc.ManagementClient.APIBaseClient.Types[resource.Type]; ok {
} else if _, ok := mc.ManagementClient.Types[resource.Type]; ok {
return mc.ManagementClient.ByID(resource.Type, resource.ID, &respObject)
} else if _, ok := mc.ProjectClient.APIBaseClient.Types[resource.Type]; ok {
} else if _, ok := mc.ProjectClient.Types[resource.Type]; ok {
return mc.ProjectClient.ByID(resource.Type, resource.ID, &respObject)
} else if _, ok := mc.ClusterClient.APIBaseClient.Types[resource.Type]; ok {
} else if _, ok := mc.ClusterClient.Types[resource.Type]; ok {
return mc.ClusterClient.ByID(resource.Type, resource.ID, &respObject)
}
return fmt.Errorf("MasterClient - unknown resource type %v", resource.Type)
Expand Down
6 changes: 3 additions & 3 deletions cmd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,23 +742,23 @@ func getClusterRAM(cluster managementClient.Cluster) string {
// parseResourceString returns GB for Ki and Mi and CPU cores from 'm'
func parseResourceString(mem string) string {
if strings.HasSuffix(mem, "Ki") {
num, err := strconv.ParseFloat(strings.Replace(mem, "Ki", "", -1), 64)
num, err := strconv.ParseFloat(strings.ReplaceAll(mem, "Ki", ""), 64)
if err != nil {
return mem
}
num = num / 1024 / 1024
return strings.TrimSuffix(fmt.Sprintf("%.2f", num), ".0")
}
if strings.HasSuffix(mem, "Mi") {
num, err := strconv.ParseFloat(strings.Replace(mem, "Mi", "", -1), 64)
num, err := strconv.ParseFloat(strings.ReplaceAll(mem, "Mi", ""), 64)
if err != nil {
return mem
}
num = num / 1024
return strings.TrimSuffix(fmt.Sprintf("%.2f", num), ".0")
}
if strings.HasSuffix(mem, "m") {
num, err := strconv.ParseFloat(strings.Replace(mem, "m", "", -1), 64)
num, err := strconv.ParseFloat(strings.ReplaceAll(mem, "m", ""), 64)
if err != nil {
return mem
}
Expand Down
24 changes: 12 additions & 12 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func loadAndVerifyCert(path string) (string, error) {

func verifyCert(caCert []byte) (string, error) {
// replace the escaped version of the line break
caCert = bytes.Replace(caCert, []byte(`\n`), []byte("\n"), -1)
caCert = bytes.ReplaceAll(caCert, []byte(`\n`), []byte("\n"))

block, _ := pem.Decode(caCert)

Expand Down Expand Up @@ -322,28 +322,28 @@ func GetClient(ctx *cli.Context) (*cliclient.MasterClient, error) {
// GetResourceType maps an incoming resource type to a valid one from the schema
func GetResourceType(c *cliclient.MasterClient, resource string) (string, error) {
if c.ManagementClient != nil {
for key := range c.ManagementClient.APIBaseClient.Types {
for key := range c.ManagementClient.Types {
if strings.EqualFold(key, resource) {
return key, nil
}
}
}
if c.ProjectClient != nil {
for key := range c.ProjectClient.APIBaseClient.Types {
for key := range c.ProjectClient.Types {
if strings.EqualFold(key, resource) {
return key, nil
}
}
}
if c.ClusterClient != nil {
for key := range c.ClusterClient.APIBaseClient.Types {
for key := range c.ClusterClient.Types {
if strings.EqualFold(key, resource) {
return key, nil
}
}
}
if c.CAPIClient != nil {
for key := range c.CAPIClient.APIBaseClient.Types {
for key := range c.CAPIClient.Types {
lowerKey := strings.ToLower(key)
if strings.HasPrefix(lowerKey, "cluster.x-k8s.io") && lowerKey == strings.ToLower(resource) {
return key, nil
Expand All @@ -370,17 +370,17 @@ func Lookup(c *cliclient.MasterClient, name string, types ...string) (*ntypes.Re
}
}
if c.ManagementClient != nil {
if _, ok := c.ManagementClient.APIBaseClient.Types[rt]; ok {
if _, ok := c.ManagementClient.Types[rt]; ok {
schemaClient = c.ManagementClient
}
}
if c.ProjectClient != nil {
if _, ok := c.ProjectClient.APIBaseClient.Types[rt]; ok {
if _, ok := c.ProjectClient.Types[rt]; ok {
schemaClient = c.ProjectClient
}
}
if c.ClusterClient != nil {
if _, ok := c.ClusterClient.APIBaseClient.Types[rt]; ok {
if _, ok := c.ClusterClient.Types[rt]; ok {
schemaClient = c.ClusterClient
}
}
Expand Down Expand Up @@ -415,7 +415,7 @@ func Lookup(c *cliclient.MasterClient, name string, types ...string) (*ntypes.Re
for _, data := range collection.Data {
ids = append(ids, data.ID)
}
return nil, fmt.Errorf("Multiple resources of type %s found for name %s: %v", schemaType, name, ids)
return nil, fmt.Errorf("multiple resources of type %s found for name %s: %v", schemaType, name, ids)
}

// No matches for this schemaType, try the next one
Expand All @@ -424,7 +424,7 @@ func Lookup(c *cliclient.MasterClient, name string, types ...string) (*ntypes.Re
}

if byName != nil {
return nil, fmt.Errorf("Multiple resources named %s: %s:%s, %s:%s", name, collection.Data[0].Type,
return nil, fmt.Errorf("multiple resources named %s: %s:%s, %s:%s", name, collection.Data[0].Type,
collection.Data[0].ID, byName.Type, byName.ID)
}

Expand All @@ -433,7 +433,7 @@ func Lookup(c *cliclient.MasterClient, name string, types ...string) (*ntypes.Re
}

if byName == nil {
return nil, fmt.Errorf("Not found: %s", name)
return nil, fmt.Errorf("not found: %s", name)
}

return byName, nil
Expand Down Expand Up @@ -546,7 +546,7 @@ func parseClusterAndProjectID(id string) (string, string, error) {
parts := SplitOnColon(id)
return parts[0], parts[1], nil
}
return "", "", fmt.Errorf("Unable to extract clusterid and projectid from [%s]", id)
return "", "", fmt.Errorf("unable to extract clusterid and projectid from [%s]", id)
}

// Return a JSON blob of the file at path
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func loadCachedCredential(ctx *cli.Context, serverConfig *config.ServerConfig, k
return cred, nil
}
ts := cred.Status.ExpirationTimestamp
if ts != nil && ts.Time.Before(time.Now()) {
if ts != nil && ts.Before(time.Now()) {
cf, err := loadConfig(ctx)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,5 @@ func TestCacheCredential(t *testing.T) {

expirationTimestamp := cfg.Servers["rancher.example.com"].KubeCredentials["dev-server"].Status.ExpirationTimestamp
require.NotNil(t, expirationTimestamp)
assert.True(t, expirationTimestamp.Time.Equal(expires.Time))
assert.True(t, expirationTimestamp.Equal(expires.Time))
}
6 changes: 3 additions & 3 deletions cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func loginSetup(ctx *cli.Context) error {
// Validate the url and drop the path
u, err := url.ParseRequestURI(ctx.Args().First())
if err != nil {
return fmt.Errorf("Failed to parse SERVERURL (%s), make sure it is a valid HTTPS URL (e.g. https://rancher.yourdomain.com or https://1.1.1.1). Error: %s", ctx.Args().First(), err)
return fmt.Errorf("failed to parse SERVERURL (%s), make sure it is a valid HTTPS URL (e.g. https://rancher.yourdomain.com or https://1.1.1.1). Error: %s", ctx.Args().First(), err)
}

u.Path = ""
Expand Down Expand Up @@ -133,12 +133,12 @@ func getProjectContext(ctx *cli.Context, c *cliclient.MasterClient) (string, err
// Check if given context is in valid format
_, _, err := parseClusterAndProjectID(context)
if err != nil {
return "", fmt.Errorf("Unable to parse context (%s). Please provide context as local:p-xxxxx, c-xxxxx:p-xxxxx, c-xxxxx:project-xxxxx, c-m-xxxxxxxx:p-xxxxx or c-m-xxxxxxxx:project-xxxxx", context)
return "", fmt.Errorf("unable to parse context (%s). Please provide context as local:p-xxxxx, c-xxxxx:p-xxxxx, c-xxxxx:project-xxxxx, c-m-xxxxxxxx:p-xxxxx or c-m-xxxxxxxx:project-xxxxx", context)
}
// Check if context exists
_, err = Lookup(c, context, "project")
if err != nil {
return "", fmt.Errorf("Unable to find context (%s). Make sure the context exists and you have permissions to use it. Error: %s", context, err)
return "", fmt.Errorf("unable to find context (%s). Make sure the context exists and you have permissions to use it. Error: %s", context, err)
}
return context, nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func wait(ctx *cli.Context) error {
for {
select {
case <-timeout:
return fmt.Errorf("Timeout reached %v:%v transitioningMessage: %v", resource.Type, resource.ID, mapResource["transitioningMessage"])
return fmt.Errorf("timeout reached %v:%v transitioningMessage: %v", resource.Type, resource.ID, mapResource["transitioningMessage"])
case <-ticker.C:
err = c.ByID(resource, &mapResource)
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions cmd/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,22 @@ func (t *TableWriter) Write(obj interface{}) {
return
}

if t.ValueFormat == "json" {
switch t.ValueFormat {
case "json":
content, err := json.Marshal(obj)
t.err = err
if t.err != nil {
return
}
_, t.err = t.Writer.Write(append(content, byte('\n')))
} else if t.ValueFormat == "yaml" {
case "yaml":
content, err := yaml.Marshal(obj)
t.err = err
if t.err != nil {
return
}
_, t.err = t.Writer.Write(append(content, byte('\n')))
} else {
default:
t.err = printTemplate(t.Writer, t.ValueFormat, obj)
}
}
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/rancher/cli

go 1.24.0
go 1.25.0

toolchain go1.24.12
toolchain go1.25.7

replace (
k8s.io/api => k8s.io/api v0.32.11
Expand All @@ -16,8 +16,8 @@ replace (
require (
github.com/ghodss/yaml v1.0.0
github.com/rancher/norman v0.5.2
github.com/rancher/rancher/pkg/apis v0.0.0-20260225185423-406b53fce52f
github.com/rancher/rancher/pkg/client v0.0.0-20260225185423-406b53fce52f
github.com/rancher/rancher/pkg/apis v0.0.0-20260309190128-6d4efe6e469e
github.com/rancher/rancher/pkg/client v0.0.0-20260309190128-6d4efe6e469e
github.com/sirupsen/logrus v1.9.4
github.com/stretchr/testify v1.11.1
github.com/tidwall/gjson v1.17.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ github.com/rancher/lasso v0.2.3 h1:74/z/C/O3ykhyMrRuEgc9kVyYiSoS7kp5BAijlcyXDg=
github.com/rancher/lasso v0.2.3/go.mod h1:G+KeeOaKRjp+qGp0bV6VbLhYrq1vHbJPbDh40ejg5yE=
github.com/rancher/norman v0.5.2 h1:rwUKZ0QeVKJEtznhRdNQUMJtKjSoLYbFuPQGXm6xTxw=
github.com/rancher/norman v0.5.2/go.mod h1:lDO9ylAYBwch9FiYyuuWlYd7+IxgRgh0ioDJBweC7t4=
github.com/rancher/rancher/pkg/apis v0.0.0-20260225185423-406b53fce52f h1:cm09o87hJxEiwnKG+hz2uxCVv8jFarD3seTa+fq236o=
github.com/rancher/rancher/pkg/apis v0.0.0-20260225185423-406b53fce52f/go.mod h1:XPRzJj/7utyBjVhF8YlmDrZfK3rMKiUMH4YXNy0J8ZU=
github.com/rancher/rancher/pkg/client v0.0.0-20260225185423-406b53fce52f h1:4ITc4C4SxSJH6leOoiZHZJ3ger9HSGI8/fR6GXqke8k=
github.com/rancher/rancher/pkg/client v0.0.0-20260225185423-406b53fce52f/go.mod h1:jD2yZAxPW3Hqd13scvvEUn4JUp5NgrdSwi2vGOObI6w=
github.com/rancher/rancher/pkg/apis v0.0.0-20260309190128-6d4efe6e469e h1:a9/EQ+A/hDWlhjQXyq30fFCTpEGfDswfkzuCPKoZpTY=
github.com/rancher/rancher/pkg/apis v0.0.0-20260309190128-6d4efe6e469e/go.mod h1:XPRzJj/7utyBjVhF8YlmDrZfK3rMKiUMH4YXNy0J8ZU=
github.com/rancher/rancher/pkg/client v0.0.0-20260309190128-6d4efe6e469e h1:vYDw/y7iPOvNLlRgT51Vd0Si9mnmNYmNCyWjFRq2YgQ=
github.com/rancher/rancher/pkg/client v0.0.0-20260309190128-6d4efe6e469e/go.mod h1:jD2yZAxPW3Hqd13scvvEUn4JUp5NgrdSwi2vGOObI6w=
github.com/rancher/rke v1.8.5 h1:dyEPIHRcatYaNPtTZhJH5Omu7BE6+UeJ8GNjw5X6hqY=
github.com/rancher/rke v1.8.5/go.mod h1:EaAkq796bgmmx/s15Xz0TvCkBOfepMOqO8tFockOmis=
github.com/rancher/wrangler/v3 v3.2.4 h1:pgpLwsmgQvTSSknxddJDq+ObIiOXFggCWdDyB0z7YcA=
Expand Down