-
Notifications
You must be signed in to change notification settings - Fork 706
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
Port build_ds_container.sh to python #7987
Port build_ds_container.sh to python #7987
Conversation
utils/build_ds_container.py
Outdated
api.create_namespace(body) | ||
log.info('Created namespace %s', namespace) | ||
except exceptions.ApiException as err: | ||
if err.status == 409: |
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.
Just curious, does 409 always only refer to when a namespace already exists.
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.
Yeah, that's AlreadyExists. Might be good to use a constant or comment this number.
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.
It should only be emitted when the namespace already exists. I added a comment to the code to make that more clear.
|
||
def build_content_locally(products, debug=False): | ||
build_binary_path = os.path.join(REPO_PATH, 'build_product') | ||
command = [build_binary_path] + products |
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.
I haven't tried the code, but I am wondering do we need space between [build_binary_path]
and products
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.
Ok, I see, this is an array
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.
Good question - it can be done either way in python. The python community issued guidance via a PEP that recommends using whitespace around operators.
https://www.python.org/dev/peps/pep-0008/#other-recommendations
I think the codes looks good! |
utils/build_ds_container.py
Outdated
return True | ||
except exceptions.ApiException as err: | ||
return False | ||
if err.status == 404: |
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.
Hmm, can we reach this if the previous line is return False
?
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.
Yep - good catch. I didn't finish smoothing out the wrinkles here before pushing this version.
I removed the if statement since I don't think it matters. Instead, I just logged something for the user and returned false.
This will be fixed in the next revision.
utils/build_ds_container.py
Outdated
|
||
def create_image_stream(): | ||
# FIXME(lbragstad) Fill this out using an openshift client, since we're | ||
# dealing with an openshift-specific resource. |
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.
Just wondering what we might gain by adding a second client lib for this. I think as long as the below works by specifying the api_version we'd be good.
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.
ack
if result.returncode == 0: | ||
log.info(f'Pushed image to {repository}:{tag}') | ||
elif result.returncode == 125: | ||
log.error( |
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.
Responded in the slack thread with some thoughts on the repo push.. It's unclear to me how the old script inherits repo and image tags to push this to the cluster.
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.
@JAORMX added that functionality recently as command line arguments. In that implementation, the script relied on podman login
.
I initially implemented this method with the ability to pass in a username/password and invoking the command with --creds
, but afterwards I removed it to keep things simpler.
Instead, @JAORMX and I agreed that we can leave authentication to the user, prior to them running this script. In that case, I think the best we can do is just detect if authentication failed for some reason and give them guidance on how to fix it.
a0c378d
to
806c914
Compare
806c914
to
757476f
Compare
The build_ds_container.sh script is useful for building content and integrating it into your kubernetes clusters. Overtime, it's grown more and more functionality, like building content in the cluster, locally, or pushing built container images to repositories. This commit attempts to reorganize the script and ports it to Python, based on recommendations from the initial authors. The primary changes include: - Quieter logging by default, while maintaining verbosity using --debug - Auto-generated container image tags when publishing content to repositories (useful for development workflows) Signed-off-by: Lance Bragstad <lbragsta@redhat.com>
Since we ported the build_ds_container.sh script to a python equivalent, we don't need to maintain both versions and introduce potential drift. This commit updates the bash script to print a message for users to adopt the new script.
757476f
to
0186161
Compare
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.
Just tested out the python code, I am wondering if we could have a more verbose output for example when Building content for ocp4, rhcos4, in case of errors?
@Vincent056 I suppressed the output by default, but it should emit the same output as the bash script if you pass |
Sorry didn't see that earlier, it looks good! |
@Vincent056 I can take the opposite approach too and emit verbose logging by default, and supply an option to suppress logging using something like |
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.
The quiet mode was a bit of a surprise to me at first (I happened to have a broken profile in tree..) but I think it's fine and we can revert the debug option to quiet later on.
/lgtm
The build_ds_container.sh script is useful for building content and
integrating it into your kubernetes clusters. Overtime, it's grown more
and more functionality, like building content in the cluster, locally,
or pushing built container images to repositories.
This commit attempts to reorganize the script and ports it to Python,
based on recommendations from the initial authors.
The primary changes include:
repositories (useful for development workflows)
This patch doesn't include support for OCP deployments as it was
originally developed to build content for EKS benchmarks. That
functionality will come in another revision of this patch and should
remain backwards compatible with
build_ds_container.sh
.Signed-off-by: Lance Bragstad lbragsta@redhat.com
Description:
Rationale:
Rationale here. Replace this text. Don't use the italics format!
Fixes # Issue number here (e.g. Updating sysctl XCCDF naming #26) or remove this line if no issue exists.