Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validating webhooks for Egress and ExternalIPPool #2358

Merged
merged 1 commit into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions build/yamls/antrea-aks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4539,6 +4539,49 @@ webhooks:
scope: Cluster
sideEffects: None
timeoutSeconds: 5
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: antrea
namespace: kube-system
path: /validate/externalippool
name: externalippoolvalidator.antrea.io
rules:
- apiGroups:
- crd.antrea.io
apiVersions:
- v1alpha2
operations:
- UPDATE
resources:
- externalippools
scope: Cluster
sideEffects: None
timeoutSeconds: 5
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: antrea
namespace: kube-system
path: /validate/egress
name: egressvalidator.antrea.io
rules:
- apiGroups:
- crd.antrea.io
apiVersions:
- v1alpha2
operations:
- CREATE
- UPDATE
resources:
- egresses
scope: Cluster
sideEffects: None
timeoutSeconds: 5
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
Expand Down
43 changes: 43 additions & 0 deletions build/yamls/antrea-eks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4541,6 +4541,49 @@ webhooks:
scope: Cluster
sideEffects: None
timeoutSeconds: 5
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: antrea
namespace: kube-system
path: /validate/externalippool
name: externalippoolvalidator.antrea.io
rules:
- apiGroups:
- crd.antrea.io
apiVersions:
- v1alpha2
operations:
- UPDATE
resources:
- externalippools
scope: Cluster
sideEffects: None
timeoutSeconds: 5
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: antrea
namespace: kube-system
path: /validate/egress
name: egressvalidator.antrea.io
rules:
- apiGroups:
- crd.antrea.io
apiVersions:
- v1alpha2
operations:
- CREATE
- UPDATE
resources:
- egresses
scope: Cluster
sideEffects: None
timeoutSeconds: 5
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
Expand Down
43 changes: 43 additions & 0 deletions build/yamls/antrea-gke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4539,6 +4539,49 @@ webhooks:
scope: Cluster
sideEffects: None
timeoutSeconds: 5
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: antrea
namespace: kube-system
path: /validate/externalippool
name: externalippoolvalidator.antrea.io
rules:
- apiGroups:
- crd.antrea.io
apiVersions:
- v1alpha2
operations:
- UPDATE
resources:
- externalippools
scope: Cluster
sideEffects: None
timeoutSeconds: 5
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: antrea
namespace: kube-system
path: /validate/egress
name: egressvalidator.antrea.io
rules:
- apiGroups:
- crd.antrea.io
apiVersions:
- v1alpha2
operations:
- CREATE
- UPDATE
resources:
- egresses
scope: Cluster
sideEffects: None
timeoutSeconds: 5
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
Expand Down
43 changes: 43 additions & 0 deletions build/yamls/antrea-ipsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4588,6 +4588,49 @@ webhooks:
scope: Cluster
sideEffects: None
timeoutSeconds: 5
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: antrea
namespace: kube-system
path: /validate/externalippool
name: externalippoolvalidator.antrea.io
rules:
- apiGroups:
- crd.antrea.io
apiVersions:
- v1alpha2
operations:
- UPDATE
resources:
- externalippools
scope: Cluster
sideEffects: None
timeoutSeconds: 5
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: antrea
namespace: kube-system
path: /validate/egress
name: egressvalidator.antrea.io
rules:
- apiGroups:
- crd.antrea.io
apiVersions:
- v1alpha2
operations:
- CREATE
- UPDATE
resources:
- egresses
scope: Cluster
sideEffects: None
timeoutSeconds: 5
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
Expand Down
43 changes: 43 additions & 0 deletions build/yamls/antrea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4544,6 +4544,49 @@ webhooks:
scope: Cluster
sideEffects: None
timeoutSeconds: 5
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: antrea
namespace: kube-system
path: /validate/externalippool
name: externalippoolvalidator.antrea.io
rules:
- apiGroups:
- crd.antrea.io
apiVersions:
- v1alpha2
operations:
- UPDATE
resources:
- externalippools
scope: Cluster
sideEffects: None
timeoutSeconds: 5
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: antrea
namespace: kube-system
path: /validate/egress
name: egressvalidator.antrea.io
rules:
- apiGroups:
- crd.antrea.io
apiVersions:
- v1alpha2
operations:
- CREATE
- UPDATE
resources:
- egresses
scope: Cluster
sideEffects: None
timeoutSeconds: 5
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
Expand Down
30 changes: 30 additions & 0 deletions build/yamls/base/controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,36 @@ webhooks:
admissionReviewVersions: ["v1", "v1beta1"]
sideEffects: None
timeoutSeconds: 5
- name: "externalippoolvalidator.antrea.io"
clientConfig:
service:
name: "antrea"
namespace: "kube-system"
path: "/validate/externalippool"
rules:
- operations: ["UPDATE"]
apiGroups: ["crd.antrea.io"]
apiVersions: ["v1alpha2"]
resources: ["externalippools"]
scope: "Cluster"
admissionReviewVersions: ["v1", "v1beta1"]
sideEffects: None
timeoutSeconds: 5
- name: "egressvalidator.antrea.io"
clientConfig:
service:
name: "antrea"
namespace: "kube-system"
path: "/validate/egress"
rules:
- operations: ["CREATE", "UPDATE"]
apiGroups: ["crd.antrea.io"]
apiVersions: ["v1alpha2"]
resources: ["egresses"]
scope: "Cluster"
admissionReviewVersions: ["v1", "v1beta1"]
sideEffects: None
timeoutSeconds: 5
---
apiVersion: apiregistration.k8s.io/v1
kind: APIService
Expand Down
7 changes: 6 additions & 1 deletion cmd/antrea-controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ var allowedPaths = []string{
"/validate/acnp",
"/validate/anp",
"/validate/clustergroup",
"/validate/externalippool",
"/validate/egress",
"/convert/clustergroup",
}

Expand Down Expand Up @@ -274,6 +276,7 @@ func run(o *Options) error {
endpointQuerier,
networkPolicyController,
networkPolicyStatusController,
egressController,
statsAggregator,
o.config.EnablePrometheusMetrics,
cipherSuites,
Expand Down Expand Up @@ -364,6 +367,7 @@ func createAPIServerConfig(kubeconfig string,
endpointQuerier networkpolicy.EndpointQuerier,
npController *networkpolicy.NetworkPolicyController,
networkPolicyStatusController *networkpolicy.StatusController,
egressController *egress.EgressController,
statsAggregator *stats.Aggregator,
enableMetrics bool,
cipherSuites []uint16,
Expand Down Expand Up @@ -424,5 +428,6 @@ func createAPIServerConfig(kubeconfig string,
controllerQuerier,
networkPolicyStatusController,
endpointQuerier,
npController), nil
npController,
egressController), nil
}
19 changes: 14 additions & 5 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import (
"antrea.io/antrea/pkg/apiserver/registry/system/controllerinfo"
"antrea.io/antrea/pkg/apiserver/registry/system/supportbundle"
"antrea.io/antrea/pkg/apiserver/storage"
"antrea.io/antrea/pkg/controller/egress"
controllernetworkpolicy "antrea.io/antrea/pkg/controller/networkpolicy"
"antrea.io/antrea/pkg/controller/querier"
"antrea.io/antrea/pkg/controller/stats"
Expand Down Expand Up @@ -98,6 +99,7 @@ type ExtraConfig struct {
controllerQuerier querier.ControllerQuerier
endpointQuerier controllernetworkpolicy.EndpointQuerier
networkPolicyController *controllernetworkpolicy.NetworkPolicyController
egressController *egress.EgressController
caCertController *certificate.CACertController
statsAggregator *stats.Aggregator
networkPolicyStatusController *controllernetworkpolicy.StatusController
Expand Down Expand Up @@ -139,7 +141,8 @@ func NewConfig(
controllerQuerier querier.ControllerQuerier,
networkPolicyStatusController *controllernetworkpolicy.StatusController,
endpointQuerier controllernetworkpolicy.EndpointQuerier,
npController *controllernetworkpolicy.NetworkPolicyController) *Config {
npController *controllernetworkpolicy.NetworkPolicyController,
egressController *egress.EgressController) *Config {
return &Config{
genericConfig: genericConfig,
extraConfig: ExtraConfig{
Expand All @@ -154,6 +157,7 @@ func NewConfig(
endpointQuerier: endpointQuerier,
networkPolicyController: npController,
networkPolicyStatusController: networkPolicyStatusController,
egressController: egressController,
},
}
}
Expand Down Expand Up @@ -292,10 +296,10 @@ func installHandlers(c *ExtraConfig, s *genericapiserver.GenericAPIServer) {
// Get new NetworkPolicyValidator
v := controllernetworkpolicy.NewNetworkPolicyValidator(c.networkPolicyController)
// Install handlers for NetworkPolicy related validation
s.Handler.NonGoRestfulMux.HandleFunc("/validate/tier", webhook.HandleValidationNetworkPolicy(v))
s.Handler.NonGoRestfulMux.HandleFunc("/validate/acnp", webhook.HandleValidationNetworkPolicy(v))
s.Handler.NonGoRestfulMux.HandleFunc("/validate/anp", webhook.HandleValidationNetworkPolicy(v))
s.Handler.NonGoRestfulMux.HandleFunc("/validate/clustergroup", webhook.HandleValidationNetworkPolicy(v))
s.Handler.NonGoRestfulMux.HandleFunc("/validate/tier", webhook.HandlerForValidateFunc(v.Validate))
s.Handler.NonGoRestfulMux.HandleFunc("/validate/acnp", webhook.HandlerForValidateFunc(v.Validate))
s.Handler.NonGoRestfulMux.HandleFunc("/validate/anp", webhook.HandlerForValidateFunc(v.Validate))
s.Handler.NonGoRestfulMux.HandleFunc("/validate/clustergroup", webhook.HandlerForValidateFunc(v.Validate))

// Install handlers for CRD conversion between versions
s.Handler.NonGoRestfulMux.HandleFunc("/convert/clustergroup", webhook.HandleCRDConversion(controllernetworkpolicy.ConvertClusterGroupCRD))
Expand All @@ -306,4 +310,9 @@ func installHandlers(c *ExtraConfig, s *genericapiserver.GenericAPIServer) {
return nil
})
}

if features.DefaultFeatureGate.Enabled(features.Egress) {
s.Handler.NonGoRestfulMux.HandleFunc("/validate/externalippool", webhook.HandlerForValidateFunc(c.egressController.ValidateExternalIPPool))
s.Handler.NonGoRestfulMux.HandleFunc("/validate/egress", webhook.HandlerForValidateFunc(c.egressController.ValidateEgress))
}
}
Loading