Skip to content

Commit

Permalink
add helm client
Browse files Browse the repository at this point in the history
  • Loading branch information
AdheipSingh committed Nov 28, 2024
1 parent 290a4d5 commit 183a1ef
Show file tree
Hide file tree
Showing 7 changed files with 933 additions and 39 deletions.
16 changes: 14 additions & 2 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,21 @@ var AnalyzeCmd = &cobra.Command{
s.Start()

client := internalHTTP.DefaultClient(&DefaultProfile)
query := `with distinct_name as (select distinct(\"involvedObject_name\") as name from \"k8s-events\" where reason ilike '%kill%' or reason ilike '%fail%' or reason ilike '%back%') select reason, message, \"involvedObject_name\", \"involvedObject_namespace\", \"reportingComponent\", timestamp from \"k8s-events\" as t1 join distinct_name t2 on t1.\"involvedObject_name\" = t2.name order by timestamp`
query := `with distinct_name as (select distinct(\"involvedObject_name\") as name from \"k8s-events\") select reason, message, \"involvedObject_name\", \"involvedObject_namespace\", \"reportingComponent\", timestamp from \"k8s-events\" as t1 join distinct_name t2 on t1.\"involvedObject_name\" = t2.name order by timestamp`

allData, err := duckdb.QueryPb(&client, query, "2024-11-11T00:00:00+00:00", "2024-11-27T00:00:00+00:00")
endTime := time.Now().UTC()
startTime := endTime.Add(-5 * time.Hour)

// Format the timestamps for the query
startTimeStr := startTime.Format(time.RFC3339)
endTimeStr := endTime.Format(time.RFC3339)

allData, err := duckdb.QueryPb(&client, query, startTimeStr, endTimeStr)

if allData == "" {
return fmt.Errorf("error no data found")
}
fmt.Println("data", allData)
s.Stop()
if err != nil {
log.Printf(red+"Error querying data in Parseable: %v\n"+reset, err)
Expand Down
114 changes: 90 additions & 24 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,98 @@

package cmd

// import (
// "fmt"
// "log"
// "os"
// "sync"
// "time"
import (
"log"
"pb/pkg/helm"

// internalHTTP "pb/pkg/http"
"github.com/spf13/cobra"
)

// "github.com/briandowns/spinner"
var GenerateK8sCmd = &cobra.Command{
Use: "k8s-events",
Short: "Generate k8s events on your k8s cluster by deploying apps in different states.",
Example: "pb generate k8s events",
RunE: func(cmd *cobra.Command, args []string) error {
apps := []helm.Helm{
{
ReleaseName: "ingress-nginx",
Namespace: "pb-ingress",
RepoName: "ingress-nginx",
RepoUrl: "https://kubernetes.github.io/ingress-nginx",
ChartName: "ingress-nginx",
Version: "4.0.3", // Example version, adjust as needed
},
{
ReleaseName: "prometheus",
Namespace: "pb-monitoring",
RepoName: "prometheus-community",
RepoUrl: "https://prometheus-community.github.io/helm-charts",
ChartName: "prometheus",
Version: "15.0.0",
},
{
ReleaseName: "grafana",
Namespace: "pb-grafana",
RepoName: "grafana",
RepoUrl: "https://grafana.github.io/helm-charts",
ChartName: "grafana",
Version: "6.16.0",
},
{
ReleaseName: "postgres",
Namespace: "pb-db",
RepoName: "bitnami",
RepoUrl: "https://charts.bitnami.com/bitnami",
ChartName: "postgresql",
Version: "11.6.15",
},
}

// "pb/pkg/analyze/anthropic"
// "pb/pkg/analyze/duckdb"
// "pb/pkg/analyze/k8s"
// "pb/pkg/analyze/ollama"
// "pb/pkg/analyze/openai"
for _, app := range apps {
log.Printf("Deploying %s...", app.ReleaseName)
if err := helm.Apply(app); err != nil {
log.Printf("Failed to deploy %s: %v", app.ReleaseName, err)
return err
}
log.Printf("%s deployed successfully.", app.ReleaseName)
}
return nil
},
}

// _ "github.com/marcboeker/go-duckdb"
// "github.com/spf13/cobra"
// )
var GenerateK8sUninstallCmd = &cobra.Command{
Use: "k8s-uninstall",
Short: "Uninstall Helm releases and generate Kubernetes events.",
Example: "pb generate k8s uninstall",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
apps := []helm.Helm{
{
ReleaseName: "ingress-nginx",
Namespace: "pb-ingress",
},
{
ReleaseName: "prometheus",
Namespace: "pb-monitoring",
},
{
ReleaseName: "grafana",
Namespace: "pb-grafana",
},
{
ReleaseName: "postgres",
Namespace: "pb-db",
},
}

// var GenerateCmd = &cobra.Command{
// Use: "k8s",
// Short: "Generate k8s events on your k8s cluster by deploying apps in different states.",
// Example: "pb generate k8s events",
// Args: cobra.ExactArgs(1),
// RunE: func(cmd *cobra.Command, args []string) error {
// }
// }
for _, app := range apps {
log.Printf("Uninstalling %s...", app.ReleaseName)
if err := helm.DeleteRelease(app.ReleaseName, app.Namespace); err != nil {
log.Printf("Failed to uninstall %s: %v", app.ReleaseName, err)
return err
}
log.Printf("%s uninstalled successfully.", app.ReleaseName)
}
return nil
},
}
95 changes: 92 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,58 +11,139 @@ require (
github.com/charmbracelet/bubbletea v0.26.6
github.com/charmbracelet/lipgloss v0.12.1
github.com/dustin/go-humanize v1.0.1
github.com/gofrs/flock v0.12.1
github.com/manifoldco/promptui v0.9.0
github.com/marcboeker/go-duckdb v1.8.3
github.com/oklog/ulid/v2 v2.1.0
github.com/pkg/errors v0.9.1
github.com/spf13/pflag v1.0.5
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0
golang.org/x/term v0.25.0
google.golang.org/grpc v1.67.1
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
helm.sh/helm/v3 v3.16.3
k8s.io/apimachinery v0.31.3
k8s.io/client-go v0.31.3
)

require (
dario.cat/mergo v1.0.1 // indirect
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.3.0 // indirect
github.com/Masterminds/sprig/v3 v3.3.0 // indirect
github.com/Masterminds/squirrel v1.5.4 // indirect
github.com/apache/arrow-go/v18 v18.0.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/charmbracelet/x/ansi v0.1.4 // indirect
github.com/charmbracelet/x/input v0.1.0 // indirect
github.com/charmbracelet/x/term v0.1.1 // indirect
github.com/charmbracelet/x/windows v0.1.0 // indirect
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/containerd/containerd v1.7.23 // indirect
github.com/containerd/errdefs v0.3.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect
github.com/cyphar/filepath-securejoin v0.3.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/cli v25.0.1+incompatible // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker v25.0.6+incompatible // indirect
github.com/docker/docker-credential-helpers v0.7.0 // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-metrics v0.0.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/evanphx/json-patch v5.9.0+incompatible // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-gorp/gorp/v3 v3.1.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/flatbuffers v24.3.25+incompatible // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gosuri/uitable v0.0.4 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/huandu/xstrings v1.5.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmoiron/sqlx v1.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/moby/locker v1.0.1 // indirect
github.com/moby/spdystream v0.4.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rubenv/sql-migrate v1.7.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
Expand All @@ -71,13 +152,21 @@ require (
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.31.3 // indirect
k8s.io/apiextensions-apiserver v0.31.1 // indirect
k8s.io/apiserver v0.31.1 // indirect
k8s.io/cli-runtime v0.31.1 // indirect
k8s.io/component-base v0.31.1 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/kubectl v0.31.1 // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
oras.land/oras-go v1.2.5 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.17.2 // indirect
sigs.k8s.io/kustomize/kyaml v0.17.1 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Expand All @@ -100,7 +189,7 @@ require (
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/cobra v1.7.0
github.com/spf13/cobra v1.8.1
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
Expand Down
Loading

0 comments on commit 183a1ef

Please sign in to comment.