From 72aaa6c6d85be2cdccb3502e47ffcc9aae77d407 Mon Sep 17 00:00:00 2001 From: "Oleksandr K." Date: Mon, 5 Aug 2024 12:37:31 +0200 Subject: [PATCH] ci: add linters in zuul CI (#419) * fix: upgrade isort version fix https://github.com/vexxhost/magnum-cluster-api/issues/418 * add linters in zuul ci * remove lint jobs from gh action * add linter job in project check * exclude charts --------- Co-authored-by: okozachenko1203 --- .github/workflows/test.yml | 29 ---------------- .gitignore | 2 +- .pre-commit-config.yaml | 6 ++-- docs/admin/troubleshooting.md | 2 +- docs/developer/cluster-topology.md | 2 +- docs/user/getting-started.md | 20 +++++------ docs/user/images.md | 2 +- docs/user/labels.md | 2 +- pyproject.toml | 2 +- tools/sync-ccm-manifests | 28 ++++++++------- tools/sync-cinder-csi-manifests | 56 +++++++++++++++++------------- tools/sync-manila-csi-manifests | 52 +++++++++++++++++---------- tox.ini | 7 ++++ zuul.d/jobs.yaml | 4 +++ zuul.d/project.yaml | 1 + 15 files changed, 114 insertions(+), 101 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c367ca9a..dad3d050 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -74,32 +74,3 @@ jobs: - name: Install package using constraints run: pip install --constraint https://releases.openstack.org/constraints/upper/${{ matrix.openstack-version }} ./dist/*.whl - - black: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: psf/black@stable - - flake8: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: "3.10" - - run: pipx install flake8 - - uses: suo/flake8-github-action@releases/v1 - with: - checkName: flake8 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - isort: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: "3.10" - - uses: isort/isort-action@master diff --git a/.gitignore b/.gitignore index 05db8a13..784c8f82 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ __pycache__ dist magnum_cluster_api/charts/vendor/* -site \ No newline at end of file +site diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 027de409..677141c9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,5 @@ +exclude: ^magnum_cluster_api/charts/ + repos: - repo: https://github.com/compilerla/conventional-pre-commit rev: v2.0.0 @@ -7,7 +9,7 @@ repos: - commit-msg - repo: https://github.com/psf/black - rev: 22.10.0 + rev: 24.8.0 hooks: - id: black @@ -17,7 +19,7 @@ repos: - id: flake8 - repo: https://github.com/pycqa/isort - rev: 5.10.1 + rev: 5.13.2 hooks: - id: isort diff --git a/docs/admin/troubleshooting.md b/docs/admin/troubleshooting.md index 1b9761a7..bd937159 100644 --- a/docs/admin/troubleshooting.md +++ b/docs/admin/troubleshooting.md @@ -41,7 +41,7 @@ state, you can follow the steps below to troubleshoot the issue: ``` !!! note - + If the cluster exists and it is in `Provisioned` state, you can skip to step 3. diff --git a/docs/developer/cluster-topology.md b/docs/developer/cluster-topology.md index 76962b17..0df789f9 100644 --- a/docs/developer/cluster-topology.md +++ b/docs/developer/cluster-topology.md @@ -9,4 +9,4 @@ In order to do this, the driver creates a [`ClusterClass`](https://cluster-api.s It's important to note that there are only _one_ scenarios where the `spec.topology.class` for a given `Cluster` will be modified and this will be when a cluster upgrade is done. This is because there is an expectation by the user that a rolling restart operation will occur if a cluster upgrade is requested. No other action should be allowed to change the `spec.topology.class` of a `Cluster`. -For users, it's important to keep in mind that if they want to use a newer `ClusterClass` in order to make sure of a new feature available in a newer `ClusterClass`, they can simply do an upgrade within Magnum to the same cluster template and it will actually force an update of the `spec.topology.class`, which might then naturally cause a full rollout to occur. \ No newline at end of file +For users, it's important to keep in mind that if they want to use a newer `ClusterClass` in order to make sure of a new feature available in a newer `ClusterClass`, they can simply do an upgrade within Magnum to the same cluster template and it will actually force an update of the `spec.topology.class`, which might then naturally cause a full rollout to occur. diff --git a/docs/user/getting-started.md b/docs/user/getting-started.md index 8343c367..60d6fd89 100644 --- a/docs/user/getting-started.md +++ b/docs/user/getting-started.md @@ -98,13 +98,13 @@ dashboard, Terraform, Ansible or the Magnum API directly. to launch a cluster, the first of which are related to it's basic configuration, the required fields are: - * **Cluster Name** + * **Cluster Name** The name of the cluster that will be created. - * **Cluster Template** + * **Cluster Template** The cluster template that will be used to create the cluster. - * **Keypair** + * **Keypair** The SSH key pair that will be used to access the cluster. In this example, we're going to create a cluster with the name of @@ -116,22 +116,22 @@ dashboard, Terraform, Ansible or the Magnum API directly. The next step is deciding on the size of the cluster and selecting if auto scaling will be enabled for the cluster. The required fields are: - * **Number of Master Nodes** + * **Number of Master Nodes** The number of master nodes that will be created in the cluster. - * **Flavor of Master Nodes** + * **Flavor of Master Nodes** The flavor of the master nodes that will be created in the cluster. - * **Number of Worker Nodes** + * **Number of Worker Nodes** The number of worker nodes that will be created in the cluster. - * **Flavor of Worker Nodes** + * **Flavor of Worker Nodes** The flavor of the worker nodes that will be created in the cluster. In addition, if you want to enable auto scaling, you will need to provide the following information: - * **Auto-scale Worker Nodes** + * **Auto-scale Worker Nodes** Whether or not to enable auto scaling for the worker nodes. * **Minimum Number of Worker Nodes** @@ -164,7 +164,7 @@ dashboard, Terraform, Ansible or the Magnum API directly. if you want to attach the cluster to an existing network with other resources. - * **Cluster API** + * **Cluster API** This setting controls if the API will get a floating IP address assigned to it. You can set this to _Accessible on private network only_ if you are using an existing network and don't want to expose the API to the @@ -181,7 +181,7 @@ dashboard, Terraform, Ansible or the Magnum API directly. the cluster which automatically detects nodes that are unhealthy and replaces them with new nodes. The required fields are: - * **Automatically Repair Unhealthy Nodes** + * **Automatically Repair Unhealthy Nodes** Whether or not to enable auto-healing for the cluster. In this example, we're going to enable auto-healing for the cluster since it diff --git a/docs/user/images.md b/docs/user/images.md index 7fffb422..652c6a95 100644 --- a/docs/user/images.md +++ b/docs/user/images.md @@ -7,7 +7,7 @@ all necessary dependencies for deploying Kubernetes clusters. These images are pre-configured with Kubernetes binaries, container runtimes, networking components, and other required software. -The images used by the Cluster API driver for Magnum are built using the +The images used by the Cluster API driver for Magnum are built using the [`kubernetes-sigs/image-builder`](https://github.com/kubernetes-sigs/image-builder) project. This project provides a comprehensive and flexible framework for constructing Kubernetes-specific images. diff --git a/docs/user/labels.md b/docs/user/labels.md index 556e8060..09519f09 100644 --- a/docs/user/labels.md +++ b/docs/user/labels.md @@ -22,7 +22,7 @@ specify the volume size and type using the following labels: `boot_volume_type` : The volume type of the boot volume. - **Default value**: Default volume + **Default value**: Default volume `etcd_volume_size` diff --git a/pyproject.toml b/pyproject.toml index c914f762..d23464fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.poetry] -name = "magnum-cluster-api" +name = "magnum-cluster-api" version = "0.21.2" description = "Cluster API driver for Magnum" authors = ["Mohammed Naser "] diff --git a/tools/sync-ccm-manifests b/tools/sync-ccm-manifests index 4be9c6dd..7d448e94 100755 --- a/tools/sync-ccm-manifests +++ b/tools/sync-ccm-manifests @@ -52,18 +52,22 @@ for manifest in MANIFESTS: del doc["spec"]["template"]["spec"]["volumes"][2]["secret"] # NOTE(okozachenko1203): Add `/etc/kuberentes/cloud_ca.crt`. - doc["spec"]["template"]["spec"]["containers"][0]["volumeMounts"].append({ - "name": "cloud-ca-cert-volume", - "readOnly": True, - "mountPath": "/etc/config/ca.crt", - }) - doc["spec"]["template"]["spec"]["volumes"].append({ - "name": "cloud-ca-cert-volume", - "hostPath": { - "type": "File", - "path": "/etc/kubernetes/cloud_ca.crt", - }, - }) + doc["spec"]["template"]["spec"]["containers"][0]["volumeMounts"].append( + { + "name": "cloud-ca-cert-volume", + "readOnly": True, + "mountPath": "/etc/config/ca.crt", + } + ) + doc["spec"]["template"]["spec"]["volumes"].append( + { + "name": "cloud-ca-cert-volume", + "hostPath": { + "type": "File", + "path": "/etc/kubernetes/cloud_ca.crt", + }, + } + ) # NOTE(mnaser): We need to run as root in order to read the `cloud.conf` # file from the host. diff --git a/tools/sync-cinder-csi-manifests b/tools/sync-cinder-csi-manifests index 722384fe..c59a093c 100755 --- a/tools/sync-cinder-csi-manifests +++ b/tools/sync-cinder-csi-manifests @@ -53,18 +53,22 @@ for manifest in MANIFESTS: del doc["spec"]["template"]["spec"]["volumes"][1]["secret"] # NOTE(okozachenko1203): Add `/etc/kuberentes/cloud_ca.crt`. - doc["spec"]["template"]["spec"]["containers"][5]["volumeMounts"].append({ - "name": "cloud-ca-cert-volume", - "readOnly": True, - "mountPath": "/etc/config/ca.crt", - }) - doc["spec"]["template"]["spec"]["volumes"].append({ - "name": "cloud-ca-cert-volume", - "hostPath": { - "type": "File", - "path": "/etc/kubernetes/cloud_ca.crt", - }, - }) + doc["spec"]["template"]["spec"]["containers"][5]["volumeMounts"].append( + { + "name": "cloud-ca-cert-volume", + "readOnly": True, + "mountPath": "/etc/config/ca.crt", + } + ) + doc["spec"]["template"]["spec"]["volumes"].append( + { + "name": "cloud-ca-cert-volume", + "hostPath": { + "type": "File", + "path": "/etc/kubernetes/cloud_ca.crt", + }, + } + ) # NOTE(mnaser): We need to run as root in order to read the `cloud.conf` # file from the host. @@ -85,18 +89,22 @@ for manifest in MANIFESTS: del doc["spec"]["template"]["spec"]["volumes"][4]["secret"] # NOTE(okozachenko1203): Add `/etc/kuberentes/cloud_ca.crt`. - doc["spec"]["template"]["spec"]["containers"][2]["volumeMounts"].append({ - "name": "cloud-ca-cert-volume", - "readOnly": True, - "mountPath": "/etc/config/ca.crt", - }) - doc["spec"]["template"]["spec"]["volumes"].append({ - "name": "cloud-ca-cert-volume", - "hostPath": { - "type": "File", - "path": "/etc/kubernetes/cloud_ca.crt", - }, - }) + doc["spec"]["template"]["spec"]["containers"][2]["volumeMounts"].append( + { + "name": "cloud-ca-cert-volume", + "readOnly": True, + "mountPath": "/etc/config/ca.crt", + } + ) + doc["spec"]["template"]["spec"]["volumes"].append( + { + "name": "cloud-ca-cert-volume", + "hostPath": { + "type": "File", + "path": "/etc/kubernetes/cloud_ca.crt", + }, + } + ) # NOTE(mnaser): We need to run as root in order to read the `cloud.conf` # file from the host. diff --git a/tools/sync-manila-csi-manifests b/tools/sync-manila-csi-manifests index 3531428c..83e52255 100755 --- a/tools/sync-manila-csi-manifests +++ b/tools/sync-manila-csi-manifests @@ -63,33 +63,49 @@ for manifest in MANIFESTS: "value" ] = "unix:///var/lib/kubelet/plugins/csi-nfsplugin/csi.sock" doc["spec"]["template"]["spec"]["containers"][3]["env"][4]["value"] = "NFS" - doc["spec"]["template"]["spec"]["containers"][3]["image"] = "registry.k8s.io/provider-os/manila-csi-plugin:latest" - doc["spec"]["template"]["spec"]["containers"][3]["volumeMounts"][1]["mountPath"] = "/var/lib/kubelet/plugins/csi-nfsplugin" - doc["spec"]["template"]["spec"]["volumes"][1]["hostPath"]["path"] = "/var/lib/kubelet/plugins/csi-nfsplugin" + doc["spec"]["template"]["spec"]["containers"][3][ + "image" + ] = "registry.k8s.io/provider-os/manila-csi-plugin:latest" + doc["spec"]["template"]["spec"]["containers"][3]["volumeMounts"][1][ + "mountPath" + ] = "/var/lib/kubelet/plugins/csi-nfsplugin" + doc["spec"]["template"]["spec"]["volumes"][1]["hostPath"][ + "path" + ] = "/var/lib/kubelet/plugins/csi-nfsplugin" # NOTE(okozachenko1203): Add `/etc/kuberentes/cloud_ca.crt`. - doc["spec"]["template"]["spec"]["containers"][3]["volumeMounts"].append({ - "name": "cloud-ca-cert-volume", - "readOnly": True, - "mountPath": "/etc/config/ca.crt", - }) - doc["spec"]["template"]["spec"]["volumes"].append({ - "name": "cloud-ca-cert-volume", - "hostPath": { - "type": "File", - "path": "/etc/kubernetes/cloud_ca.crt", - }, - }) + doc["spec"]["template"]["spec"]["containers"][3]["volumeMounts"].append( + { + "name": "cloud-ca-cert-volume", + "readOnly": True, + "mountPath": "/etc/config/ca.crt", + } + ) + doc["spec"]["template"]["spec"]["volumes"].append( + { + "name": "cloud-ca-cert-volume", + "hostPath": { + "type": "File", + "path": "/etc/kubernetes/cloud_ca.crt", + }, + } + ) if doc["kind"] == "DaemonSet": doc["spec"]["template"]["spec"]["containers"][1]["env"][3][ "value" ] = "unix:///var/lib/kubelet/plugins/csi-nfsplugin/csi.sock" doc["spec"]["template"]["spec"]["containers"][1]["env"][4]["value"] = "NFS" - doc["spec"]["template"]["spec"]["containers"][1]["image"] = "registry.k8s.io/provider-os/manila-csi-plugin:latest" + doc["spec"]["template"]["spec"]["containers"][1][ + "image" + ] = "registry.k8s.io/provider-os/manila-csi-plugin:latest" # Set FWD plugin - doc["spec"]["template"]["spec"]["containers"][1]["volumeMounts"][1]["mountPath"] = "/var/lib/kubelet/plugins/csi-nfsplugin" - doc["spec"]["template"]["spec"]["volumes"][2]["hostPath"]["path"] = "/var/lib/kubelet/plugins/csi-nfsplugin" + doc["spec"]["template"]["spec"]["containers"][1]["volumeMounts"][1][ + "mountPath" + ] = "/var/lib/kubelet/plugins/csi-nfsplugin" + doc["spec"]["template"]["spec"]["volumes"][2]["hostPath"][ + "path" + ] = "/var/lib/kubelet/plugins/csi-nfsplugin" # Set toleration doc["spec"]["template"]["spec"]["tolerations"] = [{"operator": "Exists"}] diff --git a/tox.ini b/tox.ini index fe285ae6..3f59d1c9 100644 --- a/tox.ini +++ b/tox.ini @@ -17,3 +17,10 @@ commands = [testenv:functional] commands = pytest magnum_cluster_api/tests/functional/ + +[testenv:linters] +skipsdist = True +deps = + pre-commit +commands = + pre-commit run --all-files --show-diff-on-failure diff --git a/zuul.d/jobs.yaml b/zuul.d/jobs.yaml index f8de8e2b..fafb1663 100644 --- a/zuul.d/jobs.yaml +++ b/zuul.d/jobs.yaml @@ -1,3 +1,7 @@ +- job: + name: magnum-cluster-api-linters + parent: tox-linters + - job: name: magnum-cluster-api-unit parent: tox diff --git a/zuul.d/project.yaml b/zuul.d/project.yaml index 9d38eaa6..e538d871 100644 --- a/zuul.d/project.yaml +++ b/zuul.d/project.yaml @@ -1,6 +1,7 @@ - project: check: jobs: + - magnum-cluster-api-linters - magnum-cluster-api-unit - magnum-cluster-api-functional templates: