1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-04-08 18:15:48 +00:00

NK-31: Renamed constants package to config

This commit is contained in:
belyshevdenis 2019-03-21 18:09:14 +02:00
parent dccb9e6f6e
commit c662f1c9db
5 changed files with 23 additions and 24 deletions

View file

@ -1,4 +1,4 @@
package constants
package config
const (
// These constants MUST be equal to the corresponding names in service definition in definitions/install.yaml

10
init.go
View file

@ -6,7 +6,7 @@ import (
"net/url"
"github.com/nirmata/kube-policy/kubeclient"
"github.com/nirmata/kube-policy/constants"
"github.com/nirmata/kube-policy/config"
"github.com/nirmata/kube-policy/utils"
rest "k8s.io/client-go/rest"
@ -44,14 +44,14 @@ func readTlsPairFromFiles(certFile, keyFile string) *utils.TlsPemPair {
// Loads or creates PEM private key and TLS certificate for webhook server
// Returns struct with key/certificate pair
func initTlsPemsPair(config *rest.Config, client *kubeclient.KubeClient) (*utils.TlsPemPair, error) {
apiServerUrl, err := url.Parse(config.Host)
func initTlsPemsPair(configuration *rest.Config, client *kubeclient.KubeClient) (*utils.TlsPemPair, error) {
apiServerUrl, err := url.Parse(configuration.Host)
if err != nil {
return nil, err
}
certProps := utils.TlsCertificateProps{
Service: constants.WebhookServiceName,
Namespace: constants.WebhookServiceNamespace,
Service: config.WebhookServiceName,
Namespace: config.WebhookServiceNamespace,
ApiServerHost: apiServerUrl.Hostname(),
}

View file

@ -64,8 +64,7 @@ func main() {
controller.Run(stopCh)
if err != nil {
log.Fatalf("Error running PolicyController! Error: %s\n", err)
return
log.Fatalf("Error running PolicyController: %s\n", err)
}
log.Println("Policy Controller has started")

View file

@ -14,7 +14,7 @@ import (
"github.com/nirmata/kube-policy/controller"
"github.com/nirmata/kube-policy/kubeclient"
"github.com/nirmata/kube-policy/constants"
"github.com/nirmata/kube-policy/config"
"github.com/nirmata/kube-policy/webhooks"
"github.com/nirmata/kube-policy/utils"
@ -40,23 +40,23 @@ type WebhookServerConfig struct {
// NewWebhookServer creates new instance of WebhookServer accordingly to given configuration
// Policy Controller and Kubernetes Client should be initialized in configuration
func NewWebhookServer(config WebhookServerConfig, logger *log.Logger) (*WebhookServer, error) {
func NewWebhookServer(configuration WebhookServerConfig, logger *log.Logger) (*WebhookServer, error) {
if logger == nil {
logger = log.New(os.Stdout, "HTTPS Server: ", log.LstdFlags|log.Lshortfile)
}
if config.TlsPemPair == nil || config.Controller == nil || config.Kubeclient == nil {
if configuration.TlsPemPair == nil || configuration.Controller == nil || configuration.Kubeclient == nil {
return nil, errors.New("WebhookServerConfig is not initialized properly")
}
var tlsConfig tls.Config
pair, err := tls.X509KeyPair(config.TlsPemPair.Certificate, config.TlsPemPair.PrivateKey)
pair, err := tls.X509KeyPair(configuration.TlsPemPair.Certificate, configuration.TlsPemPair.PrivateKey)
if err != nil {
return nil, err
}
tlsConfig.Certificates = []tls.Certificate{pair}
mw, err := webhooks.NewMutationWebhook(config.Kubeclient, config.Controller, logger)
mw, err := webhooks.NewMutationWebhook(configuration.Kubeclient, configuration.Controller, logger)
if err != nil {
return nil, err
}
@ -67,7 +67,7 @@ func NewWebhookServer(config WebhookServerConfig, logger *log.Logger) (*WebhookS
}
mux := http.NewServeMux()
mux.HandleFunc(constants.WebhookServicePath, ws.serve)
mux.HandleFunc(config.WebhookServicePath, ws.serve)
ws.server = http.Server{
Addr: ":443", // Listen on port for HTTPS requests
@ -83,7 +83,7 @@ func NewWebhookServer(config WebhookServerConfig, logger *log.Logger) (*WebhookS
// Main server endpoint for all requests
func (ws *WebhookServer) serve(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == constants.WebhookServicePath {
if r.URL.Path == config.WebhookServicePath {
admissionReview := ws.parseAdmissionReview(r, w)
if admissionReview == nil {
return

View file

@ -3,7 +3,7 @@ package webhooks
import (
"io/ioutil"
"github.com/nirmata/kube-policy/constants"
"github.com/nirmata/kube-policy/config"
rest "k8s.io/client-go/rest"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -25,22 +25,22 @@ func RegisterMutationWebhook(config *rest.Config) error {
return nil
}
func constructWebhookConfig(config *rest.Config) *adm.MutatingWebhookConfiguration {
func constructWebhookConfig(configuration *rest.Config) *adm.MutatingWebhookConfiguration {
return &adm.MutatingWebhookConfiguration {
ObjectMeta: meta.ObjectMeta {
Name: constants.WebhookConfigName,
Labels: constants.WebhookConfigLabels,
Name: config.WebhookConfigName,
Labels: config.WebhookConfigLabels,
},
Webhooks: []adm.Webhook {
adm.Webhook {
Name: constants.MutationWebhookName,
Name: config.MutationWebhookName,
ClientConfig: adm.WebhookClientConfig {
Service: &adm.ServiceReference {
Namespace: constants.WebhookServiceNamespace,
Name: constants.WebhookServiceName,
Path: &constants.WebhookServicePath,
Namespace: config.WebhookServiceNamespace,
Name: config.WebhookServiceName,
Path: &config.WebhookServicePath,
},
CABundle: ExtractCA(config),
CABundle: ExtractCA(configuration),
},
Rules: []adm.RuleWithOperations {
adm.RuleWithOperations {