Skip to content

Commit e9d6a06

Browse files
authored
HCP burner to be executed as containers (#27)
* dockerfile for hcp-burner * missing module * missing package for awscli * skipping validation if aws account file is not provided * py link check * added kube-burner bin * including uuid debian package
1 parent 5e022a8 commit e9d6a06

File tree

3 files changed

+51
-24
lines changed

3 files changed

+51
-24
lines changed

Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM python:3.11 as runtime
2+
USER root
3+
RUN curl -L https://go.dev/dl/go1.18.2.linux-amd64.tar.gz -o go1.18.2.linux-amd64.tar.gz
4+
RUN tar -C /usr/local -xzf go1.18.2.linux-amd64.tar.gz
5+
ENV PATH=$PATH:/usr/local/go/bin
6+
RUN python3 -m pip install --upgrade pip || true
7+
RUN yes | pip3 install openshift elasticsearch==7.13.4 gitpython packaging --upgrade || true
8+
RUN apt-get -y update
9+
RUN apt-get -y install jq groff uuid-runtime
10+
RUN curl -L $(curl -s https://api.github.com/repos/openshift/rosa/releases/latest | jq -r ".assets[] | select(.name == \"rosa-linux-amd64\") | .browser_download_url") --output /usr/local/bin/rosa
11+
RUN curl -L $(curl -s https://api.github.com/repos/openshift-online/ocm-cli/releases/latest | jq -r ".assets[] | select(.name == \"ocm-linux-amd64\") | .browser_download_url") --output /usr/local/bin/ocm
12+
RUN curl -L https://releases.hashicorp.com/terraform/1.8.0/terraform_1.8.0_linux_amd64.zip -o terraform_1.8.0_linux_amd64.zip
13+
RUN unzip terraform_1.8.0_linux_amd64.zip -d /usr/local/bin/
14+
RUN chmod +x /usr/local/bin/rosa && chmod +x /usr/local/bin/ocm && chmod +x /usr/local/bin/terraform
15+
RUN /usr/local/bin/rosa download openshift-client
16+
RUN tar xzvf openshift-client-linux.tar.gz
17+
RUN mv oc kubectl /usr/local/bin/
18+
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
19+
RUN unzip awscliv2.zip
20+
RUN ./aws/install
21+
RUN curl -sL https://aka.ms/InstallAzureCLIDeb | bash
22+
RUN curl --fail --retry 8 --retry-all-errors -sS -L "https://github.com/kube-burner/kube-burner/releases/download/v1.9.5/kube-burner-V1.9.5-linux-x86_64.tar.gz" | tar -xzC "/usr/local/bin/" kube-burner
23+
COPY . /

libs/aws.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,53 @@ class AWS:
1313
"""AWS Class"""
1414

1515
def __init__(self, logging, account_file, profile):
16+
self.logging = logging
17+
self.config_file = account_file
1618
if os.path.exists(account_file):
17-
self.logging = logging
18-
self.config_file = account_file
19-
logging.info("AWS account file found. Loading account information")
19+
self.logging.info("AWS account file found. Loading account information")
2020
self.aws_config = configparser.RawConfigParser()
2121
self.aws_config.read(account_file)
2222
if len(self.aws_config.sections()) == 1:
2323
profile = self.aws_config.sections()[0]
2424
else:
2525
if not profile:
26-
logging.error("Multiple profiles detected on AWS credentials file but no --aws-profile parameter")
26+
self.logging.error("Multiple profiles detected on AWS credentials file but no --aws-profile parameter")
2727
sys.exit("Exiting...")
2828
else:
2929
if profile not in self.aws_config.sections():
30-
logging.error(f"Profile {profile} especified as --aws-profile not found on AWS credentials file {account_file}")
30+
self.logging.error(f"Profile {profile} especified as --aws-profile not found on AWS credentials file {account_file}")
3131
sys.exit("Exiting...")
3232
if ("aws_access_key_id" not in self.aws_config[profile] or "aws_secret_access_key" not in self.aws_config[profile]):
33-
logging.error(f"Missing credentials on file {account_file} for profile {profile}")
33+
self.logging.error(f"Missing credentials on file {account_file} for profile {profile}")
3434
sys.exit("Exiting...")
3535
else:
36-
logging.info(f"AWS configuration verified for profile {profile} on file {account_file}")
36+
self.logging.info(f"AWS configuration verified for profile {profile} on file {account_file}")
3737
self.logging.debug(f"AWS Profile: {self.aws_config[profile]}")
3838
else:
39-
logging.error(f"AWS configuration file {account_file} especified as --aws-account-file not found")
40-
sys.exit("Exiting...")
39+
self.config_file = account_file
40+
self.logging.info("AWS Account file is not provided, so aws environment variables are being used")
4141

4242
def set_aws_envvars(self, profile, aws_region):
43-
""" Get AWS information from the account_file and set related environment vars"""
44-
profile = self.aws_config.sections()[0] if len(self.aws_config.sections()) == 1 else profile
45-
os.environ["AWS_PROFILE"] = profile
46-
os.environ["AWS_REGION"] = aws_region
47-
os.environ["AWS_ACCESS_KEY_ID"] = self.aws_config[profile]["aws_access_key_id"]
48-
os.environ["AWS_SECRET_ACCESS_KEY"] = self.aws_config[profile]["aws_secret_access_key"]
49-
os.environ["AWS_SHARED_CREDENTIALS_FILE"] = self.config_file
43+
""" Get AWS information from the account_file if provided and set related environment vars"""
44+
if self.config_file != "":
45+
profile = self.aws_config.sections()[0] if len(self.aws_config.sections()) == 1 else profile
46+
os.environ["AWS_PROFILE"] = profile
47+
os.environ["AWS_REGION"] = aws_region
48+
os.environ["AWS_ACCESS_KEY_ID"] = self.aws_config[profile]["aws_access_key_id"]
49+
os.environ["AWS_SECRET_ACCESS_KEY"] = self.aws_config[profile]["aws_secret_access_key"]
50+
os.environ["AWS_SHARED_CREDENTIALS_FILE"] = self.config_file
5051

5152
def set_aws_environment(self, profile, aws_region):
52-
""" Get AWS information from the account_file and save it on the environment object"""
53-
profile = self.aws_config.sections()[0] if len(self.aws_config.sections()) == 1 else profile
53+
""" Get AWS information from the account_file if provided and save it on the environment object"""
5454
aws = {}
55+
if self.config_file == "":
56+
self.logging.info("AWS Account file is not provided, so aws environment variables are being used")
57+
aws['aws_access_key_id'] = os.environ["AWS_ACCESS_KEY_ID"]
58+
aws['aws_secret_access_key'] = os.environ["AWS_SECRET_ACCESS_KEY"]
59+
else:
60+
profile = self.aws_config.sections()[0] if len(self.aws_config.sections()) == 1 else profile
61+
aws['aws_access_key_id'] = self.aws_config[profile]["aws_access_key_id"]
62+
aws['aws_secret_access_key'] = self.aws_config[profile]["aws_secret_access_key"]
5563
aws['profile'] = profile
5664
aws['region'] = aws_region
57-
aws['aws_access_key_id'] = self.aws_config[profile]["aws_access_key_id"]
58-
aws['aws_secret_access_key'] = self.aws_config[profile]["aws_secret_access_key"]
5965
return aws

libs/platforms/rosa/rosa.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,8 @@ def __init__(self, parser, config_file, environment):
490490
EnvDefault = self.EnvDefault
491491

492492
parser.add_argument("--rosa-env", action=EnvDefault, env=environment, default='staging', envvar="HCP_BURNER_ROSA_ENV", help="ROSA Environment")
493-
parser.add_argument("--aws-account-file", action=EnvDefault, env=environment, envvar="HCP_BURNER_AWS_ACCOUNT_FILE", help="File containing the AWS credentials")
494-
parser.add_argument("--aws-profile", action=EnvDefault, env=environment, envvar="HCP_BURNER_AWS_PROFILE", help="Profile to use if aws file cointains more than one")
493+
parser.add_argument("--aws-account-file", action=EnvDefault, env=environment, default='', envvar="HCP_BURNER_AWS_ACCOUNT_FILE", help="File containing the AWS credentials")
494+
parser.add_argument("--aws-profile", action=EnvDefault, env=environment, default='localenv', envvar="HCP_BURNER_AWS_PROFILE", help="Profile to use if aws file cointains more than one")
495495
parser.add_argument("--aws-region", action=EnvDefault, env=environment, envvar="HCP_BURNER_AWS_REGION", default='us-east-2', help="Token to access OCM API")
496496
parser.add_argument("--oidc-config-id", action=EnvDefault, env=environment, envvar="HCP_BURNER_OIDC_CONFIG_ID", help="OIDC Config ID to be used on all the clusters")
497497
parser.add_argument("--common-operator-roles", action="store_true", help="Create one set of operator roles and use it on all clusters")
@@ -509,8 +509,6 @@ def __init__(self, parser, config_file, environment):
509509
parser.set_defaults(**defaults)
510510

511511
temp_args, temp_unknown_args = parser.parse_known_args()
512-
if not temp_args.aws_account_file:
513-
parser.error("hcp-burner.py: error: the following arguments (or equivalent definition) are required: --aws-account-file")
514512

515513
class EnvDefault(argparse.Action):
516514
def __init__(self, env, envvar, default=None, **kwargs):

0 commit comments

Comments
 (0)