Skip to content

Commit

Permalink
Support helm charts for network resource injector
Browse files Browse the repository at this point in the history
  • Loading branch information
Vivek Thrivikraman committed Mar 29, 2022
1 parent 05cc22a commit c094794
Show file tree
Hide file tree
Showing 9 changed files with 447 additions and 0 deletions.
23 changes: 23 additions & 0 deletions network-resources-injector/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions network-resources-injector/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2022 K8s Network Plumbing Group
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: v2
name: network-resources-injector
description: Network resource injector helm chart for Kubernetes
type: application
version: 0.1.0
home: https://github.com/k8snetworkplumbingwg/network-resources-injector
sources:
- https://github.com/k8snetworkplumbingwg/network-resources-injector
maintainers:
- name: Network Plumbing Group
appVersion: 1.3
5 changes: 5 additions & 0 deletions network-resources-injector/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
network-resources-injector is installed!!

You can view the pods with the following command:

kubectl get pods -n kube-system -l app=network-resources-injector
163 changes: 163 additions & 0 deletions network-resources-injector/templates/auth.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@

# Copyright (c) 2022 K8s Network Plumbing Group
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
apiVersion: v1
kind: ServiceAccount
metadata:
namespace: kube-system
name: {{ .Values.serviceAccount.name }}
---
apiVersion: v1
kind: Secret
metadata:
name: {{ .Values.secret.name }}
namespace: kube-system
annotations:
kubernetes.io/service-account.name: {{ .Values.serviceAccount.name }}
type: kubernetes.io/service-account-token
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ .Chart.Name }}
rules:
- apiGroups:
- ""
- k8s.cni.cncf.io
- extensions
- apps
resources:
- replicationcontrollers
- replicasets
- daemonsets
- statefulsets
- pods
- network-attachment-definitions
verbs:
- '*'
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ .Values.role.secretsName }}
rules:
- apiGroups:
- ""
resources:
- secrets
verbs:
- '*'
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ .Values.role.webhookconfigName }}
rules:
- apiGroups:
- admissionregistration.k8s.io
resources:
- mutatingwebhookconfigurations
- validatingwebhookconfigurations
verbs:
- '*'
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ .Values.role.serviceName }}
rules:
- apiGroups:
- ""
resources:
- services
verbs:
- '*'
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ .Values.role.configmapsName }}
rules:
- apiGroups:
- ""
resources:
- configmaps
verbs:
- 'get'
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ .Values.roleBinding.name }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ .Chart.Name }}
subjects:
- kind: ServiceAccount
name: {{ .Values.serviceAccount.name }}
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ .Values.roleBinding.secretsName }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ .Values.role.secretsName }}
subjects:
- kind: ServiceAccount
name: {{ .Values.serviceAccount.name }}
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ .Values.roleBinding.webhookconfigName }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ .Values.role.webhookconfigName }}
subjects:
- kind: ServiceAccount
name: {{ .Values.serviceAccount.name }}
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ .Values.roleBinding.serviceName }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ .Values.role.serviceName }}
subjects:
- kind: ServiceAccount
name: {{ .Values.serviceAccount.name }}
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ .Values.roleBinding.configmapsName }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ .Values.role.configmapsName }}
subjects:
- kind: ServiceAccount
name: {{ .Values.serviceAccount.name }}
namespace: kube-system
96 changes: 96 additions & 0 deletions network-resources-injector/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Copyright (c) 2022 K8s Network Plumbing Group
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: {{ .Chart.Name }}
name: {{ .Chart.Name }}
namespace: kube-system
spec:
replicas: {{ .Values.deployment.replicas }}
selector:
matchLabels:
app: {{ .Chart.Name }}
template:
metadata:
labels:
app: {{ .Chart.Name }}
spec:
serviceAccount: {{ .Values.serviceAccount.name }}
containers:
- name: webhook-server
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- webhook
args:
- -bind-address=0.0.0.0
- -port=8443
- -tls-private-key-file=/etc/tls/tls.key
- -tls-cert-file=/etc/tls/tls.crt
- -logtostderr
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
securityContext:
runAsUser: 10000
runAsGroup: 10000
capabilities:
drop:
- ALL
add: ["NET_BIND_SERVICE"]
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
volumeMounts:
- mountPath: /etc/tls
name: tls
resources:
requests:
memory: "50Mi"
cpu: "250m"
limits:
memory: "200Mi"
cpu: "500m"
initContainers:
- name: installer
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- installer
args:
- -name={{ .Chart.Name }}
- -namespace=kube-system
- -alsologtostderr
securityContext:
runAsUser: 10000
runAsGroup: 10000
volumeMounts:
- name: tls
mountPath: /etc/tls
volumes:
- name: tls
emptyDir: {}

# For third-party certificate, use secret resource
# instead of self-generated one from installer as below:
#
# 1) Remove initContainers from Pod spec.
# 2) Replace `emptyDir: {}` with below config
#
# secret:
# secretName: network-resources-injector-secret
10 changes: 10 additions & 0 deletions network-resources-injector/templates/pdb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ .Values.pdb.name }}
namespace: kube-system
spec:
minAvailable: {{ .Values.pdb.minAvailable }}
selector:
matchLabels:
app: {{ .Chart.Name }}
26 changes: 26 additions & 0 deletions network-resources-injector/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

# Copyright (c) 2022 K8s Network Plumbing Group
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.service.name }}
namespace: kube-system
spec:
ports:
- port: {{ .Values.service.port }}
targetPort: {{ .Values.service.targetPort }}
selector:
app: {{ .Chart.Name }}
43 changes: 43 additions & 0 deletions network-resources-injector/templates/webhook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

# Copyright (c) 2022 K8s Network Plumbing Group
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
{{- if .Values.manifests.thirdpartyCertificate }}
---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: {{ .Values.webhookconf.name }}
namespace: kube-system
webhooks:
- name: {{ .Values.webhookconf.webhook.name }}
sideEffects: None
admissionReviewVersions: ["v1"]
clientConfig:
service:
name: {{ .Values.service.name }}
namespace: ${NAMESPACE}
path: "/mutate"
caBundle: ${CA_BUNDLE}
namespaceSelector:
matchExpressions:
- key: "kubernetes.io/metadata.name"
operator: "NotIn"
values:
- "kube-system"
rules:
- operations: [ "CREATE" ]
apiGroups: ["apps", ""]
apiVersions: ["v1"]
resources: ["pods"]
{{- end }}
Loading

0 comments on commit c094794

Please sign in to comment.