-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sync-root-ceph-endpoint job to openstack-dep chart
- Loading branch information
1 parent
e8bc069
commit ac80557
Showing
8 changed files
with
292 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
charts/openstack-dep/templates/bin/_sync-ceph-endpoint.py.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import logging | ||
import requests | ||
import os | ||
import sys | ||
|
||
|
||
KUBE_HOST = None | ||
KUBE_CERT = '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt' | ||
KUBE_TOKEN = None | ||
NAMESPACE = os.environ['KUBERNETES_NAMESPACE'] | ||
ROOK_CEPH_CLUSTER_NAMESPACE = os.getenv('ROOK_CEPH_CLUSTER_NAMESPACE', None) | ||
ROOK_CEPH_MON_ENDPOINTS_CONFIGMAP = os.getenv('ROOK_CEPH_MON_ENDPOINTS_CONFIGMAP', None) | ||
OS_CEPH_MON_CONFIGMAP = os.getenv('OS_CEPH_MON_CONFIGMAP', None) | ||
|
||
LOG_DATEFMT = "%Y-%m-%d %H:%M:%S" | ||
LOG_FORMAT = "%(asctime)s.%(msecs)03d - %(levelname)s - %(message)s" | ||
logging.basicConfig(format=LOG_FORMAT, datefmt=LOG_DATEFMT) | ||
LOG = logging.getLogger(__name__) | ||
LOG.setLevel(logging.INFO) | ||
|
||
|
||
def read_kube_config(): | ||
global KUBE_HOST, KUBE_TOKEN | ||
KUBE_HOST = "https://%s:%s" % ('kubernetes.default', | ||
os.environ['KUBERNETES_SERVICE_PORT']) | ||
with open('/var/run/secrets/kubernetes.io/serviceaccount/token', 'r') as f: | ||
KUBE_TOKEN = f.read() | ||
|
||
|
||
def get_rook_configmap(name): | ||
url = '%s/api/v1/namespaces/%s/configmaps/%s' % (KUBE_HOST, | ||
ROOK_CEPH_CLUSTER_NAMESPACE, | ||
name) | ||
resp = requests.get(url, | ||
headers={'Authorization': 'Bearer %s' % KUBE_TOKEN}, | ||
verify=KUBE_CERT) | ||
if resp.status_code != 200: | ||
LOG.error('Cannot get configmap %s.', name) | ||
LOG.error(resp.text) | ||
return None | ||
LOG.info('Request rook namespaces configmaps url %s.', url) | ||
return resp.json() | ||
|
||
|
||
def get_self_configmap(name): | ||
url = '%s/api/v1/namespaces/%s/configmaps/%s' % (KUBE_HOST, | ||
NAMESPACE, | ||
name) | ||
resp = requests.get(url, | ||
headers={'Authorization': 'Bearer %s' % KUBE_TOKEN}, | ||
verify=KUBE_CERT) | ||
if resp.status_code != 200: | ||
LOG.error('Cannot get configmap %s.', name) | ||
LOG.error(resp.text) | ||
return None | ||
LOG.info('Request configmaps url %s.', url) | ||
return resp.json() | ||
|
||
|
||
def update_configmap(configmap): | ||
url = '%s/api/v1/namespaces/%s/configmaps/%s' % (KUBE_HOST, | ||
NAMESPACE, | ||
OS_CEPH_MON_CONFIGMAP) | ||
resp = requests.put(url, | ||
json=configmap, | ||
headers={'Authorization': 'Bearer %s' % KUBE_TOKEN}, | ||
verify=KUBE_CERT) | ||
if resp.status_code != 200: | ||
LOG.error(resp.text) | ||
LOG.error("Update configmap failed!") | ||
return False | ||
LOG.info("Update configmap success!") | ||
return True | ||
|
||
|
||
def main(): | ||
read_kube_config() | ||
rook_cm = get_rook_configmap(ROOK_CEPH_MON_ENDPOINTS_CONFIGMAP) | ||
|
||
self_cm = get_self_configmap(OS_CEPH_MON_CONFIGMAP) | ||
self_cm['data'] = rook_cm['data'] | ||
|
||
if not update_configmap(self_cm): | ||
sys.exit(1) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{{- if .Values.ceph.enabled -}} | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: "ceph-monitor-endpoints" | ||
namespace: {{ .Release.Namespace }} | ||
data: | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: "sync-ceph-endpoint-cm" | ||
namespace: {{ .Release.Namespace }} | ||
data: | ||
sync-ceph-endpoint.py: | | ||
{{ tuple "bin/_sync-ceph-endpoint.py.tpl" . | include "common.template" | indent 4 }} | ||
{{- end }} |
44 changes: 44 additions & 0 deletions
44
charts/openstack-dep/templates/job-sync-rook-ceph-endpoint.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{{- if .Values.ceph.enabled }} | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: sync-rook-ceph-endpoint | ||
namespace: {{ .Release.Namespace }} | ||
spec: | ||
template: | ||
spec: | ||
activeDeadlineSeconds: 100 | ||
containers: | ||
- name: sync-rook-ceph-endpoint | ||
image: {{ template "sync.endpoint.image" . }} | ||
imagePullPolicy: IfNotPresent | ||
command: | ||
- /bin/sh | ||
- -c | ||
- python /tmp/sync-ceph-endpoint.py | ||
env: | ||
- name: KUBERNETES_NAMESPACE | ||
value: {{ .Release.Namespace }} | ||
- name: ROOK_CEPH_CLUSTER_NAMESPACE | ||
value: {{ .Values.ceph.cephClusterNamespace }} | ||
- name: ROOK_CEPH_MON_ENDPOINTS_CONFIGMAP | ||
value: {{ printf "%s-mon-endpoints" .Values.ceph.cephClusterName }} | ||
- name: OS_CEPH_MON_CONFIGMAP | ||
value: "ceph-monitor-endpoints" | ||
volumeMounts: | ||
- mountPath: /tmp | ||
name: pod-tmp | ||
- mountPath: /tmp/sync-ceph-endpoint.py | ||
name: sync-ceph-endpoint-cm | ||
subPath: sync-ceph-endpoint.py | ||
restartPolicy: OnFailure | ||
serviceAccount: {{ .Values.serviceAccountName }} | ||
serviceAccountName: {{ .Values.serviceAccountName }} | ||
volumes: | ||
- emptyDir: {} | ||
name: pod-tmp | ||
- name: sync-ceph-endpoint-cm | ||
configMap: | ||
defaultMode: 0755 | ||
name: sync-ceph-endpoint-cm | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
|
||
{{- if .Values.ceph.enabled }} | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: {{ .Values.serviceAccountName }} | ||
namespace: {{ .Release.Namespace | quote }} | ||
labels: {{- include "common.labels.standard" . | nindent 4 }} | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: {{ .Values.serviceAccountName }} | ||
namespace: {{ .Release.Namespace | quote }} | ||
labels: {{- include "common.labels.standard" . | nindent 4 }} | ||
rules: | ||
- apiGroups: | ||
- "" | ||
- extensions | ||
- batch | ||
- apps | ||
resources: | ||
- configmaps | ||
verbs: | ||
- get | ||
- list | ||
- create | ||
- update | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: {{ .Values.serviceAccountName }} | ||
namespace: {{ .Release.Namespace | quote }} | ||
labels: {{- include "common.labels.standard" . | nindent 4 }} | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: Role | ||
name: {{ .Values.serviceAccountName }} | ||
subjects: | ||
- kind: ServiceAccount | ||
name: {{ .Values.serviceAccountName }} | ||
namespace: {{ .Release.Namespace | quote }} | ||
--- | ||
kind: ClusterRole | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
metadata: | ||
name: {{ .Values.serviceAccountName }} | ||
namespace: {{ .Release.Namespace | quote }} | ||
labels: {{- include "common.labels.standard" . | nindent 4 }} | ||
rules: | ||
- apiGroups: | ||
- "" | ||
- apps | ||
- extensions | ||
resources: | ||
- configmaps | ||
verbs: | ||
- get | ||
--- | ||
kind: ClusterRoleBinding | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
metadata: | ||
name: {{ .Values.serviceAccountName }} | ||
namespace: {{ .Release.Namespace | quote }} | ||
labels: {{- include "common.labels.standard" . | nindent 4 }} | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: {{ .Values.serviceAccountName }} | ||
subjects: | ||
- kind: ServiceAccount | ||
name: {{ .Values.serviceAccountName }} | ||
namespace: {{ .Release.Namespace | quote }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters