Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit c93af51

Browse files
committed
update to plurals
1 parent e610bf6 commit c93af51

File tree

6 files changed

+12
-103
lines changed

6 files changed

+12
-103
lines changed

cmd/manager/server.go

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,22 @@
1515
package main
1616

1717
import (
18-
"context"
1918
"fmt"
2019
"os"
2120

22-
"istio.io/operator/pkg/apis/istio/v1alpha2"
23-
controllerruntime "sigs.k8s.io/controller-runtime"
2421
"sigs.k8s.io/controller-runtime/pkg/webhook"
25-
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
26-
27-
//"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
28-
2922
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
30-
_ "k8s.io/client-go/plugin/pkg/client/auth"
31-
3223
drm "github.com/openshift/cluster-network-operator/pkg/util/k8s"
3324
"github.com/spf13/cobra"
25+
_ "k8s.io/client-go/plugin/pkg/client/auth"
3426
"sigs.k8s.io/controller-runtime/pkg/client/config"
3527
"sigs.k8s.io/controller-runtime/pkg/manager"
3628
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
3729

3830
"istio.io/operator/pkg/apis"
3931
"istio.io/operator/pkg/controller"
4032
"istio.io/operator/pkg/controller/istiocontrolplane"
33+
iscpwebhook "istio.io/operator/pkg/webhook/istiocontrolplane"
4134
"istio.io/pkg/ctrlz"
4235
"istio.io/pkg/log"
4336
)
@@ -142,30 +135,11 @@ func run() {
142135

143136
// setup webhooks
144137
log.Info("setting up webhook server")
145-
146-
// Method 1
147-
validatingHook := &webhook.Admission{
148-
Handler: admission.HandlerFunc(func(ctx context.Context, req webhook.AdmissionRequest) webhook.AdmissionResponse {
149-
log.Info("enterring admission handler!")
150-
return webhook.Denied("Test only: none shall pass!")
151-
}),
152-
}
153138
crv := mgr.GetWebhookServer()
154139
crv.CertDir = "/tmp/k8s-webhook-server/serving-certs"
155-
//crv.Port = 8443
156-
crv.Register("/validate", validatingHook)
157-
158-
// method 2
159-
//crv.Register("/validate-install-istio-io-v1alpha2-istiocontrolplane",
160-
// &webhook.Admission{Handler: &iscpwebhook.IscpValidator{}})
161-
162-
// Method3(implement the validator inside v1alpha2.IstioControlPlane)
163-
/* err = controllerruntime.NewWebhookManagedBy(mgr).
164-
For(&v1alpha2.IstioControlPlane{}).
165-
Complete()
166-
if err != nil {
167-
os.Exit(1)
168-
}*/
140+
crv.Port = 8443
141+
crv.Register("/validate-install-istio-io-v1alpha2-istiocontrolplane",
142+
&webhook.Admission{Handler: &iscpwebhook.IscpValidator{}})
169143

170144
log.Info("Starting the Cmd.")
171145

deploy/operator.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ spec:
3333
requests:
3434
cpu: 50m
3535
memory: 128Mi
36-
securityContext:
37-
runAsUser: 0
38-
runAsNonRoot: false
39-
capabilities:
40-
add:
41-
- NET_ADMIN
4236
env:
4337
- name: WATCH_NAMESPACE
4438
value: "istio-operator"

deploy/service.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ spec:
1010
ports:
1111
- port: 443
1212
name: webhook
13-
targetPort: 443
13+
targetPort: 8443
1414
- name: http-metrics
1515
port: 8383
1616
targetPort: 8383

deploy/webhook.yaml

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,4 @@ webhooks:
2323
- CREATE
2424
- UPDATE
2525
resources:
26-
- istiocontrolplane
27-
28-
---
29-
30-
# Testing only, see if basic resource admission request can go to webserver
31-
apiVersion: admissionregistration.k8s.io/v1beta1
32-
kind: ValidatingWebhookConfiguration
33-
metadata:
34-
name: validation-webhook-example-cfg
35-
labels:
36-
app: admission-webhook-example
37-
webhooks:
38-
- name: required-labels.banzaicloud.com
39-
clientConfig:
40-
service:
41-
name: istio-operator
42-
namespace: istio-operator
43-
path: "/validate"
44-
caBundle: Cg==
45-
rules:
46-
- operations: [ "CREATE", "UPDATE" ]
47-
apiGroups: ["apps", ""]
48-
apiVersions: ["v1"]
49-
resources: ["deployments","services"]
26+
- istiocontrolplanes

pkg/apis/istio/v1alpha2/istiocontrolplane_types.pb.go

Lines changed: 0 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/webhook/istiocontrolplane/iscpwebhook.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package istiocontrolplane
1616

1717
import (
1818
"context"
19+
"fmt"
1920

2021
"sigs.k8s.io/controller-runtime/pkg/client"
2122
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
@@ -41,8 +42,10 @@ func (a *IscpValidator) Handle(ctx context.Context, req admission.Request) admis
4142
return admission.Denied(err.Error())
4243
}
4344
//TODO: update to full validation including values part after values schema formalized.
44-
if errs := validate.CheckIstioControlPlaneSpecExcludeValues(icp.Spec, true); len(errs) != 0 {
45-
return admission.Denied(errs.Error())
45+
if errs := validate.CheckIstioControlPlaneSpecExcludeValues(icp.Spec, false); len(errs) != 0 {
46+
fmt.Printf("proceed with validation err: %v", errs.Error())
47+
// TODO: allow the request now until we fully done the validation logic.
48+
return admission.Allowed("IstioControlPlane schema validated with err")
4649
}
4750
return admission.Allowed("IstioControlPlane schema validated")
4851
}

0 commit comments

Comments
 (0)