Skip to content

Commit

Permalink
Merge pull request #12 from reactiveops/release/0.8.2
Browse files Browse the repository at this point in the history
Release/0.8.2
  • Loading branch information
ejether authored Dec 5, 2018
2 parents 0aeca6a + 8308be4 commit 9da1aa6
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 32 deletions.
17 changes: 10 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [Unreleased]
- Focus around testing and testability
- Refactoring code for easier maintainability

## [0.8.2]
### Fixed
- environment variable interpolation
- fix namespace override at chart level

## [0.8.1]
### Fixed
- Nested values not being converted to strings properly
- Namespaces not being handled properly

### Updated
- Error handling in the .call() method and course.plot()
- Error handling during chart install

## [0.8.0]

Expand All @@ -24,6 +26,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Improved error handling around helm binary
- `plot` process to it actually installs the charts


## [0.7.2]

### Deprecated
Expand All @@ -44,16 +47,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- swapped the order of evaluation of the --debug and --dryrun flags to prevent --dryrun from getting lost if both flags are set


##[0.6.4]
## [0.6.4]
### Added
- Upload to PyPi

##[0.6.3]
## [0.6.3]
### Fixed
- issue where chart dependencies/requirements were not being updated
- issue where helm release would be rolled back even when using --dry-run

##[0.6.2]
## [0.6.2]
### Fixed
- issue where tags were not being pulled properly
- Description in setup.py
Expand Down
45 changes: 28 additions & 17 deletions reckoner/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __init__(self, chart):
self._chart = chart[self._release_name]
self._repository = Repository(self._chart.get('repository', default_repository))
self._chart['values'] = self.ordereddict_to_dict(self._chart.get('values', {}))
self._namespace = self._chart.get('namespace')
value_strings = self._chart.get('values-strings', {})
self._chart['values_strings'] = self.ordereddict_to_dict(value_strings)
if value_strings != {}:
Expand Down Expand Up @@ -96,15 +97,20 @@ def files(self):
""" List of values files from the course chart """
return dict(self._chart.get('files', []))

def __check_env_vars(self, args):
@property
def namespace(self):
""" Namespace to install the course chart """
return self._namespace

def __check_env_vars(self):
"""
accepts list of args
if any of those appear to be env vars
and are missing from the environment
an exception is raised
"""
try:
[Template(arg).substitute(os.environ) for arg in args]
self.args = [Template(arg).substitute(os.environ) for arg in self.args]
except KeyError, e:
raise Exception("Missing requirement environment variable: {}".format(e.args[0]))

Expand Down Expand Up @@ -182,8 +188,9 @@ def install(self, namespace):
"""
helm = Helm()

# Set the namespace
_namespace = self.namespace or namespace
# Set the namespace
if self.namespace is None:
self._namespace = namespace

self.pre_install_hook()
# TODO: Improve error handling of a repository installation
Expand All @@ -197,25 +204,29 @@ def install(self, namespace):
# Build the args for the chart installation
# And add any extra arguments

args = ['{}'.format(self._release_name), self.chart_path, ]
args.append('--namespace={}'.format(_namespace))
args.extend(self.debug_args)
args.extend(self.helm_args)
self.args = ['{}'.format(self._release_name), self.chart_path, ]
self.args.append('--namespace={}'.format(self.namespace))
self.args.extend(self.debug_args)
self.args.extend(self.helm_args)
if self.version:
args.append('--version={}'.format(self.version))
self.args.append('--version={}'.format(self.version))
for file in self.files:
args.append("-f={}".format(file))
self.args.append("-f={}".format(file))

for key, value in self.ordereddict_to_dict(self.values).iteritems():
for key, value in self.values.iteritems():
for k, v in self._format_set(key, value):
args.append("--set={}={}".format(k, v))
for key, value in self.ordereddict_to_dict(self.values_strings).iteritems():
self.args.append("--set={}={}".format(k, v))

for key, value in self.values_strings.iteritems():
for k, v in self._format_set(key, value):
args.append("--set-string={}={}".format(k, v))
self.args.append("--set={}={}".format(k, v))

self.__check_env_vars(args)

helm.upgrade(args)
self.__check_env_vars()
try:
helm.upgrade(self.args)
except ReckonerCommandException, e:
logging.error(e.stderr)
raise e

self.post_install_hook()

Expand Down
2 changes: 1 addition & 1 deletion reckoner/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = '0.8.1'
__version__ = '0.8.2'
__author__ = 'ReactiveOps, Inc.'
11 changes: 11 additions & 0 deletions test_course.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace: kube-system
repository: stable
repositories:
incubator:
url: https://kubernetes-charts-incubator.storage.googleapis.com
stable:
url: https://kubernetes-charts.storage.googleapis.com
charts:
redis:
values:
test: ${TEST}
7 changes: 7 additions & 0 deletions tests/test_course.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ charts:
string: string
integer: 10
boolean: True
test_environ_var: ${test_environ_var}
spotify-docker-gc:
version: "0.1.0"
values-strings:
string: string
integer: 10
boolean: True
test_environ_var: ${test_environ_var}
centrifugo:
repository:
git: https://github.com/kubernetes/charts.git
Expand All @@ -38,10 +40,15 @@ charts:
dictionary:
of: items
int: 999
test_environ_var: ${test_environ_var}
spotify-docker-gc-again:
chart: spotify-docker-gc
version: "0.1.0"
go-harbor:
repository:
git: https://github.com/goharbor/harbor-helm.git
version: master
redis:
namespace: redis-test-namespace
values:
test_environ_var: ${test_environ_var}
26 changes: 19 additions & 7 deletions tests/test_reckoner.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_install_succeeds(self, *args):
test_minimum_versions = ['helm', 'reckoner']
test_repository_dict = {'name': 'test_repo', 'url': 'https://kubernetes-charts.storage.googleapis.com'}
test_reckoner_version = "1.0.0"
test_namespace = 'test_namespace'
test_namespace = 'test'

test_release_name = 'spotify-docker-gc-again'
test_chart_name = 'spotify-docker-gc'
Expand All @@ -117,11 +117,16 @@ def test_install_succeeds(self, *args):
test_incubator_repository_chart = 'cluster-autoscaler'
test_incubator_repository_str = 'stable'

test_environ_var = 'test_environment_variable_string'
test_environ_var_name = 'test_environ_var'
test_environ_var_chart = "redis"

test_flat_values_chart = 'cluster-autoscaler'
test_flat_values = {
'string': 'string',
'integer': 10,
'boolean': True,
test_environ_var_name: '${' + str(test_environ_var_name) + '}'
}


Expand All @@ -138,8 +143,8 @@ def test_install_succeeds(self, *args):
'dictionary':
{
'int': 999,
'of':
'items'
'of':'items',
test_environ_var_name: '${' + str(test_environ_var_name) + '}'
}
}
}
Expand Down Expand Up @@ -186,7 +191,6 @@ def test_install_succeeds(self, *args):
Update Complete. ⎈ Happy Helming!⎈'''
test_repo_update_args = ['helm', 'repo', 'update']


test_repo_install_args = ['helm', 'repo', 'add', 'test_repo', 'https://kubernetes-charts.storage.googleapis.com']
test_repo_install_return_string = '"test_repo" has been added to your repositories'

Expand Down Expand Up @@ -337,12 +341,20 @@ def test_chart_install(self):
self.configure_subprocess_mock(test_helm_version_return_string, '', 0)
for chart in self.charts:
self.subprocess_mock.assert_called()
os.environ[test_environ_var_name] = test_environ_var
chart.install(test_namespace)
logging.debug(chart)

last_mock = self.subprocess_mock.call_args_list[-1][0][0]
self.assertEqual(
self.subprocess_mock.call_args_list[-1][0][0][0:5],
['helm', 'upgrade', '--install', chart.release_name, chart.chart_path]
last_mock[0:6],
['helm', 'upgrade', '--install', chart.release_name, chart.chart_path, '--namespace={}'.format(chart.namespace)]
)
if chart.name == test_environ_var_chart:
self.assertEqual(
last_mock,
['helm', 'upgrade', '--install', chart.release_name, chart.chart_path, '--namespace={}'.format(chart.namespace), '--set={}={}'.format(test_environ_var_name,test_environ_var)]
)


class TestRepository(TestBase):

Expand Down

0 comments on commit 9da1aa6

Please sign in to comment.