forked from Azure/osm-azure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosm-label.yml
177 lines (175 loc) · 6.33 KB
/
osm-label.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#
# The job in this YAML file tries to add 'openservicemesh.io/ignore' label to 'kube-system', 'azure-arc', and 'arc-osm-system' namespaces.
# The job is executed in helm pre-install phase of OSM release lifecycle.
#
apiVersion: v1
kind: ServiceAccount
metadata:
name: osm-label-account
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook-weight": "20"
"helm.sh/hook": pre-install
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: osm-label-cluster-role
annotations:
"helm.sh/hook-weight": "25"
"helm.sh/hook": pre-install
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
rules:
- apiGroups: [""]
resources: ["namespaces"]
verbs: ["get", "patch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: osm-label-role-binding
namespace: kube-system
annotations:
"helm.sh/hook-weight": "30"
"helm.sh/hook": pre-install
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
subjects:
- kind: ServiceAccount
name: osm-label-account
namespace: {{ .Release.Namespace }}
roleRef:
kind: ClusterRole
name: osm-label-cluster-role
apiGroup: rbac.authorization.k8s.io
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: osm-label-role-binding
namespace: azure-arc
annotations:
"helm.sh/hook-weight": "30"
"helm.sh/hook": pre-install
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
subjects:
- kind: ServiceAccount
name: osm-label-account
namespace: {{ .Release.Namespace }}
roleRef:
kind: ClusterRole
name: osm-label-cluster-role
apiGroup: rbac.authorization.k8s.io
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: osm-label-role-binding
namespace: arc-osm-system
annotations:
"helm.sh/hook-weight": "30"
"helm.sh/hook": pre-install
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
subjects:
- kind: ServiceAccount
name: osm-label-account
namespace: {{ .Release.Namespace }}
roleRef:
kind: ClusterRole
name: osm-label-cluster-role
apiGroup: rbac.authorization.k8s.io
---
apiVersion: batch/v1
kind: Job
metadata:
name: osm-label
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook-weight": "35"
"helm.sh/hook": pre-install
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
seccomp.security.alpha.kubernetes.io/pod: runtime/default
spec:
template:
metadata:
labels:
app: osm-label
annotations:
seccomp.security.alpha.kubernetes.io/pod: runtime/default
spec:
serviceAccountName: osm-label-account
automountServiceAccountToken: true
restartPolicy: Never
terminationGracePeriodSeconds: 0
containers:
- name: osm-label
image: {{ .Values.alpine.image.name }}:{{ .Values.alpine.image.tag }}
imagePullPolicy: IfNotPresent
env:
- name: labelnamespaces
value: {{ .Values.OpenServiceMesh.ignoreNamespaces }}
- name: osmnamespace
value: {{ .Release.Namespace }}
securityContext:
allowPrivilegeEscalation: false
command:
- "/bin/sh"
- "-ec"
- |
set -o pipefail
token=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
namespaces=${labelnamespaces}
for namespace in ${namespaces}
do
echo "Retrieving namespace ${namespace} details"
namespaceDetails=$(curl -s -X GET -k https://kubernetes.default.svc/api/v1/namespaces/${namespace} \
-H "Authorization: Bearer ${token}" \
-H "Content-Type: application/json" \
-H "Accept: application/json")
kind=$(echo $namespaceDetails | jq .kind)
if [ "$kind" = "\"Namespace\"" ]
then
cplabel=$(echo $namespaceDetails | jq .metadata.labels.\"openservicemesh.io/ignore\")
if [ "$cplabel" = "null" ]
then
echo "Adding openservicemesh.io/ignore label to ${namespace}"
patchstatus=$(curl -s -X PATCH -k https://kubernetes.default.svc/api/v1/namespaces/${namespace} \
-d '{ "metadata": { "labels": { "openservicemesh.io/ignore": "true" } } }' \
-H "Authorization: Bearer ${token}" \
-H "Content-Type: application/strategic-merge-patch+json" \
-H "Accept: application/json")
else
echo "openservicemesh.io/ignore label already exists on namespace ${namespace}"
fi
else
echo "Failed to retrieve ${namespace} details"
fi
done
echo "Retrieving namespace ${osmnamespace} details"
namespaceDetails=$(curl -s -X GET -k https://kubernetes.default.svc/api/v1/namespaces/${osmnamespace} \
-H "Authorization: Bearer ${token}" \
-H "Content-Type: application/json" \
-H "Accept: application/json")
kind=$(echo $namespaceDetails | jq .kind)
if [ "$kind" = "\"Namespace\"" ]
then
cplabel=$(echo $namespaceDetails | jq .metadata.labels.\"admission.policy.azure.com/ignore\")
if [ "$cplabel" = "null" ]
then
echo "Adding admission.policy.azure.com/ignore label to ${osmnamespace}"
patchstatus=$(curl -s -X PATCH -k https://kubernetes.default.svc/api/v1/namespaces/${osmnamespace} \
-d '{ "metadata": { "labels": { "admission.policy.azure.com/ignore": "true" } } }' \
-H "Authorization: Bearer ${token}" \
-H "Content-Type: application/strategic-merge-patch+json" \
-H "Accept: application/json")
else
echo "admission.policy.azure.com/ignore label already exists on namespace ${osmnamespace}"
fi
else
echo "Failed to retrieve ${osmnamespace} details"
fi
securityContext:
runAsUser: 1000
runAsGroup: 3000
fsGroup: 2000
supplementalGroups: [5555]