Skip to content

Commit

Permalink
Merge pull request #90 from stackhpc/yoga_update_csi
Browse files Browse the repository at this point in the history
Sync with upstream - Adapt Cinder CSI to upstream manifest
  • Loading branch information
mnasiadka authored Dec 15, 2022
2 parents e6b7038 + f25fe65 commit e2cc398
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 15 deletions.
2 changes: 1 addition & 1 deletion doc/source/user/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,7 @@ _`csi_node_driver_registrar_tag`
Ussuri-default: v1.1.0
Yoga-default: v2.4.0

-`liveness_probe_tag`
-`csi_liveness_probe_tag`
This label allows users to override the default container tag for CSI
liveness probe.
Yoga-default: v2.5.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ if [ "${volume_driver}" = "cinder" ] && [ "${cinder_csi_enabled}" = "true" ]; th
echo "Writing File: $CINDER_CSI_DEPLOY"
mkdir -p $(dirname ${CINDER_CSI_DEPLOY})
cat << EOF > ${CINDER_CSI_DEPLOY}
---
# This YAML file contains RBAC API objects,
# which are necessary to run csi controller plugin
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: csi-cinder-controller-sa
namespace: kube-system
---
# external attacher
kind: ClusterRole
Expand Down Expand Up @@ -131,10 +131,10 @@ rules:
verbs: ["get", "list", "watch"]
- apiGroups: ["snapshot.storage.k8s.io"]
resources: ["volumesnapshotcontents"]
verbs: ["create", "get", "list", "watch", "update", "delete"]
verbs: ["create", "get", "list", "watch", "update", "delete", "patch"]
- apiGroups: ["snapshot.storage.k8s.io"]
resources: ["volumesnapshotcontents/status"]
verbs: ["update"]
verbs: ["update", "patch"]
- apiGroups: ["coordination.k8s.io"]
resources: ["leases"]
verbs: ["get", "watch", "list", "delete", "update", "create"]
Expand Down Expand Up @@ -195,11 +195,12 @@ roleRef:
kind: ClusterRole
name: csi-resizer-role
apiGroup: rbac.authorization.k8s.io
---
# This YAML file contains CSI Controller Plugin Sidecars
# external-attacher, external-provisioner, external-snapshotter
# external-resize, liveness-probe
---
kind: Deployment
apiVersion: apps/v1
metadata:
Expand Down Expand Up @@ -250,7 +251,6 @@ spec:
mountPath: /var/lib/csi/sockets/pluginproxy/
- name: csi-provisioner
image: ${CONTAINER_INFRA_PREFIX:-k8s.gcr.io/sig-storage/}csi-provisioner:${CSI_PROVISIONER_TAG}
image: k8s.gcr.io/sig-storage/csi-provisioner:v3.0.0
args:
- "--csi-address=\$(ADDRESS)"
- "--timeout=3m"
Expand Down Expand Up @@ -303,7 +303,7 @@ spec:
- name: socket-dir
mountPath: /var/lib/csi/sockets/pluginproxy/
- name: liveness-probe
image: ${CONTAINER_INFRA_PREFIX:-k8s.gcr.io/sig-storage/}livenessprobe:${LIVENESS_PROBE_TAG}
image: ${CONTAINER_INFRA_PREFIX:-k8s.gcr.io/sig-storage/}livenessprobe:${CSI_LIVENESS_PROBE_TAG}
args:
- "--csi-address=\$(ADDRESS)"
resources:
Expand Down Expand Up @@ -364,7 +364,7 @@ spec:
type: File
---
# This YAML defines all API objects to create RBAC roles for csi node plugin.
---
apiVersion: v1
kind: ServiceAccount
metadata:
Expand All @@ -379,6 +379,7 @@ rules:
- apiGroups: [""]
resources: ["events"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
Expand All @@ -395,7 +396,7 @@ roleRef:
---
# This YAML file contains driver-registrar & csi driver nodeplugin API objects,
# which are necessary to run csi nodeplugin for cinder.
---
kind: DaemonSet
apiVersion: apps/v1
metadata:
Expand All @@ -420,10 +421,6 @@ spec:
args:
- "--csi-address=\$(ADDRESS)"
- "--kubelet-registration-path=\$(DRIVER_REG_SOCK_PATH)"
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "rm -rf /registration/cinder.csi.openstack.org /registration/cinder.csi.openstack.org-reg.sock"]
env:
- name: ADDRESS
value: /csi/csi.sock
Expand All @@ -440,7 +437,7 @@ spec:
- name: registration-dir
mountPath: /registration
- name: liveness-probe
image: ${CONTAINER_INFRA_PREFIX:-k8s.gcr.io/sig-storage/}livenessprobe:${LIVENESS_PROBE_TAG}
image: ${CONTAINER_INFRA_PREFIX:-k8s.gcr.io/sig-storage/}livenessprobe:${CSI_LIVENESS_PROBE_TAG}
args:
- --csi-address=/csi/csi.sock
resources:
Expand Down Expand Up @@ -470,6 +467,7 @@ spec:
- containerPort: 9808
name: healthz
protocol: TCP
# The probe
livenessProbe:
failureThreshold: 5
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ CSI_PROVISIONER_TAG="$CSI_PROVISIONER_TAG"
CSI_SNAPSHOTTER_TAG="$CSI_SNAPSHOTTER_TAG"
CSI_RESIZER_TAG="$CSI_RESIZER_TAG"
CSI_NODE_DRIVER_REGISTRAR_TAG="$CSI_NODE_DRIVER_REGISTRAR_TAG"
CSI_LIVENESS_PROBE_TAG="$CSI_LIVENESS_PROBE_TAG"
DRAINO_TAG="$DRAINO_TAG"
MAGNUM_AUTO_HEALER_TAG="$MAGNUM_AUTO_HEALER_TAG"
AUTOSCALER_TAG="$AUTOSCALER_TAG"
Expand Down
1 change: 1 addition & 0 deletions magnum/drivers/heat/k8s_fedora_template_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def get_params(self, context, cluster_template, cluster, **kwargs):
'csi_attacher_tag', 'csi_provisioner_tag',
'csi_snapshotter_tag', 'csi_resizer_tag',
'csi_node_driver_registrar_tag',
'csi_liveness_probe_tag',
'etcd_tag', 'flannel_tag', 'flannel_cni_tag',
'cloud_provider_tag',
'prometheus_tag', 'grafana_tag',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,12 @@ parameters:
description: tag of csi node driver registrar
default: v2.4.0

csi_liveness_probe_tag:
type: string
description: tag of cinder csi liveness probe
tag of the k8s.gcr.io/sig-storage/liveness-probe container
default: v2.5.0

node_problem_detector_tag:
type: string
description: tag of the node problem detector container
Expand Down Expand Up @@ -1424,6 +1430,7 @@ resources:
csi_snapshotter_tag: {get_param: csi_snapshotter_tag}
csi_resizer_tag: {get_param: csi_resizer_tag}
csi_node_driver_registrar_tag: {get_param: csi_node_driver_registrar_tag}
csi_liveness_probe_tag: {get_param: csi_liveness_probe_tag}
draino_tag: {get_param: draino_tag}
autoscaler_tag: {get_param: autoscaler_tag}
min_node_count: {get_param: min_node_count}
Expand Down
6 changes: 6 additions & 0 deletions magnum/drivers/k8s_fedora_coreos_v1/templates/kubemaster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,11 @@ parameters:
type: string
description: tag of csi node driver registrar

csi_liveness_probe_tag:
type: string
description: >
Tag of liveness-probe for cinder csi.
node_problem_detector_tag:
type: string
description: tag of the node problem detector container
Expand Down Expand Up @@ -948,6 +953,7 @@ resources:
"$CSI_SNAPSHOTTER_TAG": {get_param: csi_snapshotter_tag}
"$CSI_RESIZER_TAG": {get_param: csi_resizer_tag}
"$CSI_NODE_DRIVER_REGISTRAR_TAG": {get_param: csi_node_driver_registrar_tag}
"$CSI_LIVENESS_PROBE_TAG": {get_param: csi_liveness_probe_tag}
"$DRAINO_TAG": {get_param: draino_tag}
"$AUTOSCALER_TAG": {get_param: autoscaler_tag}
"$MIN_NODE_COUNT": {get_param: min_node_count}
Expand Down
6 changes: 6 additions & 0 deletions magnum/tests/unit/drivers/test_template_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,8 @@ def test_k8s_get_params(self, mock_generate_csr_and_key,
'csi_resizer_tag')
csi_node_driver_registrar_tag = mock_cluster.labels.get(
'csi_node_driver_registrar_tag')
csi_liveness_probe_tag = mock_cluster.labels.get(
'csi_liveness_probe_tag')
draino_tag = mock_cluster.labels.get('draino_tag')
autoscaler_tag = mock_cluster.labels.get('autoscaler_tag')
min_node_count = mock_cluster.labels.get('min_node_count')
Expand Down Expand Up @@ -730,6 +732,7 @@ def test_k8s_get_params(self, mock_generate_csr_and_key,
'csi_snapshotter_tag': csi_snapshotter_tag,
'csi_resizer_tag': csi_resizer_tag,
'csi_node_driver_registrar_tag': csi_node_driver_registrar_tag,
'csi_liveness_probe_tag': csi_liveness_probe_tag,
'draino_tag': draino_tag,
'autoscaler_tag': autoscaler_tag,
'min_node_count': min_node_count,
Expand Down Expand Up @@ -1170,6 +1173,8 @@ def test_k8s_get_params_insecure(self, mock_generate_csr_and_key,
'csi_resizer_tag')
csi_node_driver_registrar_tag = mock_cluster.labels.get(
'csi_node_driver_registrar_tag')
csi_liveness_probe_tag = mock_cluster.labels.get(
'csi_liveness_probe_tag')
draino_tag = mock_cluster.labels.get('draino_tag')
autoscaler_tag = mock_cluster.labels.get('autoscaler_tag')
min_node_count = mock_cluster.labels.get('min_node_count')
Expand Down Expand Up @@ -1303,6 +1308,7 @@ def test_k8s_get_params_insecure(self, mock_generate_csr_and_key,
'csi_snapshotter_tag': csi_snapshotter_tag,
'csi_resizer_tag': csi_resizer_tag,
'csi_node_driver_registrar_tag': csi_node_driver_registrar_tag,
'csi_liveness_probe_tag': csi_liveness_probe_tag,
'draino_tag': draino_tag,
'autoscaler_tag': autoscaler_tag,
'min_node_count': min_node_count,
Expand Down
162 changes: 162 additions & 0 deletions tools/sync/cinder-csi
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#!/usr/bin/env python3.9

import requests

manifest_data = []

files = requests.get("https://api.github.com/repos/kubernetes/cloud-provider-openstack/contents/manifests/cinder-csi-plugin").json()
for file in files:
if file['name'] == 'csi-secret-cinderplugin.yaml':
continue

r = requests.get(file['download_url'])
manifest_data.append(r.text)

manifests = "---\n".join(manifest_data)

# Clean-ups
manifests = manifests.replace(
"""
# - name: cacert
# mountPath: /etc/cacert
# readOnly: true
""",
"""
- name: cacert
mountPath: /etc/kubernetes/ca-bundle.crt
readOnly: true
""").replace(
"""
secretName: cloud-config
# - name: cacert
# hostPath:
# path: /etc/cacert
""",
"""
secretName: cinder-csi-cloud-config
- name: cacert
hostPath:
path: /etc/kubernetes/ca-bundle.crt
type: File
""").replace(
"""
serviceAccount: csi-cinder-controller-sa
""",
"""
serviceAccount: csi-cinder-controller-sa
hostNetwork: true
tolerations:
# Make sure the pod can be scheduled on master kubelet.
- effect: NoSchedule
operator: Exists
# Mark the pod as a critical add-on for rescheduling.
- key: CriticalAddonsOnly
operator: Exists
nodeSelector:
node-role.kubernetes.io/master: ""
""").replace(
"""
- --csi-address=/csi/csi.sock
""",
"""
- --csi-address=/csi/csi.sock
resources:
requests:
cpu: 20m
""").replace(
"""
env:
- name: ADDRESS
value: /var/lib/csi/sockets/pluginproxy/csi.sock
""",
"""
resources:
requests:
cpu: 20m
env:
- name: ADDRESS
value: /var/lib/csi/sockets/pluginproxy/csi.sock
""").replace(
"$(",
"\$("
).replace(
"k8s.gcr.io/sig-storage/",
"${CONTAINER_INFRA_PREFIX:-k8s.gcr.io/sig-storage/}"
).replace(
"docker.io/k8scloudprovider/",
"${CONTAINER_INFRA_PREFIX:-docker.io/k8scloudprovider/}",
).replace(
"csi-attacher:v3.4.0",
"csi-attacher:${CSI_ATTACHER_TAG}",
).replace(
"csi-provisioner:v3.1.0",
"csi-provisioner:${CSI_PROVISIONER_TAG}",
).replace(
"csi-snapshotter:v6.0.1",
"csi-snapshotter:${CSI_SNAPSHOTTER_TAG}",
).replace(
"csi-resizer:v1.4.0",
"csi-resizer:${CSI_RESIZER_TAG}",
).replace(
"livenessprobe:v2.7.0",
"livenessprobe:${CSI_LIVENESS_PROBE_TAG}",
).replace(
"cinder-csi-plugin:latest",
"cinder-csi-plugin:${CINDER_CSI_PLUGIN_TAG}",
).replace(
"csi-node-driver-registrar:v2.5.1",
"csi-node-driver-registrar:${CSI_NODE_DRIVER_REGISTRAR_TAG}",
).replace(
"/etc/config/cloud.conf",
"/etc/config/cloud-config"
)

template = f"""step="enable-cinder-csi"
printf "Starting to run ${{step}}\\n"
. /etc/sysconfig/heat-params
volume_driver=$(echo "${{VOLUME_DRIVER}}" | tr '[:upper:]' '[:lower:]')
cinder_csi_enabled=$(echo $CINDER_CSI_ENABLED | tr '[:upper:]' '[:lower:]')
if [ "${{volume_driver}}" = "cinder" ] && [ "${{cinder_csi_enabled}}" = "true" ]; then
# Generate Cinder CSI manifest file
CINDER_CSI_DEPLOY=/srv/magnum/kubernetes/manifests/cinder-csi.yaml
echo "Writing File: $CINDER_CSI_DEPLOY"
mkdir -p $(dirname ${{CINDER_CSI_DEPLOY}})
cat << EOF > ${{CINDER_CSI_DEPLOY}}
{manifests.strip()}
EOF
echo "Waiting for Kubernetes API..."
until [ "ok" = "$(kubectl get --raw='/healthz')" ]
do
sleep 5
done
cat <<EOF | kubectl apply -f -
---
apiVersion: v1
kind: Secret
metadata:
name: cinder-csi-cloud-config
namespace: kube-system
type: Opaque
stringData:
cloud-config: |-
[Global]
auth-url=$AUTH_URL
user-id=$TRUSTEE_USER_ID
password=$TRUSTEE_PASSWORD
trust-id=$TRUST_ID
region=$REGION_NAME
ca-file=/etc/kubernetes/ca-bundle.crt
EOF
kubectl apply -f ${{CINDER_CSI_DEPLOY}}
fi
printf "Finished running ${{step}}\\n"
"""

with open("magnum/drivers/common/templates/kubernetes/fragments/enable-cinder-csi.sh", "w") as fd:
fd.write(template)

0 comments on commit e2cc398

Please sign in to comment.