diff options
Diffstat (limited to 'kubernetes')
-rw-r--r-- | kubernetes/appc/charts/appc-ansible-server/templates/pv.yaml | 41 | ||||
-rw-r--r-- | kubernetes/appc/charts/appc-ansible-server/templates/statefulset.yaml (renamed from kubernetes/appc/charts/appc-ansible-server/templates/deployment.yaml) | 24 | ||||
-rw-r--r-- | kubernetes/appc/charts/appc-ansible-server/values.yaml | 26 | ||||
-rw-r--r-- | kubernetes/readiness/docker/init/ready.py | 84 |
4 files changed, 154 insertions, 21 deletions
diff --git a/kubernetes/appc/charts/appc-ansible-server/templates/pv.yaml b/kubernetes/appc/charts/appc-ansible-server/templates/pv.yaml new file mode 100644 index 0000000000..25257eaeaf --- /dev/null +++ b/kubernetes/appc/charts/appc-ansible-server/templates/pv.yaml @@ -0,0 +1,41 @@ +{{/* +# Copyright © 2018 Amdocs, AT&T, Bell Canada +# # +# # 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. +*/}} +{{- $global := . }} +{{- if and $global.Values.persistence.enabled (not $global.Values.persistence.existingClaim) -}} +{{- range $i, $t := until (int $global.Values.replicaCount)}} +kind: PersistentVolume +apiVersion: v1 +metadata: + name: {{ include "common.fullname" $global }}-data{{$i}} + namespace: {{ include "common.namespace" $global }} + labels: + app: {{ include "common.fullname" $global }} + chart: "{{ $global.Chart.Name }}-{{ $global.Chart.Version | replace "+" "_" }}" + release: "{{ $global.Release.Name }}" + heritage: "{{ $global.Release.Service }}" + name: {{ include "common.fullname" $global }} +spec: + capacity: + storage: {{ $global.Values.persistence.size}} + accessModes: + - {{ $global.Values.persistence.accessMode }} + storageClassName: "{{ include "common.fullname" $global }}-data" + persistentVolumeReclaimPolicy: {{ $global.Values.persistence.volumeReclaimPolicy }} + hostPath: + path: {{ $global.Values.global.persistence.mountPath | default $global.Values.persistence.mountPath }}/{{ $global.Release.Name }}/{{ $global.Values.persistence.mountSubPath }}{{$i}} +--- +{{- end -}} +{{- end -}} diff --git a/kubernetes/appc/charts/appc-ansible-server/templates/deployment.yaml b/kubernetes/appc/charts/appc-ansible-server/templates/statefulset.yaml index a7daa05143..5f1cc5ae24 100644 --- a/kubernetes/appc/charts/appc-ansible-server/templates/deployment.yaml +++ b/kubernetes/appc/charts/appc-ansible-server/templates/statefulset.yaml @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -apiVersion: extensions/v1beta1 -kind: Deployment +apiVersion: apps/v1beta1 +kind: StatefulSet metadata: name: {{ include "common.fullname" . }} namespace: {{ include "common.namespace" . }} @@ -74,6 +74,8 @@ spec: - mountPath: {{ .Values.config.configDir }}/RestServer_config name: config subPath: RestServer_config + - mountPath: {{ .Values.persistence.playbookPath }} + name: {{ include "common.fullname" . }}-data resources: {{ include "common.resources" . | indent 12 }} {{- if .Values.nodeSelector }} @@ -92,5 +94,21 @@ spec: configMap: name: {{ include "common.fullname" . }} defaultMode: 0644 - imagePullSecrets: +{{ if not .Values.persistence.enabled }} + - name: {{ include "common.fullname" . }}-data + emptyDir: {} +{{ else }} + volumeClaimTemplates: + - metadata: + name: {{ include "common.fullname" . }}-data + labels: + name: {{ include "common.fullname" . }} + spec: + accessModes: [ {{ .Values.persistence.accessMode }} ] + storageClassName: {{ include "common.fullname" . }}-data + resources: + requests: + storage: {{ .Values.persistence.size }} +{{ end }} + imagePullSecrets: - name: "{{ include "common.namespace" . }}-docker-registry-key" diff --git a/kubernetes/appc/charts/appc-ansible-server/values.yaml b/kubernetes/appc/charts/appc-ansible-server/values.yaml index b06d70f758..1e15919b82 100644 --- a/kubernetes/appc/charts/appc-ansible-server/values.yaml +++ b/kubernetes/appc/charts/appc-ansible-server/values.yaml @@ -39,7 +39,7 @@ debugEnabled: false config: appcChartName: appc mysqlServiceName: appc-dbhost - + configDir: /opt/onap/ccsdk # default number of instances replicaCount: 1 @@ -66,6 +66,30 @@ service: portName: appc-ansible-server internalPort: 8000 externalPort: 8000 + nfsprovisionerPrefix: appc + disableNfsProvisioner: true + +## Persist data to a persitent volume +persistence: + enabled: true + + ## A manually managed Persistent Volume and Claim + ## Requires persistence.enabled: true + ## If defined, PVC must be created manually before volume will be bound + # existingClaim: + volumeReclaimPolicy: Retain + + ## database data Persistent Volume Storage Class + ## If defined, storageClassName: <storageClass> + ## If set to "-", storageClassName: "", which disables dynamic provisioning + ## If undefined (the default) or set to null, no storageClassName spec is + ## set, choosing the default provisioner. (gp2 on AWS, standard on + ## GKE, AWS & OpenStack) + accessMode: ReadWriteMany + size: 1Gi + mountPath: /dockerdata-nfs + mountSubPath: appc/ansible + playbookPath: /home/ansible ingress: enabled: false diff --git a/kubernetes/readiness/docker/init/ready.py b/kubernetes/readiness/docker/init/ready.py index f4a5e5da8f..87c09a444c 100644 --- a/kubernetes/readiness/docker/init/ready.py +++ b/kubernetes/readiness/docker/init/ready.py @@ -30,6 +30,62 @@ configuration.ssl_ca_cert = cert configuration.api_key['authorization'] = token configuration.api_key_prefix['authorization'] = 'Bearer' coreV1Api = client.CoreV1Api(client.ApiClient(configuration)) +api_instance=client.ExtensionsV1beta1Api(client.ApiClient(configuration)) +api = client.AppsV1beta1Api(client.ApiClient(configuration)) +batchV1Api = client.BatchV1Api(client.ApiClient(configuration)) + +def is_job_complete(job_name): + complete = False + log.info("Checking if " + job_name + " is complete") + response = "" + try: + response = batchV1Api.read_namespaced_job_status(job_name, namespace) + if response.status.succeeded == 1: + job_status_type = response.status.conditions[0].type + if job_status_type == "Complete": + complete = True + log.info(job_name + " is complete") + else: + log.info(job_name + " is not complete") + else: + log.info(job_name + " has not succeeded yet") + return complete + except Exception as e: + log.error("Exception when calling read_namespaced_job_status: %s\n" % e) + +def wait_for_statefulset_complete(statefulset_name): + try: + response = api.read_namespaced_stateful_set(statefulset_name, namespace) + s = response.status + if ( s.updated_replicas == response.spec.replicas and + s.replicas == response.spec.replicas and + s.ready_replicas == response.spec.replicas and + s.current_replicas == response.spec.replicas and + s.observed_generation == response.metadata.generation): + log.info("Statefulset " + statefulset_name + " is ready") + return True + else: + log.info("Statefulset " + statefulset_name + " is not ready") + return False + except Exception as e: + log.error("Exception when waiting for Statefulset status: %s\n" % e) + +def wait_for_deployment_complete(deployment_name): + try: + response = api.read_namespaced_deployment(deployment_name, namespace) + s = response.status + if ( s.unavailable_replicas == None and + s.updated_replicas == response.spec.replicas and + s.replicas == response.spec.replicas and + s.ready_replicas == response.spec.replicas and + s.observed_generation == response.metadata.generation): + log.info("Deployment " + deployment_name + " is ready") + return True + else: + log.info("Deployment " + deployment_name + " is not ready") + return False + except Exception as e: + log.error("Exception when waiting for deployment status: %s\n" % e) def is_ready(container_name): ready = False @@ -41,28 +97,23 @@ def is_ready(container_name): if i.status.container_statuses is None: continue for s in i.status.container_statuses: - if i.metadata.owner_references[0].kind == "StatefulSet": - if i.metadata.name == container_name: - ready = s.ready - if not ready: - log.info(container_name + " is not ready.") - else: - log.info(container_name + " is ready!") - else: - continue - elif s.name == container_name: - ready = s.ready - if not ready: - log.info(container_name + " is not ready.") - else: - log.info(container_name + " is ready!") + if s.name == container_name: + if i.metadata.owner_references[0].kind == "StatefulSet": + ready = wait_for_statefulset_complete(i.metadata.owner_references[0].name) + elif i.metadata.owner_references[0].kind == "ReplicaSet": + api_response = api_instance.read_namespaced_replica_set_status(i.metadata.owner_references[0].name, namespace) + ready = wait_for_deployment_complete(api_response.metadata.owner_references[0].name) + elif i.metadata.owner_references[0].kind == "Job": + ready = is_job_complete(i.metadata.owner_references[0].name) + + return ready + else: continue return ready except Exception as e: log.error("Exception when calling list_namespaced_pod: %s\n" % e) - DEF_TIMEOUT = 10 DESCRIPTION = "Kubernetes container readiness check utility" USAGE = "Usage: ready.py [-t <timeout>] -c <container_name> [-c <container_name> ...]\n" \ @@ -105,7 +156,6 @@ def main(argv): else: time.sleep(5) - if __name__ == "__main__": main(sys.argv[1:]) |