checking for nil pointer in merge namespace (#2659)

mine
Jayson Wang 2024-04-21 01:05:54 +08:00 committed by GitHub
parent 363e1405e7
commit 1a25109d25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 2 deletions

View File

@ -53,9 +53,12 @@ func NewContextFromKubeConfig(ks KubeSettings) (*Context, error) {
}
func (c *Context) merge(old *Context) {
if old == nil {
if old == nil || old.Namespace == nil {
return
}
if c.Namespace == nil {
c.Namespace = NewNamespace()
}
c.Namespace.merge(old.Namespace)
}

View File

@ -70,6 +70,11 @@ func Test_contextMerge(t *testing.T) {
},
},
},
"no-namespace": {
c1: NewContext(),
c2: &Context{},
e: NewContext(),
},
}
for k, u := range uu {

View File

@ -466,7 +466,7 @@ func (a *App) switchContext(ci *cmd.Interpreter, force bool) error {
return err
}
}
a.Flash().Errf("Using %q namespace", ns)
a.Flash().Infof("Using %q namespace", ns)
if err := a.Config.Save(true); err != nil {
log.Error().Err(err).Msg("config save failed!")