Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved the "IBM - Create kubernetes secret" component #1027

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)