Skip to content

Commit

Permalink
Improved the IBM - Create kubernetes secret component (#1027)
Browse files Browse the repository at this point in the history
Fixed the following issues:
* Checking that every command finishes successfully (non-zero return code)
* Fixed the path for the secret_name output (the program was producing variable paths different from the path in component.yaml)
  • Loading branch information
Ark-kun authored and k8s-ci-robot committed Apr 4, 2019
1 parent 9269bac commit 4afa1fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
5 changes: 2 additions & 3 deletions components/ibm-components/commons/config/component.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ implementation:
/app/config.py,
--token, {inputValue: token},
--url, {inputValue: url},
--name, {inputValue: name}
--name, {inputValue: name},
--output-secret-name-file, {outputPath: secret_name},
]
fileOutputs:
secret_name: /tmp/ai-pipeline-creds
17 changes: 9 additions & 8 deletions components/ibm-components/commons/config/src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
parser.add_argument('--token', type=str, required=True)
parser.add_argument('--url', type=str, required=True)
parser.add_argument('--name', type=str)
parser.add_argument('--output-secret-name-file', type=str)
args = parser.parse_args()

access_token = args.token
Expand All @@ -28,13 +29,13 @@
config_file = os.path.basename(config_file_path)
config_local_path = os.path.join('/tmp', config_file)
command = ['curl', '-H', 'Authorization: token %s' % access_token, '-L', '-o', config_local_path, config_file_path]
subprocess.run(command)
subprocess.run(command, check=True)

secret_name = args.name
if (not secret_name):
secret_name = 'ai-pipeline-' + os.path.splitext(config_file)[0]
command = ['kubectl', 'delete', 'secret', secret_name]
subprocess.run(command)
subprocess.run(command, check=True)

# gather all secrets
command = ['kubectl', 'create', 'secret', 'generic', secret_name]
Expand All @@ -47,12 +48,12 @@
command.append('--from-literal=%s=\'%s\'' % (key, config[section][key]))

# create the secret
subprocess.run(command)
subprocess.run(command, check=True)

# verify secret is created
subprocess.run(['kubectl', 'describe', 'secret', secret_name])
subprocess.run(['kubectl', 'describe', 'secret', secret_name], check=True)

# indicate that secret is created
with open("/tmp/" + secret_name, "w") as f:
f.write('created')
f.close()
# indicate that secret is created and pass the secret name forward
from pathlib import Path
Path(args.output_secret_name_file).parent.mkdir(parents=True, exist_ok=True)
Path(args.output_secret_name_file).write_text(secret_name)

0 comments on commit 4afa1fc

Please sign in to comment.