Compare commits

..

7 Commits

Author SHA1 Message Date
Ahmet Alp Balkan
bc1b8fe34d fix(kubens): improve unset help text and success message
- Print active namespace after unset instead of generic message
- Clarify unset help text to explain it sets namespace to 'default'
- Move --version to last position in help output

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 16:10:11 -07:00
Joffrey
e8ea180cee explicit clear ns 2026-03-08 15:59:35 -07:00
Joffrey
cef93629f0 fix comment 2026-03-08 15:59:35 -07:00
Joffrey
7fc9c21f4b fix help line 2026-03-08 15:59:35 -07:00
Joffrey
63ea64cdc7 feat(kubens): add unset option 2026-03-08 15:59:35 -07:00
Ahmet Alp Balkan
a6cf1728fe chore: add dependabot config and auto-merge workflow (#462)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 15:57:13 -07:00
ultram4rine
80bbe8306a Migrate to kyaml (#412)
Closes #327.
2026-03-08 15:20:45 -07:00
6 changed files with 112 additions and 0 deletions

21
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,21 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
commit-message:
prefix: chore
include: scope
- package-ecosystem: gomod
directory: /
schedule:
interval: weekly
commit-message:
prefix: chore
include: scope
groups:
kubernetes:
patterns:
- "k8s.io/*"

24
.github/workflows/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,24 @@
name: Dependabot
on:
pull_request:
permissions:
contents: write
pull-requests: write
jobs:
auto-merge:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v2
- name: Enable auto-merge for Dependabot PRs
if: ${{ steps.metadata.outputs.update-type != 'version-update:semver-major' }}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -52,6 +52,8 @@ func parseArgs(argv []string) Op {
return VersionOp{}
case "--current", "-c":
return CurrentOp{}
case "--unset", "-u":
return UnsetOp{}
default:
return getSwitchOp(v, false)
}

View File

@@ -45,6 +45,12 @@ func Test_parseArgs_new(t *testing.T) {
{name: "current long form",
args: []string{"--current"},
want: CurrentOp{}},
{name: "unset shorthand",
args: []string{"-u"},
want: UnsetOp{}},
{name: "unset long form",
args: []string{"--unset"},
want: UnsetOp{}},
{name: "switch by name",
args: []string{"foo"},
want: SwitchOp{Target: "foo"}},

View File

@@ -39,6 +39,7 @@ func printUsage(out io.Writer) error {
%PROG% - : switch to the previous namespace in this context
%PROG% -c, --current : show the current namespace
%PROG% -h,--help : show this message
%PROG% -u,--unset : unset the namespace choice (set to 'default')
%PROG% -V,--version : show version`
// TODO this replace logic is duplicated between this and kubectx

58
cmd/kubens/unset.go Normal file
View File

@@ -0,0 +1,58 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"io"
"github.com/pkg/errors"
"github.com/ahmetb/kubectx/internal/kubeconfig"
"github.com/ahmetb/kubectx/internal/printer"
)
// UnsetOp indicates intention to remove current namespace preference.
type UnsetOp struct{}
func (_ UnsetOp) Run(_, stderr io.Writer) error {
kc := new(kubeconfig.Kubeconfig).WithLoader(kubeconfig.DefaultLoader)
defer kc.Close()
if err := kc.Parse(); err != nil {
return errors.Wrap(err, "kubeconfig error")
}
ns, err := clearNamespace(kc)
if err != nil {
return err
}
err = printer.Success(stderr, "Active namespace is \"%s\".", printer.SuccessColor.Sprint(ns))
return err
}
func clearNamespace(kc *kubeconfig.Kubeconfig) (string, error) {
ctx := kc.GetCurrentContext()
ns := "default"
if ctx == "" {
return "", errors.New("current-context is not set")
}
if err := kc.SetNamespace(ctx, ns); err != nil {
return "", errors.Wrapf(err, "failed to clear namespace")
}
if err := kc.Save(); err != nil {
return "", errors.Wrap(err, "failed to save kubeconfig file")
}
return ns, nil
}