Skip to content

Commit

Permalink
fix get all command
Browse files Browse the repository at this point in the history
  • Loading branch information
thirdeyenick committed Jul 25, 2024
1 parent 4ac2ea7 commit e6843a8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
19 changes: 18 additions & 1 deletion get/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import (
"strings"
"text/tabwriter"

infrastructure "github.com/ninech/apis/infrastructure/v1alpha1"
management "github.com/ninech/apis/management/v1alpha1"
meta "github.com/ninech/apis/meta/v1alpha1"
"github.com/ninech/nctl/api"
"github.com/ninech/nctl/internal/format"
kerrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -86,7 +88,9 @@ func (cmd *allCmd) getProjectContent(ctx context.Context, client *api.Client, pr
// types we handle them as warnings to be able to
// return as many resources as we can
if err := client.List(ctx, u, runtimeclient.InNamespace(project)); err != nil {
warnings = append(warnings, err.Error())
if !kerrors.IsForbidden(err) {
warnings = append(warnings, err.Error())
}
continue
}
// we convert to a list of pointers so that we can
Expand Down Expand Up @@ -159,12 +163,25 @@ OUTER:
return result, nil
}

func excludeListType(gvk schema.GroupVersionKind) bool {
// ClusterData is a non-namespaced resource and used to allow
// connecting to deplo.io application replicas.
if strings.EqualFold(gvk.Kind, infrastructure.ClusterDataKind+"list") &&
strings.EqualFold(gvk.Group, infrastructure.Group) {
return true
}
return false
}

func nineListTypes(s *runtime.Scheme) []schema.GroupVersionKind {
var lists []schema.GroupVersionKind
for gvk := range s.AllKnownTypes() {
if !strings.HasSuffix(strings.ToLower(gvk.Kind), "list") {
continue
}
if excludeListType(gvk) {
continue
}
if strings.HasSuffix(strings.ToLower(gvk.Group), "nine.ch") {
lists = append(lists, gvk)
}
Expand Down
32 changes: 32 additions & 0 deletions get/all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,19 @@ staging melon Release apps.nine.ch
kinds: []string{"jackofalltrades"},
errorExpected: true,
},
"excluded list kinds are not shown": {
projects: test.Projects(organization, "dev"),
objects: []client.Object{
testApplication("banana", "dev"), testRelease("pear", "dev"),
testClusterData(),
},
outputFormat: full,
allProjects: true,
output: `PROJECT NAME KIND GROUP
dev banana Application apps.nine.ch
dev pear Release apps.nine.ch
`,
},
} {
t.Run(name, func(t *testing.T) {
testCase := testCase
Expand Down Expand Up @@ -284,3 +297,22 @@ func testCluster(name, project string) *infra.KubernetesCluster {
Spec: infra.KubernetesClusterSpec{},
}
}

func testClusterData() *infra.ClusterData {
return &infra.ClusterData{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
},
TypeMeta: metav1.TypeMeta{
Kind: infra.ClusterDataKind,
APIVersion: infra.SchemeGroupVersion.String(),
},
Spec: infra.ClusterDataSpec{
ForProvider: infra.ClusterDataParameters{
ClusterReference: meta.Reference{
Name: "test",
},
},
},
}
}

0 comments on commit e6843a8

Please sign in to comment.