Skip to content

Commit

Permalink
Fix some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyo committed Dec 20, 2023
1 parent 5de20a7 commit afd287e
Show file tree
Hide file tree
Showing 14 changed files with 0 additions and 31 deletions.
4 changes: 0 additions & 4 deletions crons.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const (
// by checking the job status to determine if the job just created pod (job starting)
// or if the job exited
func runSentryCronsCheckin(ctx context.Context, job *batchv1.Job, eventHandlerType EventHandlerType) error {

hub := sentry.GetHubFromContext(ctx)
if hub == nil {
return errors.New("cannot get hub from context")
Expand All @@ -45,7 +44,6 @@ func runSentryCronsCheckin(ctx context.Context, job *batchv1.Job, eventHandlerTy
}

hub.WithScope(func(scope *sentry.Scope) {

// If DSN annotation provided, we bind a new client with that DSN
client, ok := dsnClientMapping.GetClientFromObject(ctx, &job.ObjectMeta, hub.Client().Options())
if ok {
Expand All @@ -71,7 +69,6 @@ func runSentryCronsCheckin(ctx context.Context, job *batchv1.Job, eventHandlerTy

// Sends the checkin event to sentry crons for when a job starts
func checkinJobStarting(ctx context.Context, job *batchv1.Job, cronsMonitorData *CronsMonitorData) error {

logger := zerolog.Ctx(ctx)

hub := sentry.GetHubFromContext(ctx)
Expand Down Expand Up @@ -101,7 +98,6 @@ func checkinJobStarting(ctx context.Context, job *batchv1.Job, cronsMonitorData

// Sends the checkin event to sentry crons for when a job ends
func checkinJobEnding(ctx context.Context, job *batchv1.Job, cronsMonitorData *CronsMonitorData) error {

hub := sentry.GetHubFromContext(ctx)
if hub == nil {
return errors.New("cannot get hub from context")
Expand Down
1 change: 0 additions & 1 deletion crons_monitor_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type CronsMonitorData struct {

// Constructor for cronsMonitorData
func NewCronsMonitorData(monitorSlug string, schedule string, completions *int32) *CronsMonitorData {

// Get required number of pods to complete
var requiredCompletions int32
if completions == nil {
Expand Down
9 changes: 0 additions & 9 deletions enhancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
const breadcrumbLimit = 20

func runEnhancers(ctx context.Context, eventObject *v1.Event, kind string, object metav1.Object, scope *sentry.Scope, sentryEvent *sentry.Event) error {

involvedObject := fmt.Sprintf("%s/%s", kind, object.GetName())
ctx, logger := getLoggerWithTag(ctx, "object", involvedObject)
logger.Debug().Msgf("Running the enhancer")
Expand Down Expand Up @@ -80,7 +79,6 @@ type KindObjectPair struct {
}

func findRootOwners(ctx context.Context, kindObjPair *KindObjectPair) ([]KindObjectPair, error) {

// use DFS to find the leaves of the owner references graph
rootOwners, err := ownerRefDFS(ctx, kindObjPair)
if err != nil {
Expand All @@ -93,12 +91,10 @@ func findRootOwners(ctx context.Context, kindObjPair *KindObjectPair) ([]KindObj
}

return rootOwners, nil

}

// this function finds performs DFS to find the leaves the owner references graph
func ownerRefDFS(ctx context.Context, kindObjPair *KindObjectPair) ([]KindObjectPair, error) {

parents := kindObjPair.object.GetOwnerReferences()
// the owners slice to be returned
rootOwners := []KindObjectPair{}
Expand Down Expand Up @@ -130,7 +126,6 @@ func ownerRefDFS(ctx context.Context, kindObjPair *KindObjectPair) ([]KindObject
}

func callObjectEnhancer(ctx context.Context, scope *sentry.Scope, kindObjectPair *KindObjectPair, sentryEvent *sentry.Event) error {

var err error = nil
switch kindObjectPair.kind {
case KindPod:
Expand Down Expand Up @@ -215,7 +210,6 @@ func podEnhancer(ctx context.Context, scope *sentry.Scope, object metav1.Object,
}

func jobEnhancer(ctx context.Context, scope *sentry.Scope, object metav1.Object, sentryEvent *sentry.Event) error {

jobObj, ok := object.(*batchv1.Job)
if !ok {
return errors.New("failed to cast object to Job object")
Expand Down Expand Up @@ -245,7 +239,6 @@ func jobEnhancer(ctx context.Context, scope *sentry.Scope, object metav1.Object,
}

func cronjobEnhancer(ctx context.Context, scope *sentry.Scope, object metav1.Object, sentryEvent *sentry.Event) error {

cronjobObj, ok := object.(*batchv1.CronJob)
if !ok {
return errors.New("failed to cast object to CronJob object")
Expand Down Expand Up @@ -280,7 +273,6 @@ func cronjobEnhancer(ctx context.Context, scope *sentry.Scope, object metav1.Obj
}

func replicaSetEnhancer(ctx context.Context, scope *sentry.Scope, object metav1.Object, sentryEvent *sentry.Event) error {

replicasetObj, ok := object.(*appsv1.ReplicaSet)
if !ok {
return errors.New("failed to cast object to ReplicaSet object")
Expand Down Expand Up @@ -310,7 +302,6 @@ func replicaSetEnhancer(ctx context.Context, scope *sentry.Scope, object metav1.
}

func deploymentEnhancer(ctx context.Context, scope *sentry.Scope, object metav1.Object, sentryEvent *sentry.Event) error {

deploymentObj, ok := object.(*appsv1.Deployment)
if !ok {
return errors.New("failed to cast object to Deployment object")
Expand Down
1 change: 0 additions & 1 deletion enhancers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

func TestRunEnhancers(t *testing.T) {

// Create empty context
ctx := context.Background()
// Create simple fake client
Expand Down
1 change: 0 additions & 1 deletion informer_cronjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
)

func createCronjobInformer(ctx context.Context, factory informers.SharedInformerFactory, namespace string) (cache.SharedIndexInformer, error) {

logger := zerolog.Ctx(ctx)

logger.Debug().Msgf("Starting cronjob informer\n")
Expand Down
1 change: 0 additions & 1 deletion informer_deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
)

func createDeploymentInformer(ctx context.Context, factory informers.SharedInformerFactory, namespace string) (cache.SharedIndexInformer, error) {

logger := zerolog.Ctx(ctx)

logger.Debug().Msgf("starting deployment informer\n")
Expand Down
2 changes: 0 additions & 2 deletions informer_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
)

func createJobInformer(ctx context.Context, factory informers.SharedInformerFactory, namespace string) (cache.SharedIndexInformer, error) {

logger := zerolog.Ctx(ctx)

logger.Debug().Msgf("starting job informer\n")
Expand All @@ -31,7 +30,6 @@ func createJobInformer(ctx context.Context, factory informers.SharedInformerFact
}

handler.UpdateFunc = func(oldObj, newObj interface{}) {

oldJob := oldObj.(*batchv1.Job)
newJob := newObj.(*batchv1.Job)

Expand Down
1 change: 0 additions & 1 deletion informer_replicasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
)

func createReplicasetInformer(ctx context.Context, factory informers.SharedInformerFactory, namespace string) (cache.SharedIndexInformer, error) {

logger := zerolog.Ctx(ctx)

logger.Debug().Msgf("starting replicaset informer\n")
Expand Down
1 change: 0 additions & 1 deletion informers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ var deploymentInformer cache.SharedIndexInformer
// if we opt into cronjob, attach the job/cronjob event handlers
// and add to the crons monitor data struct for Sentry Crons
func startInformers(ctx context.Context, namespace string) error {

clientset, err := getClientsetFromContext(ctx)
if err != nil {
return errors.New("failed to get clientset")
Expand Down
4 changes: 0 additions & 4 deletions sentry_dsn_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func (d *DsnClientMapping) GetClientFromMap(dsn string) (*sentry.Client, bool) {
}

func (d *DsnClientMapping) GetClientFromObject(ctx context.Context, object metav1.Object, clientOptions sentry.ClientOptions) (*sentry.Client, bool) {

// If the custom DSN flag is set to false
// then avoid searching for the custom DSN
// or adding an alternative client and instead
Expand Down Expand Up @@ -99,7 +98,6 @@ func (d *DsnClientMapping) GetClientFromObject(ctx context.Context, object metav

// Recursive function to find if there is a DSN annotation
func searchDsn(ctx context.Context, obj metav1.Object) (string, error) {

dsn, ok := obj.GetAnnotations()[DSNAnnotation]
if ok {
return dsn, nil
Expand All @@ -120,7 +118,6 @@ func searchDsn(ctx context.Context, obj metav1.Object) (string, error) {
}

func findObject(ctx context.Context, kind string, namespace string, name string) (metav1.Object, bool) {

clientset, err := getClientsetFromContext(ctx)
if err != nil {
return nil, false
Expand Down Expand Up @@ -157,7 +154,6 @@ func findObject(ctx context.Context, kind string, namespace string, name string)
obj, ok, err := deploymentInformer.GetIndexer().GetByKey(namespace + "/" + name)
if ok && err == nil {
deployment = obj.(*v1.Deployment)

}
}
if deployment == nil {
Expand Down
1 change: 0 additions & 1 deletion watcher_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ func handleWatchEvent(ctx context.Context, event *watch.Event, cutoffTime metav1
// To avoid concurrency issue
hub = hub.Clone()
hub.WithScope(func(scope *sentry.Scope) {

// Find the object meta that the event is about
object, ok := findObject(ctx, eventObject.InvolvedObject.Kind, eventObject.InvolvedObject.Namespace, eventObject.InvolvedObject.Name)
if ok {
Expand Down
1 change: 0 additions & 1 deletion watcher_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
// and checking it causes Sentry to capture the event
// with the correct message and Sentry tags
func TestHandleWatchEvent(t *testing.T) {

// Create empty context
ctx := context.Background()

Expand Down
3 changes: 0 additions & 3 deletions watcher_pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ func handlePodWatchEvent(ctx context.Context, event *watch.Event) {
continue
}
hub.WithScope(func(scope *sentry.Scope) {

// If DSN annotation provided, we bind a new client with that DSN
client, ok := dsnClientMapping.GetClientFromObject(ctx, &podObject.ObjectMeta, hub.Client().Options())
if ok {
Expand Down Expand Up @@ -202,8 +201,6 @@ func watchPodsInNamespaceForever(ctx context.Context, config *rest.Config, names

func startPodWatchers(ctx context.Context, config *rest.Config, namespaces []string) {
for _, namespace := range namespaces {

go watchPodsInNamespaceForever(ctx, config, namespace)

}
}
1 change: 0 additions & 1 deletion watcher_pods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
// and checking it causes Sentry to capture the event
// with the correct message and Sentry tags
func TestHandlePodWatchEvent(t *testing.T) {

// Create empty context
ctx := context.Background()

Expand Down

0 comments on commit afd287e

Please sign in to comment.