This repository has been archived by the owner on Apr 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
fixing issue where node groups with hooks are not parsed properly #165
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
|
||
__version__ = "2.7.0" | ||
__version__ = "2.7.1" | ||
__author__ = 'ReactiveOps, Inc.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,13 +24,13 @@ | |
|
||
readme = """ | ||
|
||
# Migration 2.6.2 -> 2.7.0 | ||
# Migration 2.6.2 -> 2.7.1 | ||
|
||
## This migration: | ||
- removes older artifacts like the `post-kops.sh` if they exist | ||
- renames `inventory/<inventory>/clusters/<cluster>/cluster` -> `inventory/<inventory>/clusters/<cluster>/cluster-config` to match the current standard | ||
- splits any Kops instance group with more than on subnet into multiple instance groups with a single subnet. | ||
* it attempts to guess on the correct min/max size of the instance groups by `current min/max / number of subnets` as an integer. | ||
- splits any Kops instance group with more than on subnet into multiple instance groups with a single subnet. | ||
* it attempts to guess on the correct min/max size of the instance groups by `current min/max / number of subnets` as an integer. | ||
* it leaves the existing instance group in place to ease the migration | ||
* there are instructions in each `inventory/<inventory>/clusters/<cluster>/cluster-config/nodes.yml` | ||
- adds audit logging to all kops clusters if not already there | ||
|
@@ -42,7 +42,7 @@ | |
- the manifold update to the kops clusters will be a multi step process and may incur some risk. | ||
|
||
## Follow up tasks: | ||
- the update to the aws-iam-authenticator config no longer requires any cloud storage. Delete the bucket if it exists. | ||
- the update to the aws-iam-authenticator config no longer requires any cloud storage. Delete the bucket if it exists. | ||
- this version update changes the standards for the EtcD verion. This is a breaking change so it is not handled automatically in this migration. | ||
|
||
""" | ||
|
@@ -255,7 +255,7 @@ def literal_unicode_representer(dumper, data): | |
|
||
class Migration(migration.Migration): | ||
_starting_version = '2.6.2' | ||
_ending_version = '2.7.0' | ||
_ending_version = '2.7.1' | ||
|
||
_readme_string = readme | ||
|
||
|
@@ -301,8 +301,14 @@ def run(self): | |
for document in yaml.load_all(yaml_file.read()): | ||
if document.get('kind') == 'InstanceGroup': | ||
if document['spec']['role'] == 'Node': | ||
for hook in document['spec'].get('hooks', []): | ||
if hook.get('manifest') is not None: | ||
hook['manifest'] = literal_unicode(hook['manifest']) | ||
nodes.append(document) | ||
elif document['spec']['role'] == 'Master': | ||
for hook in document['spec'].get('hooks', []): | ||
if hook.get('manifest') is not None: | ||
hook['manifest'] = literal_unicode(hook['manifest']) | ||
masters.append(document) | ||
else: | ||
continue | ||
|
@@ -312,14 +318,18 @@ def run(self): | |
nodes_file.write(yaml.dump_all(nodes, default_flow_style=False)) | ||
|
||
with open("{}/cluster-config/{}".format(item_path, 'masters.yml'), 'w') as masters_file: | ||
masters_file.write(yaml.dump_all(nodes, default_flow_style=False)) | ||
masters_file.write(yaml.dump_all(masters, default_flow_style=False)) | ||
|
||
# becauce the nodes.yml may hav multiple documents, we need to abuse the YamlEditor class a little bit | ||
# Because the nodes.yml may have multiple documents, we need to abuse the YamlEditor class a little bit | ||
with open(old_node_groups) as oig: | ||
new_node_groups = [] | ||
for node_group in yaml.load_all(oig.read()): | ||
|
||
# Keep exisiting node group in the file to eash manual steps | ||
# Keep exisiting node group in the file to ease manual steps | ||
for hook in node_group['spec'].get('hooks', []): | ||
if hook.get('manifest') is not None: | ||
hook['manifest'] = literal_unicode(hook['manifest']) | ||
|
||
new_node_groups.append(node_group) | ||
|
||
sn_count = len(node_group['spec']['subnets']) | ||
|
@@ -377,19 +387,27 @@ def run(self): | |
|
||
hooks = cluster_spec.get("hooks") | ||
if hooks: | ||
logging.debug(hooks) | ||
for hook in hooks: | ||
if hook['name'] == 'kops-hook-authenticator-config.service': | ||
hooks.pop(hooks.index(hook)) | ||
kops_hook_index = hooks.index(hook) | ||
logging.debug("Found kops auth hook at index %d", kops_hook_index) | ||
else: | ||
logging.debug("Found other existing hook %s", hook['name']) | ||
hook['manifest'] = literal_unicode(hook['manifest']) | ||
|
||
logging.debug("Removing existing kops-hook-authenticator-config.service at %d", kops_hook_index) | ||
hooks.pop(kops_hook_index) | ||
else: | ||
logging.debug("No hooks found in cluster spec.") | ||
cluster_spec['hooks'] = [] | ||
|
||
# Using the above magic to keep formatting on the literal strings in the yaml | ||
|
||
for policy_type in cluster_spec.get('additionalPolicies', {}): | ||
cluster_spec['additionalPolicies'][policy_type] = literal_unicode(cluster_spec['additionalPolicies'][policy_type]) | ||
|
||
hook = yaml.load(aws_iam_kops_hook) | ||
hook['manifest'] = literal_unicode(hook['manifest']) | ||
cluster_spec['hooks'].append(hook) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved this to a more logical place in the code. |
||
|
||
file_assets = cluster_spec.get('fileAssets') | ||
if not file_assets: | ||
|
@@ -407,8 +425,6 @@ def run(self): | |
if fa.get('content'): | ||
fa['content'] = literal_unicode(fa['content']) | ||
|
||
cluster_spec['hooks'].append(hook) | ||
|
||
if not cluster_spec.get('kubeAPIServer'): | ||
cluster_spec['kubeAPIServer'] = {} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the pop outside the loop so that we can actually iterate over the list properly and run the literal_unicode on the other hook manifests.