|
| 1 | +{{/* |
| 2 | +Checks whether we have a regular clouds.yaml or one with application credentials. |
| 3 | +*/}} |
| 4 | + |
| 5 | +{{- define "cloud_name" -}} |
| 6 | +{{- if ne |
| 7 | + ( keys .Values.clouds | len ) |
| 8 | + 1 |
| 9 | +-}} |
| 10 | +{{ fail "please provide values.yaml/clouds.yaml with exactly one cloud beneath the \".clouds\" key." }} |
| 11 | +{{- end -}} |
| 12 | +{{ keys .Values.clouds | first }} |
| 13 | +{{- end }} |
| 14 | + |
| 15 | +{{- define "auth_auth_url" -}} |
| 16 | +{{ get (get (get .Values.clouds (include "cloud_name" .)) "auth") "auth_url" }} |
| 17 | +{{- end }} |
| 18 | + |
| 19 | +{{- define "auth_username" -}} |
| 20 | +{{ get (get (get .Values.clouds (include "cloud_name" .)) "auth") "username" }} |
| 21 | +{{- end }} |
| 22 | + |
| 23 | +{{- define "auth_password" -}} |
| 24 | +{{ get (get (get .Values.clouds (include "cloud_name" .)) "auth") "password" }} |
| 25 | +{{- end }} |
| 26 | + |
| 27 | +{{- define "auth_project_id" -}} |
| 28 | +{{ get (get (get .Values.clouds (include "cloud_name" .)) "auth") "project_id" }} |
| 29 | +{{- end }} |
| 30 | + |
| 31 | +{{- define "auth_project_name" -}} |
| 32 | +{{ get (get (get .Values.clouds (include "cloud_name" .)) "auth") "project_name" }} |
| 33 | +{{- end }} |
| 34 | + |
| 35 | +{{- define "auth_user_domain_name" -}} |
| 36 | +{{ get (get (get .Values.clouds (include "cloud_name" .)) "auth") "user_domain_name" }} |
| 37 | +{{- end }} |
| 38 | + |
| 39 | +{{- define "auth_application_credential_id" -}} |
| 40 | +{{ get (get (get .Values.clouds (include "cloud_name" .)) "auth") "application_credential_id" }} |
| 41 | +{{- end }} |
| 42 | + |
| 43 | +{{- define "auth_application_credential_secret" -}} |
| 44 | +{{ get (get (get .Values.clouds (include "cloud_name" .)) "auth") "application_credential_secret" }} |
| 45 | +{{- end }} |
| 46 | + |
| 47 | +{{- define "region_name" -}} |
| 48 | +{{ get (get .Values.clouds (include "cloud_name" .)) "region_name" }} |
| 49 | +{{- end }} |
| 50 | + |
| 51 | +{{- define "isAppCredential" -}} |
| 52 | +{{- if and |
| 53 | + ( include "auth_username" .) |
| 54 | + (not ( include "auth_application_credential_id" . )) |
| 55 | +-}} |
| 56 | +{{- else if and |
| 57 | + ( not ( include "auth_username" . )) |
| 58 | + ( include "auth_application_credential_id" . ) |
| 59 | +-}} |
| 60 | +true |
| 61 | +{{- else }} |
| 62 | +{{ fail "please provide either username or application_credential_id, not both, not none" }} |
| 63 | +{{- end }} |
| 64 | +{{- end }} |
| 65 | + |
| 66 | +{{/* |
| 67 | +Templates the cloud.conf as needed by the openstack CCM |
| 68 | +*/}} |
| 69 | +{{- define "cloud.conf" -}} |
| 70 | +[Global] |
| 71 | +auth-url={{ include "auth_auth_url" . }} |
| 72 | +region={{ include "region_name" . }} |
| 73 | +{{ if include "isAppCredential" . }} |
| 74 | +application-credential-id={{ include "auth_application_credential_id" . }} |
| 75 | +application-credential-secret={{ include "auth_application_credential_secret" . }} |
| 76 | +{{- else -}} |
| 77 | +username={{ include "auth_username" . }} |
| 78 | +password={{ include "auth_password" . }} |
| 79 | +user-domain-name={{ include "auth_user_domain_name" . }} |
| 80 | +tenant-id={{ include "auth_project_id" . }} |
| 81 | +{{ end }} |
| 82 | + |
| 83 | +[LoadBalancer] |
| 84 | +manage-security-groups=true |
| 85 | +use-octavia=true |
| 86 | +enable-ingress-hostname=true |
| 87 | +create-monitor=true |
| 88 | +{{- end }} |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | +{{/* |
| 93 | +Templates the secret that contains cloud.conf as needed by the openstack CCM |
| 94 | +*/}} |
| 95 | +{{- define "cloud-config" -}} |
| 96 | +apiVersion: v1 |
| 97 | +data: |
| 98 | + cloud.conf: {{ include "cloud.conf" . | b64enc }} |
| 99 | +kind: Secret |
| 100 | +metadata: |
| 101 | + name: cloud-config |
| 102 | + namespace: kube-system |
| 103 | +type: Opaque |
| 104 | +{{- end }} |
0 commit comments