diff --git a/buildchain/buildchain/salt_tree.py b/buildchain/buildchain/salt_tree.py index f042fa074f..444450d679 100644 --- a/buildchain/buildchain/salt_tree.py +++ b/buildchain/buildchain/salt_tree.py @@ -344,6 +344,10 @@ def task(self) -> types.TaskDict: file_dep=[METALK8S_OPERATOR_MANIFESTS], ), Path("salt/metalk8s/addons/metalk8s-operator/deployed/init.sls"), + Path("salt/metalk8s/addons/nginx-operator/deployed/clusterextension.sls"), + Path("salt/metalk8s/addons/nginx-operator/deployed/init.sls"), + Path("salt/metalk8s/addons/nginx-operator/deployed/namespace.sls"), + Path("salt/metalk8s/addons/nginx-operator/deployed/rbac.sls"), Path("salt/metalk8s/addons/olm/catalog/deployed/cluster-catalog.sls"), Path("salt/metalk8s/addons/olm/catalog/deployed/init.sls"), Path("salt/metalk8s/addons/olm/catalogd/deployed/catalogd.sls"), diff --git a/salt/_modules/metalk8s_olm.py b/salt/_modules/metalk8s_olm.py index 5a17745c51..24c009104e 100644 --- a/salt/_modules/metalk8s_olm.py +++ b/salt/_modules/metalk8s_olm.py @@ -6,12 +6,17 @@ def __virtual__(): return __virtualname__ - -def check_clustercatalog_serving(name: str): - catalog = __salt__["metalk8s_kubernetes.get_object"]( - kind="ClusterCatalog", apiVersion="olm.operatorframework.io/v1", name=name +def check_condition_status(kind: str, name: str, condition: str, status: str): + obj = __salt__["metalk8s_kubernetes.get_object"]( + kind=kind, apiVersion="olm.operatorframework.io/v1", name=name ) - for cond in catalog["status"]["conditions"]: - if cond["type"] == "Serving": - return cond["status"] == "True" + for cond in obj["status"]["conditions"]: + if cond["type"] == condition: + return cond["status"] == status return False + +def check_clustercatalog_serving(name: str): + return check_condition_status("ClusterCatalog", name, "Serving", "True") + +def check_clusterextension_installed(name: str): + return check_condition_status("ClusterExtension", name, "Installed", "True") diff --git a/salt/metalk8s/addons/nginx-operator/deployed/clusterextension.sls b/salt/metalk8s/addons/nginx-operator/deployed/clusterextension.sls new file mode 100644 index 0000000000..7560099793 --- /dev/null +++ b/salt/metalk8s/addons/nginx-operator/deployed/clusterextension.sls @@ -0,0 +1,16 @@ +#!jinja | metalk8s_kubernetes + +--- +apiVersion: olm.operatorframework.io/v1 +kind: ClusterExtension +metadata: + name: nginx-install +spec: + namespace: nginx-operator + serviceAccount: + name: nginx-installer + source: + sourceType: Catalog + catalog: + packageName: nginx-operator + version: "v4.11.3" diff --git a/salt/metalk8s/addons/nginx-operator/deployed/init.sls b/salt/metalk8s/addons/nginx-operator/deployed/init.sls new file mode 100644 index 0000000000..6773ddc3c9 --- /dev/null +++ b/salt/metalk8s/addons/nginx-operator/deployed/init.sls @@ -0,0 +1,18 @@ +include: + - ...olm.operator-controller.deployed + - .namespace + - .rbac + - .clusterextension + +Wait for the Nginx Operator Cluster Extension to be Installed: + test.configurable_test_state: + - changes: False + - result: __slot__:salt:metalk8s_olm.check_clusterextension_installed("nginx-install") + - comment: Wait for the Nginx Operator Cluster Extension to be Installed + - retry: + attempts: 30 + - require: + - test: Wait for the Operator Controller Controller Manager Deployment to be Ready + - sls: metalk8s.addons.nginx-operator.deployed.namespace + - sls: metalk8s.addons.nginx-operator.deployed.rbac + - sls: metalk8s.addons.nginx-operator.deployed.clusterextension diff --git a/salt/metalk8s/addons/nginx-operator/deployed/namespace.sls b/salt/metalk8s/addons/nginx-operator/deployed/namespace.sls new file mode 100644 index 0000000000..8c3803f1b5 --- /dev/null +++ b/salt/metalk8s/addons/nginx-operator/deployed/namespace.sls @@ -0,0 +1,7 @@ +#!jinja | metalk8s_kubernetes + +--- +apiVersion: v1 +kind: Namespace +metadata: + name: nginx-operator diff --git a/salt/metalk8s/addons/nginx-operator/deployed/rbac.sls b/salt/metalk8s/addons/nginx-operator/deployed/rbac.sls new file mode 100644 index 0000000000..51905d9b8e --- /dev/null +++ b/salt/metalk8s/addons/nginx-operator/deployed/rbac.sls @@ -0,0 +1,21 @@ +#!jinja | metalk8s_kubernetes + +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: nginx-installer + namespace: nginx-operator +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: nginx-installer-admin +subjects: +- kind: ServiceAccount + name: nginx-installer + namespace: nginx-operator +roleRef: + kind: ClusterRole + name: cluster-admin + apiGroup: rbac.authorization.k8s.io diff --git a/salt/metalk8s/deployed/init.sls b/salt/metalk8s/deployed/init.sls index 230d968363..f24dd4ecc8 100644 --- a/salt/metalk8s/deployed/init.sls +++ b/salt/metalk8s/deployed/init.sls @@ -6,6 +6,7 @@ include: - metalk8s.addons.olm.catalogd.deployed - metalk8s.addons.olm.operator-controller.deployed - metalk8s.addons.olm.catalog.deployed + - metalk8s.addons.nginx-operator.deployed - metalk8s.addons.nginx-ingress.deployed - metalk8s.addons.nginx-ingress-control-plane.deployed - metalk8s.addons.volumes.deployed