Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
allow either yaml or json config file (#8)
Browse files Browse the repository at this point in the history
* allow either yaml or json config file
  • Loading branch information
Joseph-Irving authored Mar 25, 2019
1 parent cc00665 commit 771f329
Show file tree
Hide file tree
Showing 22 changed files with 9,427 additions and 28 deletions.
9 changes: 9 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@ Nidhogg was built using [Kubebuilder](https://github.com/kubernetes-sigs/kubebui

## Usage

Nidhogg requires a json config file to tell it what Daemonsets to watch and what nodes to act on.
Nidhogg requires a yaml/json config file to tell it what Daemonsets to watch and what nodes to act on.
`nodeSelector` is a map of keys/values corresponding to node labels. `daemonsets` is an array of Daemonsets to watch, each containing two fields `name` and `namespace`. Nodes are tainted with taint that follows the format of `nidhogg.uswitch.com/namespace.name:NoSchedule`.

Example:

YAML:
```yaml
nodeSelector:
node-role.kubernetes.io/node: ""
daemonsets:
- name: kiam
namespace: kube-system
```
JSON:
```json
{
"nodeSelector": {
Expand Down
14 changes: 2 additions & 12 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ limitations under the License.
package main

import (
"encoding/json"
"flag"
"io/ioutil"
"os"

"github.com/uswitch/nidhogg/pkg/apis"
Expand All @@ -41,17 +39,9 @@ func main() {
logf.SetLogger(logf.ZapLogger(false))
log := logf.Log.WithName("entrypoint")

var handlerConf nidhogg.HandlerConfig

bytes, err := ioutil.ReadFile(configPath)
if err != nil {
log.Error(err, "unable to read config file")
os.Exit(1)
}

err = json.Unmarshal(bytes, &handlerConf)
handlerConf, err := nidhogg.GetConfig(configPath)
if err != nil {
log.Error(err, "unable to parse config file")
log.Error(err, "unable to get config")
os.Exit(1)
}

Expand Down
11 changes: 0 additions & 11 deletions config.json

This file was deleted.

26 changes: 26 additions & 0 deletions pkg/nidhogg/decoder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package nidhogg

import (
"fmt"
"io/ioutil"

yaml "gopkg.in/yaml.v1"
)

//GetConfig reads the config file, parses it whether it be in json or yaml and returns a handler config
func GetConfig(config string) (HandlerConfig, error) {

var handlerConf HandlerConfig
bytes, err := ioutil.ReadFile(config)
if err != nil {
return HandlerConfig{}, fmt.Errorf("unable to read config file: %v", err)
}

err = yaml.Unmarshal(bytes, &handlerConf)
if err != nil {
return HandlerConfig{}, fmt.Errorf("error parsing file: %v", err)
}

return handlerConf, nil

}
8 changes: 4 additions & 4 deletions pkg/nidhogg/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ type Handler struct {

//HandlerConfig contains the options for Nidhogg
type HandlerConfig struct {
Daemonsets []Daemonset `json:"daemonsets"`
NodeSelector map[string]string `json:"nodeSelector"`
Daemonsets []Daemonset `json:"daemonsets" yaml:"daemonsets"`
NodeSelector map[string]string `json:"nodeSelector" yaml:"nodeSelector"`
}

//Daemonset contains the name and namespace of a Daemonset
type Daemonset struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
Name string `json:"name" yaml:"name"`
Namespace string `json:"namespace" yaml:"namespace"`
}

type taintChanges struct {
Expand Down
188 changes: 188 additions & 0 deletions vendor/gopkg.in/yaml.v1/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions vendor/gopkg.in/yaml.v1/LICENSE.libyaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 771f329

Please sign in to comment.