diff --git a/client/pkg/clickhouse/db_client.go b/client/pkg/clickhouse/db_client.go index 8e8a6fe7..b0e279e9 100644 --- a/client/pkg/clickhouse/db_client.go +++ b/client/pkg/clickhouse/db_client.go @@ -543,6 +543,7 @@ func (c *DBClient) InsertKubvizEvent(metrics model.Metrics) { metrics.Event.Reason, metrics.Event.Source.Host, string(eventJson), + metrics.ImageName, formattedFirstTimestamp, formattedLastTimestamp, ); err != nil { diff --git a/client/pkg/clickhouse/statements.go b/client/pkg/clickhouse/statements.go index c248aab3..19e0c377 100644 --- a/client/pkg/clickhouse/statements.go +++ b/client/pkg/clickhouse/statements.go @@ -222,7 +222,7 @@ const InsertKetall DBStatement = "INSERT INTO getall_resources (ClusterName, Nam const InsertOutdated DBStatement = "INSERT INTO outdated_images (ClusterName, Namespace, Pod, CurrentImage, CurrentTag, LatestVersion, VersionsBehind, EventTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" const InsertDepricatedApi DBStatement = "INSERT INTO DeprecatedAPIs (ClusterName, ObjectName, Description, Kind, Deprecated, Scope, EventTime) VALUES (?, ?, ?, ?, ?, ?, ?)" const InsertDeletedApi DBStatement = "INSERT INTO DeletedAPIs (ClusterName, ObjectName, Group, Kind, Version, Name, Deleted, Scope, EventTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)" -const InsertKubvizEvent DBStatement = "INSERT INTO events (ClusterName, Id, EventTime, OpType, Name, Namespace, Kind, Message, Reason, Host, Event, FirstTime, LastTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" +const InsertKubvizEvent DBStatement = "INSERT INTO events (ClusterName, Id, EventTime, OpType, Name, Namespace, Kind, Message, Reason, Host, Event, ImageName, FirstTime, LastTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" const clickhouseExperimental DBStatement = `SET allow_experimental_object_type=1;` const containerGithubTable DBStatement = `CREATE table IF NOT EXISTS container_github(event JSON) ENGINE = MergeTree ORDER BY tuple();` const InsertKubeScore string = "INSERT INTO kubescore(id,clustername,object_name,kind,apiVersion,name,namespace,target_type,description,path,summary,file_name,file_row,EventTime) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)" diff --git a/graphqlserver/graph/generated.go b/graphqlserver/graph/generated.go index ba3f13df..6916e996 100644 --- a/graphqlserver/graph/generated.go +++ b/graphqlserver/graph/generated.go @@ -46,12 +46,27 @@ type DirectiveRoot struct { } type ComplexityRoot struct { + Cluster struct { + Name func(childComplexity int) int + } + + ClusterAPIsCount struct { + ClusterName func(childComplexity int) int + Count func(childComplexity int) int + } + ClusterNamespaceOutdatedCount struct { ClusterName func(childComplexity int) int Namespace func(childComplexity int) int OutdatedCount func(childComplexity int) int } + ClusterNamespaceResourceCount struct { + ClusterName func(childComplexity int) int + Namespace func(childComplexity int) int + ResourceCount func(childComplexity int) int + } + DeletedAPI struct { ClusterName func(childComplexity int) int Deleted func(childComplexity int) int @@ -138,6 +153,10 @@ type ComplexityRoot struct { TargetType func(childComplexity int) int } + Namespace struct { + Name func(childComplexity int) int + } + NamespaceData struct { KubeScores func(childComplexity int) int Namespace func(childComplexity int) int @@ -157,7 +176,10 @@ type ComplexityRoot struct { } Query struct { + AllClusterDeletedAPIsCounts func(childComplexity int) int + AllClusterDeprecatedAPIsCounts func(childComplexity int) int AllClusterNamespaceOutdatedCounts func(childComplexity int) int + AllClusterNamespaceResourceCounts func(childComplexity int) int AllDeletedAPIs func(childComplexity int) int AllDeprecatedAPIs func(childComplexity int) int AllEvents func(childComplexity int) int @@ -277,11 +299,14 @@ type QueryResolver interface { AllKubeScores(ctx context.Context) ([]*model.Kubescore, error) AllTrivyVuls(ctx context.Context) ([]*model.TrivyVul, error) AllTrivyMisconfigs(ctx context.Context) ([]*model.TrivyMisconfig, error) - UniqueClusters(ctx context.Context) ([]string, error) - UniqueNamespaces(ctx context.Context) ([]string, error) + UniqueNamespaces(ctx context.Context) ([]*model.Namespace, error) + UniqueClusters(ctx context.Context) ([]*model.Cluster, error) OutdatedImagesByClusterAndNamespace(ctx context.Context, clusterName string, namespace string) ([]*model.OutdatedImage, error) OutdatedImagesCount(ctx context.Context, clusterName string, namespace string) (int, error) AllClusterNamespaceOutdatedCounts(ctx context.Context) ([]*model.ClusterNamespaceOutdatedCount, error) + AllClusterDeprecatedAPIsCounts(ctx context.Context) ([]*model.ClusterAPIsCount, error) + AllClusterDeletedAPIsCounts(ctx context.Context) ([]*model.ClusterAPIsCount, error) + AllClusterNamespaceResourceCounts(ctx context.Context) ([]*model.ClusterNamespaceResourceCount, error) } type executableSchema struct { @@ -303,6 +328,27 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in _ = ec switch typeName + "." + field { + case "Cluster.name": + if e.complexity.Cluster.Name == nil { + break + } + + return e.complexity.Cluster.Name(childComplexity), true + + case "ClusterAPIsCount.clusterName": + if e.complexity.ClusterAPIsCount.ClusterName == nil { + break + } + + return e.complexity.ClusterAPIsCount.ClusterName(childComplexity), true + + case "ClusterAPIsCount.count": + if e.complexity.ClusterAPIsCount.Count == nil { + break + } + + return e.complexity.ClusterAPIsCount.Count(childComplexity), true + case "ClusterNamespaceOutdatedCount.clusterName": if e.complexity.ClusterNamespaceOutdatedCount.ClusterName == nil { break @@ -324,6 +370,27 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.ClusterNamespaceOutdatedCount.OutdatedCount(childComplexity), true + case "ClusterNamespaceResourceCount.clusterName": + if e.complexity.ClusterNamespaceResourceCount.ClusterName == nil { + break + } + + return e.complexity.ClusterNamespaceResourceCount.ClusterName(childComplexity), true + + case "ClusterNamespaceResourceCount.namespace": + if e.complexity.ClusterNamespaceResourceCount.Namespace == nil { + break + } + + return e.complexity.ClusterNamespaceResourceCount.Namespace(childComplexity), true + + case "ClusterNamespaceResourceCount.resourceCount": + if e.complexity.ClusterNamespaceResourceCount.ResourceCount == nil { + break + } + + return e.complexity.ClusterNamespaceResourceCount.ResourceCount(childComplexity), true + case "DeletedAPI.ClusterName": if e.complexity.DeletedAPI.ClusterName == nil { break @@ -800,6 +867,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Kubescore.TargetType(childComplexity), true + case "Namespace.name": + if e.complexity.Namespace.Name == nil { + break + } + + return e.complexity.Namespace.Name(childComplexity), true + case "NamespaceData.kubeScores": if e.complexity.NamespaceData.KubeScores == nil { break @@ -884,6 +958,20 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.OutdatedImage.VersionsBehind(childComplexity), true + case "Query.allClusterDeletedAPIsCounts": + if e.complexity.Query.AllClusterDeletedAPIsCounts == nil { + break + } + + return e.complexity.Query.AllClusterDeletedAPIsCounts(childComplexity), true + + case "Query.allClusterDeprecatedAPIsCounts": + if e.complexity.Query.AllClusterDeprecatedAPIsCounts == nil { + break + } + + return e.complexity.Query.AllClusterDeprecatedAPIsCounts(childComplexity), true + case "Query.allClusterNamespaceOutdatedCounts": if e.complexity.Query.AllClusterNamespaceOutdatedCounts == nil { break @@ -891,6 +979,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.AllClusterNamespaceOutdatedCounts(childComplexity), true + case "Query.allClusterNamespaceResourceCounts": + if e.complexity.Query.AllClusterNamespaceResourceCounts == nil { + break + } + + return e.complexity.Query.AllClusterNamespaceResourceCounts(childComplexity), true + case "Query.allDeletedAPIs": if e.complexity.Query.AllDeletedAPIs == nil { break @@ -1712,8 +1807,8 @@ func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArg // region **************************** field.gotpl ***************************** -func (ec *executionContext) _ClusterNamespaceOutdatedCount_clusterName(ctx context.Context, field graphql.CollectedField, obj *model.ClusterNamespaceOutdatedCount) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_ClusterNamespaceOutdatedCount_clusterName(ctx, field) +func (ec *executionContext) _Cluster_name(ctx context.Context, field graphql.CollectedField, obj *model.Cluster) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Cluster_name(ctx, field) if err != nil { return graphql.Null } @@ -1726,7 +1821,7 @@ func (ec *executionContext) _ClusterNamespaceOutdatedCount_clusterName(ctx conte }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.ClusterName, nil + return obj.Name, nil }) if err != nil { ec.Error(ctx, err) @@ -1743,9 +1838,9 @@ func (ec *executionContext) _ClusterNamespaceOutdatedCount_clusterName(ctx conte return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_ClusterNamespaceOutdatedCount_clusterName(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Cluster_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "ClusterNamespaceOutdatedCount", + Object: "Cluster", Field: field, IsMethod: false, IsResolver: false, @@ -1756,8 +1851,8 @@ func (ec *executionContext) fieldContext_ClusterNamespaceOutdatedCount_clusterNa return fc, nil } -func (ec *executionContext) _ClusterNamespaceOutdatedCount_namespace(ctx context.Context, field graphql.CollectedField, obj *model.ClusterNamespaceOutdatedCount) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_ClusterNamespaceOutdatedCount_namespace(ctx, field) +func (ec *executionContext) _ClusterAPIsCount_clusterName(ctx context.Context, field graphql.CollectedField, obj *model.ClusterAPIsCount) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ClusterAPIsCount_clusterName(ctx, field) if err != nil { return graphql.Null } @@ -1770,7 +1865,7 @@ func (ec *executionContext) _ClusterNamespaceOutdatedCount_namespace(ctx context }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Namespace, nil + return obj.ClusterName, nil }) if err != nil { ec.Error(ctx, err) @@ -1787,9 +1882,9 @@ func (ec *executionContext) _ClusterNamespaceOutdatedCount_namespace(ctx context return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_ClusterNamespaceOutdatedCount_namespace(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_ClusterAPIsCount_clusterName(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "ClusterNamespaceOutdatedCount", + Object: "ClusterAPIsCount", Field: field, IsMethod: false, IsResolver: false, @@ -1800,8 +1895,8 @@ func (ec *executionContext) fieldContext_ClusterNamespaceOutdatedCount_namespace return fc, nil } -func (ec *executionContext) _ClusterNamespaceOutdatedCount_outdatedCount(ctx context.Context, field graphql.CollectedField, obj *model.ClusterNamespaceOutdatedCount) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_ClusterNamespaceOutdatedCount_outdatedCount(ctx, field) +func (ec *executionContext) _ClusterAPIsCount_count(ctx context.Context, field graphql.CollectedField, obj *model.ClusterAPIsCount) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ClusterAPIsCount_count(ctx, field) if err != nil { return graphql.Null } @@ -1814,7 +1909,7 @@ func (ec *executionContext) _ClusterNamespaceOutdatedCount_outdatedCount(ctx con }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.OutdatedCount, nil + return obj.Count, nil }) if err != nil { ec.Error(ctx, err) @@ -1831,9 +1926,9 @@ func (ec *executionContext) _ClusterNamespaceOutdatedCount_outdatedCount(ctx con return ec.marshalNInt2int(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_ClusterNamespaceOutdatedCount_outdatedCount(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_ClusterAPIsCount_count(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "ClusterNamespaceOutdatedCount", + Object: "ClusterAPIsCount", Field: field, IsMethod: false, IsResolver: false, @@ -1844,8 +1939,8 @@ func (ec *executionContext) fieldContext_ClusterNamespaceOutdatedCount_outdatedC return fc, nil } -func (ec *executionContext) _DeletedAPI_ClusterName(ctx context.Context, field graphql.CollectedField, obj *model.DeletedAPI) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_DeletedAPI_ClusterName(ctx, field) +func (ec *executionContext) _ClusterNamespaceOutdatedCount_clusterName(ctx context.Context, field graphql.CollectedField, obj *model.ClusterNamespaceOutdatedCount) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ClusterNamespaceOutdatedCount_clusterName(ctx, field) if err != nil { return graphql.Null } @@ -1865,16 +1960,19 @@ func (ec *executionContext) _DeletedAPI_ClusterName(ctx context.Context, field g return graphql.Null } if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - res := resTmp.(*string) + res := resTmp.(string) fc.Result = res - return ec.marshalOString2ᚖstring(ctx, field.Selections, res) + return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_DeletedAPI_ClusterName(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_ClusterNamespaceOutdatedCount_clusterName(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "DeletedAPI", + Object: "ClusterNamespaceOutdatedCount", Field: field, IsMethod: false, IsResolver: false, @@ -1885,8 +1983,8 @@ func (ec *executionContext) fieldContext_DeletedAPI_ClusterName(ctx context.Cont return fc, nil } -func (ec *executionContext) _DeletedAPI_ObjectName(ctx context.Context, field graphql.CollectedField, obj *model.DeletedAPI) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_DeletedAPI_ObjectName(ctx, field) +func (ec *executionContext) _ClusterNamespaceOutdatedCount_namespace(ctx context.Context, field graphql.CollectedField, obj *model.ClusterNamespaceOutdatedCount) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ClusterNamespaceOutdatedCount_namespace(ctx, field) if err != nil { return graphql.Null } @@ -1899,23 +1997,26 @@ func (ec *executionContext) _DeletedAPI_ObjectName(ctx context.Context, field gr }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.ObjectName, nil + return obj.Namespace, nil }) if err != nil { ec.Error(ctx, err) return graphql.Null } if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - res := resTmp.(*string) + res := resTmp.(string) fc.Result = res - return ec.marshalOString2ᚖstring(ctx, field.Selections, res) + return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_DeletedAPI_ObjectName(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_ClusterNamespaceOutdatedCount_namespace(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "DeletedAPI", + Object: "ClusterNamespaceOutdatedCount", Field: field, IsMethod: false, IsResolver: false, @@ -1926,8 +2027,8 @@ func (ec *executionContext) fieldContext_DeletedAPI_ObjectName(ctx context.Conte return fc, nil } -func (ec *executionContext) _DeletedAPI_Group(ctx context.Context, field graphql.CollectedField, obj *model.DeletedAPI) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_DeletedAPI_Group(ctx, field) +func (ec *executionContext) _ClusterNamespaceOutdatedCount_outdatedCount(ctx context.Context, field graphql.CollectedField, obj *model.ClusterNamespaceOutdatedCount) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ClusterNamespaceOutdatedCount_outdatedCount(ctx, field) if err != nil { return graphql.Null } @@ -1940,35 +2041,38 @@ func (ec *executionContext) _DeletedAPI_Group(ctx context.Context, field graphql }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Group, nil + return obj.OutdatedCount, nil }) if err != nil { ec.Error(ctx, err) return graphql.Null } if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - res := resTmp.(*string) + res := resTmp.(int) fc.Result = res - return ec.marshalOString2ᚖstring(ctx, field.Selections, res) + return ec.marshalNInt2int(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_DeletedAPI_Group(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_ClusterNamespaceOutdatedCount_outdatedCount(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "DeletedAPI", + Object: "ClusterNamespaceOutdatedCount", Field: field, IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type String does not have child fields") + return nil, errors.New("field of type Int does not have child fields") }, } return fc, nil } -func (ec *executionContext) _DeletedAPI_Kind(ctx context.Context, field graphql.CollectedField, obj *model.DeletedAPI) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_DeletedAPI_Kind(ctx, field) +func (ec *executionContext) _ClusterNamespaceResourceCount_clusterName(ctx context.Context, field graphql.CollectedField, obj *model.ClusterNamespaceResourceCount) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ClusterNamespaceResourceCount_clusterName(ctx, field) if err != nil { return graphql.Null } @@ -1981,23 +2085,26 @@ func (ec *executionContext) _DeletedAPI_Kind(ctx context.Context, field graphql. }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Kind, nil + return obj.ClusterName, nil }) if err != nil { ec.Error(ctx, err) return graphql.Null } if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - res := resTmp.(*string) + res := resTmp.(string) fc.Result = res - return ec.marshalOString2ᚖstring(ctx, field.Selections, res) + return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_DeletedAPI_Kind(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_ClusterNamespaceResourceCount_clusterName(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "DeletedAPI", + Object: "ClusterNamespaceResourceCount", Field: field, IsMethod: false, IsResolver: false, @@ -2008,8 +2115,8 @@ func (ec *executionContext) fieldContext_DeletedAPI_Kind(ctx context.Context, fi return fc, nil } -func (ec *executionContext) _DeletedAPI_Version(ctx context.Context, field graphql.CollectedField, obj *model.DeletedAPI) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_DeletedAPI_Version(ctx, field) +func (ec *executionContext) _ClusterNamespaceResourceCount_namespace(ctx context.Context, field graphql.CollectedField, obj *model.ClusterNamespaceResourceCount) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ClusterNamespaceResourceCount_namespace(ctx, field) if err != nil { return graphql.Null } @@ -2022,23 +2129,26 @@ func (ec *executionContext) _DeletedAPI_Version(ctx context.Context, field graph }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Version, nil + return obj.Namespace, nil }) if err != nil { ec.Error(ctx, err) return graphql.Null } if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - res := resTmp.(*string) + res := resTmp.(string) fc.Result = res - return ec.marshalOString2ᚖstring(ctx, field.Selections, res) + return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_DeletedAPI_Version(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_ClusterNamespaceResourceCount_namespace(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "DeletedAPI", + Object: "ClusterNamespaceResourceCount", Field: field, IsMethod: false, IsResolver: false, @@ -2049,8 +2159,8 @@ func (ec *executionContext) fieldContext_DeletedAPI_Version(ctx context.Context, return fc, nil } -func (ec *executionContext) _DeletedAPI_Name(ctx context.Context, field graphql.CollectedField, obj *model.DeletedAPI) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_DeletedAPI_Name(ctx, field) +func (ec *executionContext) _ClusterNamespaceResourceCount_resourceCount(ctx context.Context, field graphql.CollectedField, obj *model.ClusterNamespaceResourceCount) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ClusterNamespaceResourceCount_resourceCount(ctx, field) if err != nil { return graphql.Null } @@ -2063,35 +2173,38 @@ func (ec *executionContext) _DeletedAPI_Name(ctx context.Context, field graphql. }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Name, nil + return obj.ResourceCount, nil }) if err != nil { ec.Error(ctx, err) return graphql.Null } if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - res := resTmp.(*string) + res := resTmp.(int) fc.Result = res - return ec.marshalOString2ᚖstring(ctx, field.Selections, res) + return ec.marshalNInt2int(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_DeletedAPI_Name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_ClusterNamespaceResourceCount_resourceCount(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "DeletedAPI", + Object: "ClusterNamespaceResourceCount", Field: field, IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type String does not have child fields") + return nil, errors.New("field of type Int does not have child fields") }, } return fc, nil } -func (ec *executionContext) _DeletedAPI_Deleted(ctx context.Context, field graphql.CollectedField, obj *model.DeletedAPI) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_DeletedAPI_Deleted(ctx, field) +func (ec *executionContext) _DeletedAPI_ClusterName(ctx context.Context, field graphql.CollectedField, obj *model.DeletedAPI) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_DeletedAPI_ClusterName(ctx, field) if err != nil { return graphql.Null } @@ -2104,7 +2217,7 @@ func (ec *executionContext) _DeletedAPI_Deleted(ctx context.Context, field graph }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Deleted, nil + return obj.ClusterName, nil }) if err != nil { ec.Error(ctx, err) @@ -2113,26 +2226,26 @@ func (ec *executionContext) _DeletedAPI_Deleted(ctx context.Context, field graph if resTmp == nil { return graphql.Null } - res := resTmp.(*bool) + res := resTmp.(*string) fc.Result = res - return ec.marshalOBoolean2ᚖbool(ctx, field.Selections, res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_DeletedAPI_Deleted(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_DeletedAPI_ClusterName(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "DeletedAPI", Field: field, IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type Boolean does not have child fields") + return nil, errors.New("field of type String does not have child fields") }, } return fc, nil } -func (ec *executionContext) _DeletedAPI_Scope(ctx context.Context, field graphql.CollectedField, obj *model.DeletedAPI) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_DeletedAPI_Scope(ctx, field) +func (ec *executionContext) _DeletedAPI_ObjectName(ctx context.Context, field graphql.CollectedField, obj *model.DeletedAPI) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_DeletedAPI_ObjectName(ctx, field) if err != nil { return graphql.Null } @@ -2145,7 +2258,7 @@ func (ec *executionContext) _DeletedAPI_Scope(ctx context.Context, field graphql }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Scope, nil + return obj.ObjectName, nil }) if err != nil { ec.Error(ctx, err) @@ -2159,7 +2272,7 @@ func (ec *executionContext) _DeletedAPI_Scope(ctx context.Context, field graphql return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_DeletedAPI_Scope(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_DeletedAPI_ObjectName(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "DeletedAPI", Field: field, @@ -2172,8 +2285,8 @@ func (ec *executionContext) fieldContext_DeletedAPI_Scope(ctx context.Context, f return fc, nil } -func (ec *executionContext) _DeletedAPI_EventTime(ctx context.Context, field graphql.CollectedField, obj *model.DeletedAPI) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_DeletedAPI_EventTime(ctx, field) +func (ec *executionContext) _DeletedAPI_Group(ctx context.Context, field graphql.CollectedField, obj *model.DeletedAPI) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_DeletedAPI_Group(ctx, field) if err != nil { return graphql.Null } @@ -2186,7 +2299,7 @@ func (ec *executionContext) _DeletedAPI_EventTime(ctx context.Context, field gra }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.EventTime, nil + return obj.Group, nil }) if err != nil { ec.Error(ctx, err) @@ -2200,7 +2313,7 @@ func (ec *executionContext) _DeletedAPI_EventTime(ctx context.Context, field gra return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_DeletedAPI_EventTime(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_DeletedAPI_Group(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "DeletedAPI", Field: field, @@ -2213,8 +2326,8 @@ func (ec *executionContext) fieldContext_DeletedAPI_EventTime(ctx context.Contex return fc, nil } -func (ec *executionContext) _DeletedAPI_ExpiryDate(ctx context.Context, field graphql.CollectedField, obj *model.DeletedAPI) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_DeletedAPI_ExpiryDate(ctx, field) +func (ec *executionContext) _DeletedAPI_Kind(ctx context.Context, field graphql.CollectedField, obj *model.DeletedAPI) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_DeletedAPI_Kind(ctx, field) if err != nil { return graphql.Null } @@ -2227,7 +2340,7 @@ func (ec *executionContext) _DeletedAPI_ExpiryDate(ctx context.Context, field gr }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.ExpiryDate, nil + return obj.Kind, nil }) if err != nil { ec.Error(ctx, err) @@ -2241,7 +2354,7 @@ func (ec *executionContext) _DeletedAPI_ExpiryDate(ctx context.Context, field gr return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_DeletedAPI_ExpiryDate(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_DeletedAPI_Kind(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "DeletedAPI", Field: field, @@ -2254,8 +2367,8 @@ func (ec *executionContext) fieldContext_DeletedAPI_ExpiryDate(ctx context.Conte return fc, nil } -func (ec *executionContext) _DeprecatedAPI_ClusterName(ctx context.Context, field graphql.CollectedField, obj *model.DeprecatedAPI) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_DeprecatedAPI_ClusterName(ctx, field) +func (ec *executionContext) _DeletedAPI_Version(ctx context.Context, field graphql.CollectedField, obj *model.DeletedAPI) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_DeletedAPI_Version(ctx, field) if err != nil { return graphql.Null } @@ -2268,7 +2381,7 @@ func (ec *executionContext) _DeprecatedAPI_ClusterName(ctx context.Context, fiel }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.ClusterName, nil + return obj.Version, nil }) if err != nil { ec.Error(ctx, err) @@ -2282,9 +2395,9 @@ func (ec *executionContext) _DeprecatedAPI_ClusterName(ctx context.Context, fiel return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_DeprecatedAPI_ClusterName(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_DeletedAPI_Version(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "DeprecatedAPI", + Object: "DeletedAPI", Field: field, IsMethod: false, IsResolver: false, @@ -2295,8 +2408,8 @@ func (ec *executionContext) fieldContext_DeprecatedAPI_ClusterName(ctx context.C return fc, nil } -func (ec *executionContext) _DeprecatedAPI_ObjectName(ctx context.Context, field graphql.CollectedField, obj *model.DeprecatedAPI) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_DeprecatedAPI_ObjectName(ctx, field) +func (ec *executionContext) _DeletedAPI_Name(ctx context.Context, field graphql.CollectedField, obj *model.DeletedAPI) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_DeletedAPI_Name(ctx, field) if err != nil { return graphql.Null } @@ -2309,7 +2422,7 @@ func (ec *executionContext) _DeprecatedAPI_ObjectName(ctx context.Context, field }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.ObjectName, nil + return obj.Name, nil }) if err != nil { ec.Error(ctx, err) @@ -2323,9 +2436,9 @@ func (ec *executionContext) _DeprecatedAPI_ObjectName(ctx context.Context, field return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_DeprecatedAPI_ObjectName(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_DeletedAPI_Name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "DeprecatedAPI", + Object: "DeletedAPI", Field: field, IsMethod: false, IsResolver: false, @@ -2336,8 +2449,8 @@ func (ec *executionContext) fieldContext_DeprecatedAPI_ObjectName(ctx context.Co return fc, nil } -func (ec *executionContext) _DeprecatedAPI_Description(ctx context.Context, field graphql.CollectedField, obj *model.DeprecatedAPI) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_DeprecatedAPI_Description(ctx, field) +func (ec *executionContext) _DeletedAPI_Deleted(ctx context.Context, field graphql.CollectedField, obj *model.DeletedAPI) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_DeletedAPI_Deleted(ctx, field) if err != nil { return graphql.Null } @@ -2350,7 +2463,7 @@ func (ec *executionContext) _DeprecatedAPI_Description(ctx context.Context, fiel }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Description, nil + return obj.Deleted, nil }) if err != nil { ec.Error(ctx, err) @@ -2359,26 +2472,26 @@ func (ec *executionContext) _DeprecatedAPI_Description(ctx context.Context, fiel if resTmp == nil { return graphql.Null } - res := resTmp.(*string) + res := resTmp.(*bool) fc.Result = res - return ec.marshalOString2ᚖstring(ctx, field.Selections, res) + return ec.marshalOBoolean2ᚖbool(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_DeprecatedAPI_Description(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_DeletedAPI_Deleted(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "DeprecatedAPI", + Object: "DeletedAPI", Field: field, IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type String does not have child fields") + return nil, errors.New("field of type Boolean does not have child fields") }, } return fc, nil } -func (ec *executionContext) _DeprecatedAPI_Kind(ctx context.Context, field graphql.CollectedField, obj *model.DeprecatedAPI) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_DeprecatedAPI_Kind(ctx, field) +func (ec *executionContext) _DeletedAPI_Scope(ctx context.Context, field graphql.CollectedField, obj *model.DeletedAPI) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_DeletedAPI_Scope(ctx, field) if err != nil { return graphql.Null } @@ -2391,7 +2504,7 @@ func (ec *executionContext) _DeprecatedAPI_Kind(ctx context.Context, field graph }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Kind, nil + return obj.Scope, nil }) if err != nil { ec.Error(ctx, err) @@ -2405,9 +2518,9 @@ func (ec *executionContext) _DeprecatedAPI_Kind(ctx context.Context, field graph return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_DeprecatedAPI_Kind(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_DeletedAPI_Scope(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "DeprecatedAPI", + Object: "DeletedAPI", Field: field, IsMethod: false, IsResolver: false, @@ -2418,8 +2531,8 @@ func (ec *executionContext) fieldContext_DeprecatedAPI_Kind(ctx context.Context, return fc, nil } -func (ec *executionContext) _DeprecatedAPI_Deprecated(ctx context.Context, field graphql.CollectedField, obj *model.DeprecatedAPI) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_DeprecatedAPI_Deprecated(ctx, field) +func (ec *executionContext) _DeletedAPI_EventTime(ctx context.Context, field graphql.CollectedField, obj *model.DeletedAPI) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_DeletedAPI_EventTime(ctx, field) if err != nil { return graphql.Null } @@ -2432,7 +2545,7 @@ func (ec *executionContext) _DeprecatedAPI_Deprecated(ctx context.Context, field }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Deprecated, nil + return obj.EventTime, nil }) if err != nil { ec.Error(ctx, err) @@ -2441,14 +2554,260 @@ func (ec *executionContext) _DeprecatedAPI_Deprecated(ctx context.Context, field if resTmp == nil { return graphql.Null } - res := resTmp.(*bool) + res := resTmp.(*string) fc.Result = res - return ec.marshalOBoolean2ᚖbool(ctx, field.Selections, res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_DeprecatedAPI_Deprecated(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_DeletedAPI_EventTime(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "DeprecatedAPI", + Object: "DeletedAPI", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _DeletedAPI_ExpiryDate(ctx context.Context, field graphql.CollectedField, obj *model.DeletedAPI) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_DeletedAPI_ExpiryDate(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ExpiryDate, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_DeletedAPI_ExpiryDate(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "DeletedAPI", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _DeprecatedAPI_ClusterName(ctx context.Context, field graphql.CollectedField, obj *model.DeprecatedAPI) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_DeprecatedAPI_ClusterName(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ClusterName, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_DeprecatedAPI_ClusterName(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "DeprecatedAPI", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _DeprecatedAPI_ObjectName(ctx context.Context, field graphql.CollectedField, obj *model.DeprecatedAPI) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_DeprecatedAPI_ObjectName(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ObjectName, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_DeprecatedAPI_ObjectName(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "DeprecatedAPI", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _DeprecatedAPI_Description(ctx context.Context, field graphql.CollectedField, obj *model.DeprecatedAPI) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_DeprecatedAPI_Description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_DeprecatedAPI_Description(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "DeprecatedAPI", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _DeprecatedAPI_Kind(ctx context.Context, field graphql.CollectedField, obj *model.DeprecatedAPI) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_DeprecatedAPI_Kind(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Kind, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_DeprecatedAPI_Kind(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "DeprecatedAPI", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _DeprecatedAPI_Deprecated(ctx context.Context, field graphql.CollectedField, obj *model.DeprecatedAPI) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_DeprecatedAPI_Deprecated(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Deprecated, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*bool) + fc.Result = res + return ec.marshalOBoolean2ᚖbool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_DeprecatedAPI_Deprecated(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "DeprecatedAPI", Field: field, IsMethod: false, IsResolver: false, @@ -4677,8 +5036,8 @@ func (ec *executionContext) fieldContext_Kubescore_expiryDate(ctx context.Contex return fc, nil } -func (ec *executionContext) _NamespaceData_namespace(ctx context.Context, field graphql.CollectedField, obj *model.NamespaceData) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_NamespaceData_namespace(ctx, field) +func (ec *executionContext) _Namespace_name(ctx context.Context, field graphql.CollectedField, obj *model.Namespace) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Namespace_name(ctx, field) if err != nil { return graphql.Null } @@ -4691,7 +5050,7 @@ func (ec *executionContext) _NamespaceData_namespace(ctx context.Context, field }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Namespace, nil + return obj.Name, nil }) if err != nil { ec.Error(ctx, err) @@ -4708,9 +5067,9 @@ func (ec *executionContext) _NamespaceData_namespace(ctx context.Context, field return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_NamespaceData_namespace(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Namespace_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "NamespaceData", + Object: "Namespace", Field: field, IsMethod: false, IsResolver: false, @@ -4721,9 +5080,53 @@ func (ec *executionContext) fieldContext_NamespaceData_namespace(ctx context.Con return fc, nil } -func (ec *executionContext) _NamespaceData_outdatedImages(ctx context.Context, field graphql.CollectedField, obj *model.NamespaceData) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_NamespaceData_outdatedImages(ctx, field) - if err != nil { +func (ec *executionContext) _NamespaceData_namespace(ctx context.Context, field graphql.CollectedField, obj *model.NamespaceData) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_NamespaceData_namespace(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Namespace, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_NamespaceData_namespace(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "NamespaceData", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _NamespaceData_outdatedImages(ctx context.Context, field graphql.CollectedField, obj *model.NamespaceData) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_NamespaceData_outdatedImages(ctx, field) + if err != nil { return graphql.Null } ctx = graphql.WithFieldContext(ctx, fc) @@ -6019,8 +6422,8 @@ func (ec *executionContext) fieldContext_Query_allTrivyMisconfigs(ctx context.Co return fc, nil } -func (ec *executionContext) _Query_uniqueClusters(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Query_uniqueClusters(ctx, field) +func (ec *executionContext) _Query_uniqueNamespaces(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_uniqueNamespaces(ctx, field) if err != nil { return graphql.Null } @@ -6033,7 +6436,7 @@ func (ec *executionContext) _Query_uniqueClusters(ctx context.Context, field gra }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().UniqueClusters(rctx) + return ec.resolvers.Query().UniqueNamespaces(rctx) }) if err != nil { ec.Error(ctx, err) @@ -6045,26 +6448,30 @@ func (ec *executionContext) _Query_uniqueClusters(ctx context.Context, field gra } return graphql.Null } - res := resTmp.([]string) + res := resTmp.([]*model.Namespace) fc.Result = res - return ec.marshalNString2ᚕstringᚄ(ctx, field.Selections, res) + return ec.marshalNNamespace2ᚕᚖgithubᚗcomᚋintelopsᚋkubvizᚋgraphqlserverᚋgraphᚋmodelᚐNamespaceᚄ(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Query_uniqueClusters(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Query_uniqueNamespaces(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "Query", Field: field, IsMethod: true, IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type String does not have child fields") + switch field.Name { + case "name": + return ec.fieldContext_Namespace_name(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Namespace", field.Name) }, } return fc, nil } -func (ec *executionContext) _Query_uniqueNamespaces(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Query_uniqueNamespaces(ctx, field) +func (ec *executionContext) _Query_uniqueClusters(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_uniqueClusters(ctx, field) if err != nil { return graphql.Null } @@ -6077,7 +6484,7 @@ func (ec *executionContext) _Query_uniqueNamespaces(ctx context.Context, field g }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().UniqueNamespaces(rctx) + return ec.resolvers.Query().UniqueClusters(rctx) }) if err != nil { ec.Error(ctx, err) @@ -6089,19 +6496,23 @@ func (ec *executionContext) _Query_uniqueNamespaces(ctx context.Context, field g } return graphql.Null } - res := resTmp.([]string) + res := resTmp.([]*model.Cluster) fc.Result = res - return ec.marshalNString2ᚕstringᚄ(ctx, field.Selections, res) + return ec.marshalNCluster2ᚕᚖgithubᚗcomᚋintelopsᚋkubvizᚋgraphqlserverᚋgraphᚋmodelᚐClusterᚄ(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Query_uniqueNamespaces(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Query_uniqueClusters(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "Query", Field: field, IsMethod: true, IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type String does not have child fields") + switch field.Name { + case "name": + return ec.fieldContext_Cluster_name(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Cluster", field.Name) }, } return fc, nil @@ -6287,6 +6698,158 @@ func (ec *executionContext) fieldContext_Query_allClusterNamespaceOutdatedCounts return fc, nil } +func (ec *executionContext) _Query_allClusterDeprecatedAPIsCounts(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_allClusterDeprecatedAPIsCounts(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().AllClusterDeprecatedAPIsCounts(rctx) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*model.ClusterAPIsCount) + fc.Result = res + return ec.marshalNClusterAPIsCount2ᚕᚖgithubᚗcomᚋintelopsᚋkubvizᚋgraphqlserverᚋgraphᚋmodelᚐClusterAPIsCountᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_allClusterDeprecatedAPIsCounts(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "clusterName": + return ec.fieldContext_ClusterAPIsCount_clusterName(ctx, field) + case "count": + return ec.fieldContext_ClusterAPIsCount_count(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type ClusterAPIsCount", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _Query_allClusterDeletedAPIsCounts(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_allClusterDeletedAPIsCounts(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().AllClusterDeletedAPIsCounts(rctx) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*model.ClusterAPIsCount) + fc.Result = res + return ec.marshalNClusterAPIsCount2ᚕᚖgithubᚗcomᚋintelopsᚋkubvizᚋgraphqlserverᚋgraphᚋmodelᚐClusterAPIsCountᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_allClusterDeletedAPIsCounts(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "clusterName": + return ec.fieldContext_ClusterAPIsCount_clusterName(ctx, field) + case "count": + return ec.fieldContext_ClusterAPIsCount_count(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type ClusterAPIsCount", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _Query_allClusterNamespaceResourceCounts(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_allClusterNamespaceResourceCounts(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().AllClusterNamespaceResourceCounts(rctx) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*model.ClusterNamespaceResourceCount) + fc.Result = res + return ec.marshalNClusterNamespaceResourceCount2ᚕᚖgithubᚗcomᚋintelopsᚋkubvizᚋgraphqlserverᚋgraphᚋmodelᚐClusterNamespaceResourceCountᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_allClusterNamespaceResourceCounts(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "clusterName": + return ec.fieldContext_ClusterNamespaceResourceCount_clusterName(ctx, field) + case "namespace": + return ec.fieldContext_ClusterNamespaceResourceCount_namespace(ctx, field) + case "resourceCount": + return ec.fieldContext_ClusterNamespaceResourceCount_resourceCount(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type ClusterNamespaceResourceCount", field.Name) + }, + } + return fc, nil +} + func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Query___type(ctx, field) if err != nil { @@ -11138,29 +11701,19 @@ func (ec *executionContext) fieldContext___Type_specifiedByURL(ctx context.Conte // region **************************** object.gotpl **************************** -var clusterNamespaceOutdatedCountImplementors = []string{"ClusterNamespaceOutdatedCount"} +var clusterImplementors = []string{"Cluster"} -func (ec *executionContext) _ClusterNamespaceOutdatedCount(ctx context.Context, sel ast.SelectionSet, obj *model.ClusterNamespaceOutdatedCount) graphql.Marshaler { - fields := graphql.CollectFields(ec.OperationContext, sel, clusterNamespaceOutdatedCountImplementors) +func (ec *executionContext) _Cluster(ctx context.Context, sel ast.SelectionSet, obj *model.Cluster) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, clusterImplementors) out := graphql.NewFieldSet(fields) deferred := make(map[string]*graphql.FieldSet) for i, field := range fields { switch field.Name { case "__typename": - out.Values[i] = graphql.MarshalString("ClusterNamespaceOutdatedCount") - case "clusterName": - out.Values[i] = ec._ClusterNamespaceOutdatedCount_clusterName(ctx, field, obj) - if out.Values[i] == graphql.Null { - out.Invalids++ - } - case "namespace": - out.Values[i] = ec._ClusterNamespaceOutdatedCount_namespace(ctx, field, obj) - if out.Values[i] == graphql.Null { - out.Invalids++ - } - case "outdatedCount": - out.Values[i] = ec._ClusterNamespaceOutdatedCount_outdatedCount(ctx, field, obj) + out.Values[i] = graphql.MarshalString("Cluster") + case "name": + out.Values[i] = ec._Cluster_name(ctx, field, obj) if out.Values[i] == graphql.Null { out.Invalids++ } @@ -11187,37 +11740,27 @@ func (ec *executionContext) _ClusterNamespaceOutdatedCount(ctx context.Context, return out } -var deletedAPIImplementors = []string{"DeletedAPI"} +var clusterAPIsCountImplementors = []string{"ClusterAPIsCount"} -func (ec *executionContext) _DeletedAPI(ctx context.Context, sel ast.SelectionSet, obj *model.DeletedAPI) graphql.Marshaler { - fields := graphql.CollectFields(ec.OperationContext, sel, deletedAPIImplementors) +func (ec *executionContext) _ClusterAPIsCount(ctx context.Context, sel ast.SelectionSet, obj *model.ClusterAPIsCount) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, clusterAPIsCountImplementors) out := graphql.NewFieldSet(fields) deferred := make(map[string]*graphql.FieldSet) for i, field := range fields { switch field.Name { case "__typename": - out.Values[i] = graphql.MarshalString("DeletedAPI") - case "ClusterName": - out.Values[i] = ec._DeletedAPI_ClusterName(ctx, field, obj) - case "ObjectName": - out.Values[i] = ec._DeletedAPI_ObjectName(ctx, field, obj) - case "Group": - out.Values[i] = ec._DeletedAPI_Group(ctx, field, obj) - case "Kind": - out.Values[i] = ec._DeletedAPI_Kind(ctx, field, obj) - case "Version": - out.Values[i] = ec._DeletedAPI_Version(ctx, field, obj) - case "Name": - out.Values[i] = ec._DeletedAPI_Name(ctx, field, obj) - case "Deleted": - out.Values[i] = ec._DeletedAPI_Deleted(ctx, field, obj) - case "Scope": - out.Values[i] = ec._DeletedAPI_Scope(ctx, field, obj) - case "EventTime": - out.Values[i] = ec._DeletedAPI_EventTime(ctx, field, obj) - case "ExpiryDate": - out.Values[i] = ec._DeletedAPI_ExpiryDate(ctx, field, obj) + out.Values[i] = graphql.MarshalString("ClusterAPIsCount") + case "clusterName": + out.Values[i] = ec._ClusterAPIsCount_clusterName(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "count": + out.Values[i] = ec._ClusterAPIsCount_count(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -11241,24 +11784,176 @@ func (ec *executionContext) _DeletedAPI(ctx context.Context, sel ast.SelectionSe return out } -var deprecatedAPIImplementors = []string{"DeprecatedAPI"} +var clusterNamespaceOutdatedCountImplementors = []string{"ClusterNamespaceOutdatedCount"} -func (ec *executionContext) _DeprecatedAPI(ctx context.Context, sel ast.SelectionSet, obj *model.DeprecatedAPI) graphql.Marshaler { - fields := graphql.CollectFields(ec.OperationContext, sel, deprecatedAPIImplementors) +func (ec *executionContext) _ClusterNamespaceOutdatedCount(ctx context.Context, sel ast.SelectionSet, obj *model.ClusterNamespaceOutdatedCount) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, clusterNamespaceOutdatedCountImplementors) out := graphql.NewFieldSet(fields) deferred := make(map[string]*graphql.FieldSet) for i, field := range fields { switch field.Name { case "__typename": - out.Values[i] = graphql.MarshalString("DeprecatedAPI") - case "ClusterName": - out.Values[i] = ec._DeprecatedAPI_ClusterName(ctx, field, obj) - case "ObjectName": - out.Values[i] = ec._DeprecatedAPI_ObjectName(ctx, field, obj) - case "Description": - out.Values[i] = ec._DeprecatedAPI_Description(ctx, field, obj) - case "Kind": + out.Values[i] = graphql.MarshalString("ClusterNamespaceOutdatedCount") + case "clusterName": + out.Values[i] = ec._ClusterNamespaceOutdatedCount_clusterName(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "namespace": + out.Values[i] = ec._ClusterNamespaceOutdatedCount_namespace(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "outdatedCount": + out.Values[i] = ec._ClusterNamespaceOutdatedCount_outdatedCount(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var clusterNamespaceResourceCountImplementors = []string{"ClusterNamespaceResourceCount"} + +func (ec *executionContext) _ClusterNamespaceResourceCount(ctx context.Context, sel ast.SelectionSet, obj *model.ClusterNamespaceResourceCount) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, clusterNamespaceResourceCountImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("ClusterNamespaceResourceCount") + case "clusterName": + out.Values[i] = ec._ClusterNamespaceResourceCount_clusterName(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "namespace": + out.Values[i] = ec._ClusterNamespaceResourceCount_namespace(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "resourceCount": + out.Values[i] = ec._ClusterNamespaceResourceCount_resourceCount(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var deletedAPIImplementors = []string{"DeletedAPI"} + +func (ec *executionContext) _DeletedAPI(ctx context.Context, sel ast.SelectionSet, obj *model.DeletedAPI) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, deletedAPIImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("DeletedAPI") + case "ClusterName": + out.Values[i] = ec._DeletedAPI_ClusterName(ctx, field, obj) + case "ObjectName": + out.Values[i] = ec._DeletedAPI_ObjectName(ctx, field, obj) + case "Group": + out.Values[i] = ec._DeletedAPI_Group(ctx, field, obj) + case "Kind": + out.Values[i] = ec._DeletedAPI_Kind(ctx, field, obj) + case "Version": + out.Values[i] = ec._DeletedAPI_Version(ctx, field, obj) + case "Name": + out.Values[i] = ec._DeletedAPI_Name(ctx, field, obj) + case "Deleted": + out.Values[i] = ec._DeletedAPI_Deleted(ctx, field, obj) + case "Scope": + out.Values[i] = ec._DeletedAPI_Scope(ctx, field, obj) + case "EventTime": + out.Values[i] = ec._DeletedAPI_EventTime(ctx, field, obj) + case "ExpiryDate": + out.Values[i] = ec._DeletedAPI_ExpiryDate(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var deprecatedAPIImplementors = []string{"DeprecatedAPI"} + +func (ec *executionContext) _DeprecatedAPI(ctx context.Context, sel ast.SelectionSet, obj *model.DeprecatedAPI) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, deprecatedAPIImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("DeprecatedAPI") + case "ClusterName": + out.Values[i] = ec._DeprecatedAPI_ClusterName(ctx, field, obj) + case "ObjectName": + out.Values[i] = ec._DeprecatedAPI_ObjectName(ctx, field, obj) + case "Description": + out.Values[i] = ec._DeprecatedAPI_Description(ctx, field, obj) + case "Kind": out.Values[i] = ec._DeprecatedAPI_Kind(ctx, field, obj) case "Deprecated": out.Values[i] = ec._DeprecatedAPI_Deprecated(ctx, field, obj) @@ -11572,6 +12267,45 @@ func (ec *executionContext) _Kubescore(ctx context.Context, sel ast.SelectionSet return out } +var namespaceImplementors = []string{"Namespace"} + +func (ec *executionContext) _Namespace(ctx context.Context, sel ast.SelectionSet, obj *model.Namespace) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, namespaceImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Namespace") + case "name": + out.Values[i] = ec._Namespace_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + var namespaceDataImplementors = []string{"NamespaceData"} func (ec *executionContext) _NamespaceData(ctx context.Context, sel ast.SelectionSet, obj *model.NamespaceData) graphql.Marshaler { @@ -11961,7 +12695,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) - case "uniqueClusters": + case "uniqueNamespaces": field := field innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { @@ -11970,7 +12704,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr ec.Error(ctx, ec.Recover(ctx, r)) } }() - res = ec._Query_uniqueClusters(ctx, field) + res = ec._Query_uniqueNamespaces(ctx, field) if res == graphql.Null { atomic.AddUint32(&fs.Invalids, 1) } @@ -11983,7 +12717,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) - case "uniqueNamespaces": + case "uniqueClusters": field := field innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { @@ -11992,7 +12726,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr ec.Error(ctx, ec.Recover(ctx, r)) } }() - res = ec._Query_uniqueNamespaces(ctx, field) + res = ec._Query_uniqueClusters(ctx, field) if res == graphql.Null { atomic.AddUint32(&fs.Invalids, 1) } @@ -12070,6 +12804,72 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) + case "allClusterDeprecatedAPIsCounts": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_allClusterDeprecatedAPIsCounts(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, + func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + } + + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) + case "allClusterDeletedAPIsCounts": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_allClusterDeletedAPIsCounts(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, + func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + } + + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) + case "allClusterNamespaceResourceCounts": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_allClusterNamespaceResourceCounts(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, + func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) case "__type": out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { @@ -12819,6 +13619,114 @@ func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.Se return res } +func (ec *executionContext) marshalNCluster2ᚕᚖgithubᚗcomᚋintelopsᚋkubvizᚋgraphqlserverᚋgraphᚋmodelᚐClusterᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.Cluster) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNCluster2ᚖgithubᚗcomᚋintelopsᚋkubvizᚋgraphqlserverᚋgraphᚋmodelᚐCluster(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalNCluster2ᚖgithubᚗcomᚋintelopsᚋkubvizᚋgraphqlserverᚋgraphᚋmodelᚐCluster(ctx context.Context, sel ast.SelectionSet, v *model.Cluster) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._Cluster(ctx, sel, v) +} + +func (ec *executionContext) marshalNClusterAPIsCount2ᚕᚖgithubᚗcomᚋintelopsᚋkubvizᚋgraphqlserverᚋgraphᚋmodelᚐClusterAPIsCountᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.ClusterAPIsCount) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNClusterAPIsCount2ᚖgithubᚗcomᚋintelopsᚋkubvizᚋgraphqlserverᚋgraphᚋmodelᚐClusterAPIsCount(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalNClusterAPIsCount2ᚖgithubᚗcomᚋintelopsᚋkubvizᚋgraphqlserverᚋgraphᚋmodelᚐClusterAPIsCount(ctx context.Context, sel ast.SelectionSet, v *model.ClusterAPIsCount) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._ClusterAPIsCount(ctx, sel, v) +} + func (ec *executionContext) marshalNClusterNamespaceOutdatedCount2ᚕᚖgithubᚗcomᚋintelopsᚋkubvizᚋgraphqlserverᚋgraphᚋmodelᚐClusterNamespaceOutdatedCountᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.ClusterNamespaceOutdatedCount) graphql.Marshaler { ret := make(graphql.Array, len(v)) var wg sync.WaitGroup @@ -12873,6 +13781,60 @@ func (ec *executionContext) marshalNClusterNamespaceOutdatedCount2ᚖgithubᚗco return ec._ClusterNamespaceOutdatedCount(ctx, sel, v) } +func (ec *executionContext) marshalNClusterNamespaceResourceCount2ᚕᚖgithubᚗcomᚋintelopsᚋkubvizᚋgraphqlserverᚋgraphᚋmodelᚐClusterNamespaceResourceCountᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.ClusterNamespaceResourceCount) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNClusterNamespaceResourceCount2ᚖgithubᚗcomᚋintelopsᚋkubvizᚋgraphqlserverᚋgraphᚋmodelᚐClusterNamespaceResourceCount(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalNClusterNamespaceResourceCount2ᚖgithubᚗcomᚋintelopsᚋkubvizᚋgraphqlserverᚋgraphᚋmodelᚐClusterNamespaceResourceCount(ctx context.Context, sel ast.SelectionSet, v *model.ClusterNamespaceResourceCount) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._ClusterNamespaceResourceCount(ctx, sel, v) +} + func (ec *executionContext) marshalNDeletedAPI2ᚕᚖgithubᚗcomᚋintelopsᚋkubvizᚋgraphqlserverᚋgraphᚋmodelᚐDeletedAPIᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.DeletedAPI) graphql.Marshaler { ret := make(graphql.Array, len(v)) var wg sync.WaitGroup @@ -13227,6 +14189,60 @@ func (ec *executionContext) marshalNKubescore2ᚖgithubᚗcomᚋintelopsᚋkubvi return ec._Kubescore(ctx, sel, v) } +func (ec *executionContext) marshalNNamespace2ᚕᚖgithubᚗcomᚋintelopsᚋkubvizᚋgraphqlserverᚋgraphᚋmodelᚐNamespaceᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.Namespace) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNNamespace2ᚖgithubᚗcomᚋintelopsᚋkubvizᚋgraphqlserverᚋgraphᚋmodelᚐNamespace(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalNNamespace2ᚖgithubᚗcomᚋintelopsᚋkubvizᚋgraphqlserverᚋgraphᚋmodelᚐNamespace(ctx context.Context, sel ast.SelectionSet, v *model.Namespace) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._Namespace(ctx, sel, v) +} + func (ec *executionContext) marshalNNamespaceData2ᚕᚖgithubᚗcomᚋintelopsᚋkubvizᚋgraphqlserverᚋgraphᚋmodelᚐNamespaceDataᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.NamespaceData) graphql.Marshaler { ret := make(graphql.Array, len(v)) var wg sync.WaitGroup @@ -13458,38 +14474,6 @@ func (ec *executionContext) marshalNString2string(ctx context.Context, sel ast.S return res } -func (ec *executionContext) unmarshalNString2ᚕstringᚄ(ctx context.Context, v interface{}) ([]string, error) { - var vSlice []interface{} - if v != nil { - vSlice = graphql.CoerceList(v) - } - var err error - res := make([]string, len(vSlice)) - for i := range vSlice { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) - res[i], err = ec.unmarshalNString2string(ctx, vSlice[i]) - if err != nil { - return nil, err - } - } - return res, nil -} - -func (ec *executionContext) marshalNString2ᚕstringᚄ(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler { - ret := make(graphql.Array, len(v)) - for i := range v { - ret[i] = ec.marshalNString2string(ctx, sel, v[i]) - } - - for _, e := range ret { - if e == graphql.Null { - return graphql.Null - } - } - - return ret -} - func (ec *executionContext) marshalNTrivyImage2ᚕᚖgithubᚗcomᚋintelopsᚋkubvizᚋgraphqlserverᚋgraphᚋmodelᚐTrivyImageᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.TrivyImage) graphql.Marshaler { ret := make(graphql.Array, len(v)) var wg sync.WaitGroup diff --git a/graphqlserver/graph/model/models_gen.go b/graphqlserver/graph/model/models_gen.go index 3f28f8bc..1aff036e 100644 --- a/graphqlserver/graph/model/models_gen.go +++ b/graphqlserver/graph/model/models_gen.go @@ -2,12 +2,27 @@ package model +type Cluster struct { + Name string `json:"name"` +} + +type ClusterAPIsCount struct { + ClusterName string `json:"clusterName"` + Count int `json:"count"` +} + type ClusterNamespaceOutdatedCount struct { ClusterName string `json:"clusterName"` Namespace string `json:"namespace"` OutdatedCount int `json:"outdatedCount"` } +type ClusterNamespaceResourceCount struct { + ClusterName string `json:"clusterName"` + Namespace string `json:"namespace"` + ResourceCount int `json:"resourceCount"` +} + type DeletedAPI struct { ClusterName *string `json:"ClusterName,omitempty"` ObjectName *string `json:"ObjectName,omitempty"` @@ -94,6 +109,10 @@ type Kubescore struct { ExpiryDate *string `json:"expiryDate,omitempty"` } +type Namespace struct { + Name string `json:"name"` +} + type NamespaceData struct { Namespace string `json:"namespace"` OutdatedImages []*OutdatedImage `json:"outdatedImages"` diff --git a/graphqlserver/graph/schema.graphqls b/graphqlserver/graph/schema.graphqls index dc755361..37783b48 100644 --- a/graphqlserver/graph/schema.graphqls +++ b/graphqlserver/graph/schema.graphqls @@ -10,13 +10,35 @@ type Query { allKubeScores: [Kubescore!]! allTrivyVuls: [TrivyVul!]! allTrivyMisconfigs: [TrivyMisconfig!]! - uniqueClusters: [String!]! - uniqueNamespaces: [String!]! + uniqueNamespaces: [Namespace!]! + uniqueClusters: [Cluster!]! outdatedImagesByClusterAndNamespace(clusterName: String!, namespace: String!): [OutdatedImage!]! outdatedImagesCount(clusterName: String!, namespace: String!): Int! allClusterNamespaceOutdatedCounts: [ClusterNamespaceOutdatedCount!]! + allClusterDeprecatedAPIsCounts: [ClusterAPIsCount!]! + allClusterDeletedAPIsCounts: [ClusterAPIsCount!]! + allClusterNamespaceResourceCounts: [ClusterNamespaceResourceCount!]! } +type Namespace { + name: String! +} + +type Cluster { + name: String! +} + +type ClusterNamespaceResourceCount { + clusterName: String! + namespace: String! + resourceCount: Int! +} +type ClusterAPIsCount { + clusterName: String! + count: Int! +} + + type ClusterNamespaceOutdatedCount { clusterName: String! namespace: String! diff --git a/graphqlserver/graph/schema.resolvers.go b/graphqlserver/graph/schema.resolvers.go index e58892de..e6229bc9 100644 --- a/graphqlserver/graph/schema.resolvers.go +++ b/graphqlserver/graph/schema.resolvers.go @@ -395,38 +395,34 @@ func (r *queryResolver) AllTrivyMisconfigs(ctx context.Context) ([]*model.TrivyM return misconfigs, nil } -// UniqueClusters is the resolver for the uniqueClusters field. -func (r *queryResolver) UniqueClusters(ctx context.Context) ([]string, error) { - if r.DB == nil { - return nil, fmt.Errorf("database connection is not initialized") - } - query := `SELECT DISTINCT ClusterName FROM events` - - rows, err := r.DB.QueryContext(ctx, query) +// UniqueNamespaces is the resolver for the uniqueNamespaces field. +func (r *queryResolver) UniqueNamespaces(ctx context.Context) ([]*model.Namespace, error) { + namespaces, err := r.fetchNamespacesFromDatabase(ctx) if err != nil { - return nil, fmt.Errorf("error executing query: %v", err) + return nil, err } - defer rows.Close() - var clusters []string - for rows.Next() { - var cluster string - if err := rows.Scan(&cluster); err != nil { - return nil, fmt.Errorf("error scanning row: %v", err) - } - clusters = append(clusters, cluster) + var namespaceObjects []*model.Namespace + for _, ns := range namespaces { + namespaceObjects = append(namespaceObjects, &model.Namespace{Name: ns}) } - if err := rows.Err(); err != nil { - return nil, fmt.Errorf("error iterating rows: %v", err) + return namespaceObjects, nil +} + +// UniqueClusters is the resolver for the uniqueClusters field. +func (r *queryResolver) UniqueClusters(ctx context.Context) ([]*model.Cluster, error) { + clusters, err := r.fetchClustersFromDatabase(ctx) + if err != nil { + return nil, err } - return clusters, nil -} + var clusterObjects []*model.Cluster + for _, cluster := range clusters { + clusterObjects = append(clusterObjects, &model.Cluster{Name: cluster}) + } -// UniqueNamespaces is the resolver for the uniqueNamespaces field. -func (r *queryResolver) UniqueNamespaces(ctx context.Context) ([]string, error) { - return r.fetchNamespacesFromDatabase(ctx) + return clusterObjects, nil } // OutdatedImagesByClusterAndNamespace is the resolver for the outdatedImagesByClusterAndNamespace field. @@ -524,6 +520,106 @@ func (r *queryResolver) AllClusterNamespaceOutdatedCounts(ctx context.Context) ( return results, nil } +// AllClusterDeprecatedAPIsCounts is the resolver for the allClusterDeprecatedAPIsCounts field. +func (r *queryResolver) AllClusterDeprecatedAPIsCounts(ctx context.Context) ([]*model.ClusterAPIsCount, error) { + if r.DB == nil { + return nil, fmt.Errorf("database connection is not initialized") + } + query := ` + SELECT ClusterName, COUNT(*) as count + FROM DeprecatedAPIs + GROUP BY ClusterName +` + + rows, err := r.DB.QueryContext(ctx, query) + if err != nil { + return nil, fmt.Errorf("error executing query: %v", err) + } + defer rows.Close() + var results []*model.ClusterAPIsCount + for rows.Next() { + var result model.ClusterAPIsCount + if err := rows.Scan(&result.ClusterName, &result.Count); err != nil { + return nil, fmt.Errorf("error scanning row: %v", err) + } + results = append(results, &result) + } + + if err := rows.Err(); err != nil { + return nil, fmt.Errorf("error iterating rows: %v", err) + } + + return results, nil +} + +// AllClusterDeletedAPIsCounts is the resolver for the allClusterDeletedAPIsCounts field. +func (r *queryResolver) AllClusterDeletedAPIsCounts(ctx context.Context) ([]*model.ClusterAPIsCount, error) { + if r.DB == nil { + return nil, fmt.Errorf("database connection is not initialized") + } + + query := ` + SELECT ClusterName, COUNT(*) as count + FROM DeletedAPIs + GROUP BY ClusterName + ` + + rows, err := r.DB.QueryContext(ctx, query) + if err != nil { + return nil, fmt.Errorf("error executing query: %v", err) + } + defer rows.Close() + + var results []*model.ClusterAPIsCount + for rows.Next() { + var result model.ClusterAPIsCount + if err := rows.Scan(&result.ClusterName, &result.Count); err != nil { + return nil, fmt.Errorf("error scanning row: %v", err) + } + results = append(results, &result) + } + + if err := rows.Err(); err != nil { + return nil, fmt.Errorf("error iterating rows: %v", err) + } + + return results, nil +} + +// AllClusterNamespaceResourceCounts is the resolver for the allClusterNamespaceResourceCounts field. +func (r *queryResolver) AllClusterNamespaceResourceCounts(ctx context.Context) ([]*model.ClusterNamespaceResourceCount, error) { + if r.DB == nil { + return nil, fmt.Errorf("database connection is not initialized") + } + + query := ` + SELECT ClusterName, Namespace, COUNT(*) as resourceCount + FROM getall_resources + GROUP BY ClusterName, Namespace + ` + + rows, err := r.DB.QueryContext(ctx, query) + if err != nil { + return nil, fmt.Errorf("error executing query: %v", err) + } + defer rows.Close() + + var results []*model.ClusterNamespaceResourceCount + for rows.Next() { + var result model.ClusterNamespaceResourceCount + if err := rows.Scan(&result.ClusterName, &result.Namespace, &result.ResourceCount); err != nil { + return nil, fmt.Errorf("error scanning row: %v", err) + } + results = append(results, &result) + } + + if err := rows.Err(); err != nil { + return nil, fmt.Errorf("error iterating rows: %v", err) + } + + return results, nil +} + // Query returns QueryResolver implementation. func (r *Resolver) Query() QueryResolver { return &queryResolver{r} } diff --git a/graphqlserver/graph/utils.go b/graphqlserver/graph/utils.go index 23959ee4..01ad5c2d 100644 --- a/graphqlserver/graph/utils.go +++ b/graphqlserver/graph/utils.go @@ -8,6 +8,34 @@ import ( "github.com/intelops/kubviz/graphqlserver/graph/model" ) +func (r *Resolver) fetchClustersFromDatabase(ctx context.Context) ([]string, error) { + if r.DB == nil { + return nil, fmt.Errorf("database connection is not initialized") + } + query := `SELECT DISTINCT ClusterName FROM events` + + rows, err := r.DB.QueryContext(ctx, query) + if err != nil { + return nil, fmt.Errorf("error executing query: %v", err) + } + defer rows.Close() + + var clusters []string + for rows.Next() { + var cluster string + if err := rows.Scan(&cluster); err != nil { + return nil, fmt.Errorf("error scanning row: %v", err) + } + clusters = append(clusters, cluster) + } + + if err := rows.Err(); err != nil { + return nil, fmt.Errorf("error iterating rows: %v", err) + } + + return clusters, nil +} + func (r *Resolver) fetchNamespacesFromDatabase(ctx context.Context) ([]string, error) { if r.DB == nil { return nil, fmt.Errorf("database connection is not initialized") diff --git a/model/metrics.go b/model/metrics.go index 9a462ef1..6e339720 100644 --- a/model/metrics.go +++ b/model/metrics.go @@ -7,4 +7,5 @@ type Metrics struct { Type string Event *v1.Event ClusterName string + ImageName string } diff --git a/sql/000001_events.up.sql b/sql/000001_events.up.sql index a410aaf5..2ba1313f 100644 --- a/sql/000001_events.up.sql +++ b/sql/000001_events.up.sql @@ -10,6 +10,7 @@ CREATE TABLE IF NOT EXISTS events ( Reason String, Host String, Event String, + ImageName String, FirstTime String, LastTime String, ExpiryDate DateTime DEFAULT now() + INTERVAL {{.TTLValue}} {{.TTLUnit}} diff --git a/steps-to-test.txt b/steps-to-test.txt index 8aee4a19..6e2b1af7 100644 --- a/steps-to-test.txt +++ b/steps-to-test.txt @@ -133,3 +133,5 @@ query { ] } } + + ...