forked from red-hat-storage/ocs-ci
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multus deployment with nmstate operator (red-hat-storage#9777)
* Added NMState deployment Signed-off-by: oviner <[email protected]>
- Loading branch information
Showing
10 changed files
with
284 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
from ocs_ci.ocs import constants | ||
from ocs_ci.utility import templating | ||
from ocs_ci.ocs import exceptions | ||
from ocs_ci.ocs.resources.ocs import OCS | ||
from ocs_ci.utility.utils import TimeoutSampler | ||
from ocs_ci.ocs.resources.csv import CSV, get_csvs_start_with_prefix | ||
from ocs_ci.ocs.ocp import OCP | ||
from ocs_ci.ocs.exceptions import TimeoutExpiredError | ||
|
||
|
||
class NMStateInstaller(object): | ||
""" | ||
NMState Installer class for NMState deployment | ||
""" | ||
|
||
def __init__(self): | ||
self.namespace = constants.NMSTATE_NAMESPACE | ||
|
||
def create_nmstate_operator_namespace(self): | ||
""" | ||
Creates the namespace for NMState resources | ||
Raises: | ||
CommandFailed: If the 'oc create' command fails. | ||
""" | ||
try: | ||
logger.info(f"Creating namespace {self.namespace} for NMState resources") | ||
namespace_yaml_file = templating.load_yaml(constants.NMSTATE_NAMESPACE_YAML) | ||
namespace_yaml = OCS(**namespace_yaml_file) | ||
namespace_yaml.create() | ||
logger.info(f"NMState namespace {self.namespace} was created successfully") | ||
except exceptions.CommandFailed as ef: | ||
if ( | ||
f'project.project.openshift.io "{self.namespace}" already exists' | ||
in str(ef) | ||
): | ||
logger.info(f"Namespace {self.namespace} already present") | ||
raise ef | ||
|
||
def create_nmstate_operatorgroup(self): | ||
""" | ||
Creates an OperatorGroup for NMState | ||
""" | ||
logger.info("Creating OperatorGroup for NMState") | ||
operatorgroup_yaml_file = templating.load_yaml( | ||
constants.NMSTATE_OPERATORGROUP_YAML | ||
) | ||
operatorgroup_yaml = OCS(**operatorgroup_yaml_file) | ||
operatorgroup_yaml.create() | ||
logger.info("NMState OperatorGroup created successfully") | ||
|
||
def create_nmstate_subscription(self): | ||
""" | ||
Creates subscription for NMState operator | ||
""" | ||
logger.info("Creating Subscription for NMState") | ||
subscription_yaml_file = templating.load_yaml( | ||
constants.NMSTATE_SUBSCRIPTION_YAML | ||
) | ||
subscription_yaml = OCS(**subscription_yaml_file) | ||
subscription_yaml.create() | ||
logger.info("NMState Subscription created successfully") | ||
|
||
def verify_nmstate_csv_status(self): | ||
""" | ||
Verify the CSV status for the nmstate Operator deployment equals Succeeded | ||
""" | ||
for csv in TimeoutSampler( | ||
timeout=900, | ||
sleep=15, | ||
func=get_csvs_start_with_prefix, | ||
csv_prefix=constants.NMSTATE_CSV_NAME, | ||
namespace=self.namespace, | ||
): | ||
if csv: | ||
break | ||
csv_name = csv[0]["metadata"]["name"] | ||
csv_obj = CSV(resource_name=csv_name, namespace=self.namespace) | ||
csv_obj.wait_for_phase(phase="Succeeded", timeout=720) | ||
|
||
def create_nmstate_instance(self): | ||
""" | ||
Create an instance of the nmstate Operator | ||
""" | ||
logger.info("Creating NMState Instance") | ||
subscription_yaml_file = templating.load_yaml(constants.NMSTATE_INSTANCE_YAML) | ||
subscription_yaml = OCS(**subscription_yaml_file) | ||
subscription_yaml.create() | ||
logger.info("NMState Instance created successfully") | ||
|
||
def verify_nmstate_pods_running(self): | ||
""" | ||
Verify the pods for NMState Operator are running | ||
""" | ||
sample = TimeoutSampler( | ||
timeout=300, | ||
sleep=10, | ||
func=self.count_nmstate_pods_running, | ||
count=10, | ||
) | ||
if not sample.wait_for_func_status(result=True): | ||
raise TimeoutExpiredError( | ||
"Not all nmstate pods in Running state after 300 seconds" | ||
) | ||
|
||
def count_nmstate_pods_running(self, count): | ||
""" | ||
Count the pods for NMState Operator are running | ||
Returns: | ||
bool: | ||
""" | ||
count_running_nmstate_pods = 0 | ||
ocp_pod = OCP(kind=constants.POD, namespace=self.namespace) | ||
pod_items = ocp_pod.get().get("items") | ||
# Check if nmstate pods are in running state | ||
for nmstate_pod in pod_items: | ||
nmstate_pod_name = nmstate_pod.get("metadata").get("name") | ||
status = ocp_pod.get_resource_status(nmstate_pod_name) | ||
if status == constants.STATUS_RUNNING: | ||
logger.info(f"NMState pod {nmstate_pod_name} in running state") | ||
count_running_nmstate_pods += 1 | ||
return count_running_nmstate_pods >= count | ||
|
||
def running_nmstate(self): | ||
""" | ||
Install NMState operator and create an instance | ||
""" | ||
self.create_nmstate_operator_namespace() | ||
self.create_nmstate_operatorgroup() | ||
self.create_nmstate_subscription() | ||
self.verify_nmstate_csv_status() | ||
self.create_nmstate_instance() | ||
self.verify_nmstate_pods_running() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
labels: | ||
kubernetes.io/metadata.name: openshift-nmstate | ||
name: openshift-nmstate | ||
name: openshift-nmstate | ||
spec: | ||
finalizers: | ||
- kubernetes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: nmstate.io/v1 | ||
kind: NMState | ||
metadata: | ||
name: nmstate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: operators.coreos.com/v1 | ||
kind: OperatorGroup | ||
metadata: | ||
annotations: | ||
olm.providedAPIs: NMState.v1.nmstate.io | ||
name: openshift-nmstate | ||
namespace: openshift-nmstate | ||
spec: | ||
targetNamespaces: | ||
- openshift-nmstate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: operators.coreos.com/v1alpha1 | ||
kind: Subscription | ||
metadata: | ||
labels: | ||
operators.coreos.com/kubernetes-nmstate-operator.openshift-nmstate: "" | ||
name: kubernetes-nmstate-operator | ||
namespace: openshift-nmstate | ||
spec: | ||
channel: stable | ||
installPlanApproval: Automatic | ||
name: kubernetes-nmstate-operator | ||
source: redhat-operators | ||
sourceNamespace: openshift-marketplace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
ocs_ci/templates/ocs-deployment/node_network_configuration_policy.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
apiVersion: nmstate.io/v1 | ||
kind: NodeNetworkConfigurationPolicy | ||
metadata: | ||
name: ceph-public-net-shim-worker-node | ||
namespace: openshift-storage | ||
spec: | ||
nodeSelector: | ||
node-role.kubernetes.io/worker: "" | ||
kubernetes.io/hostname: worker-node | ||
desiredState: | ||
interfaces: | ||
- name: odf-pub-shim | ||
description: Shim interface used to connect host to OpenShift Data Foundation public Multus network | ||
type: mac-vlan | ||
state: up | ||
mac-vlan: | ||
base-iface: enp1s0f1 | ||
mode: bridge | ||
promiscuous: true | ||
ipv4: | ||
enabled: true | ||
dhcp: false | ||
address: | ||
- ip: 192.168.252.1 # STATIC IP FOR worker node | ||
prefix-length: 24 | ||
routes: | ||
config: | ||
- destination: 192.168.20.0/24 | ||
next-hop-interface: odf-pub-shim |