Skip to content

Commit

Permalink
new uniqueNamespaces handler with clustername filter
Browse files Browse the repository at this point in the history
  • Loading branch information
vijeyash1 committed Feb 20, 2024
1 parent c751564 commit 4bafdee
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 207 deletions.
32 changes: 16 additions & 16 deletions client/pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package config

type Config struct {
NatsAddress string `envconfig:"NATS_ADDRESS"`
NatsToken string `envconfig:"NATS_TOKEN"`
DbPort int `envconfig:"DB_PORT"`
DBAddress string `envconfig:"DB_ADDRESS"`
ClickHouseUsername string `envconfig:"CLICKHOUSE_USERNAME"`
ClickHousePassword string `envconfig:"CLICKHOUSE_PASSWORD"`
KetallConsumer string `envconfig:"KETALL_EVENTS_CONSUMER" required:"true"`
RakeesConsumer string `envconfig:"RAKEES_METRICS_CONSUMER" required:"true"`
OutdatedConsumer string `envconfig:"OUTDATED_EVENTS_CONSUMER" required:"true"`
DeprecatedConsumer string `envconfig:"DEPRECATED_API_CONSUMER" required:"true"`
DeletedConsumer string `envconfig:"DELETED_API_CONSUMER" required:"true"`
KubvizConsumer string `envconfig:"KUBVIZ_EVENTS_CONSUMER" required:"true"`
KubscoreConsumer string `envconfig:"KUBSCORE_CONSUMER" required:"true"`
TrivyConsumer string `envconfig:"TRIVY_CONSUMER" required:"true"`
TrivyImageConsumer string `envconfig:"TRIVY_IMAGE_CONSUMER" required:"true"`
TrivySbomConsumer string `envconfig:"TRIVY_SBOM_CONSUMER" required:"true"`
NatsAddress string `envconfig:"NATS_ADDRESS"`
NatsToken string `envconfig:"NATS_TOKEN"`
DbPort int `envconfig:"DB_PORT"`
DBAddress string `envconfig:"DB_ADDRESS"`
ClickHouseUsername string `envconfig:"CLICKHOUSE_USERNAME"`
ClickHousePassword string `envconfig:"CLICKHOUSE_PASSWORD"`
KetallConsumer string `envconfig:"KETALL_EVENTS_CONSUMER" required:"true"`
RakeesConsumer string `envconfig:"RAKEES_METRICS_CONSUMER" required:"true"`
OutdatedConsumer string `envconfig:"OUTDATED_EVENTS_CONSUMER" required:"true"`
DeprecatedConsumer string `envconfig:"DEPRECATED_API_CONSUMER" required:"true"`
DeletedConsumer string `envconfig:"DELETED_API_CONSUMER" required:"true"`
KubvizConsumer string `envconfig:"KUBVIZ_EVENTS_CONSUMER" required:"true"`
KubscoreConsumer string `envconfig:"KUBSCORE_CONSUMER" required:"true"`
TrivyConsumer string `envconfig:"TRIVY_CONSUMER" required:"true"`
TrivyImageConsumer string `envconfig:"TRIVY_IMAGE_CONSUMER" required:"true"`
TrivySbomConsumer string `envconfig:"TRIVY_SBOM_CONSUMER" required:"true"`
KuberhealthyConsumer string `envconfig:"KUBERHEALTHY_CONSUMER" required:"true"`
}
178 changes: 35 additions & 143 deletions graphqlserver/graph/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions graphqlserver/graph/schema.graphqls
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
type Query {
allNamespaceData: [NamespaceData!]!
allEvents: [Event!]!
allRakkess: [Rakkess!]!
allDeprecatedAPIs: [DeprecatedAPI!]!
Expand All @@ -10,7 +9,7 @@ type Query {
allKubeScores: [Kubescore!]!
allTrivyVuls: [TrivyVul!]!
allTrivyMisconfigs: [TrivyMisconfig!]!
uniqueNamespaces: [Namespace!]!
uniqueNamespaces(clusterName: String!): [Namespace!]!
uniqueClusters: [Cluster!]!
outdatedImagesByClusterAndNamespace(clusterName: String!, namespace: String!): [OutdatedImage!]!
outdatedImagesCount(clusterName: String!, namespace: String!): Int!
Expand Down
45 changes: 2 additions & 43 deletions graphqlserver/graph/schema.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions graphqlserver/graph/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ func (r *Resolver) fetchClustersFromDatabase(ctx context.Context) ([]string, err
return clusters, nil
}

func (r *Resolver) fetchNamespacesFromDatabase(ctx context.Context) ([]string, error) {
func (r *Resolver) fetchNamespacesFromDatabase(ctx context.Context, clusterName string) ([]string, error) {
if r.DB == nil {
return nil, fmt.Errorf("database connection is not initialized")
}
query := `SELECT DISTINCT Namespace FROM events`
// Include the cluster name in the WHERE clause to filter namespaces by cluster
query := `SELECT DISTINCT Namespace FROM events WHERE ClusterName = ?`

rows, err := r.DB.QueryContext(ctx, query)
rows, err := r.DB.QueryContext(ctx, query, clusterName)
if err != nil {
return nil, fmt.Errorf("error executing query: %v", err)
}
Expand Down

0 comments on commit 4bafdee

Please sign in to comment.