Skip to content

Commit

Permalink
remove DRPolicy webhook
Browse files Browse the repository at this point in the history
Signed-off-by: rakeshgm <[email protected]>
  • Loading branch information
rakeshgm committed Mar 8, 2024
1 parent 9bd126d commit 1504dcf
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 111 deletions.
3 changes: 0 additions & 3 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ resources:
kind: DRPolicy
path: github.com/ramendr/ramen/api/v1alpha1
version: v1alpha1
webhooks:
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
Expand Down
17 changes: 13 additions & 4 deletions api/v1alpha1/drpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// nolint:lll

// DRPolicySpec defines the desired state of DRPolicy
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.replicationClassSelector) || has(self.replicationClassSelector)", message="replicationClassSelector is required once set"

Check failure on line 13 in api/v1alpha1/drpolicy_types.go

View workflow job for this annotation

GitHub Actions / Golangci Lint (api)

line is 179 characters (lll)
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.volumeSnapshotClassSelector) || has(self.volumeSnapshotClassSelector)", message="volumeSnapshotClassSelector is required once set"

Check failure on line 14 in api/v1alpha1/drpolicy_types.go

View workflow job for this annotation

GitHub Actions / Golangci Lint (api)

line is 188 characters (lll)
type DRPolicySpec struct {
// Important: Run "make" to regenerate code after modifying this file

Expand All @@ -16,22 +20,27 @@ type DRPolicySpec struct {
// form <num><m,h,d>. Here <num> is a number, 'm' means
// minutes, 'h' means hours and 'd' stands for days.
// +kubebuilder:validation:Required
// +kubebuilder:validation:Pattern=`^\d+[mhd]$`
SchedulingInterval string `json:"schedulingInterval,omitempty"`
// +kubebuilder:validation:Pattern=`^(|\d+[mhd])$`
// +kubebuilder:validation:XValidation:rule="self == oldSelf", message="schedulingInterval is immutable"
SchedulingInterval string `json:"schedulingInterval"`

// Label selector to identify all the VolumeReplicationClasses.
// This selector is assumed to be the same for all subscriptions that
// need DR protection. It will be passed in to the VRG when it is created
//+optional
// +kubebuilder:validation:Optional
// +kubebuilder:validation:XValidation:rule="self == oldSelf", message="replicationClassSelector is immutable"
ReplicationClassSelector metav1.LabelSelector `json:"replicationClassSelector,omitempty"`

// Label selector to identify all the VolumeSnapshotClasses.
// This selector is assumed to be the same for all subscriptions that
// need DR protection. It will be passed in to the VRG when it is created
//+optional
// +kubebuilder:validation:Optional
// +kubebuilder:validation:XValidation:rule="self == oldSelf", message="volumeSnapshotClassSelector is immutable"
VolumeSnapshotClassSelector metav1.LabelSelector `json:"volumeSnapshotClassSelector,omitempty"`

// List of DRCluster resources that are governed by this policy
// +kubebuilder:validation:Required
// +kubebuilder:validation:XValidation:rule="self == oldSelf", message="drClusters is immutable"
DRClusters []string `json:"drClusters"`
}

Expand Down
73 changes: 0 additions & 73 deletions api/v1alpha1/drpolicy_webhook.go

This file was deleted.

20 changes: 19 additions & 1 deletion config/crd/bases/ramendr.openshift.io_drpolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ spec:
items:
type: string
type: array
x-kubernetes-validations:
- message: drClusters is immutable
rule: self == oldSelf
replicationClassSelector:
description: |-
Label selector to identify all the VolumeReplicationClasses.
Expand Down Expand Up @@ -92,14 +95,20 @@ spec:
type: object
type: object
x-kubernetes-map-type: atomic
x-kubernetes-validations:
- message: replicationClassSelector is immutable
rule: self == oldSelf
schedulingInterval:
description: |-
scheduling Interval for replicating Persistent Volume
data to a peer cluster. Interval is typically in the
form <num><m,h,d>. Here <num> is a number, 'm' means
minutes, 'h' means hours and 'd' stands for days.
pattern: ^\d+[mhd]$
pattern: ^(|\d+[mhd])$
type: string
x-kubernetes-validations:
- message: schedulingInterval is immutable
rule: self == oldSelf
volumeSnapshotClassSelector:
description: |-
Label selector to identify all the VolumeSnapshotClasses.
Expand Down Expand Up @@ -147,9 +156,18 @@ spec:
type: object
type: object
x-kubernetes-map-type: atomic
x-kubernetes-validations:
- message: volumeSnapshotClassSelector is immutable
rule: self == oldSelf
required:
- drClusters
- schedulingInterval
type: object
x-kubernetes-validations:
- message: replicationClassSelector is required once set
rule: '!has(oldSelf.replicationClassSelector) || has(self.replicationClassSelector)'
- message: volumeSnapshotClassSelector is required once set
rule: '!has(oldSelf.volumeSnapshotClassSelector) || has(self.volumeSnapshotClassSelector)'
status:
description: |-
DRPolicyStatus defines the observed state of DRPolicy
Expand Down
2 changes: 0 additions & 2 deletions config/crd/patches/webhook_in_drpolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ spec:
namespace: system
name: webhook-service
path: /convert
conversionReviewVersions:
- v1
2 changes: 0 additions & 2 deletions config/hub/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ resources:
patchesStrategicMerge:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
- ../../crd/patches/webhook_in_drpolicies.yaml
- ../../crd/patches/webhook_in_drplacementcontrols.yaml
- ../../crd/patches/webhook_in_drclusters.yaml
# +kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
- ../../crd/patches/cainjection_in_drpolicies.yaml
- ../../crd/patches/cainjection_in_drplacementcontrols.yaml
- ../../crd/patches/cainjection_in_drclusters.yaml
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
Expand Down
19 changes: 0 additions & 19 deletions config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,3 @@ webhooks:
resources:
- drplacementcontrols
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /validate-ramendr-openshift-io-v1alpha1-drpolicy
failurePolicy: Fail
name: vdrpolicy.kb.io
rules:
- apiGroups:
- ramendr.openshift.io
apiVersions:
- v1alpha1
operations:
- UPDATE
resources:
- drpolicies
sideEffects: None
5 changes: 4 additions & 1 deletion controllers/drpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ var _ = Describe("DrpolicyController", func() {
validationErrors.FailedPattern(
path.String(),
`body`,
`^\d+[mhd]$`,
`^(|\d+[mhd])$`,
value,
).Error(),
),
Expand Down Expand Up @@ -321,6 +321,9 @@ var _ = Describe("DrpolicyController", func() {
path,
"",
),
field.Invalid(nil, "null",
"some validation rules were not checked because the object was invalid; "+
"correct the existing errors to complete validation"),
},
)
}()
Expand Down
6 changes: 0 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,6 @@ func setupReconcilersHub(mgr ctrl.Manager) {
os.Exit(1)
}

// setup webhook for DRPolicy
if err := (&ramendrv1alpha1.DRPolicy{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "DRPolicy")
os.Exit(1)
}

// setup webhook for drpc
if err := (&ramendrv1alpha1.DRPlacementControl{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "DRPlacementControl")
Expand Down

0 comments on commit 1504dcf

Please sign in to comment.