Commit Graph

147 Commits

Author SHA1 Message Date
changzhen 262fcb328a fix validate panic when ResourceInterpreterWebhookConfiguration .webhooks[*].clientConfig.service.port is nil
Signed-off-by: changzhen <changzhen5@huawei.com>
2024-12-20 15:16:38 +08:00
chaosi-zju 13c28a00b2 fix code typo errors
Signed-off-by: chaosi-zju <chaosi@zju.edu.cn>
2024-11-28 11:01:54 +08:00
chaunceyjiang f45aedb716 feat: validate fieldOverrider operation
Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
2024-10-11 14:59:04 +08:00
karmada-bot 376d20376c
Merge pull request #5542 from mohamedawnallah/unitTestInterpreter
pkg/webhook: unit test Interpreter
2024-10-09 11:52:20 +08:00
Mohamed Awnallah c571cfb39a pkg/webhook: test Interpreter
In this commit, we introduce unit tests for the `Interpreter` webhook
across `Decoder`, `HTTP`, `Injection`, `Response`, and `Webhook` components.

Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
2024-10-09 05:26:27 +03:00
sophie 6bf6f305b8 feat: add fieldoverrider
Signed-off-by: sophie <yl5357@columbia.edu>
2024-10-08 10:36:32 -04:00
karmada-bot 721107da86
Merge pull request #5507 from mohamedawnallah/unitTestFederatedHPAWebhook
pkg/webhook: unit test Federated HPA
2024-09-23 17:40:07 +08:00
karmada-bot 9864a29684
Merge pull request #5580 from XiShanYongYe-Chang/fix-ut-failed-in-federatedresourcequota
fix ut failed in federatedresourcequota
2024-09-23 12:13:07 +08:00
karmada-bot 2d95f7cbc7
Merge pull request #5498 from mohamedawnallah/unitTestClusterResourceBindingWebhook
pkg/webhook: unit test cluster resource binding
2024-09-21 18:53:06 +08:00
karmada-bot 673a603fb5
Merge pull request #5497 from mohamedawnallah/unitTestResourceBindingWebhook
pkg/webhook: unit test resource binding
2024-09-21 17:51:06 +08:00
karmada-bot b630d14544
Merge pull request #5496 from mohamedawnallah/unitTestClusterOverridePolicy
pkg/webhook: unit test cluster override policy
2024-09-21 17:29:06 +08:00
karmada-bot 6804af4d04
Merge pull request #5495 from mohamedawnallah/unitTestOverridePolicy
pkg/webhook: unit test override policy
2024-09-21 17:09:06 +08:00
changzhen 99c5bf4f22 fix ut failed in federatedresourcequota
Signed-off-by: changzhen <changzhen5@huawei.com>
2024-09-21 16:50:58 +08:00
karmada-bot 6c484ca2ec
Merge pull request #5518 from mohamedawnallah/unitTestMultiClusterIngress
pkg/webhook: unit test Multi-Cluster Ingress
2024-09-21 14:35:06 +08:00
karmada-bot 21c18eb132
Merge pull request #5544 from mohamedawnallah/refactorFederatedResourceQuota
pkg/webhook: refactor Federated Resource Quota test
2024-09-21 10:40:05 +08:00
Mohamed Awnallah 466634ac3d pkg/webhook: test ResourceInterpreterCustomization
In this commit, we introduce unit tests for `ValidationAdmission`
webhook for the `ResourceInterpreterCustomization` resource. The
tests include:

- Tests how the webhook responds when decoding the request object fails.
- Tests how the webhook responds when it fails to retrieve list of objects from a namespace.
- Ensures that invalid `ResourceInterpreterCustomization` spec denies the admission.
- Confirms that valid `ResourceInterpreterCustomization` spec are allowed through without errors.

Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
2024-09-16 16:17:13 +03:00
Mohamed Awnallah d2259d52a1 pkg/webhook: test Multi-Cluster Ingress
In this commit we introduce unit tests for the `Validation Admission`. These
tests ensure correct behavior for various validation scenarios and improve coverage:

- Tests the behavior when decoding the request object fails, verifying
  that admission is denied with an appropriate error message.
- Validates that the webhook denies admission when encountering invalid values in the
  `MultiClusterIngress` spec, ensuring error messaging.
- Confirms that valid `MultiClusterIngress` objects are admitted without errors.

Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
2024-09-14 13:13:49 +03:00
Mohamed Awnallah fe408f9ad6 pkg/webhook: refactor Federated Resource Quota
In this commit, we refactor `FederatedResourceQuota` webhook
mainly matching on substrings instead of whole strings for reliability
and resilience and reformat the test case names to follow format
`Function_Scenario_ExpectedResult` for better readability.

Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
2024-09-13 19:29:17 +03:00
karmada-bot 2e60a6e8a5
Merge pull request #5494 from mohamedawnallah/unitTestClusterPropagationPolicy
pkg/webhook: unit test cluster propagation policy
2024-09-13 16:36:59 +08:00
karmada-bot c3d582ba31
Merge pull request #5537 from mohamedawnallah/refactorPropagationPolicyTest
pkg/webhook: refactor Propagation Policy test
2024-09-13 16:10:59 +08:00
Mohamed Awnallah 14c303022d pkg: test ClusterResourceBinding mutating webhook
In this commit, we introduce unit tests for the `MutatingAdmission`
webhook that mutates the `ClusterResourceBinding` resource. These tests
ensure correct behavior for various mutation scenarios and improve coverage:

- Testing the handling of decode errors and ensuring that admission is denied
when decoding fails.
- Full coverage testing of policy mutation, including setting default UUID
labels for the `ClusterResourceBinding`.
- Verifying that only the expected patch for the UUID label is applied, ensuring
no other unnecessary mutations.

Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
2024-09-13 10:27:01 +03:00
Mohamed Awnallah e689eafd3f pkg: test ResourceBinding mutating webhook
In this commit, we introduce unit tests for the `MutatingAdmission`
webhook that mutates the `ResourceBinding` resource. These tests ensure
correct behavior for various mutation scenarios and improve coverage:

- Testing the handling of decode errors and ensuring that admission
is denied when decoding fails.
- Full coverage testing of policy mutation, including setting default
UUID labels for the `ResourceBinding`.
- Verifying that only the expected patch for the UUID label is applied,
ensuring no other unnecessary mutations.

Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
2024-09-13 10:21:05 +03:00
Mohamed Awnallah f19f9c4a45 pkg/webhook: test OverridePolicy
In this commit, we introduce unit tests for both the `ValidationAdmission`
and `MutatingAdmission` webhooks specifically for the `OverridePolicy` resource.

- Validation webhook tests:
  - Tests the behavior when decoding the request object fails, verifying
    that admission is denied with an appropriate error message.
  - Validates that the webhook denies admission when encountering invalid
    label values in the `OverridePolicy` spec, ensuring proper error messaging.
  - Confirms that valid `OverridePolicy` objects are admitted without errors.

- Mutation webhook tests:
  - Handles decode errors and denies admission when decoding fails.
  - Provides full coverage of policy mutation, including setting default
    namespaces and validating no unnecessary patches.

Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
2024-09-13 10:14:04 +03:00
Mohamed Awnallah 87958641ae pkg/webhook: test ClusterPropagationPolicy
In this commit, we introduce unit tests for both the `ValidatingAdmission`
and `MutatingAdmission` webhooks for the `ClusterPropagationPolicy` resource.

The tests include:

- Validation webhook tests:
  - Tests how the webhook responds when decoding the request object fails.
  - Ensures updates to the `SchedulerName` field are denied, as it should remain immutable.
  - Validates that changes to the `ClusterPropagationPolicyPermanentIDLabel` label and its absence in creation requests are correctly handled.
  - Confirms that valid `ClusterPropagationPolicy` objects are allowed through without errors.

- Mutation webhook tests:
  - Handles decode errors and denies admission when decoding fails.
  - Provides full coverage of cluster policy mutation with default values and patch application.

Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
2024-09-13 10:08:43 +03:00
Mohamed Awnallah 368b4b171d pkg/webhook: refactor propagation policy
In this commit, we refactor propagation policy names and check
on number of patches the mutation happens.

Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
2024-09-13 09:56:50 +03:00
karmada-bot 02e5e922e9
Merge pull request #5517 from mohamedawnallah/unitTestMultiClusterService
pkg/webhook: unit test Multi-Cluster Service
2024-09-12 15:58:59 +08:00
Mohamed Awnallah bd847422af pkg/webhook: test Work
In this commit, we introduce unit tests for the `MutatingAdmission`
webhook specifically for the `Work` resource. The mutation webhook
tests include the following:

- Handles decode errors and denies admission when decoding fails.
- Provides full coverage of policy mutation, including setting default
  and validating no unnecessary patches.

Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
2024-09-12 07:28:03 +03:00
Mohamed Awnallah d5c9a9d803 pkg/webhook: test Multi-Cluster Service
In this commit, we introduce unit tests for both the `ValidationAdmission`
and `MutatingAdmission` webooks specifically for the `MultiClusterService` resource.

- Validation webhook tests:
  - Tests the behavior when decoding the request object fails, verifying
    that admission is denied with an appropriate error message.
  - Validates that the webhook denies admission when encountering invalid
    values in the `MultiClusterService` spec, ensuring error messaging.
  - Confirms that valid `MultiClusterService` objects are admitted without errors.

- Mutation webhook tests:
  - Handles decode errors and denies admission when decoding fails.
  - Provides full coverage of `MultiClusterService` object mutation,
    including setting default namespaces and validating no unnecessary patches.

Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
2024-09-12 07:27:34 +03:00
karmada-bot 927dc33d58
Merge pull request #5521 from mohamedawnallah/logMutatingWebhookHandlers
pkg/webhook: log mutating handlers in `OverridePolicy`, `ClusterPropagationPolicy`, and `MultiClusterService`
2024-09-12 10:47:58 +08:00
Mohamed Awnallah df270fab91 pkg/webhook: log mutating webhook handlers
In this commit, we log the mutating handlers for `OverridePolicy`,
`ClusterPropagationPolicy`, and `MultiClusterService`. Specifically, it logs
information about the mutation of these resources, including the namespace,
name, and the operation type from the admission request.

Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
2024-09-11 07:53:16 +03:00
karmada-bot ca1b2ce3c7
Merge pull request #5492 from mohamedawnallah/unitTestPropagationPolicy
pkg/webhook: unit test propagation policy
2024-09-10 14:13:56 +08:00
Mohamed Awnallah e2a3f5942c pkg/webhook: test PropagationPolicy
In this commit, we introduce unit tests for both the `ValidatingAdmission`
and `MutatingAdmission` webhooks for the `PropagationPolicy` resource.

The tests include:

- Validation webhook tests:
  - Tests how the webhook responds when decoding the request object fails.
  - Ensures that updates to the `SchedulerName` field are denied, as it should remain immutable.
  - Validates that changes to the `PropagationPolicyPermanentIDLabel` label and its absence in creation requests are correctly handled.
  - Confirms that valid `PropagationPolicy` objects are allowed through without errors.

- Mutation webhook tests:
  - Handles decode errors and denies admission when decoding fails.
  - Provides full coverage of policy mutation with default values and patch application.

Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
2024-09-10 06:39:20 +03:00
Mohamed Awnallah e5169f8889 pkg/webhook: test FederatedHPA
In this commit, we introduce unit tests for both the `MutatingAdmission`
and `ValidatingAdmission` webhooks specifically for the `FederatedHPA`
resource.

The tests include:

- Validation webhook tests:
  - Verifies that admission is denied with an appropriate error message
    when decoding the request object fails.
  - Ensures admission is denied when the `FederatedHPA` spec contains
    invalid values, such as a `minReplicas` set to zero, and the correct
    error message is returned.
  - Confirms that a valid `FederatedHPA` object is allowed through without
    errors.

- Mutation webhook tests:
  - Verifies that admission is denied when decoding the request object
    fails, returning the appropriate error message.
  - Ensures that the `FederatedHPA` object is correctly mutated when
    provided with default values, including scale policies and CPU
    utilization.
  - Confirms that no patches are applied when the `FederatedHPA` object is
    handled correctly and that admission is allowed for valid
    `FederatedHPA` objects.

Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
2024-09-09 15:51:02 +03:00
Mohamed Awnallah fa4a077865 pkg: test ResourceDeletionProtection valid webhook
In this commit, we add unit tests for the `ValidatingAdmission` validation webhook
specifically for the resource deletion protection feature. These tests ensure
that the webhook correctly handles various admission scenarios:

- Tests the behavior when decoding the request object fails, verifying that admission
is denied with an appropriate error message.
- Ensures that resources labeled with `DeletionProtectionAlways` are denied deletion,
validating that the error message is returned.
- Confirms that resources without the deletion protection label are allowed to be deleted
without errors.
- Validates that resources with other labels are not impacted and are allowed to be deleted.
- Confirms that non-delete operations (e.g., create) are allowed by default.

Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
2024-09-09 03:56:52 +03:00
Mohamed Awnallah 5a2e714a3b pkg: test ClusterOverridePolicy validation webhook
In this commit, we add unit tests for the `ValidationAdmission`
webhook specifically for the `ClusterOverridePolicy` resource. These
tests ensure that the webhook correctly handles various admission
scenarios:

- Tests the behavior when decoding the request object fails, verifying
that the admission is denied with an approriate error message.
- Validates that the webhook denies admission when encountering invalid
label values in the `ClusterOverridePolicy` spec, ensuring proper error messaging.
- Confirms that valid `ClusterOverridePolicy` objects are admissionly allowed
without errors.

Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
2024-09-09 03:26:49 +03:00
changzhen 911cc44974 remove pp/cpp name length limit
Signed-off-by: changzhen <changzhen5@huawei.com>
2024-08-16 10:34:15 +08:00
Mohamed Awnallah 7373ab303e pkg: test `federatedresourcequota` webhook
In this commit, we add unit tests for the `FederatedResourceQuota`
validation logic and its related components. The tests ensure that
the validation logic correctly handles various scenarios, including:

- Validating `FederatedResourceQuota` specifications with appropriate resource assignments.
- Detecting cases where overall resource limits are less than the assigned resources.
- Handling scenarios where resource names in assignments do not exist in the overall resources.
- Validating `FederatedResourceQuotaStatus` to ensure standard resource types and correct cluster names.
- Handling invalid resource lists in both `Overall` and `AggregatedStatus`.

Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
2024-08-01 02:39:44 +00:00
RainbowMango e8164eeebd Adopt controller-runtime braking changes: generics support PR2783
Adopt controller-runtime breaking changes: make decoder as interface. PR2736

Signed-off-by: RainbowMango <qdurenhongcai@gmail.com>
2024-07-13 16:49:01 +08:00
whitewindmills 91f72f998c Transplant propagation policy finalizer to karmada-webhook
Signed-off-by: whitewindmills <jayfantasyhjh@gmail.com>
2024-07-08 10:23:38 +08:00
whitewindmills 2450bd6041 Correct licenses format
Signed-off-by: whitewindmills <jayfantasyhjh@gmail.com>
2024-07-04 10:35:16 +08:00
karmada-bot d05b92153b
Merge pull request #4998 from chaosi-zju/dev
fix demo for dependencyInterpretation
2024-06-05 10:50:34 +08:00
chaosi-zju 3c731e5d08 fix demo for dependencyInterpretation
Signed-off-by: chaosi-zju <chaosi@zju.edu.cn>
2024-06-04 11:50:30 +08:00
changzhen 6edf69debb fix upgrade error with #5003
Signed-off-by: changzhen <changzhen5@huawei.com>
2024-05-30 18:07:07 +08:00
Lan Liang ed0f26c328 cleanup pointer, use ptr.Toto obtain a pointer, ptr.Deref to dereference a pointer.
The new k8s.io/utils/ptr package provides generic wrapper functions,
which can be used instead of type-specific pointer wrapper functions.
This replaces the latter with the former, and migrates other uses of
the deprecated pointer package to ptr in affacted files.

See kubernetes/utils#283 for details.

Signed-off-by: Lan Liang <gcslyp@gmail.com>
2024-05-28 05:32:33 +00:00
whitewindmills b7678c92b2 Add validation on policy permanent ID
Signed-off-by: whitewindmills <jayfantasyhjh@gmail.com>
2024-05-22 17:59:52 +08:00
whitewindmills 93a04cbf0d Generate work permanent id in webhook
Signed-off-by: whitewindmills <jayfantasyhjh@gmail.com>
2024-05-11 09:38:37 +08:00
karmada-bot e30ca1b9cc
Merge pull request #4882 from whitewindmills/work-labels-annotations
Use webhook to set associated labels and annotations of work
2024-05-10 11:51:33 +08:00
whitewindmills a5d8ba7c09 Use webhook to set associated labels and annotations of work
Signed-off-by: whitewindmills <jayfantasyhjh@gmail.com>
2024-05-10 11:03:19 +08:00
RainbowMango d4b610cad6 fix lint issues
Signed-off-by: RainbowMango <qdurenhongcai@gmail.com>
2024-05-06 11:36:54 +08:00
karmada-bot f33f3f8bf3
Merge pull request #4474 from jwcesign/add-uid
feat: add permanent id label to pp/cpp/rb/crb/work resources
2024-04-30 11:39:24 +08:00