mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
Merge pull request #35 from nirmata/feature_proposal_redesign_policycontroller_eventcontroller_violationbuilder
- Resolve conflicts with PR #36. - Merge policy v2, update pkg structure
This commit is contained in:
commit
af9d1071e9
22 changed files with 91 additions and 48 deletions
|
@ -10,7 +10,6 @@ import (
|
||||||
types "github.com/nirmata/kube-policy/pkg/apis/policy/v1alpha1"
|
types "github.com/nirmata/kube-policy/pkg/apis/policy/v1alpha1"
|
||||||
apps "k8s.io/api/apps/v1"
|
apps "k8s.io/api/apps/v1"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
|
@ -43,7 +42,7 @@ func NewKubeClient(config *rest.Config, logger *log.Logger) (*KubeClient, error)
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kc *KubeClient) GetEventsInterface(namespace string) event.EventInterface {
|
func (kc *KubeClient) GetEvents(namespace string) event.EventInterface {
|
||||||
return kc.client.CoreV1().Events(namespace)
|
return kc.client.CoreV1().Events(namespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +50,7 @@ func (kc *KubeClient) GetKubePolicyDeployment() (*apps.Deployment, error) {
|
||||||
kubePolicyDeployment, err := kc.client.
|
kubePolicyDeployment, err := kc.client.
|
||||||
AppsV1().
|
AppsV1().
|
||||||
Deployments(config.KubePolicyNamespace).
|
Deployments(config.KubePolicyNamespace).
|
||||||
Get(config.KubePolicyDeploymentName, meta.GetOptions{})
|
Get(config.KubePolicyDeploymentName, metav1.GetOptions{})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
18
main.go
18
main.go
|
@ -5,15 +5,13 @@ import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/nirmata/kube-policy/kubeclient"
|
"github.com/nirmata/kube-policy/kubeclient"
|
||||||
"github.com/nirmata/kube-policy/pkg/webhooks"
|
|
||||||
"github.com/nirmata/kube-policy/policycontroller"
|
|
||||||
|
|
||||||
policyclientset "github.com/nirmata/kube-policy/pkg/client/clientset/versioned"
|
policyclientset "github.com/nirmata/kube-policy/pkg/client/clientset/versioned"
|
||||||
informers "github.com/nirmata/kube-policy/pkg/client/informers/externalversions"
|
informers "github.com/nirmata/kube-policy/pkg/client/informers/externalversions"
|
||||||
policyengine "github.com/nirmata/kube-policy/pkg/policyengine"
|
controller "github.com/nirmata/kube-policy/pkg/controller"
|
||||||
policyviolation "github.com/nirmata/kube-policy/pkg/policyviolation"
|
engine "github.com/nirmata/kube-policy/pkg/engine"
|
||||||
|
|
||||||
event "github.com/nirmata/kube-policy/pkg/event"
|
event "github.com/nirmata/kube-policy/pkg/event"
|
||||||
|
violation "github.com/nirmata/kube-policy/pkg/violation"
|
||||||
|
"github.com/nirmata/kube-policy/pkg/webhooks"
|
||||||
"k8s.io/sample-controller/pkg/signals"
|
"k8s.io/sample-controller/pkg/signals"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -44,10 +42,10 @@ func main() {
|
||||||
policyInformer := policyInformerFactory.Kubepolicy().V1alpha1().Policies()
|
policyInformer := policyInformerFactory.Kubepolicy().V1alpha1().Policies()
|
||||||
|
|
||||||
eventController := event.NewEventController(kubeclient, policyInformer.Lister(), nil)
|
eventController := event.NewEventController(kubeclient, policyInformer.Lister(), nil)
|
||||||
violationBuilder := policyviolation.NewPolicyViolationBuilder(kubeclient, policyInformer.Lister(), policyClientset, eventController, nil)
|
violationBuilder := violation.NewPolicyViolationBuilder(kubeclient, policyInformer.Lister(), policyClientset, eventController, nil)
|
||||||
policyEngine := policyengine.NewPolicyEngine(kubeclient, nil)
|
policyEngine := engine.NewPolicyEngine(kubeclient, nil)
|
||||||
|
|
||||||
policyController := policycontroller.NewPolicyController(policyClientset,
|
policyController := controller.NewPolicyController(policyClientset,
|
||||||
policyInformer,
|
policyInformer,
|
||||||
policyEngine,
|
policyEngine,
|
||||||
violationBuilder,
|
violationBuilder,
|
||||||
|
@ -64,7 +62,7 @@ func main() {
|
||||||
log.Fatalf("Failed to initialize TLS key/certificate pair: %v\n", err)
|
log.Fatalf("Failed to initialize TLS key/certificate pair: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
server, err := webhooks.NewWebhookServer(tlsPair, kubeclient, policyInformer.Lister(), nil)
|
server, err := webhooks.NewWebhookServer(tlsPair, kubeclient, policyInformer.Lister(), policyEngine, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to create webhook server: %v\n", err)
|
log.Fatalf("Unable to create webhook server: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package policycontroller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -11,9 +11,9 @@ import (
|
||||||
policyclientset "github.com/nirmata/kube-policy/pkg/client/clientset/versioned"
|
policyclientset "github.com/nirmata/kube-policy/pkg/client/clientset/versioned"
|
||||||
infomertypes "github.com/nirmata/kube-policy/pkg/client/informers/externalversions/policy/v1alpha1"
|
infomertypes "github.com/nirmata/kube-policy/pkg/client/informers/externalversions/policy/v1alpha1"
|
||||||
lister "github.com/nirmata/kube-policy/pkg/client/listers/policy/v1alpha1"
|
lister "github.com/nirmata/kube-policy/pkg/client/listers/policy/v1alpha1"
|
||||||
|
engine "github.com/nirmata/kube-policy/pkg/engine"
|
||||||
event "github.com/nirmata/kube-policy/pkg/event"
|
event "github.com/nirmata/kube-policy/pkg/event"
|
||||||
policyengine "github.com/nirmata/kube-policy/pkg/policyengine"
|
violation "github.com/nirmata/kube-policy/pkg/violation"
|
||||||
policyviolation "github.com/nirmata/kube-policy/pkg/policyviolation"
|
|
||||||
"k8s.io/apimachinery/pkg/api/errors"
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
|
@ -28,8 +28,8 @@ type PolicyController struct {
|
||||||
policyLister lister.PolicyLister
|
policyLister lister.PolicyLister
|
||||||
policyInterface policyclientset.Interface
|
policyInterface policyclientset.Interface
|
||||||
policySynced cache.InformerSynced
|
policySynced cache.InformerSynced
|
||||||
policyEngine policyengine.PolicyEngine
|
policyEngine engine.PolicyEngine
|
||||||
violationBuilder policyviolation.Generator
|
violationBuilder violation.Generator
|
||||||
eventBuilder event.Generator
|
eventBuilder event.Generator
|
||||||
logger *log.Logger
|
logger *log.Logger
|
||||||
queue workqueue.RateLimitingInterface
|
queue workqueue.RateLimitingInterface
|
||||||
|
@ -38,8 +38,8 @@ type PolicyController struct {
|
||||||
// NewPolicyController from cmd args
|
// NewPolicyController from cmd args
|
||||||
func NewPolicyController(policyInterface policyclientset.Interface,
|
func NewPolicyController(policyInterface policyclientset.Interface,
|
||||||
policyInformer infomertypes.PolicyInformer,
|
policyInformer infomertypes.PolicyInformer,
|
||||||
policyEngine policyengine.PolicyEngine,
|
policyEngine engine.PolicyEngine,
|
||||||
violationBuilder policyviolation.Generator,
|
violationBuilder violation.Generator,
|
||||||
eventController event.Generator,
|
eventController event.Generator,
|
||||||
logger *log.Logger,
|
logger *log.Logger,
|
||||||
kubeClient *kubeClient.KubeClient) *PolicyController {
|
kubeClient *kubeClient.KubeClient) *PolicyController {
|
|
@ -1,4 +1,4 @@
|
||||||
package policycontroller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
|
@ -1,4 +1,4 @@
|
||||||
package policycontroller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
types "github.com/nirmata/kube-policy/pkg/apis/policy/v1alpha1"
|
types "github.com/nirmata/kube-policy/pkg/apis/policy/v1alpha1"
|
||||||
event "github.com/nirmata/kube-policy/pkg/event"
|
event "github.com/nirmata/kube-policy/pkg/event"
|
||||||
policyviolation "github.com/nirmata/kube-policy/pkg/policyviolation"
|
violation "github.com/nirmata/kube-policy/pkg/violation"
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
|
@ -41,7 +41,7 @@ func (pc *PolicyController) runForPolicy(key string) {
|
||||||
|
|
||||||
// processPolicy process the policy to all the matched resources
|
// processPolicy process the policy to all the matched resources
|
||||||
func (pc *PolicyController) processPolicy(policy types.Policy) (
|
func (pc *PolicyController) processPolicy(policy types.Policy) (
|
||||||
violations []policyviolation.Info, events []event.Info, err error) {
|
violations []violation.Info, events []event.Info, err error) {
|
||||||
|
|
||||||
for _, rule := range policy.Spec.Rules {
|
for _, rule := range policy.Spec.Rules {
|
||||||
resources, err := pc.filterResourceByRule(rule)
|
resources, err := pc.filterResourceByRule(rule)
|
|
@ -1,4 +1,4 @@
|
||||||
package policycontroller
|
package controller
|
||||||
|
|
||||||
const policyWorkQueueName = "policyworkqueue"
|
const policyWorkQueueName = "policyworkqueue"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package policyengine
|
package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -6,9 +6,9 @@ import (
|
||||||
|
|
||||||
kubeClient "github.com/nirmata/kube-policy/kubeclient"
|
kubeClient "github.com/nirmata/kube-policy/kubeclient"
|
||||||
types "github.com/nirmata/kube-policy/pkg/apis/policy/v1alpha1"
|
types "github.com/nirmata/kube-policy/pkg/apis/policy/v1alpha1"
|
||||||
|
"github.com/nirmata/kube-policy/pkg/engine/mutation"
|
||||||
event "github.com/nirmata/kube-policy/pkg/event"
|
event "github.com/nirmata/kube-policy/pkg/event"
|
||||||
"github.com/nirmata/kube-policy/pkg/policyengine/mutation"
|
violation "github.com/nirmata/kube-policy/pkg/violation"
|
||||||
policyviolation "github.com/nirmata/kube-policy/pkg/policyviolation"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -26,9 +26,10 @@ type PolicyEngine interface {
|
||||||
// when there is an create / update of the policy
|
// when there is an create / update of the policy
|
||||||
// we should process the policy on matched resources, generate violations accordingly
|
// we should process the policy on matched resources, generate violations accordingly
|
||||||
// TODO: This method should not be in PolicyEngine. Validate will do this work instead
|
// TODO: This method should not be in PolicyEngine. Validate will do this work instead
|
||||||
ProcessExisting(policy types.Policy, rawResource []byte) ([]policyviolation.Info, []event.Info, error)
|
ProcessExisting(policy types.Policy, rawResource []byte) ([]violation.Info, []event.Info, error)
|
||||||
|
|
||||||
// TODO: Add Generate method
|
// TODO: Add Generate method
|
||||||
|
// Generate()
|
||||||
}
|
}
|
||||||
|
|
||||||
type policyEngine struct {
|
type policyEngine struct {
|
||||||
|
@ -44,8 +45,8 @@ func NewPolicyEngine(kubeClient *kubeClient.KubeClient, logger *log.Logger) Poli
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *policyEngine) ProcessExisting(policy types.Policy, rawResource []byte) ([]policyviolation.Info, []event.Info, error) {
|
func (p *policyEngine) ProcessExisting(policy types.Policy, rawResource []byte) ([]violation.Info, []event.Info, error) {
|
||||||
var violations []policyviolation.Info
|
var violations []violation.Info
|
||||||
var events []event.Info
|
var events []event.Info
|
||||||
|
|
||||||
for _, rule := range policy.Spec.Rules {
|
for _, rule := range policy.Spec.Rules {
|
||||||
|
@ -75,9 +76,9 @@ func (p *policyEngine) ProcessExisting(policy types.Policy, rawResource []byte)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *policyEngine) processRuleOnResource(policyName string, rule types.Rule, rawResource []byte) (
|
func (p *policyEngine) processRuleOnResource(policyName string, rule types.Rule, rawResource []byte) (
|
||||||
policyviolation.Info, []event.Info, error) {
|
violation.Info, []event.Info, error) {
|
||||||
|
|
||||||
var violationInfo policyviolation.Info
|
var violationInfo violation.Info
|
||||||
var eventInfos []event.Info
|
var eventInfos []event.Info
|
||||||
|
|
||||||
resourceKind := mutation.ParseKindFromObject(rawResource)
|
resourceKind := mutation.ParseKindFromObject(rawResource)
|
||||||
|
@ -92,7 +93,7 @@ func (p *policyEngine) processRuleOnResource(policyName string, rule types.Rule,
|
||||||
if rulePatchesProcessed != nil {
|
if rulePatchesProcessed != nil {
|
||||||
log.Printf("Rule %s: prepared %d patches", rule.Name, len(rulePatchesProcessed))
|
log.Printf("Rule %s: prepared %d patches", rule.Name, len(rulePatchesProcessed))
|
||||||
|
|
||||||
violationInfo = policyviolation.NewViolation(policyName, resourceKind, resourceNamespace+"/"+resourceName, rule.Name)
|
violationInfo = violation.NewViolation(policyName, resourceKind, resourceNamespace+"/"+resourceName, rule.Name)
|
||||||
// add a violation to queue
|
// add a violation to queue
|
||||||
|
|
||||||
// add an event to policy
|
// add an event to policy
|
|
@ -1,10 +1,10 @@
|
||||||
package policyengine
|
package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
kubepolicy "github.com/nirmata/kube-policy/pkg/apis/policy/v1alpha1"
|
kubepolicy "github.com/nirmata/kube-policy/pkg/apis/policy/v1alpha1"
|
||||||
"github.com/nirmata/kube-policy/pkg/policyengine/mutation"
|
"github.com/nirmata/kube-policy/pkg/engine/mutation"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: To be reworked due to spec policy-v2
|
// TODO: To be reworked due to spec policy-v2
|
|
@ -1,8 +1,8 @@
|
||||||
package policyengine
|
package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
kubepolicy "github.com/nirmata/kube-policy/pkg/apis/policy/v1alpha1"
|
kubepolicy "github.com/nirmata/kube-policy/pkg/apis/policy/v1alpha1"
|
||||||
"github.com/nirmata/kube-policy/pkg/policyengine/mutation"
|
"github.com/nirmata/kube-policy/pkg/engine/mutation"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
)
|
)
|
||||||
|
|
44
pkg/engine/mutation/checkRules.go
Normal file
44
pkg/engine/mutation/checkRules.go
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
package mutation
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/minio/minio/pkg/wildcard"
|
||||||
|
types "github.com/nirmata/kube-policy/pkg/apis/policy/v1alpha1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
// kind is the type of object being manipulated
|
||||||
|
// Checks requests kind, name and labels to fit the policy
|
||||||
|
func IsRuleApplicableToResource(resourceRaw []byte, description types.ResourceDescription) (bool, error) {
|
||||||
|
kind := ParseKindFromObject(resourceRaw)
|
||||||
|
if description.Kind != kind {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if resourceRaw != nil {
|
||||||
|
meta := ParseMetadataFromObject(resourceRaw)
|
||||||
|
name := ParseNameFromObject(resourceRaw)
|
||||||
|
|
||||||
|
if description.Name != nil {
|
||||||
|
|
||||||
|
if !wildcard.Match(*description.Name, name) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if description.Selector != nil {
|
||||||
|
selector, err := metav1.LabelSelectorAsSelector(description.Selector)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
labelMap := ParseLabelsFromMetadata(meta)
|
||||||
|
|
||||||
|
if !selector.Matches(labelMap) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
|
@ -1,11 +1,11 @@
|
||||||
package policyengine
|
package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
kubepolicy "github.com/nirmata/kube-policy/pkg/apis/policy/v1alpha1"
|
kubepolicy "github.com/nirmata/kube-policy/pkg/apis/policy/v1alpha1"
|
||||||
"github.com/nirmata/kube-policy/pkg/policyengine/mutation"
|
"github.com/nirmata/kube-policy/pkg/engine/mutation"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
)
|
)
|
||||||
|
|
|
@ -66,7 +66,7 @@ func initRecorder(kubeClient *kubeClient.KubeClient) record.EventRecorder {
|
||||||
eventBroadcaster.StartLogging(log.Printf)
|
eventBroadcaster.StartLogging(log.Printf)
|
||||||
eventBroadcaster.StartRecordingToSink(
|
eventBroadcaster.StartRecordingToSink(
|
||||||
&typedcorev1.EventSinkImpl{
|
&typedcorev1.EventSinkImpl{
|
||||||
Interface: kubeClient.GetEventsInterface("")})
|
Interface: kubeClient.GetEvents("")})
|
||||||
recorder := eventBroadcaster.NewRecorder(
|
recorder := eventBroadcaster.NewRecorder(
|
||||||
scheme.Scheme,
|
scheme.Scheme,
|
||||||
v1.EventSource{Component: eventSource})
|
v1.EventSource{Component: eventSource})
|
|
@ -19,11 +19,12 @@ func (k MsgKey) String() string {
|
||||||
|
|
||||||
const argRegex = "%[s,d,v]"
|
const argRegex = "%[s,d,v]"
|
||||||
|
|
||||||
|
var re = regexp.MustCompile(argRegex)
|
||||||
|
|
||||||
//GetEventMsg return the application message based on the message id and the arguments,
|
//GetEventMsg return the application message based on the message id and the arguments,
|
||||||
// if the number of arguments passed to the message are incorrect generate an error
|
// if the number of arguments passed to the message are incorrect generate an error
|
||||||
func getEventMsg(key MsgKey, args ...interface{}) (string, error) {
|
func getEventMsg(key MsgKey, args ...interface{}) (string, error) {
|
||||||
// Verify the number of arguments
|
// Verify the number of arguments
|
||||||
re := regexp.MustCompile(argRegex)
|
|
||||||
argsCount := len(re.FindAllString(key.String(), -1))
|
argsCount := len(re.FindAllString(key.String(), -1))
|
||||||
if argsCount != len(args) {
|
if argsCount != len(args) {
|
||||||
return "", fmt.Errorf("message expects %d arguments, but %d arguments passed", argsCount, len(args))
|
return "", fmt.Errorf("message expects %d arguments, but %d arguments passed", argsCount, len(args))
|
|
@ -1,4 +1,4 @@
|
||||||
package policyviolation
|
package violation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -1,4 +1,4 @@
|
||||||
package policyviolation
|
package violation
|
||||||
|
|
||||||
import policytype "github.com/nirmata/kube-policy/pkg/apis/policy/v1alpha1"
|
import policytype "github.com/nirmata/kube-policy/pkg/apis/policy/v1alpha1"
|
||||||
|
|
|
@ -15,8 +15,8 @@ import (
|
||||||
"github.com/nirmata/kube-policy/config"
|
"github.com/nirmata/kube-policy/config"
|
||||||
"github.com/nirmata/kube-policy/kubeclient"
|
"github.com/nirmata/kube-policy/kubeclient"
|
||||||
policylister "github.com/nirmata/kube-policy/pkg/client/listers/policy/v1alpha1"
|
policylister "github.com/nirmata/kube-policy/pkg/client/listers/policy/v1alpha1"
|
||||||
"github.com/nirmata/kube-policy/pkg/policyengine"
|
engine "github.com/nirmata/kube-policy/pkg/engine"
|
||||||
"github.com/nirmata/kube-policy/pkg/policyengine/mutation"
|
"github.com/nirmata/kube-policy/pkg/engine/mutation"
|
||||||
tlsutils "github.com/nirmata/kube-policy/pkg/tls"
|
tlsutils "github.com/nirmata/kube-policy/pkg/tls"
|
||||||
v1beta1 "k8s.io/api/admission/v1beta1"
|
v1beta1 "k8s.io/api/admission/v1beta1"
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
|
@ -27,7 +27,7 @@ import (
|
||||||
// MutationWebhook gets policies from policyController and takes control of the cluster with kubeclient.
|
// MutationWebhook gets policies from policyController and takes control of the cluster with kubeclient.
|
||||||
type WebhookServer struct {
|
type WebhookServer struct {
|
||||||
server http.Server
|
server http.Server
|
||||||
policyEngine policyengine.PolicyEngine
|
policyEngine engine.PolicyEngine
|
||||||
policyLister policylister.PolicyLister
|
policyLister policylister.PolicyLister
|
||||||
logger *log.Logger
|
logger *log.Logger
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ func NewWebhookServer(
|
||||||
tlsPair *tlsutils.TlsPemPair,
|
tlsPair *tlsutils.TlsPemPair,
|
||||||
kubeClient *kubeclient.KubeClient,
|
kubeClient *kubeclient.KubeClient,
|
||||||
policyLister policylister.PolicyLister,
|
policyLister policylister.PolicyLister,
|
||||||
|
policyEngine engine.PolicyEngine,
|
||||||
logger *log.Logger) (*WebhookServer, error) {
|
logger *log.Logger) (*WebhookServer, error) {
|
||||||
if logger == nil {
|
if logger == nil {
|
||||||
logger = log.New(os.Stdout, "Webhook Server: ", log.LstdFlags)
|
logger = log.New(os.Stdout, "Webhook Server: ", log.LstdFlags)
|
||||||
|
@ -53,7 +54,6 @@ func NewWebhookServer(
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
tlsConfig.Certificates = []tls.Certificate{pair}
|
tlsConfig.Certificates = []tls.Certificate{pair}
|
||||||
policyEngine := policyengine.NewPolicyEngine(kubeClient, logger)
|
|
||||||
|
|
||||||
ws := &WebhookServer{
|
ws := &WebhookServer{
|
||||||
policyEngine: policyEngine,
|
policyEngine: policyEngine,
|
||||||
|
|
Loading…
Add table
Reference in a new issue