mirror of
https://github.com/lukaszraczylo/kportal.git
synced 2026-07-10 06:52:00 +00:00
bugfixes nov2025 (#3)
* Fix enter misbehaving. * Cleanup after previous tui implementation. * Fix race condition and improve logging * Add filtering of the namespaces by text input in the wizard UI
This commit is contained in:
@@ -136,38 +136,3 @@ func (c *Config) GetAllForwards() []Forward {
|
||||
|
||||
return forwards
|
||||
}
|
||||
|
||||
// GetForwardsByContext returns all forwards for a specific context.
|
||||
func (c *Config) GetForwardsByContext(contextName string) []Forward {
|
||||
var forwards []Forward
|
||||
|
||||
for _, ctx := range c.Contexts {
|
||||
if ctx.Name == contextName {
|
||||
for _, ns := range ctx.Namespaces {
|
||||
forwards = append(forwards, ns.Forwards...)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return forwards
|
||||
}
|
||||
|
||||
// GetForwardsByNamespace returns all forwards for a specific context and namespace.
|
||||
func (c *Config) GetForwardsByNamespace(contextName, namespaceName string) []Forward {
|
||||
var forwards []Forward
|
||||
|
||||
for _, ctx := range c.Contexts {
|
||||
if ctx.Name == contextName {
|
||||
for _, ns := range ctx.Namespaces {
|
||||
if ns.Name == namespaceName {
|
||||
forwards = append(forwards, ns.Forwards...)
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return forwards
|
||||
}
|
||||
|
||||
@@ -298,72 +298,6 @@ func TestConfig_GetAllForwards(t *testing.T) {
|
||||
assert.Len(t, forwards, 4, "should return all forwards from all contexts and namespaces")
|
||||
}
|
||||
|
||||
func TestConfig_GetForwardsByContext(t *testing.T) {
|
||||
yamlData := []byte(`contexts:
|
||||
- name: cluster1
|
||||
namespaces:
|
||||
- name: ns1
|
||||
forwards:
|
||||
- resource: pod/app1
|
||||
port: 8080
|
||||
localPort: 8080
|
||||
- resource: pod/app2
|
||||
port: 8081
|
||||
localPort: 8081
|
||||
- name: cluster2
|
||||
namespaces:
|
||||
- name: ns2
|
||||
forwards:
|
||||
- resource: pod/app3
|
||||
port: 9090
|
||||
localPort: 9090
|
||||
`)
|
||||
|
||||
cfg, err := ParseConfig(yamlData)
|
||||
assert.NoError(t, err)
|
||||
|
||||
forwards := cfg.GetForwardsByContext("cluster1")
|
||||
assert.Len(t, forwards, 2, "should return forwards only from cluster1")
|
||||
|
||||
forwards2 := cfg.GetForwardsByContext("cluster2")
|
||||
assert.Len(t, forwards2, 1, "should return forwards only from cluster2")
|
||||
|
||||
forwards3 := cfg.GetForwardsByContext("non-existent")
|
||||
assert.Len(t, forwards3, 0, "should return empty slice for non-existent context")
|
||||
}
|
||||
|
||||
func TestConfig_GetForwardsByNamespace(t *testing.T) {
|
||||
yamlData := []byte(`contexts:
|
||||
- name: cluster1
|
||||
namespaces:
|
||||
- name: ns1
|
||||
forwards:
|
||||
- resource: pod/app1
|
||||
port: 8080
|
||||
localPort: 8080
|
||||
- resource: pod/app2
|
||||
port: 8081
|
||||
localPort: 8081
|
||||
- name: ns2
|
||||
forwards:
|
||||
- resource: pod/app3
|
||||
port: 9090
|
||||
localPort: 9090
|
||||
`)
|
||||
|
||||
cfg, err := ParseConfig(yamlData)
|
||||
assert.NoError(t, err)
|
||||
|
||||
forwards := cfg.GetForwardsByNamespace("cluster1", "ns1")
|
||||
assert.Len(t, forwards, 2, "should return forwards only from cluster1/ns1")
|
||||
|
||||
forwards2 := cfg.GetForwardsByNamespace("cluster1", "ns2")
|
||||
assert.Len(t, forwards2, 1, "should return forwards only from cluster1/ns2")
|
||||
|
||||
forwards3 := cfg.GetForwardsByNamespace("cluster1", "non-existent")
|
||||
assert.Len(t, forwards3, 0, "should return empty slice for non-existent namespace")
|
||||
}
|
||||
|
||||
func TestForward_SetContext(t *testing.T) {
|
||||
fwd := Forward{
|
||||
Resource: "pod/my-app",
|
||||
|
||||
Reference in New Issue
Block a user