Skip to content

Commit

Permalink
Add kubebuilder validatoin rules to drivers.csi.ceph.io API
Browse files Browse the repository at this point in the history
Signed-off-by: nb-ohad <[email protected]>
  • Loading branch information
nb-ohad committed Jul 29, 2024
1 parent ef334af commit 9727975
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 62 deletions.
145 changes: 102 additions & 43 deletions api/v1alpha1/driver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,34 @@ const (

type LogRotationSpec struct {
// MaxFiles is the number of logrtoate files
// +optional
//+kubebuilder:validation:Optional
MaxFiles int `json:"maxFiles,omitempty"`

// MaxLogSize is the maximum size of the log file per csi pods
// +optional
//+kubebuilder:validation:Optional
MaxLogSize resource.Quantity `json:"maxLogSize,omitempty"`

// Periodicity is the periodicity of the log rotation.
// +kubebuilder:validation:Enum=hourly;daily;weekly;monthly
// +optional
//+kubebuilder:validation:Optional
//+kubebuilder:validation:Enum:=hourly;daily;weekly;monthly
Periodicity PeriodicityType `json:"periodicity,omitempty"`

// LogHostPath is the prefix directory path for the csi log files
// +optional
//+kubebuilder:validation:Optional
LogHostPath string `json:"logHostPath,omitempty"`
}

type LogSpec struct {
// Log level for driver pods,
// Supported values from 0 to 5. 0 for general useful logs (the default), 5 for trace level verbosity.
// Default to 0
//+kubebuilder:validation:Minimum=0
//+kubebuilder:validation:Maximum=5
//+kubebuilder:validation:Optional
LogLevel int `json:"logLevel,omitempty"`

// log rotation for csi pods
// +optional
//+kubebuilder:validation:Optional
Rotation *LogRotationSpec `json:"rotation,omitempty"`
}

Expand All @@ -81,46 +84,69 @@ const (
)

type EncryptionSpec struct {
//+kubebuilder:validation:Required
ConfigMapRef corev1.LocalObjectReference `json:"configMapName,omitempty"`
}

type VolumeSpec struct {
Volume corev1.Volume `json:"volume,omitempty"`
Mount corev1.VolumeMount `json:"mount,omitempty"`
//+kubebuilder:validation:Required
Volume corev1.Volume `json:"volume,omitempty"`

//+kubebuilder:validation:Required
Mount corev1.VolumeMount `json:"mount,omitempty"`
}

type PodCommonSpec struct {
// Service account name to be used for driver's pods
//+kubebuilder:validation:Optional
ServiceAccountName *string `json:"serviceAccountName,omitempty"`

// Pod's user defined priority class name
//+kubebuilder:validation:Optional
PrioritylClassName *string `json:"priorityClassName,omitempty"`

// Pod's labels
//+kubebuilder:validation:Optional
Labels map[string]string `json:"labels,omitempty"`

// Pod's annotations
//+kubebuilder:validation:Optional
Annotations map[string]string `json:"annotations,omitempty"`

// Pod's affinity settings
//+kubebuilder:validation:Optional
Affinity *corev1.Affinity `json:"affinity,omitempty"`

// Pod's tolerations list
//+kubebuilder:validation:Optional
//+kubebuilder:validation:minItems:=1
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`

// Volume and volume mount definitions to attach to the pod
//+kubebuilder:validation:Optional
//+kubebuilder:validation:minItems:=1
Volumes []VolumeSpec `json:"volumes,omitempty"`

// To indicate the image pull policy to be applied to all the containers in the csi driver pods.
//+kubebuilder:validation:Optional
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy"`
}

type NodePluginResourcesSpec struct {
Registrar *corev1.ResourceRequirements `json:"registrar,omitempty"`
Liveness *corev1.ResourceRequirements `json:"liveness,omitempty"`
Addons *corev1.ResourceRequirements `json:"addons,omitempty"`
//+kubebuilder:validation:Optional
Registrar *corev1.ResourceRequirements `json:"registrar,omitempty"`

//+kubebuilder:validation:Optional
Liveness *corev1.ResourceRequirements `json:"liveness,omitempty"`

//+kubebuilder:validation:Optional
Addons *corev1.ResourceRequirements `json:"addons,omitempty"`

//+kubebuilder:validation:Optional
LogRotator *corev1.ResourceRequirements `json:"logRotator,omitempty"`
Plugin *corev1.ResourceRequirements `json:"plugin,omitempty"`

//+kubebuilder:validation:Optional
Plugin *corev1.ResourceRequirements `json:"plugin,omitempty"`
}

type NodePluginSpec struct {
Expand All @@ -129,62 +155,96 @@ type NodePluginSpec struct {

// Driver's plugin daemonset update strategy, supported values are OnDelete and RollingUpdate.
// Default value is RollingUpdate with MaxAvailabile set to 1
//+kubebuilder:validation:Optional
UpdateStrategy *appsv1.DaemonSetUpdateStrategy `json:"updateStrategy,omitempty"`

// Resource requirements for plugin's containers
//+kubebuilder:validation:Optional
Resources NodePluginResourcesSpec `json:"resources,omitempty"`

// kubelet directory path, if kubelet configured to use other than /var/lib/kubelet path.
//+kubebuilder:validation:Optional
KubeletDirPath string `json:"kubeletDirPath,omitempty"`

// Control the host mount of /etc/selinux for csi plugin pods. Defaults to false
//+kubebuilder:validation:Optional
EnableSeLinuxHostMount *bool `json:"EnableSeLinuxHostMount,omitempty"`
}

type ControllerPluginResourcesSpec struct {
Attacher *corev1.ResourceRequirements `json:"attacher,omitempty"`
Snapshotter *corev1.ResourceRequirements `json:"snapshotter,omitempty"`
Resizer *corev1.ResourceRequirements `json:"resizer,omitempty"`
Provisioner *corev1.ResourceRequirements `json:"provisioner,omitempty"`
//+kubebuilder:validation:Optional
Attacher *corev1.ResourceRequirements `json:"attacher,omitempty"`

//+kubebuilder:validation:Optional
Snapshotter *corev1.ResourceRequirements `json:"snapshotter,omitempty"`

//+kubebuilder:validation:Optional
Resizer *corev1.ResourceRequirements `json:"resizer,omitempty"`

//+kubebuilder:validation:Optional
Provisioner *corev1.ResourceRequirements `json:"provisioner,omitempty"`

//+kubebuilder:validation:Optional
OMapGenerator *corev1.ResourceRequirements `json:"omapGenerator,omitempty"`
Liveness *corev1.ResourceRequirements `json:"liveness,omitempty"`
Addons *corev1.ResourceRequirements `json:"addons,omitempty"`
LogRotator *corev1.ResourceRequirements `json:"logRotator,omitempty"`
Plugin *corev1.ResourceRequirements `json:"plugin,omitempty"`

//+kubebuilder:validation:Optional
Liveness *corev1.ResourceRequirements `json:"liveness,omitempty"`

//+kubebuilder:validation:Optional
Addons *corev1.ResourceRequirements `json:"addons,omitempty"`

//+kubebuilder:validation:Optional
LogRotator *corev1.ResourceRequirements `json:"logRotator,omitempty"`

//+kubebuilder:validation:Optional
Plugin *corev1.ResourceRequirements `json:"plugin,omitempty"`
}

type ControllerPluginSpec struct {
// Embedded common pods spec
PodCommonSpec `json:"inline"`

// Set replicas for controller plugin's deployment. Defaults to 2
//+kubebuilder:validation:Optional
//+kubebuilder:validation:Minimum:=1
Replicas *int32 `json:"replicas,omitempty"`

// Resource requirements for controller plugin's containers
//+kubebuilder:validation:Optional
Resources ControllerPluginResourcesSpec `json:"resources,omitempty"`

// To enable logrotation for csi pods,
// Some platforms require controller plugin to run privileged,
// For example, OpenShift with SELinux restrictions requires the pod to be privileged to write to hostPath.
Privileged bool `json:"privileged,omitempty"`
//+kubebuilder:validation:Optional
Privileged *bool `json:"privileged,omitempty"`
}

type LivenessSpec struct {
// Port to expose liveness metrics
//+kubebuilder:validation:Required
//+kubebuilder:validation:Minimum:=1024
//+kubebuilder:validation:Maximum:=65535
MetricsPort int `json:"metricsPort,omitempty"`
}

type LeaderElectionSpec struct {
// Duration in seconds that non-leader candidates will wait to force acquire leadership.
// Default to 137 seconds.
//+kubebuilder:validation:Optional
//+kubebuilder:validation:Minimum:=0
LeaseDuration int `json:"leaseDuration,omitempty"`

// Deadline in seconds that the acting leader will retry refreshing leadership before giving up.
// Defaults to 107 seconds.
//+kubebuilder:validation:Optional
//+kubebuilder:validation:Minimum:=0
RenewDeadline int `json:"renewDeadline,omitempty"`

// Retry Period in seconds the LeaderElector clients should wait between tries of actions.
// Defaults to 26 seconds.
//+kubebuilder:validation:Optional
//+kubebuilder:validation:Minimum:=0
RetryPeriod int `json:"retryPeriod,omitempty"`
}

Expand All @@ -201,44 +261,57 @@ const (
// DriverSpec defines the desired state of Driver
type DriverSpec struct {
// Logging configuration for driver's pods
//+kubebuilder:validation:Optional
Log *LogSpec `json:"log,omitempty"`

// A reference to a ConfigMap resource holding image overwrite for deployed
// containers
//+kubebuilder:validation:Optional
ImageSet *corev1.LocalObjectReference `json:"imageSet,omitempty"`

// Cluster name identifier to set as metadata on the CephFS subvolume and RBD images. This will be useful in cases
// when two container orchestrator clusters (Kubernetes/OCP) are using a single ceph cluster.
//+kubebuilder:validation:Optional
ClusterName *string `json:"clusterName,omitempty"`

// Set to true to enable adding volume metadata on the CephFS subvolumes and RBD images.
// Not all users might be interested in getting volume/snapshot details as metadata on CephFS subvolume and RBD images.
// Hence enable metadata is false by default.
//+kubebuilder:validation:Optional
EnableMetadata *bool `json:"enableMetadata,omitempty"`

// Set the gRPC timeout for gRPC call issued by the driver components
//+kubebuilder:validation:Optional
//+kubebuilder:validation:Minimum:=0
GRpcTimeout int `json:"grpcTimeout,omitempty"`

// Select a policy for snapshot behavior: none, autodetect, snapshot, sanpshotGroup
//+kubebuilder:validation:Optional
//+kubebuilder:validation:Enum:=none|autodetect|volumegroupsnapshot|volumesnapshot
SnapshotPolicy SnapshotPolicyType `json:"snapshotPolicy,omitempty"`

// OMAP generator will generate the omap mapping between the PV name and the RBD image.
// Need to be enabled when we are using rbd mirroring feature.
// By default OMAP generator sidecar is deployed with Csi controller plugin pod, to disable
// it set it to false.
//+kubebuilder:validation:Optional
GenerateOMapInfo *bool `json:"generateOMapInfo,omitempty"`

// Policy for modifying a volume's ownership or permissions when the PVC is being mounted.
// supported values are documented at https://kubernetes-csi.github.io/docs/support-fsgroup.html
//+kubebuilder:validation:Optional
FsGroupPolicy storagev1.FSGroupPolicy `json:"fsGroupPolicy,omitempty"`

// Driver's encryption settings
//+kubebuilder:validation:Optional
Encryption *EncryptionSpec `json:"encryption,omitempty"`

// Driver's plugin configuration
//+kubebuilder:validation:Optional
NodePlugin *NodePluginSpec `json:"nodePlugin,omitempty"`

// Driver's controller plugin configuration
//+kubebuilder:validation:Optional
ControllerPlugin *ControllerPluginSpec `json:"controllerPlugin,omitempty"`

// Whether to skip any attach operation altogether for CephCsi PVCs.
Expand All @@ -248,57 +321,43 @@ type DriverSpec struct {
// csi-addons operations like Reclaimspace and PVC Keyrotation will also not be supported if set to false
// since we'll have no VolumeAttachments to determine which node the PVC is mounted on.
// Refer to this [issue](https://github.com/kubernetes/kubernetes/issues/103305) for more details.
//+kubebuilder:validation:Optional
AttachRequired *bool `json:"attachRequired,omitempty"`

// Liveness metrics configuration.
// disabled by default.
//+kubebuilder:validation:Optional
Liveness *LivenessSpec `json:"liveness,omitempty"`

// Leader election setting
//+kubebuilder:validation:Optional
LeaderElection *LeaderElectionSpec `json:"leaderElection,omitempty"`

// TODO: do we want Csi addon specific field? or should we generalize to
// a list of additional sidecars?
//+kubebuilder:validation:Optional
DeployCsiAddons *bool `json:"deployCsiAddons,omitempty"`

// Select between between cephfs kernel driver and ceph-fuse
// If you select a non-kernel client, your application may be disrupted during upgrade.
// See the upgrade guide: https://rook.io/docs/rook/latest/ceph-upgrade.html
// NOTE! cephfs quota is not supported in kernel version < 4.17
//+kubebuilder:validation:Optional
//+kubebuilder:validation:Enum:=autodetect;kernel
CephFsClientType CephFsClientType `json:"cephFsClientType,omitempty"`

// Set mount options to use https://docs.ceph.com/en/latest/man/8/mount.ceph/#options
// Set to "ms_mode=secure" when connections.encrypted is enabled in Ceph
//+kubebuilder:validation:Optional
KernelMountOptions map[string]string `json:"kernelMountOptions,omitempty"`

// Set mount options to use when using the Fuse client
//+kubebuilder:validation:Optional
FuseMountOptions map[string]string `json:"fuseMountOptions,omitempty"`
}

type DriverPhaseType string

const (
ReadyDriverPhase DriverPhaseType = "Ready"
)

type DriverReasonType string

// TODO: Add failure reason codes
const ()

// DriverStatus defines the observed state of Driver
type DriverStatus struct {
// TODO: Consider to move away from a single phase to a conditions based approach
// or the a Ready list approach. Main reason this reconciler address multiple

// The last known state of the latest reconcile
Phase DriverPhaseType `json:"phase,omitempty"`

// The reason for the last transition change.
Reason DriverReasonType `json:"reason,omitempty"`

// A human readable message indicating details about the last transition.
Message string `json:"message,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit 9727975

Please sign in to comment.