Skip to content

Commit

Permalink
Merge pull request #12 from morenod/rosa_terraform
Browse files Browse the repository at this point in the history
Add terraform subplatform on rosa platform
  • Loading branch information
morenod authored Oct 30, 2023
2 parents 2b05039 + 40fe518 commit 6cb23fd
Show file tree
Hide file tree
Showing 19 changed files with 942 additions and 214 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
matrix:
subplatform:
- hypershift
- terraform
steps:

- name: Check out code
Expand Down
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.35.0
rev: v0.37.0
hooks:
- id: markdownlint
args: [--disable, MD013, MD002]
Expand All @@ -9,20 +9,20 @@ repos:
hooks:
- id: shellcheck
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-json
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
rev: 6.1.0
hooks:
- id: flake8
args:
- --max-line-length=400
- --max-line-length=450
- repo: https://github.com/PyCQA/pylint
rev: v3.0.0a6
rev: v3.0.1
hooks:
- id: pylint
args:
- --max-line-length=400
- --max-line-length=450
- --errors-only
- --disable=C,R,E0401
4 changes: 2 additions & 2 deletions libs/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"""
import argparse
import configparser
import re
import importlib
import sys
import re
from libs.elasticsearch import ElasticArguments
from libs.logging import LoggingArguments

Expand Down Expand Up @@ -35,7 +35,7 @@ def __init__(self, environment):

self.common_parser.add_argument("--cluster-name-seed", action=EnvDefault, env=environment, envvar="ROSA_BURNER_CLUSTER_NAME_SEED", type=str, help="Seed used to generate cluster names. 6 chars max")

self.common_parser.add_argument("--workers", action=EnvDefault, env=environment, envvar="ROSA_BURNER_WORKERS", type=self._verify_workers, default="3",
self.common_parser.add_argument("--workers", action=EnvDefault, env=environment, envvar="ROSA_BURNER_WORKERS", type=str, default="3",
help="Number of workers for the hosted cluster (min: 3). If list (comma separated), iteration over the list until reach number of clusters")
self.common_parser.add_argument("--workers-wait-time", type=int, default=60, action=EnvDefault, env=environment, envvar="ROSA_BURNER_WORKERS_WAIT_TIME",
help="Waiting time in minutes for the workers to be Ready after cluster installation or machinepool creation . If 0, do not wait. Default: 60 minutes")
Expand Down
79 changes: 2 additions & 77 deletions libs/platforms/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
# -*- coding: utf-8 -*-
import uuid
import sys
import os
import yaml
import json
import time
import datetime
import argparse
import configparser

Expand Down Expand Up @@ -178,80 +175,8 @@ def get_ocm_cluster_info(self, cluster_name):
metadata['network_type'] = cluster.get("network", {}).get("type", None)
return metadata

def _wait_for_workers(
self, kubeconfig, worker_nodes, wait_time, cluster_name, machinepool_name
):
self.logging.info(
f"Waiting {wait_time} minutes for {worker_nodes} workers to be ready on {machinepool_name} machinepool on {cluster_name}"
)
myenv = os.environ.copy()
myenv["KUBECONFIG"] = kubeconfig
result = [machinepool_name]
starting_time = datetime.datetime.utcnow().timestamp()
self.logging.debug(
f"Waiting {wait_time} minutes for nodes to be Ready on cluster {cluster_name} until {datetime.datetime.fromtimestamp(starting_time + wait_time * 60)}"
)
while datetime.datetime.utcnow().timestamp() < starting_time + wait_time * 60:
# if force_terminate:
# logging.error("Exiting workers waiting on the cluster %s after capturing Ctrl-C" % cluster_name)
# return []
self.logging.info("Getting node information for cluster %s" % cluster_name)
nodes_code, nodes_out, nodes_err = self.utils.subprocess_exec(
"oc get nodes -o json",
extra_params={"env": myenv, "universal_newlines": True},
)
try:
nodes_json = json.loads(nodes_out)
except Exception as err:
self.logging.error(
f"Cannot load command result for cluster {cluster_name}. Waiting 15 seconds for next check..."
)
self.logging.error(err)
time.sleep(15)
continue
nodes = nodes_json["items"] if "items" in nodes_json else []

# First we find nodes which label nodePool match the machinepool name and then we check if type:Ready is on the conditions
ready_nodes = (
sum(
len(
list(
filter(
lambda x: x.get("type") == "Ready"
and x.get("status") == "True",
node["status"]["conditions"],
)
)
)
for node in nodes
if node.get("metadata", {})
.get("labels", {})
.get("hypershift.openshift.io/nodePool")
and machinepool_name
in node["metadata"]["labels"]["hypershift.openshift.io/nodePool"]
)
if nodes
else 0
)

if ready_nodes == worker_nodes:
self.logging.info(
f"Found {ready_nodes}/{worker_nodes} ready nodes on machinepool {machinepool_name} for cluster {cluster_name}. Stopping wait."
)
result.append(ready_nodes)
result.append(int(datetime.datetime.utcnow().timestamp()))
return result
else:
self.logging.info(
f"Found {ready_nodes}/{worker_nodes} ready nodes on machinepool {machinepool_name} for cluster {cluster_name}. Waiting 15 seconds for next check..."
)
time.sleep(15)
self.logging.error(
f"Waiting time expired. After {wait_time} minutes there are {ready_nodes}/{worker_nodes} ready nodes on {machinepool_name} machinepool for cluster {cluster_name}"
)
result.append(ready_nodes)
result.append("")
return result
def get_workers_ready(self, kubeconfig, cluster_name):
pass

def create_cluster(self, platform, cluster_name):
pass
Expand Down
4 changes: 2 additions & 2 deletions libs/platforms/rosa/hypershift/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Hypershift Platform
# Hypershift Subplatform


Classes related to Hypershift platform
Classes related to Hypershift subplatform

As hypershift is a subplatform or ROSA, select rosa as platform parameter and hypershift as subplatform:
`rosa-burner --platform rosa --subplatform hypershift`
Expand Down
Loading

0 comments on commit 6cb23fd

Please sign in to comment.