fix(kubernetes/cli): unexport a field BE-12259 (#1228)

pull/12854/merge
andres-portainer 2025-09-18 14:39:38 -03:00 committed by GitHub
parent 2e7acc73d8
commit 290374f6fc
8 changed files with 38 additions and 23 deletions

View File

@ -149,7 +149,7 @@ func (kcl *KubeClient) GetIsKubeAdmin() bool {
kcl.mu.Lock()
defer kcl.mu.Unlock()
return kcl.IsKubeAdmin
return kcl.isKubeAdmin
}
// UpdateIsKubeAdmin sets whether the kube client is admin
@ -157,7 +157,7 @@ func (kcl *KubeClient) SetIsKubeAdmin(isKubeAdmin bool) {
kcl.mu.Lock()
defer kcl.mu.Unlock()
kcl.IsKubeAdmin = isKubeAdmin
kcl.isKubeAdmin = isKubeAdmin
}
// GetClientNonAdminNamespaces retrieves non-admin namespaces
@ -165,7 +165,7 @@ func (kcl *KubeClient) GetClientNonAdminNamespaces() []string {
kcl.mu.Lock()
defer kcl.mu.Unlock()
return kcl.NonAdminNamespaces
return kcl.nonAdminNamespaces
}
// UpdateClientNonAdminNamespaces sets the client non admin namespace list
@ -173,5 +173,5 @@ func (kcl *KubeClient) SetClientNonAdminNamespaces(nonAdminNamespaces []string)
kcl.mu.Lock()
defer kcl.mu.Unlock()
kcl.NonAdminNamespaces = nonAdminNamespaces
kcl.nonAdminNamespaces = nonAdminNamespaces
}

View File

@ -312,7 +312,7 @@ func TestGetApplications(t *testing.T) {
kubeClient := &KubeClient{
cli: fakeClient,
instanceID: "test-instance",
IsKubeAdmin: true,
isKubeAdmin: true,
}
// Test cases
@ -387,8 +387,8 @@ func TestGetApplications(t *testing.T) {
kubeClient := &KubeClient{
cli: fakeClient,
instanceID: "test-instance",
IsKubeAdmin: false,
NonAdminNamespaces: []string{namespace1},
isKubeAdmin: false,
nonAdminNamespaces: []string{namespace1},
}
// Test that only resources from allowed namespace are returned
@ -447,7 +447,7 @@ func TestGetApplications(t *testing.T) {
kubeClient := &KubeClient{
cli: fakeClient,
instanceID: "test-instance",
IsKubeAdmin: true,
isKubeAdmin: true,
}
// Test filtering by node name

View File

@ -42,8 +42,8 @@ type (
cli kubernetes.Interface
instanceID string
mu sync.Mutex
IsKubeAdmin bool
NonAdminNamespaces []string
isKubeAdmin bool
nonAdminNamespaces []string
}
)
@ -180,8 +180,8 @@ func (factory *ClientFactory) CreateKubeClientFromKubeConfig(clusterID string, k
return &KubeClient{
cli: cli,
instanceID: factory.instanceID,
IsKubeAdmin: IsKubeAdmin,
NonAdminNamespaces: NonAdminNamespaces,
isKubeAdmin: IsKubeAdmin,
nonAdminNamespaces: NonAdminNamespaces,
}, nil
}
@ -194,7 +194,7 @@ func (factory *ClientFactory) createCachedPrivilegedKubeClient(endpoint *portain
return &KubeClient{
cli: cli,
instanceID: factory.instanceID,
IsKubeAdmin: true,
isKubeAdmin: true,
}, nil
}

View File

@ -16,7 +16,7 @@ import (
// GetClusterRoles gets all the clusterRoles for at the cluster level in a k8s endpoint.
// It returns a list of K8sClusterRole objects.
func (kcl *KubeClient) GetClusterRoles() ([]models.K8sClusterRole, error) {
if kcl.IsKubeAdmin {
if kcl.GetIsKubeAdmin() {
return kcl.fetchClusterRoles()
}

View File

@ -18,7 +18,7 @@ func (kcl *KubeClient) TestFetchCronJobs(t *testing.T) {
t.Run("admin client can fetch Cron Jobs from all namespaces", func(t *testing.T) {
kcl.cli = kfake.NewSimpleClientset()
kcl.instanceID = "test"
kcl.IsKubeAdmin = true
kcl.isKubeAdmin = true
cronJobs, err := kcl.GetCronJobs("")
if err != nil {
@ -31,7 +31,7 @@ func (kcl *KubeClient) TestFetchCronJobs(t *testing.T) {
t.Run("non-admin client can fetch Cron Jobs from the default namespace only", func(t *testing.T) {
kcl.cli = kfake.NewSimpleClientset()
kcl.instanceID = "test"
kcl.IsKubeAdmin = false
kcl.isKubeAdmin = false
kcl.SetClientNonAdminNamespaces([]string{"default"})
cronJobs, err := kcl.GetCronJobs("")

View File

@ -19,7 +19,7 @@ func TestGetEvents(t *testing.T) {
kcl := &KubeClient{
cli: kfake.NewSimpleClientset(),
instanceID: "instance",
IsKubeAdmin: true,
isKubeAdmin: true,
}
event := corev1.Event{
@ -47,8 +47,8 @@ func TestGetEvents(t *testing.T) {
kcl := &KubeClient{
cli: kfake.NewSimpleClientset(),
instanceID: "instance",
IsKubeAdmin: false,
NonAdminNamespaces: []string{"nonAdmin"},
isKubeAdmin: false,
nonAdminNamespaces: []string{"nonAdmin"},
}
event := corev1.Event{
@ -77,8 +77,8 @@ func TestGetEvents(t *testing.T) {
kcl := &KubeClient{
cli: kfake.NewSimpleClientset(),
instanceID: "instance",
IsKubeAdmin: false,
NonAdminNamespaces: []string{"nonAdmin"},
isKubeAdmin: false,
nonAdminNamespaces: []string{"nonAdmin"},
}
event := corev1.Event{

View File

@ -21,7 +21,7 @@ func (kcl *KubeClient) TestFetchJobs(t *testing.T) {
t.Run("admin client can fetch jobs from all namespaces", func(t *testing.T) {
kcl.cli = kfake.NewSimpleClientset()
kcl.instanceID = "test"
kcl.IsKubeAdmin = true
kcl.isKubeAdmin = true
jobs, err := kcl.GetJobs("", false)
if err != nil {
@ -34,7 +34,7 @@ func (kcl *KubeClient) TestFetchJobs(t *testing.T) {
t.Run("non-admin client can fetch jobs from the default namespace only", func(t *testing.T) {
kcl.cli = kfake.NewSimpleClientset()
kcl.instanceID = "test"
kcl.IsKubeAdmin = false
kcl.isKubeAdmin = false
kcl.SetClientNonAdminNamespaces([]string{"default"})
jobs, err := kcl.GetJobs("", false)

View File

@ -0,0 +1,15 @@
package cli
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestGetResourceQuotas(t *testing.T) {
kcl := &KubeClient{}
resourceQuotas, err := kcl.GetResourceQuotas("default")
require.NoError(t, err)
require.Empty(t, resourceQuotas)
}