Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Commit

Permalink
Jazz 馃檶 support for Istio (#22)
Browse files Browse the repository at this point in the history
* makes manager webhook port configurable

this was hard-coded here and in the chart. making this configurable
since there's no need to lock in a value. default remains 9443

* changes changes for istio

adds "--webhook-server-port" flag for manager
uses new default value to set previously hard-coded 9443 port
renames root container "manager"
enables psps/netpols by default (security-first measure)

* adds ns suffix to cluster-scope resources

gk! (gross kid) this ensures dco can be deployed multiple times.
strictly speaking, if you use a unique release name for each instance,
then is is not required. ugh...this hurts so much.

* fixes helm chart incorrect ref

clusterrole name needs to change to match clusterrolebinding ref
  • Loading branch information
sonnysideup committed Apr 2, 2021
1 parent ecc90eb commit 22e657e
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 17 deletions.
5 changes: 4 additions & 1 deletion cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var (
namespace string
probeAddr string
metricsAddr string
webhookPort int
enableLeaderElection bool

zapOpts = zap.Options{}
Expand All @@ -26,6 +27,7 @@ var startCmd = &cobra.Command{
Namespace: namespace,
MetricsAddr: metricsAddr,
HealthProbeAddr: probeAddr,
WebhookServerPort: webhookPort,
EnableLeaderElection: enableLeaderElection,
ZapOptions: zapOpts,
}
Expand All @@ -39,9 +41,10 @@ func init() {

fs := new(flag.FlagSet)
zapOpts.BindFlags(fs)
startCmd.Flags().AddGoFlagSet(fs)

startCmd.Flags().AddGoFlagSet(fs)
startCmd.Flags().StringVar(&namespace, "namespace", "default", "Reconcile clusters resources in this namespace")
startCmd.Flags().IntVar(&webhookPort, "webhook-server-port", 9443, "Webhook server will bind to this port")
startCmd.Flags().StringVar(&metricsAddr, "metrics-bind-address", ":8080",
"Metrics endpoint will bind to this address")
startCmd.Flags().StringVar(&probeAddr, "health-probe-bind-address", ":8081",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
- name: manager
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: {{ include "dco.image" . }}
Expand All @@ -35,6 +35,7 @@ spec:
- start
- --namespace={{ .Release.Namespace }}
{{- with .Values.config }}
- --webhook-server-port={{ .webhookPort }}
- --metrics-bind-address=:{{ .metricsPort }}
- --health-probe-bind-address=:{{ .healthProbePort }}
{{- if .enableLeaderElection }}
Expand All @@ -55,7 +56,7 @@ spec:
{{- end }}
ports:
- name: webhooks
containerPort: 9443
containerPort: {{ .Values.config.webhookPort }}
protocol: TCP
- name: metrics
containerPort: {{ .Values.config.metricsPort }}
Expand Down
6 changes: 3 additions & 3 deletions deploy/helm/distributed-compute-operator/templates/hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ metadata:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "dco.rbac.hookName" . }}
name: {{ include "dco.rbac.hookName" . }}.{{ .Release.Namespace }}
labels:
{{- include "common.labels.standard" . | nindent 4 }}
annotations:
Expand Down Expand Up @@ -42,7 +42,7 @@ rules:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "dco.rbac.hookName" . }}
name: {{ include "dco.rbac.hookName" . }}.{{ .Release.Namespace }}
labels:
{{- include "common.labels.standard" . | nindent 4 }}
annotations:
Expand All @@ -52,7 +52,7 @@ metadata:
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "dco.rbac.hookName" . }}
name: {{ include "dco.rbac.hookName" . }}.{{ .Release.Namespace }}
subjects:
- kind: ServiceAccount
name: {{ include "dco.serviceAccountName" . }}-hook
Expand Down
17 changes: 17 additions & 0 deletions deploy/helm/distributed-compute-operator/templates/istio.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- if .Values.istio.enabled }}
apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
name: {{ include "dco.webhook.service" .}}
labels:
{{- include "common.labels.standard" . | nindent 4 }}
spec:
selector:
matchLabels:
{{- include "common.labels.matchLabels" . | nindent 6 }}
mtls:
mode: UNSET
portLevelMtls:
{{ .Values.config.webhookPort }}:
mode: PERMISSIVE
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
- Ingress
ingress:
- ports:
- port: 9443
- port: {{ .Values.config.webhookPort }}
protocol: TCP
- port: {{ .Values.config.healthProbePort }}
protocol: TCP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: {{ include "common.names.fullname" . }}
name: {{ include "common.names.fullname" . }}.{{ .Release.Namespace }}
labels:
{{- include "common.labels.standard" . | nindent 4 }}
annotations:
Expand Down
6 changes: 3 additions & 3 deletions deploy/helm/distributed-compute-operator/templates/rbac.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "dco.rbac.managerName" . }}
name: {{ include "dco.rbac.managerName" . }}.{{ .Release.Namespace }}
labels:
{{- include "common.labels.standard" . | nindent 4 }}
rules:
Expand All @@ -18,13 +18,13 @@ rules:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "dco.rbac.managerName" . }}
name: {{ include "dco.rbac.managerName" . }}.{{ .Release.Namespace }}
labels:
{{- include "common.labels.standard" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "dco.rbac.managerName" . }}
name: {{ include "dco.rbac.managerName" . }}.{{ .Release.Namespace }}
subjects:
- kind: ServiceAccount
name: {{ include "dco.serviceAccountName" . }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: {{ include "common.names.fullname" . }}
name: {{ include "common.names.fullname" . }}.{{ .Release.Namespace }}
labels:
{{- include "common.labels.standard" . | nindent 4 }}
annotations:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: {{ include "common.names.fullname" . }}
name: {{ include "common.names.fullname" . }}.{{ .Release.Namespace }}
labels:
{{- include "common.labels.standard" . | nindent 4 }}
annotations:
Expand Down
6 changes: 4 additions & 2 deletions deploy/helm/distributed-compute-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ installCRDs: true

# Controller manager configuration
config:
# Webhook server port
webhookPort: 9443
# Prometheus metrics port
metricsPort: 8080
# Health probe port
Expand All @@ -36,11 +38,11 @@ istio:

podSecurityPolicy:
# Create custom PSP for operator
enabled: false
enabled: true

networkPolicy:
# Restrict network ingress to operator pods
enabled: false
enabled: true

image:
registry: ghcr.io
Expand Down
1 change: 1 addition & 0 deletions pkg/manager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Config struct {
Namespace string
MetricsAddr string
HealthProbeAddr string
WebhookServerPort int
EnableLeaderElection bool
ZapOptions zap.Options
}
6 changes: 4 additions & 2 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
//+kubebuilder:scaffold:imports
)

const leaderElectionID = "a846cbf2.dominodatalab.com"

var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
Expand All @@ -33,10 +35,10 @@ func Start(cfg *Config) error {
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: cfg.MetricsAddr,
Port: 9443,
Port: cfg.WebhookServerPort,
HealthProbeBindAddress: cfg.HealthProbeAddr,
LeaderElection: cfg.EnableLeaderElection,
LeaderElectionID: "a846cbf2.dominodatalab.com",
LeaderElectionID: leaderElectionID,
Namespace: cfg.Namespace,
})
if err != nil {
Expand Down

0 comments on commit 22e657e

Please sign in to comment.