Skip to content

Commit

Permalink
Adding parameter loglevel (#5)
Browse files Browse the repository at this point in the history
* Add verbosity 

Co-authored-by: Santiago Núñez-Cacho <[email protected]>
  • Loading branch information
santinoncs and santinoncs authored Aug 3, 2020
1 parent 264860c commit f39d65d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
BIN := node-policy-webhook
CRD_OPTIONS ?= "crd:trivialVersions=true"
PKG := github.com/softonic/node-policy-webhook
VERSION ?= 0.1.0-dev
VERSION ?= 0.1.6-dev
ARCH ?= amd64
APP ?= node-policy-webhook
NAMESPACE ?= default
Expand Down
1 change: 1 addition & 0 deletions chart/node-policy-webhook/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ spec:
args:
- --tls-cert={{ .Values.certs.mountPath }}/cert.pem
- --tls-key={{ .Values.certs.mountPath }}/key.pem
- -v={{ .Values.verbosity }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
Expand Down
4 changes: 4 additions & 0 deletions chart/node-policy-webhook/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ certs:
# Key key.pem
key: ""


# LogLevel passed as an argument
verbosity: 2

# Cluster's CA bundle
caBundle: ""

Expand Down
40 changes: 16 additions & 24 deletions cmd/node-policy-webhook/node-policy-webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@ package main
import (
"crypto/tls"
"errors"
"flag"
"fmt"
_ "github.com/golang/glog"
"github.com/softonic/node-policy-webhook/pkg/admission"
h "github.com/softonic/node-policy-webhook/pkg/http"
"github.com/softonic/node-policy-webhook/pkg/version"
"github.com/spf13/cobra"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/rest"
"k8s.io/klog"
"net/http"
"os"
"path"
)

type params struct {
version bool
certificate string
privateKey string
LogLevel int
}

const DEFAULT_BIND_ADDRESS = ":8443"
Expand All @@ -29,35 +28,28 @@ var handler *h.HttpHandler

func init() {
handler = getHttpHandler()
klog.InitFlags(nil)
}

func main() {
var params params

commandName := path.Base(os.Args[0])

rootCmd := &cobra.Command{
Use: commandName,
Short: fmt.Sprintf("%v handles node policy profiles in kubernetes", commandName),
Run: func(cmd *cobra.Command, args []string) {
if params.version {
fmt.Println("Version:", version.Version)
} else {
run(&params)
}
},
if len(os.Args) < 2 {
klog.Fatalf("Minimum arguments are 2")
os.Exit(1)
}
rootCmd.Flags().BoolVarP(&params.version, "version", "v", false, "print version and exit")
rootCmd.Flags().StringVarP(&params.certificate, "tls-cert", "c", "default", "certificate (required)")
rootCmd.Flags().StringVarP(&params.privateKey, "tls-key", "p", "default", "privateKey (required)")

rootCmd.MarkFlagRequired("tls-cert")
rootCmd.MarkFlagRequired("tls-key")
flag.StringVar(&params.certificate, "tls-cert", "bar", "a string var")
flag.StringVar(&params.privateKey, "tls-key", "bar", "a string var")

if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
flag.Parse()

if params.version {
fmt.Println("Version:", version.Version)
} else {
run(&params)
}

}

func run(params *params) {
Expand Down Expand Up @@ -89,7 +81,7 @@ func run(params *params) {
if address == "" {
address = DEFAULT_BIND_ADDRESS
}
klog.V(0).Infof("Starting server, bound at %v", address)
klog.V(2).Infof("Starting server, bound at %v", address)
klog.Infof("Listening to address %v", address)
srv := &http.Server{
Addr: address,
Expand Down

0 comments on commit f39d65d

Please sign in to comment.