Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new uniqueNamespaces handler with clustername filter #327

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading