Skip to content

Commit

Permalink
nats sdk in ketall kubepug outdated rakees
Browse files Browse the repository at this point in the history
  • Loading branch information
an1l4 committed May 15, 2024
1 parent 22f69ee commit 8d1f910
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions agent/kubviz/k8smetrics_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ func main() {
}
go server.StartServer()
collectAndPublishMetrics := func() {
err := outdated.OutDatedImages(config, js)
err := outdated.OutDatedImages(config, natsCli)
events.LogErr(err)
err = kubepreupgrade.KubePreUpgradeDetector(config, js)
err = kubepreupgrade.KubePreUpgradeDetector(config, natsCli)
events.LogErr(err)
err = ketall.GetAllResources(config, js)
err = ketall.GetAllResources(config, natsCli)
events.LogErr(err)
err = rakkess.RakeesOutput(config, js)
err = rakkess.RakeesOutput(config, natsCli)
events.LogErr(err)
err = trivy.RunTrivySbomScan(config, natsCli)
events.LogErr(err)
Expand Down
10 changes: 5 additions & 5 deletions agent/kubviz/plugins/ketall/ketall.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"go.opentelemetry.io/otel/attribute"

"github.com/intelops/kubviz/model"
"github.com/nats-io/nats.go"
"github.com/intelops/kubviz/pkg/nats/sdk"
log "github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/discovery"
Expand All @@ -22,19 +22,19 @@ import (

var ClusterName string = os.Getenv("CLUSTER_NAME")

func PublishAllResources(result model.Resource, js nats.JetStreamContext) error {
func PublishAllResources(result model.Resource, natsCli *sdk.NATSClient) error {
metrics := result
metrics.ClusterName = ClusterName
metricsJson, _ := json.Marshal(metrics)
_, err := js.Publish(constants.EventSubject_getall_resource, metricsJson)
err := natsCli.Publish(constants.EventSubject_getall_resource, metricsJson)
if err != nil {
return err
}
log.Printf("Metrics with resource %s in the %s namespace has been published", result.Resource, result.Namespace)
return nil
}

func GetAllResources(config *rest.Config, js nats.JetStreamContext) error {
func GetAllResources(config *rest.Config, natsCli *sdk.NATSClient) error {

ctx := context.Background()
tracer := otel.Tracer("ketall")
Expand Down Expand Up @@ -88,7 +88,7 @@ func GetAllResources(config *rest.Config, js nats.JetStreamContext) error {
}

}
err := PublishAllResources(resource, js)
err := PublishAllResources(resource, natsCli)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions agent/kubviz/plugins/kubepreupgrade/kubePreUpgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

"github.com/davecgh/go-spew/spew"
"github.com/intelops/kubviz/model"
"github.com/nats-io/nats.go"
"github.com/intelops/kubviz/pkg/nats/sdk"
log "github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
Expand Down Expand Up @@ -59,11 +59,11 @@ var (
)
var result *model.Result

func publishK8sDepricated_Deleted_Api(result *model.Result, js nats.JetStreamContext) error {
func publishK8sDepricated_Deleted_Api(result *model.Result, natsCli *sdk.NATSClient) error {
for _, deprecatedAPI := range result.DeprecatedAPIs {
deprecatedAPI.ClusterName = ClusterName
deprecatedAPIJson, _ := json.Marshal(deprecatedAPI)
_, err := js.Publish(constants.EventSubject_depricated, deprecatedAPIJson)
err := natsCli.Publish(constants.EventSubject_depricated, deprecatedAPIJson)
if err != nil {
return err
}
Expand All @@ -73,7 +73,7 @@ func publishK8sDepricated_Deleted_Api(result *model.Result, js nats.JetStreamCon
deletedAPI.ClusterName = ClusterName
fmt.Println("deletedAPI", deletedAPI)
deletedAPIJson, _ := json.Marshal(deletedAPI)
_, err := js.Publish(constants.EventSubject_deleted, deletedAPIJson)
err := natsCli.Publish(constants.EventSubject_deleted, deletedAPIJson)
if err != nil {
return err
}
Expand All @@ -83,7 +83,7 @@ func publishK8sDepricated_Deleted_Api(result *model.Result, js nats.JetStreamCon
return nil
}

func KubePreUpgradeDetector(config *rest.Config, js nats.JetStreamContext) error {
func KubePreUpgradeDetector(config *rest.Config, natsCli *sdk.NATSClient) error {

ctx := context.Background()
tracer := otel.Tracer("kubepreupgrade")
Expand All @@ -109,7 +109,7 @@ func KubePreUpgradeDetector(config *rest.Config, js nats.JetStreamContext) error
return err
}
result = getResults(config, kubernetesAPIs)
err = publishK8sDepricated_Deleted_Api(result, js)
err = publishK8sDepricated_Deleted_Api(result, natsCli)
return err
}

Expand Down
14 changes: 7 additions & 7 deletions agent/kubviz/plugins/outdated/outdated.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
"go.opentelemetry.io/otel/attribute"

"github.com/intelops/kubviz/model"
"github.com/nats-io/nats.go"

types "github.com/docker/docker/api/types/registry"
"github.com/genuinetools/reg/registry"
semver "github.com/hashicorp/go-version"
"github.com/intelops/kubviz/pkg/nats/sdk"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -60,7 +60,7 @@ func truncateTagName(tagName string) string {
}
return truncatedTagName
}
func PublishOutdatedImages(out model.CheckResultfinal, js nats.JetStreamContext) error {
func PublishOutdatedImages(out model.CheckResultfinal, natsCli *sdk.NATSClient) error {

ctx := context.Background()
tracer := otel.Tracer("outdated-images")
Expand All @@ -71,15 +71,15 @@ func PublishOutdatedImages(out model.CheckResultfinal, js nats.JetStreamContext)
metrics := out
metrics.ClusterName = ClusterName
metricsJson, _ := json.Marshal(metrics)
_, err := js.Publish(constants.EventSubject_outdated_images, metricsJson)
err := natsCli.Publish(constants.EventSubject_outdated_images, metricsJson)
if err != nil {
return err
}
log.Printf("Metrics with outdated images has been published")
return nil
}

func OutDatedImages(config *rest.Config, js nats.JetStreamContext) error {
func OutDatedImages(config *rest.Config, natsCli *sdk.NATSClient) error {
images, err := ListImages(config)
if err != nil {
log.Println("unable to list images")
Expand All @@ -102,7 +102,7 @@ func OutDatedImages(config *rest.Config, js nats.JetStreamContext) error {
final.LatestVersion = message
final.Namespace = namespace
final.Pod = pod
err := PublishOutdatedImages(final, js)
err := PublishOutdatedImages(final, natsCli)
if err != nil {
return err
}
Expand All @@ -118,7 +118,7 @@ func OutDatedImages(config *rest.Config, js nats.JetStreamContext) error {
final.VersionsBehind = checkResult.VersionsBehind
final.Namespace = namespace
final.Pod = pod
err := PublishOutdatedImages(final, js)
err := PublishOutdatedImages(final, natsCli)
if err != nil {
return err
}
Expand All @@ -135,7 +135,7 @@ func OutDatedImages(config *rest.Config, js nats.JetStreamContext) error {
final.LatestVersion = message
final.Namespace = namespace
final.Pod = pod
err := PublishOutdatedImages(final, js)
err := PublishOutdatedImages(final, natsCli)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions agent/kubviz/plugins/rakkess/rakees_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"go.opentelemetry.io/otel/attribute"

"github.com/intelops/kubviz/model"
"github.com/nats-io/nats.go"
"github.com/intelops/kubviz/pkg/nats/sdk"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
Expand All @@ -37,7 +37,7 @@ func accessToOutcome(access Access) (Outcome, error) {
}
}

func RakeesOutput(config *rest.Config, js nats.JetStreamContext) error {
func RakeesOutput(config *rest.Config, natsCli *sdk.NATSClient) error {

ctx := context.Background()
tracer := otel.Tracer("rakees")
Expand Down Expand Up @@ -96,7 +96,7 @@ func RakeesOutput(config *rest.Config, js nats.JetStreamContext) error {
Update: HumanreadableAccessCode(updateOutcome),
}
metricsJson, _ := json.Marshal(metrics)
_, err = js.Publish(constants.EventSubject_rakees, metricsJson)
err = natsCli.Publish(constants.EventSubject_rakees, metricsJson)
if err != nil {
return err
}
Expand Down

0 comments on commit 8d1f910

Please sign in to comment.