From 4d8f14681373118f7577452a004e244b624ae111 Mon Sep 17 00:00:00 2001 From: Meni Yakove <441263+myakove@users.noreply.github.com> Date: Wed, 19 Jul 2023 14:05:54 +0300 Subject: [PATCH] Sync from main (#1253) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add v4.14 to renovate.json * Exapnd MachineConfigPool for creation (#1204) * Exapnd MachineConfigPool for creation * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * ICSP: set repository_digest_mirrors to None (#1231) * Add close-stale-issues workflow * [pre-commit.ci] pre-commit autoupdate (#1239) updates: - [github.com/hadialqattan/pycln: v2.1.3 → v2.1.5](https://github.com/hadialqattan/pycln/compare/v2.1.3...v2.1.5) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * rmemove pre-commit-hooks * remove ruff from pre-commit * Update OWNERS (#1241) * adding omrirh to owners * Update OWNERS Co-authored-by: oharan2 --------- Co-authored-by: Meni Yakove <441263+myakove@users.noreply.github.com> Co-authored-by: oharan2 * StorageClass - add support for resource creation (#1246) * Update StorageClass class * fix per review * fix per review * wait_for_condition: use sampler, not watcher (#1248) * wait_for_condition: use sampler, not watcher * wait_for_condition: use sampler, not watcher * [pre-commit.ci] pre-commit autoupdate (#1245) updates: - [github.com/PyCQA/autoflake: v2.1.1 → v2.2.0](https://github.com/PyCQA/autoflake/compare/v2.1.1...v2.2.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * disable stale.yml * Update close-stale-issues.yml * [pre-commit.ci] pre-commit autoupdate (#1252) updates: - [github.com/psf/black: 23.3.0 → 23.7.0](https://github.com/psf/black/compare/23.3.0...23.7.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --------- Co-authored-by: Yossi Segev <40713576+yossisegev@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Omri Bar Haim Co-authored-by: oharan2 Co-authored-by: dalia-frank <65129017+dalia-frank@users.noreply.github.com> Co-authored-by: Ruth Netser --- .github/stale.yml | 17 ------ .github/workflows/close-stale-issues.yml | 15 +++++ .pre-commit-config.yaml | 6 +- OWNERS | 2 + ocp_resources/machine_config_pool.py | 71 ++++++++++++++++++++++++ ocp_resources/storage_class.py | 58 +++++++++++++++++++ renovate.json | 1 + 7 files changed, 150 insertions(+), 20 deletions(-) delete mode 100644 .github/stale.yml create mode 100644 .github/workflows/close-stale-issues.yml diff --git a/.github/stale.yml b/.github/stale.yml deleted file mode 100644 index 7c4e86674d..0000000000 --- a/.github/stale.yml +++ /dev/null @@ -1,17 +0,0 @@ -# Number of days of inactivity before an issue becomes stale -daysUntilStale: 60 -# Number of days of inactivity before a stale issue is closed -daysUntilClose: 7 -# Issues with these labels will never be considered stale -exemptLabels: - - pinned - - security -# Label to use when marking an issue as stale -staleLabel: stale -# Comment to post when marking an issue as stale. Set to `false` to disable -markComment: > - This issue has been automatically marked as stale because it has not had - recent activity. It will be closed if no further activity occurs. Thank you - for your contributions. -# Comment to post when closing a stale issue. Set to `false` to disable -closeComment: true diff --git a/.github/workflows/close-stale-issues.yml b/.github/workflows/close-stale-issues.yml new file mode 100644 index 0000000000..936231a302 --- /dev/null +++ b/.github/workflows/close-stale-issues.yml @@ -0,0 +1,15 @@ +name: 'Close stale issues and PRs' +on: + schedule: + - cron: '30 1 * * *' + +jobs: + stale: + runs-on: ubuntu-latest + steps: + - uses: actions/stale@v8 + with: + stale-issue-message: 'This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.' + days-before-stale: 60 + days-before-close: 7 + ignore-updates: true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0dc9208924..a7464f3b17 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ default_language_version: repos: - repo: https://github.com/PyCQA/autoflake - rev: "v2.1.1" + rev: "v2.2.0" hooks: - id: autoflake args: @@ -12,7 +12,7 @@ repos: - --remove-all-unused-imports - repo: https://github.com/hadialqattan/pycln - rev: "v2.1.3" + rev: "v2.1.5" hooks: - id: pycln @@ -22,7 +22,7 @@ repos: - id: isort - repo: https://github.com/psf/black - rev: "23.3.0" + rev: "23.7.0" hooks: - id: black diff --git a/OWNERS b/OWNERS index 83a727f907..c70c7a6705 100644 --- a/OWNERS +++ b/OWNERS @@ -4,3 +4,5 @@ approvers: reviewers: - myakove - rnetser + - omrirh + - oharan2 diff --git a/ocp_resources/machine_config_pool.py b/ocp_resources/machine_config_pool.py index 4c68fa0b39..d1fe0fcb8d 100644 --- a/ocp_resources/machine_config_pool.py +++ b/ocp_resources/machine_config_pool.py @@ -2,8 +2,79 @@ class MachineConfigPool(Resource): + """ + MachineConfigPool object. API reference: + https://docs.openshift.com/container-platform/4.12/rest_api/machine_apis/machineconfigpool-machineconfiguration-openshift-io-v1.html + + Args: + node_selector (dict): Matching dict with supported selector logic, either labels or expressions. + matchLabels example: + matchLabels: + component: + matchExpressions: + - { key: tier, operator: In, values: [cache] } + - { key: environment, operator: NotIn, values: [dev] } + matchExpressions example: + matchExpressions: + - key: /role + operator: In + values: + - value_1 + - value_2 + machine_config_selector (dict): Matching labels/expressions, to determine which MachineConfig objects + to apply this MachineConfigPool object. + For filtering based on labels, the `matchLabels` dict is used - the same way as it is used in the + nodeSelector (see the example of node_selector["matchLabels"] above). + For filtering based on expressions, the `matchExpressions` dict is used - the same way as it is used in the + nodeSelector (see the example of node_selector["matchExpressions"] above). + configuration (dict): Targeted MachineConfig object for the machine config pool, in the following format: + {"name": (str), "source": } + max_unavailable (int or str): Number/percentage of nodes that can go Unavailable during an update. + paused (bool): Whether changes to this MachineConfigPool should be stopped. + """ + api_group = Resource.ApiGroup.MACHINECONFIGURATION_OPENSHIFT_IO class Status(Resource.Status): UPDATED = "Updated" UPDATING = "Updating" + + def __init__( + self, + machine_config_selector=None, + configuration=None, + node_selector=None, + max_unavailable=None, + paused=None, + **kwargs, + ): + super().__init__(**kwargs) + self.configuration = configuration + self.machine_config_selector = machine_config_selector + self.node_selector = node_selector + self.max_unavailable = max_unavailable + self.paused = paused + + def to_dict(self): + super().to_dict() + if not self.yaml_file: + self.res.update( + { + "spec": { + "configuration": self.configuration or {}, + }, + }, + ) + + manifest_spec = self.res["spec"] + if self.machine_config_selector: + manifest_spec["machineConfigSelector"] = self.machine_config_selector + + if self.node_selector: + manifest_spec["nodeSelector"] = self.node_selector + + if self.max_unavailable: + manifest_spec["maxUnavailable"] = self.max_unavailable + + if self.paused: + manifest_spec["paused"] = self.paused diff --git a/ocp_resources/storage_class.py b/ocp_resources/storage_class.py index 87a66f66a4..4f10436456 100644 --- a/ocp_resources/storage_class.py +++ b/ocp_resources/storage_class.py @@ -45,3 +45,61 @@ class Annotations: IS_DEFAULT_CLASS = ( f"{Resource.ApiGroup.STORAGECLASS_KUBERNETES_IO}/is-default-class" ) + + class ReclaimPolicy: + DELETE = "Delete" + RETAIN = "Retain" + + def __init__( + self, + provisioner=None, + reclaim_policy=None, + volume_binding_mode=None, + allow_volume_expansion=None, + parameters=None, + allowed_topologies=None, + mount_options=None, + **kwargs, + ): + """ + StorageClass object + + Args: + provisioner (str): The provisioner of the storage class + reclaim_policy (str): Can be either "Delete" or "Retain" + volume_binding_mode (str): When volume binding and dynamic provisioning should occur + allow_volume_expansion (bool): True for allowing the volume expansion + parameters (dict): Describe volumes belonging to the storage class. + allowed_topologies (list): Restrict provisioning to specific topologies + mount_options (list): PV's that are dynamically created by the SC will have the mount options + """ + super().__init__( + **kwargs, + ) + + self.provisioner = provisioner + self.reclaim_policy = reclaim_policy + self.volume_binding_mode = volume_binding_mode + self.allow_volume_expansion = allow_volume_expansion + self.parameters = parameters + self.allowed_topologies = allowed_topologies + self.mount_options = mount_options + + def to_dict(self): + super().to_dict() + if not self.yaml_file: + if not self.provisioner: + raise ValueError("provisioner must be specified") + self.res.update({"provisioner": self.provisioner}) + if self.reclaim_policy: + self.res.update({"reclaimPolicy": self.reclaim_policy}) + if self.volume_binding_mode: + self.res.update({"volumeBindingMode": self.volume_binding_mode}) + if self.allow_volume_expansion: + self.res.update({"allowVolumeExpansion": self.allow_volume_expansion}) + if self.parameters: + self.res.update({"parameters": self.parameters}) + if self.allowed_topologies: + self.res.update({"allowedTopologies": self.allowed_topologies}) + if self.mount_options: + self.res.update({"mountOptions": self.mount_options}) diff --git a/renovate.json b/renovate.json index 033e4f959b..de908abd76 100644 --- a/renovate.json +++ b/renovate.json @@ -2,6 +2,7 @@ "$schema": "https://docs.renovatebot.com/renovate-schema.json", "baseBranches": [ "main", + "v4.14", "v4.13", "v4.12", "v4.11",