Skip to content

Commit

Permalink
Automate nginx-operator install
Browse files Browse the repository at this point in the history
  • Loading branch information
eg-ayoub committed Jan 6, 2025
1 parent d7cfce1 commit 70c48db
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 7 deletions.
4 changes: 4 additions & 0 deletions buildchain/buildchain/salt_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
19 changes: 12 additions & 7 deletions salt/_modules/metalk8s_olm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
16 changes: 16 additions & 0 deletions salt/metalk8s/addons/nginx-operator/deployed/clusterextension.sls
Original file line number Diff line number Diff line change
@@ -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"
18 changes: 18 additions & 0 deletions salt/metalk8s/addons/nginx-operator/deployed/init.sls
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions salt/metalk8s/addons/nginx-operator/deployed/namespace.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!jinja | metalk8s_kubernetes

---
apiVersion: v1
kind: Namespace
metadata:
name: nginx-operator
21 changes: 21 additions & 0 deletions salt/metalk8s/addons/nginx-operator/deployed/rbac.sls
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions salt/metalk8s/deployed/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 70c48db

Please sign in to comment.