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

Weldr/Cloud API: simplify GCP upload options #3023

Merged
merged 10 commits into from
Oct 11, 2022

Conversation

thozza
Copy link
Member

@thozza thozza commented Sep 27, 2022

In both, the Weldr and Cloud APIs, users had to previously provide values, which could have been generated automatically by osbuild-composer, or were in reality static and could be configured on the worker.

Specifically:

  • Bucket - bucket name usually does not change for Cloud API calls, since it is specific to the GCP credentials provisioned on the worker and as a result, to the respective GCP project. Therefore it makes more sense to allow setting the GCP bucket in the worker configuration when composer is running in a SaaS deployment.
  • Object - object name used for the image when uploading it to the GCP Storage had to be previously provided by the user of the Weldr API. For Cloud API, the value has been generated by the implementation. In reality, the object name is not very important, as long as it is unique. The reason is that the object gets deleted after the image importing finishes.

Notable changes:

  • Allow setting of the GCP Bucket in the worker configuration.
  • Make the Bucket optional for GCP upload options in the Cloud API. Adjust the Cloud API test case to set the Bucket in the worker configuration, instead of passing it in the compose request.
  • Extend Weldr API to generate a unique GCP Object name if it was not provided in the job.
  • Make the GCP Object name optional for Weldr API. Adjust the Weldr API test case to not provide the Object name when passing the GCP upload options.
  • Flip the logic in the worker when uploading image to AWS EC2/S3 WRT the Bucket name preference. The Bucket value set in the worker configuration is now used only if the Bucket was not provided in the job.
  • Extend the packer template ansible role to configure the GCP Bucket in worker configuration.

This pull request includes:

  • adequate testing for the new functionality or fixed issue
  • adequate documentation informing people about the change such as

achilleas-k
achilleas-k previously approved these changes Sep 29, 2022
Copy link
Member

@achilleas-k achilleas-k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. One tiny question.

internal/cloudapi/v2/server.go Outdated Show resolved Hide resolved
Copy link
Member

@ondrejbudai ondrejbudai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have concerns about generating the GCP object names on multiple levels, I think that we should make it more consistent and do it in the API.

Also, I would really love to make the worker more dumb and predictive.

cmd/osbuild-worker/jobimpl-osbuild.go Show resolved Hide resolved
cmd/osbuild-worker/jobimpl-osbuild.go Show resolved Hide resolved
cmd/osbuild-worker/jobimpl-osbuild.go Show resolved Hide resolved
cmd/osbuild-worker/jobimpl-osbuild.go Outdated Show resolved Hide resolved
internal/weldr/upload.go Outdated Show resolved Hide resolved
@croissanne
Copy link
Member

croissanne commented Oct 3, 2022

Should we update

#!/bin/bash
set -eo pipefail
source /tmp/cloud_init_vars
echo "Deploy GCP credentials."
if [[ -z "$GCP_SERVICE_ACCOUNT_IMAGE_BUILDER_ARN" ]]; then
echo "GCP_SERVICE_ACCOUNT_IMAGE_BUILDER_ARN not defined, skipping."
exit 0
fi
# Deploy the GCP Service Account credentials file.
/usr/local/bin/aws secretsmanager get-secret-value \
--endpoint-url "${SECRETS_MANAGER_ENDPOINT_URL}" \
--secret-id "${GCP_SERVICE_ACCOUNT_IMAGE_BUILDER_ARN}" | jq -r ".SecretString" > /etc/osbuild-worker/gcp_credentials.json
sudo tee -a /etc/osbuild-worker/osbuild-worker.toml > /dev/null << EOF
[gcp]
credentials = "/etc/osbuild-worker/gcp_credentials.json"
EOF
in this PR?

@thozza
Copy link
Member Author

thozza commented Oct 3, 2022

Should we update
...
in this PR?

Looking at it, probably yes. Everything should keep working even without this change as the option to pass the bucket via the API call is still present. Nevertheless changing the script will be needed anyway in order to stop passing the bucket over the API, so I may as well change it now.

Thanks for pointing this out!

@thozza
Copy link
Member Author

thozza commented Oct 3, 2022

I addressed all review comments and added a change for the packer template as suggested by Sanne. Please have a look.

@ondrejbudai
Copy link
Member

Oh no, it now needs to be rebased. :/ Otherwise, this is amazing!

@thozza
Copy link
Member Author

thozza commented Oct 5, 2022

Rebased on top of main... 🦾

ondrejbudai
ondrejbudai previously approved these changes Oct 5, 2022
Copy link
Member

@ondrejbudai ondrejbudai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, a great cleanup!

@thozza
Copy link
Member Author

thozza commented Oct 10, 2022

Rebase on main without doing any other changes.

achilleas-k
achilleas-k previously approved these changes Oct 10, 2022
Flip the logic when deciding if to use the Bucket from the job or worker
configuration. Previously, the Bucket from the worker configuration was
always preferred if it was set, even if it was provided in the job
itself. This made it impossible to override the configuration.

Change the logic to use the Bucket from the worker configuration only if
it was not set in the job.

Report an error if no bucket name was provided with the job and there is
also none specified in the configuration.
There is a desire to make the worker as "dumb" as possible. Therefore it
is not desired to generate the AWS object key names in the worker if it
was not provided in the job.

Modify the worker code to not generate the AWS object key in any case
and instead set an error in case the object key was not provided.

Modify Weldr API implementation to generate the object key, if it was
not provided by the user. This is consistent with Cloud API
implementation.
Previously, the internal `OSBuildJobImpl` structure defined only
`GCPCreds` member. This is not practical, once there will be more
than one GCP-related variable.

Define a new `GCPConfiguration` structure, move the credentials variable
into it and use it in `OSBuildJobImpl` instead.
Extend the worker's configuration to allow setting GCP Bucket to use
when uploading images to GCP. The value from the configuration is used
only if not provided in the TargetOptions of the job.

In GCP, the region of the bucket does not limit importing of the image
to a particular region. So it is completely possible to use a single
Bucket to import images to any and all regions.

Return an error in case no bucket name was set in the job nor in the
worker configuration.
The Bucket can now be set also in the worker configuration.
GCP Bucket to use can be now configured in the worker configuration.
Make the `Bucket` optional in the Cloud API when uploading image to GCP.

Adjust the Cloud API test case to configure GCP Bucket on the worker and
not provide it in the API request.
The object key is required in order to upload the image to GCP. Return
an error if it is not set.
Previously, it was expected from the user to provide the Object name
when uploading image to GCP. The object name does not matter much,
because the object is deleted once image import finishes. Make
the specification of the object name optional and generate it if not
provided.

Adjust the GCP Weldr test case to not provide the Object name when
uploading the image.

The user can still provide the Object name if needed.
Similar to AWS, set the GCP bucket in the worker configuration.
Add a comment explaining why it is important to set the AWS bucket in
the worker configuration, even if the `AWS_ACCOUNT_IMAGE_BUILDER_ARN` is
empty.
@ondrejbudai ondrejbudai merged commit 6ae8904 into osbuild:main Oct 11, 2022
@thozza thozza deleted the gcp-bucket-optional branch October 11, 2022 13:23
thozza added a commit to thozza/koji-osbuild that referenced this pull request Oct 25, 2022
The GCP Bucket may be (and usually will be) set on the composer-worker.

Related to osbuild/osbuild-composer#3023.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
thozza added a commit to thozza/koji-osbuild that referenced this pull request Nov 11, 2022
The GCP Bucket may be (and usually will be) set on the composer-worker.

Related to osbuild/osbuild-composer#3023.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
ochosi pushed a commit to thozza/koji-osbuild that referenced this pull request Nov 17, 2022
The GCP Bucket may be (and usually will be) set on the composer-worker.

Related to osbuild/osbuild-composer#3023.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
ondrejbudai pushed a commit to osbuild/koji-osbuild that referenced this pull request Nov 21, 2022
The GCP Bucket may be (and usually will be) set on the composer-worker.

Related to osbuild/osbuild-composer#3023.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants