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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>