Skip to content

Commit

Permalink
feat: restrict UIPlugin CRD names to allow a single instance per type (
Browse files Browse the repository at this point in the history
  • Loading branch information
jgbernalp authored Jun 25, 2024
1 parent 351ead5 commit 62c1920
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bundle/manifests/observability.openshift.io_uiplugins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,16 @@ spec:
- conditions
type: object
type: object
x-kubernetes-validations:
- message: UIPlugin name must be 'logging' if type is Logging
rule: self.spec.type != 'Logging' || self.metadata.name == 'logging'
- message: UIPlugin name must be 'troubleshooting-panel' if type is TroubleshootingPanel
rule: self.spec.type != 'TroubleshootingPanel' || self.metadata.name ==
'troubleshooting-panel'
- message: UIPlugin name must be 'distributed-tracing' if type is DistributedTracing
rule: self.spec.type != 'DistributedTracing' || self.metadata.name == 'distributed-tracing'
- message: UIPlugin name must be 'dashboards' if type is Dashboards
rule: self.spec.type != 'Dashboards' || self.metadata.name == 'dashboards'
served: true
storage: true
subresources:
Expand Down
10 changes: 10 additions & 0 deletions deploy/crds/common/observability.openshift.io_uiplugins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,16 @@ spec:
- conditions
type: object
type: object
x-kubernetes-validations:
- message: UIPlugin name must be 'logging' if type is Logging
rule: self.spec.type != 'Logging' || self.metadata.name == 'logging'
- message: UIPlugin name must be 'troubleshooting-panel' if type is TroubleshootingPanel
rule: self.spec.type != 'TroubleshootingPanel' || self.metadata.name ==
'troubleshooting-panel'
- message: UIPlugin name must be 'distributed-tracing' if type is DistributedTracing
rule: self.spec.type != 'DistributedTracing' || self.metadata.name == 'distributed-tracing'
- message: UIPlugin name must be 'dashboards' if type is Dashboards
rule: self.spec.type != 'Dashboards' || self.metadata.name == 'dashboards'
served: true
storage: true
subresources:
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/uiplugin/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import (
// +k8s:openapi-gen=true
// +kubebuilder:resource:scope=Cluster
// +kubebuilder:subresource:status
// +kubebuilder:validation:XValidation:rule="self.spec.type != 'Logging' || self.metadata.name == 'logging'",message="UIPlugin name must be 'logging' if type is Logging"
// +kubebuilder:validation:XValidation:rule="self.spec.type != 'TroubleshootingPanel' || self.metadata.name == 'troubleshooting-panel'",message="UIPlugin name must be 'troubleshooting-panel' if type is TroubleshootingPanel"
// +kubebuilder:validation:XValidation:rule="self.spec.type != 'DistributedTracing' || self.metadata.name == 'distributed-tracing'",message="UIPlugin name must be 'distributed-tracing' if type is DistributedTracing"
// +kubebuilder:validation:XValidation:rule="self.spec.type != 'Dashboards' || self.metadata.name == 'dashboards'",message="UIPlugin name must be 'dashboards' if type is Dashboards"
type UIPlugin struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down

0 comments on commit 62c1920

Please sign in to comment.