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

Refactor IBMCLOUD_API_KEY references #671

Merged
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
2 changes: 1 addition & 1 deletion cmd/image/import/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ var Cmd = &cobra.Command{
pvsadm image import --help for information

# Set the API key or feed the --api-key commandline argument
export IBMCLOUD_API_KEY=<IBM_CLOUD_API_KEY>
export IBMCLOUD_APIKEY=<IBMCLOUD_APIKEY>

# To Import the image across the two different IBM account use "--accesskey" and "--secretkey" options

Expand Down
2 changes: 1 addition & 1 deletion cmd/image/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ var Cmd = &cobra.Command{
pvsadm image sync --help for information

# Set the API key or feed the --api-key commandline argument
export IBMCLOUD_API_KEY=<IBM_CLOUD_API_KEY>
export IBMCLOUD_APIKEY=<IBMCLOUD_APIKEY>

Examples:

Expand Down
2 changes: 1 addition & 1 deletion cmd/image/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var Cmd = &cobra.Command{
pvsadm image upload --help for information

# Set the API key or feed the --api-key commandline argument
export IBMCLOUD_API_KEY=<IBM_CLOUD_API_KEY>
export IBMCLOUD_APIKEY=<IBMCLOUD_APIKEY>

Examples:

Expand Down
2 changes: 1 addition & 1 deletion cmd/purge/purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var Cmd = &cobra.Command{
Long: `Purge the PowerVS resources

# Set the API key or feed the --api-key commandline argument
export IBMCLOUD_API_KEY=<IBM_CLOUD_API_KEY>
export IBMCLOUD_APIKEY=<IBMCLOUD_APIKEY>

Examples:
# Delete all the virtual machines which are created before 4hrs
Expand Down
4 changes: 1 addition & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ Integrated with the IBM Cloud platform for on-demand provisioning.
This is a tool built for the Power Systems Virtual Server helps managing and maintaining the resources easily`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if pkg.Options.APIKey == "" {
// TODO : deprecate IBMCLOUD_API_KEY for IBMCLOUD_APIKEY
// The GetAuthenticatorFromEnvironment requires "IBMCLOUD_APIKEY" to be set, apart from IBMCLOUD_API_KEY used in the project.
// In order to use the resourcecontrollerv2's functionality, the IBMCLOUD_API_KEY is re-exported as IBMCLOUD_APIKEY.
// The GetAuthenticatorFromEnvironment requires "IBMCLOUD_APIKEY" to be set.
// Ref: github.com/ibm/go-sdk-core/v5@v5.17.2/core/config_utils.go, which is available from either from a credentials file, environment or VCAP service.
if pkg.Options.APIKey = os.Getenv("IBMCLOUD_API_KEY"); pkg.Options.APIKey != "" {
klog.Warning("IBMCLOUD_API_KEY will be deprecated in future releases. Use IBMCLOUD_APIKEY instead.")
Expand Down
4 changes: 2 additions & 2 deletions docs/How to Import Image to PowerVS Instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ This guide talks about how to import image to PowerVS workspace using pvsadm.

# Prerequisite
- pvsadm tool
- IBMCLOUD_API_KEY. [How to create API key](https://cloud.ibm.com/docs/account?topic=account-userapikey#create_user_key)
- IBMCLOUD_APIKEY. [How to create API key](https://cloud.ibm.com/docs/account?topic=account-userapikey#create_user_key)
- S3 BucketName, Bucket Region, ObjectName
- PowerVS Workspace Name/PowerVS Workspace ID.

Expand All @@ -30,7 +30,7 @@ Flags:

Set the API key variable
```shell
$export IBMCLOUD_API_KEY=<IBM_CLOUD_API_KEY>
$export IBMCLOUD_APIKEY=<IBMCLOUD_APIKEY>
```

### case 1:
Expand Down
2 changes: 1 addition & 1 deletion docs/How to Upload Image to COS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This guide talks about how to upload image file to Cloud object Storage instance
# Prerequisite
- pvsadm tool
- Image file(RHEL/CENTOS/CoreOS)
- IBMCLOUD_API_KEY. [How to create api key](https://cloud.ibm.com/docs/account?topic=account-userapikey#create_user_key)
- IBMCLOUD_APIKEY. [How to create api key](https://cloud.ibm.com/docs/account?topic=account-userapikey#create_user_key)

# Image upload command help:
```shell
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/s3client.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func NewS3Client(c *Client, instanceName, region string) (s3client *S3Client, er
}

if pkg.Options.APIKey == "" {
s3client.ApiKey = os.Getenv("IBMCLOUD_API_KEY")
s3client.ApiKey = os.Getenv("IBMCLOUD_APIKEY")
} else {
s3client.ApiKey = pkg.Options.APIKey
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ function variables {
rm -f "$VAR_TEMPLATE" "$VAR_FILE"

debug_switch
[ "${IBMCLOUD_API_KEY}" == "" ] && error "Please export IBMCLOUD_API_KEY"
log "Trying to login with the provided IBMCLOUD_API_KEY..."
$CLI_PATH login --apikey "$IBMCLOUD_API_KEY" -q --no-region > /dev/null
[ "${IBMCLOUD_APIKEY}" == "" ] && error "Please export IBMCLOUD_APIKEY"
log "Trying to login with the provided IBMCLOUD_APIKEY..."
$CLI_PATH login --apikey "$IBMCLOUD_APIKEY" -q --no-region > /dev/null
debug_switch

service_instance=$SERVICE_NAME
Expand Down Expand Up @@ -427,7 +427,7 @@ function upload_image_remote {
for i in $(seq 1 "$NO_OF_RETRY"); do
echo "Attempt: $i/$NO_OF_RETRY"
LOG_FILE="logs/upload_image_remote_${i}_${LOGFILE}.log"
ssh -o 'StrictHostKeyChecking no' -o 'ServerAliveInterval 60' -o 'ServerAliveCountMax 10' -i $VAR_PRIVATE_KEY_FILE root@${BASTION_PUBLIC_IP} "cd \"$REMOTE_TEMP_DIR\"; pvsadm image upload --api-key \"$IBMCLOUD_API_KEY\" --bucket \"$cos_bucket_name\" --file \"$image_name\" --bucket-region \"$cos_region_name\" 2>&1" > $LOG_FILE || true
ssh -o 'StrictHostKeyChecking no' -o 'ServerAliveInterval 60' -o 'ServerAliveCountMax 10' -i $VAR_PRIVATE_KEY_FILE root@${BASTION_PUBLIC_IP} "cd \"$REMOTE_TEMP_DIR\"; pvsadm image upload --api-key \"$IBMCLOUD_APIKEY\" --bucket \"$cos_bucket_name\" --file \"$image_name\" --bucket-region \"$cos_region_name\" 2>&1" > $LOG_FILE || true
if grep -c "object already exists in the $cos_bucket_name bucket" "$LOG_FILE" >/dev/null; then
warn "$image_name object already exists in the $cos_bucket_name bucket. Skipping upload"
time_taken "$message"
Expand Down Expand Up @@ -493,7 +493,7 @@ function import_image_remote {
for i in $(seq 1 "$NO_OF_RETRY"); do
echo "Attempt: $i/$NO_OF_RETRY"
LOG_FILE="logs/import_image_remote_${service_name}_${i}_${LOGFILE}.log"
import_cmd="cd \"$REMOTE_TEMP_DIR\"; pvsadm image import --workspace-name \"$service_name\" --bucket \"$cos_bucket_name\" --bucket-region \"$cos_bucket_region\" --object \"$object_name\" --pvs-image-name \"$image_name\" --api-key \"$IBMCLOUD_API_KEY\" -w --watch-timeout 2h "
import_cmd="cd \"$REMOTE_TEMP_DIR\"; pvsadm image import --workspace-name \"$service_name\" --bucket \"$cos_bucket_name\" --bucket-region \"$cos_bucket_region\" --object \"$object_name\" --pvs-image-name \"$image_name\" --api-key \"$IBMCLOUD_APIKEY\" -w --watch-timeout 2h "
if [ -n "${access_key}" ] && [ -n "${secret_key}" ] ; then
import_cmd+="--accesskey \"$access_key\" --secretkey \"$secret_key\" "
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function create_and_upload_image() {
dnf install -y qemu-img cloud-utils-growpart
echo 'Initializing pvsadm tool !'
curl -sL https://raw.githubusercontent.com/ppc64le-cloud/pvsadm/main/get.sh | FORCE=1 bash
export IBMCLOUD_API_KEY=$API_KEY
export IBMCLOUD_APIKEY=$API_KEY

if [ -n "$CENTOS_URL" ]; then
create_and_upload_image $CENTOS_URL
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/qcow2ova/qcow2ova.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var _ = CMDDescribe("pvsadm qcow2ova tests", func() {

BeforeSuite(func() {
var err error
Expect(os.Getenv("IBMCLOUD_API_KEY")).NotTo(BeEmpty(), "IBMCLOUD_API_KEY must be set before running \"make test\"")
Expect(os.Getenv("IBMCLOUD_APIKEY")).NotTo(BeEmpty(), "IBMCLOUD_APIKEY must be set before running \"make test\"")
image, err = os.CreateTemp("", "qcow2ova")
Expect(err).NotTo(HaveOccurred())
_, err = image.WriteString("some dummy image")
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var (
err error
s3client *client.Client
serviceInstance *resourcecontrollerv2.ResourceInstance
APIKey = os.Getenv("IBMCLOUD_API_KEY")
APIKey = os.Getenv("IBMCLOUD_APIKEY")
Copy link
Contributor

Choose a reason for hiding this comment

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

Hope we're good to make this change before we completely deprecate IBMCLOUD_API_KEY

Copy link
Author

Choose a reason for hiding this comment

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

Yes good to make this change.

Copy link
Contributor

Choose a reason for hiding this comment

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

cc: @mkumatag.
I hope it's alright to switch to using IBMCLOUD_APIKEY is okay for make test command.
Right now, we have an error that points to theIBMCLOUD_APIKEY variable not set:

  IBMCLOUD_APIKEY must be set before running "make test"
  Expected
      <string>:
  not to be empty

objectsFolderName = "tempFolder"
SpecFileName = "spec/spec.yaml"
)
Expand Down