mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-09-20 18:58:47 +00:00
feat: add ClusterServiceVersion, Subscription, InstallPlan, OperatorGroup, and CatalogSource analyzers (#1564)
Signed-off-by: Bruno Andrade <bruno.balint@gmail.com>
This commit is contained in:
70
pkg/analyzer/operatorgroup_test.go
Normal file
70
pkg/analyzer/operatorgroup_test.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package analyzer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/k8sgpt-ai/k8sgpt/pkg/common"
|
||||
"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
dynamicfake "k8s.io/client-go/dynamic/fake"
|
||||
)
|
||||
|
||||
func TestOperatorGroupAnalyzer(t *testing.T) {
|
||||
og1 := &unstructured.Unstructured{
|
||||
Object: map[string]any{
|
||||
"apiVersion": "operators.coreos.com/v1",
|
||||
"kind": "OperatorGroup",
|
||||
"metadata": map[string]any{
|
||||
"name": "og-1",
|
||||
"namespace": "ns-a",
|
||||
},
|
||||
},
|
||||
}
|
||||
og2 := &unstructured.Unstructured{
|
||||
Object: map[string]any{
|
||||
"apiVersion": "operators.coreos.com/v1",
|
||||
"kind": "OperatorGroup",
|
||||
"metadata": map[string]any{
|
||||
"name": "og-2",
|
||||
"namespace": "ns-a",
|
||||
},
|
||||
},
|
||||
}
|
||||
og3 := &unstructured.Unstructured{
|
||||
Object: map[string]any{
|
||||
"apiVersion": "operators.coreos.com/v1",
|
||||
"kind": "OperatorGroup",
|
||||
"metadata": map[string]any{
|
||||
"name": "og-3",
|
||||
"namespace": "ns-b",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
listKinds := map[schema.GroupVersionResource]string{
|
||||
{Group: "operators.coreos.com", Version: "v1", Resource: "operatorgroups"}: "OperatorGroupList",
|
||||
}
|
||||
|
||||
scheme := runtime.NewScheme()
|
||||
dc := dynamicfake.NewSimpleDynamicClientWithCustomListKinds(scheme, listKinds, og1, og2, og3)
|
||||
|
||||
a := common.Analyzer{
|
||||
Context: context.TODO(),
|
||||
Client: &kubernetes.Client{DynamicClient: dc},
|
||||
}
|
||||
|
||||
res, err := (OperatorGroupAnalyzer{}).Analyze(a)
|
||||
if err != nil {
|
||||
t.Fatalf("Analyze error: %v", err)
|
||||
}
|
||||
|
||||
if len(res) != 1 {
|
||||
t.Fatalf("expected 1 result for ns-a overlap, got %d", len(res))
|
||||
}
|
||||
if res[0].Kind != "OperatorGroup" || res[0].Name != "ns-a" {
|
||||
t.Fatalf("unexpected result: %#v", res[0])
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user