-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34fb57b
commit 1e27d0f
Showing
10 changed files
with
138 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package main | ||
|
||
const ( | ||
KindPod string = "Pod" | ||
KindJob string = "Job" | ||
KindCronjob string = "CronJob" | ||
KindReplicaset string = "ReplicaSet" | ||
KindDeployment string = "Deployment" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"time" | ||
|
||
"k8s.io/client-go/informers" | ||
"k8s.io/client-go/tools/cache" | ||
) | ||
|
||
var cronjobInformer cache.SharedIndexInformer | ||
var jobInformer cache.SharedIndexInformer | ||
var replicasetInformer cache.SharedIndexInformer | ||
var deploymentInformer cache.SharedIndexInformer | ||
|
||
// Starts all informers (jobs, cronjobs, replicasets, deployments) | ||
// 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") | ||
} | ||
|
||
// Create factory that will produce both the cronjob informer and job informer | ||
factory := informers.NewSharedInformerFactoryWithOptions( | ||
clientset, | ||
5*time.Second, | ||
informers.WithNamespace(namespace), | ||
) | ||
|
||
// Create the job informer | ||
jobInformer, err = createJobInformer(ctx, factory, namespace) | ||
if err != nil { | ||
return err | ||
} | ||
// Create the cronjob informer | ||
cronjobInformer, err = createCronjobInformer(ctx, factory, namespace) | ||
if err != nil { | ||
return err | ||
} | ||
// Create the replicaset informer | ||
replicasetInformer, err = createReplicasetInformer(ctx, factory, namespace) | ||
if err != nil { | ||
return err | ||
} | ||
// Create the deployment informer | ||
deploymentInformer, err = createDeploymentInformer(ctx, factory, namespace) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Channel to tell the factory to stop the informers | ||
doneChan := make(chan struct{}) | ||
factory.Start(doneChan) | ||
|
||
// Sync the cronjob informer cache | ||
if ok := cache.WaitForCacheSync(doneChan, cronjobInformer.HasSynced); !ok { | ||
return errors.New("cronjob informer failed to sync") | ||
} | ||
// Sync the job informer cache | ||
if ok := cache.WaitForCacheSync(doneChan, jobInformer.HasSynced); !ok { | ||
return errors.New("job informer failed to sync") | ||
} | ||
// Sync the replicaset informer cache | ||
if ok := cache.WaitForCacheSync(doneChan, replicasetInformer.HasSynced); !ok { | ||
return errors.New("replicaset informer failed to sync") | ||
} | ||
// Sync the deployment informer cache | ||
if ok := cache.WaitForCacheSync(doneChan, deploymentInformer.HasSynced); !ok { | ||
return errors.New("deployment informer failed to sync") | ||
} | ||
|
||
// Wait for the channel to be closed | ||
<-doneChan | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.