This repository has been archived by the owner on Feb 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ConfigMap to pass configuration to the webhook, make the base con…
…figuration the default
- Loading branch information
Sam Naser
committed
Dec 14, 2018
1 parent
6834b24
commit d671858
Showing
13 changed files
with
105 additions
and
62 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,44 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"io/ioutil" | ||
|
||
yaml "gopkg.in/yaml.v2" | ||
) | ||
|
||
// DefaultConfigPath refers to location of configuration mount dir specified in deployment | ||
const DefaultConfigPath = "/etc/webhook/config/config.yaml" | ||
|
||
// Config represents all config we need to initialize the webhook server | ||
type Config struct { | ||
Trace struct { | ||
SampleRate float64 `yaml:"sampleRate"` | ||
} | ||
} | ||
|
||
// ParseConfigFromPath reads YAML config into config struct | ||
func ParseConfigFromPath(c *Config, path string) (bool, error) { | ||
|
||
configYaml, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
return false, fmt.Errorf("could not read YAML configuration file: %v", err) | ||
} | ||
|
||
err = yaml.Unmarshal(configYaml, &c) | ||
if err != nil { | ||
return false, fmt.Errorf("could not umarshal YAML configuration file: %v", err) | ||
} | ||
|
||
return true, nil | ||
} | ||
|
||
// Validate accepts a WebhookServerConfig and returns whether the config was valid and an error if needed | ||
func (cfg *Config) Validate() (bool, error) { | ||
if cfg.Trace.SampleRate < 0 || cfg.Trace.SampleRate > 1 { | ||
return false, errors.New("sampling rate must be between 0 and 1 inclusive") | ||
} | ||
|
||
return true, nil | ||
} |
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,8 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: trace-context-injector-webhook-config-map | ||
data: | ||
config.yaml: | | ||
trace: | ||
sampleRate: 1.0 |
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 |
---|---|---|
|
@@ -4,3 +4,4 @@ resources: | |
- deployment.yaml | ||
- mutatingwebhook-ca-bundle.yaml | ||
- service.yaml | ||
- configmap.yaml |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,5 @@ | ||
|
||
bases: | ||
- ../../base | ||
patches: | ||
- trace-context-injector-config.yaml |
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,8 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: trace-context-injector-webhook-config-map | ||
data: | ||
config.yaml: | | ||
trace: | ||
sampleRate: 0.1 |
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