diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d77cd18 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM python:2.7 + +RUN apt-get update +RUN apt-get install zip +RUN pip install boto3 +RUN pip install botocore + +COPY ./openshift-install / +COPY ./process-ignition-manifests-and-kubeconfig.py / + +ENTRYPOINT ["python", "process-ignition-manifests-and-kubeconfig.py"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..cd305f3 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +This is a image for generating ignition manifests & kubeconfig + +after updating the installer-config.yaml file template run this image with the directory containing the installer-config.yaml file mounted +for example: + +docker run -v $(pwd)/installer_dir:/installer_dir -it quay.io/oscohen/ignition-manifests-and-kubeconfig-generate:latest +in the mounted dir the ignition files and the kubeconfig will be generated. diff --git a/installer_dir/install-config.yaml b/installer_dir/install-config.yaml new file mode 100644 index 0000000..9aeb652 --- /dev/null +++ b/installer_dir/install-config.yaml @@ -0,0 +1,23 @@ +apiVersion: v1 +baseDomain: example.com +compute: +- hyperthreading: Enabled + name: worker + replicas: 0 +controlPlane: + hyperthreading: Enabled + name: master + replicas: 3 +metadata: + name: test +networking: + clusterNetwork: + - cidr: 10.128.0.0/14 + hostPrefix: 23 + networkType: OpenShiftSDN + serviceNetwork: + - 172.30.0.0/16 +platform: + none: {} +pullSecret: '{"auths": ...}' +sshKey: 'ssh-ed25519 AAAA...' diff --git a/process-ignition-manifests-and-kubeconfig.py b/process-ignition-manifests-and-kubeconfig.py new file mode 100644 index 0000000..b0cca26 --- /dev/null +++ b/process-ignition-manifests-and-kubeconfig.py @@ -0,0 +1,61 @@ +import subprocess +import random +import os +import boto3 +from botocore.exceptions import NoCredentialsError +import logging +import argparse + +FILES_TO_COPY = ["master.ign", "worker.ign", "bootstrap.ign", "metadata.json", "auth"] + +def upload_to_aws(local_file, bucket, s3_file): + aws_access_key_id = os.environ.get("aws_access_key_id", "accessKey1") + aws_secret_access_key = os.environ.get("aws_secret_access_key", "verySecretKey1") + endpoint_url = args.s3_endpoint_url + + s3 = boto3.client( + 's3', + aws_access_key_id=aws_access_key_id, + aws_secret_access_key=aws_secret_access_key, + endpoint_url=endpoint_url + ) + try: + s3.upload_file(local_file, bucket, s3_file, ExtraArgs={'ACL': 'public-read'}) + print("Upload Successful") + return True + except NoCredentialsError: + print("Credentials not available") + return False + + +parser = argparse.ArgumentParser(description='Generate ignition manifest & kubeconfig') +# TODO support pass yaml as string +# parser.add_argument('--install_config_string', help='install config string', default=None) +parser.add_argument('--file_name', help='output directory name', default="output_dir") +parser.add_argument('--s3_endpoint_url', help='s3 endpoint url', default=None) +parser.add_argument('--s3_bucket', help='s3 bucket', default='test') +args = parser.parse_args() + +# TODO support pass yaml as string +# if not (args.install_config_string or os.path.isfile('install-config.yaml')): +# raise Exception("Must pass install_config file or string") +# +# if args.install_config_string: +# with open('install-config.yaml', 'w') as f: +# f.write(args.install_config_string) + +if not os.path.isdir('/installer_dir'): + raise Exception('installer directory is not mounted') + +if not os.path.isfile('/installer_dir/install-config.yaml'): + raise Exception("install config file not located in installer dir") + +command = "./openshift-install create ignition-configs --dir /installer_dir" +try: + subprocess.check_output(command, shell=True) +except Exception as ex: + raise Exception('Failed to generate files, exception: {}'.format(ex)) + +if args.s3_endpoint_url: + subprocess.check_output("zip {file_name}.zip {file_name} ".format(file_name=args.file_name), shell=True) + uploaded = upload_to_aws(args.file_name+'.zip', args.s3_bucket, args.file_name+'.zip')