Skip to content

Instantly share code, notes, and snippets.

View mayankshah1607's full-sized avatar
๐Ÿ•
Focusing

Mayank Shah mayankshah1607

๐Ÿ•
Focusing
View GitHub Profile
@mayankshah1607
mayankshah1607 / setup.sh
Created February 28, 2024 07:37
Dotfiles setup
#!/usr/bin/env bash
git clone --bare [email protected]:mayankshah1607/dotfiles.git $HOME/dotfiles
# define config alias locally since the dotfiles
# aren't installed on the system yet
function config {
git --git-dir=$HOME/dotfiles/ --work-tree=$HOME $@
}
package main
import (
"time"
)
type Batch struct {
events []int
}
### Keybase proof
I hereby claim:
* I am mayankshah1607 on github.
* I am mayankshah1607 (https://keybase.io/mayankshah1607) on keybase.
* I have a public key ASAo84WtFyNl0p685QEtF5oMmgKCIjaFMT9xYOm1zgBWWgo
To claim this, I am signing this object:
@mayankshah1607
mayankshah1607 / test.yaml
Last active May 17, 2022 10:26
test.yaml
# AddonCR
apiVersion: addons.managed.openshift.io/v1alpha1
kind: Addon
metadata:
name: reference-addon
spec:
# <remaining spec omitted for redability>
monitoring:
monitoringStack:
enabled: true
@mayankshah1607
mayankshah1607 / gist:04d73298130e73571ef191a3515f976e
Created November 11, 2021 07:59
Gitlab verification script
import gitlab
gl = gitlab.Gitlab('https://gitlab.cee.redhat.com/', private_token='', ssl_verify=False)
gl.auth()
project = gl.projects.get() # Enter project ID here
data = {
'branch': 'main',
diff --git a/controllers/clusterconfigmap_controller.go b/controllers/clusterconfigmap_controller.go
index 913832f..675fea3 100644
--- a/controllers/clusterconfigmap_controller.go
+++ b/controllers/clusterconfigmap_controller.go
@@ -24,7 +24,9 @@ import (
"k8s.io/apimachinery/pkg/types"
ref "k8s.io/client-go/tools/reference"
+ "sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
@mayankshah1607
mayankshah1607 / leaderelection.go
Created October 25, 2021 07:15
tryAcquireOrRenew
func (le *LeaderElector) tryAcquireOrRenew(ctx context.Context) bool {
now := metav1.Now()
leaderElectionRecord := rl.LeaderElectionRecord{
HolderIdentity: le.config.Lock.Identity(),
LeaseDurationSeconds: int(le.config.LeaseDuration / time.Second),
RenewTime: now,
AcquireTime: now,
}
// 1. obtain or create the ElectionRecord
// Run starts the leader election loop. Run will not return
// before leader election loop is stopped by ctx or it has
// stopped holding the leader lease
func (le *LeaderElector) Run(ctx context.Context) {
defer runtime.HandleCrash()
defer func() {
le.config.Callbacks.OnStoppedLeading()
}()
if !le.acquire(ctx) {
// RunOrDie starts a client with the provided config or panics if the config
// fails to validate. RunOrDie blocks until leader election loop is
// stopped by ctx or it has stopped holding the leader lease
func RunOrDie(ctx context.Context, lec LeaderElectionConfig) {
le, err := NewLeaderElector(lec)
if err != nil {
panic(err)
}
if lec.WatchDog != nil {
lec.WatchDog.SetLeaderElection(le)
@mayankshah1607
mayankshah1607 / main.go
Created October 25, 2021 06:39
runLeaderElection
func runLeaderElection(lock *resourcelock.LeaseLock, ctx context.Context, id string) {
leaderelection.RunOrDie(ctx, leaderelection.LeaderElectionConfig{
Lock: lock,
ReleaseOnCancel: true,
LeaseDuration: 15 * time.Second,
RenewDeadline: 10 * time.Second,
RetryPeriod: 2 * time.Second,
Callbacks: leaderelection.LeaderCallbacks{
OnStartedLeading: func(c context.Context) {
doStuff()