diff options
Diffstat (limited to 'kubernetes/readiness')
-rw-r--r-- | kubernetes/readiness/.gitignore | 15 | ||||
-rw-r--r-- | kubernetes/readiness/pom.xml | 109 | ||||
-rw-r--r-- | kubernetes/readiness/src/main/docker/Dockerfile (renamed from kubernetes/readiness/docker/init/Dockerfile) | 9 | ||||
-rw-r--r-- | kubernetes/readiness/src/main/scripts/job_complete.py (renamed from kubernetes/readiness/docker/init/job_complete.py) | 0 | ||||
-rw-r--r-- | kubernetes/readiness/src/main/scripts/ready.py (renamed from kubernetes/readiness/docker/init/ready.py) | 20 |
5 files changed, 145 insertions, 8 deletions
diff --git a/kubernetes/readiness/.gitignore b/kubernetes/readiness/.gitignore new file mode 100644 index 0000000000..90cb66eacd --- /dev/null +++ b/kubernetes/readiness/.gitignore @@ -0,0 +1,15 @@ +# Eclipse +.classpath +.factorypath +.project +.pydevproject +.settings/ + +# IntelliJ +.idea/* +*.iml + +# Mac OS +*DS_Store* + +/target
\ No newline at end of file diff --git a/kubernetes/readiness/pom.xml b/kubernetes/readiness/pom.xml new file mode 100644 index 0000000000..af834ff4c2 --- /dev/null +++ b/kubernetes/readiness/pom.xml @@ -0,0 +1,109 @@ +<!-- + + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + ================================================================================ + 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. + ============LICENSE_END========================================================= + +--> +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.oparent</groupId> + <artifactId>oparent</artifactId> + <version>2.0.0</version> + </parent> + + <groupId>org.onap.oom.readiness.check</groupId> + <artifactId>readiness-check-docker</artifactId> + <version>2.2.1-SNAPSHOT</version> + <packaging>pom</packaging> + <name>oom-readiness-check-image</name> + <description>Contains dockerfiles and scrtipts for readiness-ckeck image.</description> + + <properties> + <docker.fabric.version>0.31.0</docker.fabric.version> + <oom.docker.namespace>onap</oom.docker.namespace> + </properties> + + <build> + <plugins> + <plugin> + <groupId>io.fabric8</groupId> + <artifactId>docker-maven-plugin</artifactId> + <version>${docker.fabric.version}</version> + <configuration> + <verbose>true</verbose> + <apiVersion>1.23</apiVersion> + <images> + <image> + <name>${docker.push.registry}/${oom.docker.namespace}/readiness-check:%l</name> + <build> + <filter>@</filter> + <assembly> + <mode>dir</mode> + <inline xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> + <fileSets> + <fileSet> + <directory>${project.basedir}/src/main/scripts</directory> + <outputDirectory>/</outputDirectory> + <includes> + <include>**/*</include> + </includes> + </fileSet> + </fileSets> + </inline> + </assembly> + <tags> + <tag>latest</tag> + <tag>latest-${project.version}</tag> + </tags> + <cleanup>try</cleanup> + <dockerFileDir>${project.basedir}/src/main/docker</dockerFileDir> + </build> + </image> + </images> + </configuration> + <executions> + <execution> + <id>clean-images</id> + <phase>pre-clean</phase> + <goals> + <goal>remove</goal> + </goals> + <configuration> + <removeAll>true</removeAll> + </configuration> + </execution> + <execution> + <id>generate-images</id> + <phase>package</phase> + <goals> + <goal>build</goal> + </goals> + </execution> + <execution> + <id>push-images</id> + <phase>deploy</phase> + <goals> + <goal>push</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project>
\ No newline at end of file diff --git a/kubernetes/readiness/docker/init/Dockerfile b/kubernetes/readiness/src/main/docker/Dockerfile index b060915354..638e8efd67 100644 --- a/kubernetes/readiness/docker/init/Dockerfile +++ b/kubernetes/readiness/src/main/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM python:2-alpine +FROM python:3-alpine3.9 ENV no_proxy "localhost,127.0.0.1,.cluster.local,$KUBERNETES_SERVICE_HOST" # Setup Corporate proxy @@ -10,11 +10,8 @@ RUN pip install requests pyyaml kubernetes ENV CERT="/var/run/secrets/kubernetes.io/serviceaccount/ca.crt" ENV TOKEN="/var/run/secrets/kubernetes.io/serviceaccount/token" -COPY ready.py /root/ready.py -RUN chmod a+x /root/ready.py - -COPY job_complete.py /root/job_complete.py -RUN chmod a+x /root/job_complete.py +COPY maven/ /root/ +RUN chmod -R a+x /root/ ENTRYPOINT ["/root/ready.py"] CMD [""]
\ No newline at end of file diff --git a/kubernetes/readiness/docker/init/job_complete.py b/kubernetes/readiness/src/main/scripts/job_complete.py index a9570c5951..a9570c5951 100644 --- a/kubernetes/readiness/docker/init/job_complete.py +++ b/kubernetes/readiness/src/main/scripts/job_complete.py diff --git a/kubernetes/readiness/docker/init/ready.py b/kubernetes/readiness/src/main/scripts/ready.py index db7105a18d..93932073cd 100644 --- a/kubernetes/readiness/docker/init/ready.py +++ b/kubernetes/readiness/src/main/scripts/ready.py @@ -79,7 +79,7 @@ def wait_for_deployment_complete(deployment_name): response = api.read_namespaced_deployment(deployment_name, namespace) s = response.status if (s.unavailable_replicas is None and - s.updated_replicas == response.spec.replicas and + ( s.updated_replicas is None or 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): @@ -92,6 +92,20 @@ def wait_for_deployment_complete(deployment_name): log.error("Exception when waiting for deployment status: %s\n" % e) +def wait_for_daemonset_complete(daemonset_name): + try: + response = api_instance.read_namespaced_daemon_set(daemonset_name, namespace) + s = response.status + if s.desired_number_scheduled == s.number_ready: + log.info("DaemonSet: " + str(s.number_ready) + "/" + str(s.desired_number_scheduled) + " nodes ready --> " + daemonset_name + " is ready") + return True + else: + log.info("DaemonSet: " + str(s.number_ready) + "/" + str(s.desired_number_scheduled) + " nodes ready --> " + daemonset_name + " is not ready") + return False + except Exception as e: + log.error("Exception when waiting for DaemonSet status: %s\n" % e) + + def is_ready(container_name): ready = False log.info("Checking if " + container_name + " is ready") @@ -112,6 +126,8 @@ def is_ready(container_name): ready = wait_for_deployment_complete(deployment_name) elif i.metadata.owner_references[0].kind == "Job": ready = is_job_complete(name) + elif i.metadata.owner_references[0].kind == "DaemonSet": + ready = wait_for_daemonset_complete(i.metadata.owner_references[0].name) return ready @@ -123,7 +139,7 @@ def is_ready(container_name): def read_name(item): - return item.metadata.owner_reference[0].name + return item.metadata.owner_references[0].name def get_deployment_name(replicaset): |