-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure old CSVs are included in redhat bundle manifest or else upgrad…
…ing is not possible
- Loading branch information
Will James
committed
Sep 9, 2020
1 parent
50425ed
commit ff45890
Showing
7 changed files
with
73 additions
and
10 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.7.0 |
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
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import requests, io, tarfile, yaml, semver, argparse | ||
|
||
parser = argparse.ArgumentParser(description='Fetch old CSVs for the operator, dump csvs to outdir and print latest version') | ||
parser.add_argument('--outdir', default='target', help='target directory for the old CSVs') | ||
parser.add_argument('--source', default='redhat', help='if "olm", get the latest upstream community operators version and print it') | ||
args = parser.parse_args() | ||
|
||
if args.source == 'olm': | ||
package_raw = requests.get('https://raw.githubusercontent.com/operator-framework/community-operators/master/upstream-community-operators/instana-agent/instana-agent.package.yaml') | ||
package = yaml.load(package_raw.content, Loader=yaml.SafeLoader) | ||
print(package['channels'][0]['currentCSV']) | ||
exit(0) | ||
|
||
if args.source != 'redhat': | ||
print('unrecognized source "%s"' % args.source) | ||
exit(1) | ||
|
||
bundles = requests.get('https://quay.io/cnr/api/v1/packages/certified-operators/instana-agent/').json() | ||
|
||
digests = [bundle['content']['digest'] for bundle in bundles] | ||
|
||
csvs_by_version = {} | ||
|
||
for digest in digests: | ||
response = requests.get('https://quay.io/cnr/api/v1/packages/certified-operators/instana-agent/blobs/sha256/%s' % digest, stream=True) | ||
|
||
tar = tarfile.open(fileobj=io.BytesIO(response.content), mode='r') | ||
|
||
bundle_member = [member for member in tar.getmembers() if 'bundle.yaml' in member.name][0] | ||
|
||
bundle = tar.extractfile(bundle_member) | ||
|
||
data = yaml.load(bundle, Loader=yaml.SafeLoader) | ||
|
||
csv_bundles = yaml.load_all(data['data']['clusterServiceVersions'], Loader=yaml.SafeLoader) | ||
|
||
for csv_bundle in csv_bundles: | ||
for csv in csv_bundle: | ||
csvs_by_version[csv['spec']['version']] = csv | ||
|
||
|
||
ordered_csvs = sorted(csvs_by_version.values(), key=lambda csv: semver.VersionInfo.parse(csv['spec']['version'])) | ||
|
||
prior = '' | ||
for csv in ordered_csvs: | ||
if (csv['spec']['maturity'] == 'alpha'): | ||
continue | ||
name = csv['metadata']['name'] | ||
if prior: | ||
csv['spec']['replaces'] = prior | ||
prior = name | ||
with open('%s/%s.yaml' % (args.outdir, name), 'w') as f: | ||
yaml.safe_dump(csv, f, default_flow_style=False) | ||
|
||
print(ordered_csvs[len(ordered_csvs) - 1]['metadata']['name']) |
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,5 +1,9 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys, yaml, json | ||
import sys, yaml, json, datetime | ||
|
||
json.dump(list(yaml.load_all(sys.stdin, Loader=yaml.SafeLoader)), sys.stdout, indent=4) | ||
def DateEncoder(obj): | ||
if isinstance(obj, (datetime.datetime, datetime.date)): | ||
return obj.isoformat() | ||
|
||
json.dump(list(yaml.load_all(sys.stdin, Loader=yaml.SafeLoader)), sys.stdout, indent=4, default=DateEncoder) |