-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Watch changes to ConfigMaps and Secrets
- Loading branch information
Showing
12 changed files
with
461 additions
and
19 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
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,56 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/bmaynard/kubevol/pkg/core" | ||
"github.com/spf13/cobra" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/watch" | ||
"k8s.io/client-go/tools/cache" | ||
|
||
w "github.com/bmaynard/kubevol/pkg/watch" | ||
|
||
apiv1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func NewWatchConfigmapCommand(f core.Factory) *cobra.Command { | ||
var cmd = &cobra.Command{ | ||
Use: "watch-configmap", | ||
Short: "Watch for updates to ConfigMaps", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientset, err := f.CoreClient() | ||
|
||
if err != nil { | ||
f.Logger.Fatal(err) | ||
} | ||
|
||
informer := cache.NewSharedIndexInformer( | ||
&cache.ListWatch{ | ||
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { | ||
return clientset.CoreV1().ConfigMaps("").List(options) | ||
}, | ||
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { | ||
return clientset.CoreV1().ConfigMaps("").Watch(options) | ||
}, | ||
}, | ||
&apiv1.ConfigMap{}, | ||
0, //Skip resync | ||
cache.Indexers{}, | ||
) | ||
|
||
watcher := w.NewWatch(&f) | ||
|
||
informer.AddEventHandler(cache.ResourceEventHandlerFuncs{ | ||
UpdateFunc: watcher.UpateConfigMapTracker, | ||
DeleteFunc: watcher.DeleteConfigMapTracker, | ||
}) | ||
|
||
stopCh := make(chan struct{}) | ||
defer close(stopCh) | ||
informer.Run(stopCh) | ||
return nil | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
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,56 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/bmaynard/kubevol/pkg/core" | ||
"github.com/spf13/cobra" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/watch" | ||
"k8s.io/client-go/tools/cache" | ||
|
||
w "github.com/bmaynard/kubevol/pkg/watch" | ||
|
||
apiv1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func NewWatchSecretCommand(f core.Factory) *cobra.Command { | ||
var cmd = &cobra.Command{ | ||
Use: "watch-secret", | ||
Short: "Watch for updates to Secrets", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientset, err := f.CoreClient() | ||
|
||
if err != nil { | ||
f.Logger.Fatal(err) | ||
} | ||
|
||
informer := cache.NewSharedIndexInformer( | ||
&cache.ListWatch{ | ||
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { | ||
return clientset.CoreV1().Secrets("").List(options) | ||
}, | ||
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { | ||
return clientset.CoreV1().Secrets("").Watch(options) | ||
}, | ||
}, | ||
&apiv1.Secret{}, | ||
0, //Skip resync | ||
cache.Indexers{}, | ||
) | ||
|
||
watcher := w.NewWatch(&f) | ||
|
||
informer.AddEventHandler(cache.ResourceEventHandlerFuncs{ | ||
UpdateFunc: watcher.UpateSecretTracker, | ||
DeleteFunc: watcher.DeleteSecretTracker, | ||
}) | ||
|
||
stopCh := make(chan struct{}) | ||
defer close(stopCh) | ||
informer.Run(stopCh) | ||
return nil | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
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,72 @@ | ||
package core | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type Logger struct { | ||
logger *logrus.Logger | ||
} | ||
|
||
func NewLogger() *Logger { | ||
return &Logger{ | ||
logger: &logrus.Logger{ | ||
Out: os.Stdout, | ||
Formatter: &logrus.TextFormatter{ | ||
FullTimestamp: true, | ||
DisableLevelTruncation: true, | ||
}, | ||
Level: logrus.DebugLevel, | ||
}, | ||
} | ||
} | ||
|
||
func (l *Logger) Debugf(format string, args ...interface{}) { | ||
l.logger.Debugf(format, args...) | ||
} | ||
|
||
func (l *Logger) Infof(format string, args ...interface{}) { | ||
l.logger.Infof(format, args...) | ||
} | ||
|
||
func (l *Logger) Warnf(format string, args ...interface{}) { | ||
l.logger.Warnf(format, args...) | ||
} | ||
|
||
func (l *Logger) Errorf(format string, args ...interface{}) { | ||
l.logger.Errorf(format, args...) | ||
} | ||
|
||
func (l *Logger) Fatalf(format string, args ...interface{}) { | ||
l.logger.Fatalf(format, args...) | ||
} | ||
|
||
func (l *Logger) Panicf(format string, args ...interface{}) { | ||
l.logger.Fatalf(format, args...) | ||
} | ||
|
||
func (l *Logger) Debug(args ...interface{}) { | ||
l.logger.Debug(args...) | ||
} | ||
|
||
func (l *Logger) Info(args ...interface{}) { | ||
l.logger.Info(args...) | ||
} | ||
|
||
func (l *Logger) Warn(args ...interface{}) { | ||
l.logger.Warn(args...) | ||
} | ||
|
||
func (l *Logger) Error(args ...interface{}) { | ||
l.logger.Error(args...) | ||
} | ||
|
||
func (l *Logger) Fatal(args ...interface{}) { | ||
l.logger.Fatal(args...) | ||
} | ||
|
||
func (l *Logger) Panic(args ...interface{}) { | ||
l.logger.Fatal(args...) | ||
} |
Oops, something went wrong.