armada/armada/exceptions/armada_exceptions.py
Sean Eagan 6b96bbf28d Correctly identify latest release
This fixes the following issues with listing releases from tiller,
which could cause Armada to be confused about the state of the
latest release, and do the wrong thing.

- Was not filtering out old releases, so we could find both a
  FAILED and DEPLOYED release for the same chart. When this is the
  case it likely means the FAILED release is the latest, since
  otherwise armada would have purged the release (and all its
  history) upon seeing the FAILED release in a previous run.
  The issue is that after the purge it would try to upgrade
  rather than re-install, since it also sees the old DEPLOYED
  release. Also if a release gets manually fixed (DEPLOYED)
  outside of armada, armada still sees the old FAILED release,
  and will purge the fixed release.
- Was only fetching DEPLOYED and FAILED releases from tiller, so if
  the latest release has another status Armada won't see it at all.

This changes to:

- Fetch releases with all statuses.
- Filter out old releases.
- Raise an error if latest release has status other than DEPLOYED
  or FAILED, since it's not clear what other action to take in
  this scenario.

Change-Id: I84712c1486c19d2bba302bf3420df916265ba70c
2018-10-19 09:14:15 -05:00

101 lines
3.3 KiB
Python

# Copyright 2017 The Armada Authors.
#
# 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.
from armada.exceptions import base_exception
class ArmadaException(base_exception.ArmadaBaseException):
'''Base class for Armada handler exception and error handling.'''
message = 'An unknown Armada handler error occurred.'
class ArmadaTimeoutException(ArmadaException):
'''Exception that occurs when Armada times out while processing.'''
def __init__(self, reason):
self._message = 'Armada timed out waiting on: %s' % (reason)
super(ArmadaTimeoutException, self).__init__(self._message)
class ProtectedReleaseException(ArmadaException):
'''
Exception that occurs when Armada encounters a FAILED release that is
designated `protected` in the Chart and `continue_processing` is False.
'''
def __init__(self, reason):
self._message = (
'Armada encountered protected release %s in FAILED status' %
reason)
super(ProtectedReleaseException, self).__init__(self._message)
class InvalidValuesYamlException(ArmadaException):
'''
Exception that occurs when Armada encounters invalid values.yaml content in
a helm chart.
'''
def __init__(self, chart_description):
self._message = (
'Armada encountered invalid values.yaml in helm chart: %s' %
chart_description)
super(InvalidValuesYamlException, self).__init__(self._message)
class InvalidOverrideValuesYamlException(ArmadaException):
'''
Exception that occurs when Armada encounters invalid override yaml in
helm chart.
'''
def __init__(self, chart_description):
self._message = (
'Armada encountered invalid values.yaml in helm chart: %s' %
chart_description)
super(InvalidValuesYamlException, self).__init__(self._message)
class ChartDeployException(ArmadaException):
'''
Exception that occurs while deploying charts.
'''
def __init__(self, chart_names):
self._message = ('Exception deploying charts: %s' % chart_names)
super(ChartDeployException, self).__init__(self._message)
class WaitException(ArmadaException):
'''
Exception that occurs while waiting for resources to become ready.
'''
def __init__(self, message):
self._message = message
super(WaitException, self).__init__(message)
class UnexpectedReleaseStatusException(ArmadaException):
'''
Exception that occurs when armada encounters an existing release for a
chart with an unexpected status which armada does not know what to do with.
'''
def __init__(self, release_name, status):
self._message = "Found release {} in unexpected status {}".format(
release_name, status)
super(UnexpectedReleaseStatusException, self).__init__(self._message)