Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .coderabbit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,29 @@ reviews:
of these files entirely, as reviewing code changes in kubernetes would be wildly out of scope.
The one exception to this is `vendor/github.com/openshift/hive/**`, which should be a direct copy
of the `apis` folder found in the root of the repo, referenced by the CRD generation guidance above.
- path: config/hiveadmission/*-webhook.yaml
instructions: |-
These are configuration files for admission webhooks for hive CRs. Files named *-webhook.yaml
contain ValidatingWebhookConfiguration (or, hypothetically, MutatingWebhookConfiguration -- but
we don't have any of those at this time) manifests. Please validate:
- They have been built into pkg/operator/assets/bindata.go (today our `verify` CI job should
also check this).
- They are all in the `webhookAssets` list in pkg/operator/hive/hiveadmission.go -- else they
will not be deployed!
- Each has a corresponding implementation in pkg/validating-webhooks/hive/v1.
- When any file in this directory is added or modified, also cross-check ALL other
existing *-webhook.yaml files in config/hiveadmission/ to verify their operations
are consistent with their implementations. Do not limit the audit to only the file(s)
in the diff.
- The `Operation`s in `.webhooks[].rules[].operations` must exactly match the
operations handled by explicit `case` branches in the implementation's `Validate()`
switch. A `default: Allowed: true` branch does NOT count as handling an operation.
If an operation appears in the YAML but has no corresponding `case`, flag it; and
vice versa.
- path: pkg/validating-webhooks/hive/v1/*_admission_hook.go
instructions: |-
These are implementations for validating (or, hypothetically, mutating -- but we don't have any
of those at this time) webhooks handled by our hiveadmission service. Mirroring the above checks
for config/hiveadmission/*-webhook.yaml, please validate that each has a corresponding
ValidatingWebhookConfiguration (or MutatingWebhookConfiguration) manifest under config/hiveadmission/,
built into bindata, with matching `Operation`s, and is listed for installation in hiveadmission.go.
27 changes: 27 additions & 0 deletions config/hiveadmission/clusterdeploymentcustomization-webhook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: clusterdeploymentcustomizationvalidators.admission.hive.openshift.io
webhooks:
- name: clusterdeploymentcustomizationvalidators.admission.hive.openshift.io
admissionReviewVersions:
- v1beta1
clientConfig:
service:
# reach the webhook via the registered aggregated API
namespace: default
name: kubernetes
path: /apis/admission.hive.openshift.io/v1/clusterdeploymentcustomizationvalidators
rules:
- operations:
- CREATE
- UPDATE
apiGroups:
- hive.openshift.io
apiVersions:
- v1
resources:
- clusterdeploymentcustomizations
failurePolicy: Fail
sideEffects: None
1 change: 0 additions & 1 deletion config/hiveadmission/clusterpool-webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ webhooks:
- operations:
- CREATE
- UPDATE
- DELETE
apiGroups:
- hive.openshift.io
apiVersions:
Expand Down
140 changes: 93 additions & 47 deletions pkg/operator/assets/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/operator/hive/hiveadmission.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const (

var webhookAssets = []string{
"config/hiveadmission/clusterdeployment-webhook.yaml",
"config/hiveadmission/clusterdeploymentcustomization-webhook.yaml",
Comment thread
coderabbitai[bot] marked this conversation as resolved.
"config/hiveadmission/clusterimageset-webhook.yaml",
"config/hiveadmission/clusterpool-webhook.yaml",
"config/hiveadmission/clusterprovision-webhook.yaml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
const (
clusterDeploymentCustomizationGroup = "hive.openshift.io"
clusterDeploymentCustomizationVersion = "v1"
clusterDeploymentCustomizationResource = "clusterdeploymentcustomization"
clusterDeploymentCustomizationResource = "clusterdeploymentcustomizations"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "1) Find ClusterDeploymentCustomization validating hook tests"
fd 'clusterdeploymentcustomization.*_test\.go$' pkg || true

echo
echo "2) Find test coverage for this hook/resource/operations"
rg -nP --type=go '(ClusterDeploymentCustomizationValidatingAdmissionHook|clusterdeploymentcustomizations|admissionv1beta1\.(Create|Update))' pkg -g '*_test.go' || true

Repository: openshift/hive

Length of output: 31435


🏁 Script executed:

cat -n pkg/validating-webhooks/hive/v1/clusterdeploymentcustomization_validating_admission_hook.go | head -80

Repository: openshift/hive

Length of output: 4442


🏁 Script executed:

find config -name '*clusterdeploymentcustomization*' -o -name '*webhook*' | grep -i customization || echo "No webhook config found for customization"

Repository: openshift/hive

Length of output: 189


🏁 Script executed:

rg -l 'clusterdeploymentcustomizations|ClusterDeploymentCustomization' config/ || echo "No matches in config/"

Repository: openshift/hive

Length of output: 358


🏁 Script executed:

cat -n pkg/validating-webhooks/hive/v1/clusterdeploymentcustomization_validating_admission_hook.go | tail -100

Repository: openshift/hive

Length of output: 4476


🏁 Script executed:

cat -n config/hiveadmission/clusterdeploymentcustomization-webhook.yaml

Repository: openshift/hive

Length of output: 982


🏁 Script executed:

rg -n 'ClusterDeploymentCustomization' pkg/ -g 'hiveadmission.go' -A 3 -B 3

Repository: openshift/hive

Length of output: 40


🏁 Script executed:

find pkg -name 'hiveadmission.go' -type f

Repository: openshift/hive

Length of output: 92


🏁 Script executed:

rg -n 'NewClusterDeploymentCustomization|clusterdeploymentcustomization' pkg/ --type go -i | grep -i admission

Repository: openshift/hive

Length of output: 8251


🏁 Script executed:

rg -A 10 -B 5 'clusterdeploymentcustomization-webhook.yaml' pkg/operator/hive/hiveadmission.go

Repository: openshift/hive

Length of output: 835


Add dedicated test file for ClusterDeploymentCustomization validating webhook.

This hook lacks regression tests despite other similar hooks (clusterdeployment, syncset, dnszone, etc.) having comprehensive test coverage. Create a clusterdeploymentcustomization_validating_admission_hook_test.go to cover:

  • Resource matching via shouldValidate() (group, version, resource)
  • CREATE operation validation
  • UPDATE operation validation with old/new object handling
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@pkg/validating-webhooks/hive/v1/clusterdeploymentcustomization_validating_admission_hook.go`
at line 22, Add a dedicated test file to cover the
ClusterDeploymentCustomization validating webhook: create
clusterdeploymentcustomization_validating_admission_hook_test.go and implement
unit tests that assert shouldValidate() matches the intended
group/version/resource for "clusterdeploymentcustomizations", test CREATE
validation by calling the webhook's Admit/Validate function with a new
ClusterDeploymentCustomization object (both valid and invalid cases), and test
UPDATE validation by invoking the webhook with old and new objects to verify
update-specific logic; reference the shouldValidate() function and the
ClusterDeploymentCustomization validating admission hook methods (e.g.,
Validate/Admit or AdmitFunc) in your tests and mirror patterns used for the
existing clusterdeployment/syncset/dnszone tests for setup, fake clients, and
expected error assertions.


clusterDeploymentCustomizationAdmissionGroup = "admission.hive.openshift.io"
clusterDeploymentCustomizationAdmissionVersion = "v1"
Expand Down Expand Up @@ -124,7 +124,7 @@ func (a *ClusterDeploymentCustomizationValidatingAdmissionHook) shouldValidate(a
}

if admissionSpec.Resource.Resource != clusterDeploymentCustomizationResource {
contextLogger.Info("Returning False, it's our group and version, but not the right resource")
contextLogger.WithField("resource", admissionSpec.Resource.Resource).Info("Returning False, it's our group and version, but not the right resource")
return false
}

Expand Down