Remove unused config from reloader

This commit is contained in:
faizanahmad055
2018-07-10 14:35:14 +05:00
parent acc0271dc6
commit 0004271e34
6 changed files with 14 additions and 112 deletions
-2
View File
@@ -1,2 +0,0 @@
controllers:
- type: pods
@@ -26,17 +26,8 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: CONFIG_FILE_PATH
value: {{ .Values.reloader.configFilePath }}
image: "{{ .Values.reloader.image.name }}:{{ .Values.reloader.image.tag }}"
imagePullPolicy: {{ .Values.reloader.image.pullPolicy }}
name: {{ template "name" . }}
volumeMounts:
- mountPath: /configs
name: config-volume
serviceAccountName: {{ template "name" . }}
volumes:
- configMap:
name: {{ template "name" . }}
name: config-volume
@@ -11,8 +11,4 @@ reloader:
image:
name: stakater/reloader
tag: "1.0.0"
pullPolicy: IfNotPresent
controllers:
- type: pods
configFilePath: /configs/config.yaml
pullPolicy: IfNotPresent
+2 -22
View File
@@ -1,12 +1,9 @@
package cmd
import (
"os"
"github.com/spf13/cobra"
"github.com/stakater/Reloader/internal/pkg/controller"
"github.com/stakater/Reloader/pkg/kube"
"github.com/stakater/Reloader/internal/pkg/config"
"github.com/sirupsen/logrus"
)
@@ -28,11 +25,8 @@ func startReloader(cmd *cobra.Command, args []string) {
logrus.Fatal(err)
}
// get the Controller config file
config := getControllerConfig()
for _, v := range kube.ResourceMap {
c, err := controller.NewController(clientset, config.Controllers[0], v)
for k, v := range kube.ResourceMap {
c, err := controller.NewController(clientset, k, v)
if err != nil {
logrus.Fatalf("%s", err)
}
@@ -47,17 +41,3 @@ func startReloader(cmd *cobra.Command, args []string) {
// Wait forever
select {}
}
// get the yaml configuration for the controller
func getControllerConfig() config.Config {
configFilePath := os.Getenv("CONFIG_FILE_PATH")
if len(configFilePath) == 0 {
//Default config file is placed in configs/ folder
configFilePath = "configs/config.yaml"
}
configuration, err := config.ReadConfig(configFilePath)
if err != nil {
logrus.Panic(err)
}
return configuration
}
-62
View File
@@ -1,62 +0,0 @@
package config
import (
"io/ioutil"
yaml "gopkg.in/yaml.v2"
)
// Config which would be read from the config.yaml
type Config struct {
Controllers []Controller
}
// Controller which contains all the information for a specific controller
type Controller struct {
Type string
WatchCriterion Criterion
Actions []Action
}
// Criterion as to what fields should the controller be looking at
type Criterion struct {
Operator string
Identifiers []string
}
// Action that the controller will be taking based on the Parameters
type Action struct {
Name string
Params map[interface{}]interface{}
}
// ReadConfig function that reads the yaml file
func ReadConfig(filePath string) (Config, error) {
var config Config
// Read YML
source, err := ioutil.ReadFile(filePath)
if err != nil {
return config, err
}
// Unmarshall
err = yaml.Unmarshal(source, &config)
if err != nil {
return config, err
}
return config, nil
}
// WriteConfig function that can write to the yaml file
func WriteConfig(config Config, path string) error {
b, err := yaml.Marshal(config)
if err != nil {
return err
}
err = ioutil.WriteFile(path, b, 0644)
if err != nil {
return err
}
return nil
}
+11 -12
View File
@@ -7,7 +7,6 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/apimachinery/pkg/util/runtime"
informerruntime "k8s.io/apimachinery/pkg/runtime"
"github.com/stakater/Reloader/internal/pkg/config"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/util/wait"
errorHandler "k8s.io/apimachinery/pkg/util/runtime"
@@ -33,10 +32,10 @@ type Event struct {
// Controller for checking events
type Controller struct {
client kubernetes.Interface
indexer cache.Indexer
queue workqueue.RateLimitingInterface
informer cache.Controller
controllerConfig config.Controller
indexer cache.Indexer
queue workqueue.RateLimitingInterface
informer cache.Controller
resource string
stopCh chan struct{}
}
@@ -44,16 +43,16 @@ type Controller struct {
// NewController for initializing a Controller
func NewController(
client kubernetes.Interface,
controllerConfig config.Controller, objType informerruntime.Object) (*Controller, error) {
resource string, objType informerruntime.Object) (*Controller, error) {
c := Controller{
client: client,
controllerConfig: controllerConfig,
stopCh: make(chan struct{}),
client: client,
resource: resource,
stopCh: make(chan struct{}),
}
queue := workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter())
listWatcher := cache.NewListWatchFromClient(client.CoreV1().RESTClient(), controllerConfig.Type, AllNamespaces, fields.Everything())
listWatcher := cache.NewListWatchFromClient(client.CoreV1().RESTClient(), resource, AllNamespaces, fields.Everything())
indexer, informer := cache.NewIndexerInformer(listWatcher, objType, 0, cache.ResourceEventHandlerFuncs {
AddFunc: c.Add,
@@ -98,7 +97,7 @@ func (c *Controller) Delete(obj interface{}) {
//Run function for controller which handles the queue
func (c *Controller) Run(threadiness int, stopCh chan struct{}) {
logrus.Infof("Starting Controller for type ", c.controllerConfig.Type)
logrus.Infof("Starting Controller for type ", c.resource)
defer errorHandler.HandleCrash()
// Let the workers stop when we are done
@@ -117,7 +116,7 @@ func (c *Controller) Run(threadiness int, stopCh chan struct{}) {
}
<-stopCh
logrus.Infof("Stopping Controller for type ", c.controllerConfig.Type)
logrus.Infof("Stopping Controller for type ", c.resource)
}
func (c *Controller) runWorker() {