Skip to content

Commit

Permalink
Fix webhook rbac and add istio tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ukclivecox authored and seldondev committed Dec 16, 2019
1 parent 444fc04 commit e12524f
Show file tree
Hide file tree
Showing 16 changed files with 25,086 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ spec:
value: '{{ .Values.istio.enabled }}'
- name: ISTIO_GATEWAY
value: '{{ .Values.istio.gateway }}'
- name: ISTIO_TLS_MODE
value: '{{ .Values.istio.tlsMode }}'
image: '{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}'
imagePullPolicy: '{{ .Values.image.pullPolicy }}'
name: manager
Expand Down
148 changes: 126 additions & 22 deletions helm-charts/seldon-core-operator/templates/webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,39 @@ webhooks:
resources:
- seldondeployments
- clientConfig:
caBundle: Cg==
caBundle: '{{ $ca.Cert | b64enc }}'
service:
name: seldon-webhook-service
namespace: seldon-system
namespace: '{{ .Release.Namespace }}'
path: /validate-machinelearning-seldon-io-v1alpha2-seldondeployment
failurePolicy: Fail
name: vseldondeployment.kb.io
{{- if semverCompare ">=1.15.0" .Capabilities.KubeVersion.Version }}
{{- if not .Values.singleNamespace }}
namespaceSelector:
matchExpressions:
- key: seldon.io/controller-id
operator: DoesNotExist
{{- end }}
{{- end }}
{{- if .Values.singleNamespace }}
namespaceSelector:
matchLabels:
seldon.io/controller-id: {{ .Release.Namespace }}
{{- end }}
{{- if semverCompare ">=1.15.0" .Capabilities.KubeVersion.Version }}
{{- if not .Values.controllerId }}
objectSelector:
matchExpressions:
- key: seldon.io/controller-id
operator: DoesNotExist
{{- end }}
{{- end }}
{{- if .Values.controllerId }}
objectSelector:
matchLabels:
seldon.io/controller-id: {{ .Values.controllerId }}
{{- end }}
rules:
- apiGroups:
- machinelearning.seldon.io
Expand All @@ -79,13 +105,39 @@ webhooks:
resources:
- seldondeployments
- clientConfig:
caBundle: Cg==
caBundle: '{{ $ca.Cert | b64enc }}'
service:
name: seldon-webhook-service
namespace: seldon-system
namespace: '{{ .Release.Namespace }}'
path: /validate-machinelearning-seldon-io-v1alpha3-seldondeployment
failurePolicy: Fail
name: vseldondeployment.kb.io
{{- if semverCompare ">=1.15.0" .Capabilities.KubeVersion.Version }}
{{- if not .Values.singleNamespace }}
namespaceSelector:
matchExpressions:
- key: seldon.io/controller-id
operator: DoesNotExist
{{- end }}
{{- end }}
{{- if .Values.singleNamespace }}
namespaceSelector:
matchLabels:
seldon.io/controller-id: {{ .Release.Namespace }}
{{- end }}
{{- if semverCompare ">=1.15.0" .Capabilities.KubeVersion.Version }}
{{- if not .Values.controllerId }}
objectSelector:
matchExpressions:
- key: seldon.io/controller-id
operator: DoesNotExist
{{- end }}
{{- end }}
{{- if .Values.controllerId }}
objectSelector:
matchLabels:
seldon.io/controller-id: {{ .Values.controllerId }}
{{- end }}
rules:
- apiGroups:
- machinelearning.seldon.io
Expand All @@ -98,20 +150,6 @@ webhooks:
- seldondeployments
---

{{- if not .Values.certManager.enabled -}}
apiVersion: v1
data:
ca.crt: '{{ $ca.Cert | b64enc }}'
tls.crt: '{{ $cert.Cert | b64enc }}'
tls.key: '{{ $cert.Key | b64enc }}'
kind: Secret
metadata:
name: seldon-webhook-server-cert
namespace: '{{ .Release.Namespace }}'
type: kubernetes.io/tls
{{- end }}
---

apiVersion: admissionregistration.k8s.io/v1beta1
kind: MutatingWebhookConfiguration
metadata:
Expand Down Expand Up @@ -170,13 +208,39 @@ webhooks:
resources:
- seldondeployments
- clientConfig:
caBundle: Cg==
caBundle: '{{ $ca.Cert | b64enc }}'
service:
name: seldon-webhook-service
namespace: seldon-system
namespace: '{{ .Release.Namespace }}'
path: /mutate-machinelearning-seldon-io-v1alpha2-seldondeployment
failurePolicy: Fail
name: mseldondeployment.kb.io
{{- if semverCompare ">=1.15.0" .Capabilities.KubeVersion.Version }}
{{- if not .Values.singleNamespace }}
namespaceSelector:
matchExpressions:
- key: seldon.io/controller-id
operator: DoesNotExist
{{- end }}
{{- end }}
{{- if .Values.singleNamespace }}
namespaceSelector:
matchLabels:
seldon.io/controller-id: {{ .Release.Namespace }}
{{- end }}
{{- if semverCompare ">=1.15.0" .Capabilities.KubeVersion.Version }}
{{- if not .Values.controllerId }}
objectSelector:
matchExpressions:
- key: seldon.io/controller-id
operator: DoesNotExist
{{- end }}
{{- end }}
{{- if .Values.controllerId }}
objectSelector:
matchLabels:
seldon.io/controller-id: {{ .Values.controllerId }}
{{- end }}
rules:
- apiGroups:
- machinelearning.seldon.io
Expand All @@ -188,13 +252,39 @@ webhooks:
resources:
- seldondeployments
- clientConfig:
caBundle: Cg==
caBundle: '{{ $ca.Cert | b64enc }}'
service:
name: seldon-webhook-service
namespace: seldon-system
namespace: '{{ .Release.Namespace }}'
path: /mutate-machinelearning-seldon-io-v1alpha3-seldondeployment
failurePolicy: Fail
name: mseldondeployment.kb.io
{{- if semverCompare ">=1.15.0" .Capabilities.KubeVersion.Version }}
{{- if not .Values.singleNamespace }}
namespaceSelector:
matchExpressions:
- key: seldon.io/controller-id
operator: DoesNotExist
{{- end }}
{{- end }}
{{- if .Values.singleNamespace }}
namespaceSelector:
matchLabels:
seldon.io/controller-id: {{ .Release.Namespace }}
{{- end }}
{{- if semverCompare ">=1.15.0" .Capabilities.KubeVersion.Version }}
{{- if not .Values.controllerId }}
objectSelector:
matchExpressions:
- key: seldon.io/controller-id
operator: DoesNotExist
{{- end }}
{{- end }}
{{- if .Values.controllerId }}
objectSelector:
matchLabels:
seldon.io/controller-id: {{ .Values.controllerId }}
{{- end }}
rules:
- apiGroups:
- machinelearning.seldon.io
Expand All @@ -205,3 +295,17 @@ webhooks:
- UPDATE
resources:
- seldondeployments
---

{{- if not .Values.certManager.enabled -}}
apiVersion: v1
data:
ca.crt: '{{ $ca.Cert | b64enc }}'
tls.crt: '{{ $cert.Cert | b64enc }}'
tls.key: '{{ $cert.Key | b64enc }}'
kind: Secret
metadata:
name: seldon-webhook-server-cert
namespace: '{{ .Release.Namespace }}'
type: kubernetes.io/tls
{{- end }}
3 changes: 2 additions & 1 deletion helm-charts/seldon-core-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ engine:
name: default
user: 8888
image:
pullPolicy: Always
pullPolicy: IfNotPresent
registry: docker.io
repository: seldonio/seldon-core-operator
tag: 0.5.2-SNAPSHOT
istio:
enabled: false
gateway: seldon-gateway
tlsMode: ''
predictiveUnit:
port: 9000
rbac:
Expand Down
2 changes: 2 additions & 0 deletions operator/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ spec:
value: "false"
- name: ISTIO_GATEWAY
value: seldon-gateway
- name: ISTIO_TLS_MODE
value: ""
image: controller:latest
name: manager
resources:
Expand Down
15 changes: 13 additions & 2 deletions operator/config/webhook/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,16 @@ configurations:
- kustomizeconfig.yaml

# Comment this if you have a k8s cluster < 1.15 and want to use namespaced or labelled operators
patchesStrategicMerge:
- patch_object_selector.yaml
patchesJson6902:
- target:
group: admissionregistration.k8s.io
version: v1beta1
kind: MutatingWebhookConfiguration
name: mutating-webhook-configuration
path: patch_webhook.yaml
- target:
group: admissionregistration.k8s.io
version: v1beta1
kind: ValidatingWebhookConfiguration
name: validating-webhook-configuration
path: patch_webhook.yaml
29 changes: 0 additions & 29 deletions operator/config/webhook/patch_object_selector.yaml

This file was deleted.

1 change: 1 addition & 0 deletions operator/controllers/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package controllers
const (
ENV_ISTIO_ENABLED = "ISTIO_ENABLED"
ENV_ISTIO_GATEWAY = "ISTIO_GATEWAY"
ENV_ISTIO_TLS_MODE = "ISTIO_TLS_MODE"
ANNOTATION_ISTIO_GATEWAY = "seldon.io/istio-gateway"
)
23 changes: 13 additions & 10 deletions operator/controllers/seldondeployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func createIstioResources(mlDep *machinelearningv1.SeldonDeployment,
grpcAllowed bool) ([]*istio.VirtualService, []*istio.DestinationRule) {

istio_gateway := GetEnv(ENV_ISTIO_GATEWAY, "seldon-gateway")
istioTLSMode := GetEnv(ENV_ISTIO_TLS_MODE, "")
httpVsvc := &istio.VirtualService{
ObjectMeta: metav1.ObjectMeta{
Name: seldonId + "-http",
Expand Down Expand Up @@ -197,11 +198,6 @@ func createIstioResources(mlDep *machinelearningv1.SeldonDeployment,
},
Spec: istio.DestinationRuleSpec{
Host: pSvcName,
TrafficPolicy: &istio.TrafficPolicy{
TLS: &istio.TLSSettings{
Mode: istio.TLSmodeIstioMutual,
},
},
Subsets: []istio.Subset{
{
Name: p.Name,
Expand All @@ -213,6 +209,13 @@ func createIstioResources(mlDep *machinelearningv1.SeldonDeployment,
},
}

if istioTLSMode != "" {
drule.Spec.TrafficPolicy = &istio.TrafficPolicy{
TLS: &istio.TLSSettings{
Mode: istio.TLSmode(istioTLSMode),
},
}
}
drules[i] = drule

if p.Shadow == true {
Expand Down Expand Up @@ -1353,17 +1356,17 @@ func (r *SeldonDeploymentReconciler) Reconcile(req ctrl.Request) (ctrl.Result, e
return ctrl.Result{}, err
}

virtualServicesReady, err := createIstioServices(r, components, instance, log)
if err != nil {
return ctrl.Result{}, err
}
//virtualServicesReady, err := createIstioServices(r, components, instance, log)
//if err != nil {
// return ctrl.Result{}, err
//}

hpasReady, err := createHpas(r, components, instance, log)
if err != nil {
return ctrl.Result{}, err
}

if deploymentsReady && servicesReady && hpasReady && virtualServicesReady {
if deploymentsReady && servicesReady && hpasReady {
instance.Status.State = "Available"
} else {
instance.Status.State = "Creating"
Expand Down
5 changes: 5 additions & 0 deletions operator/helm/split_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"ENGINE_CONTAINER_SERVICE_ACCOUNT_NAME": "engine.serviceAccount.name",
"ISTIO_ENABLED":"istio.enabled",
"ISTIO_GATEWAY":"istio.gateway",
"ISTIO_TLS_MODE":"istio.tlsMode",
"PREDICTIVE_UNIT_SERVICE_PORT":"predictiveUnit.port"

}
Expand Down Expand Up @@ -135,6 +136,10 @@ def helm_release(value: str):
res["metadata"]["name"] = res["metadata"]["name"] + "-" + helm_release("Namespace")
res["webhooks"][0]["clientConfig"]["caBundle"] = "{{ $ca.Cert | b64enc }}"
res["webhooks"][0]["clientConfig"]["service"]["namespace"] = helm_release("Namespace")
res["webhooks"][1]["clientConfig"]["caBundle"] = "{{ $ca.Cert | b64enc }}"
res["webhooks"][1]["clientConfig"]["service"]["namespace"] = helm_release("Namespace")
res["webhooks"][2]["clientConfig"]["caBundle"] = "{{ $ca.Cert | b64enc }}"
res["webhooks"][2]["clientConfig"]["service"]["namespace"] = helm_release("Namespace")
if "certmanager.k8s.io/inject-ca-from" in res["metadata"]["annotations"]:
res["metadata"]["annotations"]["certmanager.k8s.io/inject-ca-from"] = helm_release("Namespace") + "/seldon-serving-cert"

Expand Down
14 changes: 14 additions & 0 deletions testing/resources/seldon-gateway.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: seldon-gateway
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
Loading

0 comments on commit e12524f

Please sign in to comment.