diff --git a/.travis.yml b/.travis.yml index a3a8ef9a..d3411088 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,12 +5,6 @@ python: - '3.6' service: - docker -notifications: - slack: - secure: imXU/zt9IjKk5OvjZkTICTmxOTKGaZIej2kf7m5iSAKrdM7Lsjhj1m464qOViH3AMjMMZeprC1SL/jFF5azu2DNkQe5j1UlUu1ZxQpwnpmXJaLyTznDZSa76LPoY/R4sqJYozZLzfMQivnIUe6NGTP5vDX8CXpndaOgfAulDzks6xXDTw8q1dyKTtqFx8aPbAFAYRPagaNpy62j09aeNXDY8OVUSJsx8xylRmbHY+t1AH5AMkDPY5AeI0D/CJH1Hnbq88MmvdgUn8OqjvWMgiXsrDFAPZ4WdZCgJZuP2D4jrDuAsnchrOrVi6wKJWA9rNqJD8TqqF8Q8JhdeVAJ098GXAyhkJlDtfeEbh8TYIkLNgpW7e/auh5rzHk5MvH7kTVzyZjGMb7Vo+7c7nypFoWeom1m8Pg5rCT7vx7+0NhQjg1moMQ2kPWzaZkITDdblxuf6rpraEx2ydqPh6pAAto+VWXRrdbJJTGSTVIfPFDHYeqkCq+QVGfdCi2BucnnQVZJLUqEdGxnn86ICwhjJ5uC4Ah7Czd/pZOrdgFMWTT6DS9fjRiIHOnAAp1wKYzAoRBKQkhltDFMrayDxN5dp+IXDnnlQWPm14mwAyNd/zt8pWCue5hT2oK7oeuQsNfSemSPg92DCZRZNZ684UbJGKn0RJlSpXLyQRjja0IjA+Kk= - on_success: change - on_failure: always - on_pull_requests: false stages: - name: test - name: build diff --git a/kqueen/engines/gce.py b/kqueen/engines/gce.py index bdd7e702..22e10d3e 100644 --- a/kqueen/engines/gce.py +++ b/kqueen/engines/gce.py @@ -223,7 +223,12 @@ def cluster_get(self): First we try to get cluster by external_id, because its much more efficient in this implementation. If its not possible yet, we return from the slower method """ - request = self.client.projects().zones().clusters().get(projectId=self.project, zone=self.zone, clusterId=self.cluster_id) + request = self.client.projects().zones().clusters().get( + projectId=self.project, + zone=self.zone, + clusterId=self.cluster_id + ) + try: response = request.execute() except Exception as e: diff --git a/kqueen/models.py b/kqueen/models.py index 852289a9..d1793d1e 100644 --- a/kqueen/models.py +++ b/kqueen/models.py @@ -1,3 +1,5 @@ +from datetime import datetime +from datetime import timedelta from importlib import import_module from kqueen.config import current_config from kqueen.kubeapi import KubernetesAPI @@ -11,7 +13,6 @@ from kqueen.storages.etcd import RelationField from kqueen.storages.etcd import StringField from tempfile import mkstemp -from datetime import datetime, timedelta import logging import os @@ -38,15 +39,16 @@ class Cluster(Model, metaclass=ModelMeta): def get_state(self): try: - cluster = self.engine.cluster_get() + remote_cluster = self.engine.cluster_get() except Exception as e: logger.error('Unable to get data from backend for cluster {}'.format(self.name)) - cluster = {} + remote_cluster = {} - if 'state' in cluster: - if cluster['state'] == self.state: + if 'state' in remote_cluster: + if remote_cluster['state'] == self.state: return self.state - self.state = cluster['state'] + + self.state = remote_cluster['state'] self.save() else: self.state = config.get('CLUSTER_UNKNOWN_STATE') @@ -56,6 +58,7 @@ def get_state(self): max_age = timedelta(seconds=config.get('PROVISIONER_TIMEOUT')) if self.state == config.get('CLUSTER_PROVISIONING_STATE') and datetime.utcnow() - self.created_at > max_age: self.state = config.get('CLUSTER_ERROR_STATE') + self.save() return self.state