Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: init CacheRuntime and CacheRuntimeClass api #4478

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
84 changes: 84 additions & 0 deletions api/v1alpha1/cacheruntime_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
Copyright 2020 The Fluid Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// CacheRuntimeStatus defines the observed state of CacheRuntime
type CacheRuntimeStatus struct {
// ValueFileConfigmap used to set helm chart values configurations
ValueFileConfigmap string `json:"valueFile"`

// ConfigFileConfigmap used to set cacheruntime configurations
ConfigFileConfigmap string `json:"configFile"`

// SetupDuration tell user how much time was spent to setup the runtime
SetupDuration string `json:"setupDuration,omitempty"`

// Represents the latest available observations of a ddc runtime's current state.
// +patchMergeKey=type
// +patchStrategy=merge
Conditions []RuntimeCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`

// CacheStatus represents the total resources of the dataset.
// TODO: support by cacheManager
// CacheStates common.CacheStateList `json:"cacheStates,omitempty"`

// Selector is used for auto-scaling
Selector string `json:"selector,omitempty"` // this must be the string form of the selector

// CacheAffinity represents the runtime worker pods node affinity including node selector
CacheAffinity *corev1.NodeAffinity `json:"cacheAffinity,omitempty"`

// ComponentsStatus is a map of RuntimeComponent and its status
ComponentsStatus []RuntimeComponentStatus `json:"componentsStatus,omitempty"`

// MountPointsStatuses represents the mount points specified in the bounded dataset
MountPointsStatuses []MountPointStatus `json:"mountPointsStatus,omitempty"`
}

type MountPointStatus struct {
// MountPoints represents the mount points specified in the bounded dataset
Mount `json:"mount,omitempty"`

// MountTime represents time last mount happened
// if MountTime is earlier than master starting time, remount will be required
MountTime *metav1.Time `json:"mountTime,omitempty"`
}

type RuntimeComponentStatus struct {
// Phase is the running phase of component
Phase RuntimePhase `json:"phase"`

// Reason for component's condition transition
Reason string `json:"reason,omitempty"`

// The total number of nodes that should be running the runtime
// pod (including nodes correctly running the runtime master pod).
DesiredScheduledReplicas int32 `json:"desiredScheduledReplicas"`

// The total number of nodes that should be running the runtime
// pod (including nodes correctly running the runtime master pod).
CurrentScheduledReplicas int32 `json:"currentScheduledReplicas"`

// The number of nodes that should be running the runtime worker pod and have zero
// or more of the runtime master pod running and ready.
ReadyReplicas int32 `json:"readyReplicas"`
}
235 changes: 235 additions & 0 deletions api/v1alpha1/cacheruntime_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
/*
Copyright 2020 The Fluid Author.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// +groupName=data
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Namespaced

// CacheRuntimeList contains a list of CacheRuntime
type CacheRuntimeList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []CacheRuntime `json:"items"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.runtimeComponentStatuses.worker.currentScheduledReplicas
// +kubebuilder:printcolumn:name="Ready Masters",type="integer",JSONPath=`.status.runtimeComponentStatuses.master.readyReplicas`,priority=10
// +kubebuilder:printcolumn:name="Desired Masters",type="integer",JSONPath=`.status.runtimeComponentStatuses.master.desiredScheduledReplicas`,priority=10
// +kubebuilder:printcolumn:name="Master Phase",type="string",JSONPath=`.status.runtimeComponentStatuses.master.phase`,priority=0
// +kubebuilder:printcolumn:name="Ready Workers",type="integer",JSONPath=`.status.runtimeComponentStatuses.worker.readyReplicas`,priority=10
// +kubebuilder:printcolumn:name="Desired Workers",type="integer",JSONPath=`.status.runtimeComponentStatuses.worker.desiredScheduledReplicas`,priority=10
// +kubebuilder:printcolumn:name="Worker Phase",type="string",JSONPath=`.status.runtimeComponentStatuses.worker.phase`,priority=0
// +kubebuilder:printcolumn:name="Ready Clients",type="integer",JSONPath=`.status.runtimeComponentStatuses.client.readyReplicas`,priority=10
// +kubebuilder:printcolumn:name="Desired Clients",type="integer",JSONPath=`.status.runtimeComponentStatuses.client.desiredScheduledReplica`,priority=10
// +kubebuilder:printcolumn:name="Client Phase",type="string",JSONPath=`.status.runtimeComponentStatuses.client.phase`,priority=0
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=`.metadata.creationTimestamp`,priority=0
// +kubebuilder:resource:scope=Namespaced
// +kubebuilder:resource:categories={fluid},shortName=Cache
// +genclient

// CacheRuntime is the Schema for the CacheRuntimes API
type CacheRuntime struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec CacheRuntimeSpec `json:"spec,omitempty"`
Status CacheRuntimeStatus `json:"status,omitempty"`
}

// CacheRuntimeSpec defines the desired state of CacheRuntime
type CacheRuntimeSpec struct {
// RuntimeClassName is the name of the RuntimeClass required by the cacheRuntime.
RuntimeClassName string `json:"runtimeClassName,omitempty"`

// The component spec of master
// +optional
Master CacheRuntimeMasterSpec `json:"master,omitempty"`

// The component spec of worker
// +optional
Worker CacheRuntimeWorkerSpec `json:"worker,omitempty"`

// The component spec of worker group
// +optional
WorkerGroup []CacheRuntimeWorkerSpec `json:"workerGroup,omitempty"`

// The component spec of client
// +optional
Client CacheRuntimeClientSpec `json:"client,omitempty"`

// PodMetadata defines labels and annotations that will be propagated to the all components' pods
// +optional
PodMetadata PodMetadata `json:"podMetadata,omitempty"`

// Options defines the configurable options for Cache system.
// +optional
Options map[string]string `json:"options,omitempty"`

// Volumes is the list of Kubernetes volumes that can be mounted by the cache runtime components.
// +optional
Volumes []corev1.Volume `json:"volumes,omitempty"`

// NetworkMode indicates whether to use ContainerNetwork or not
// +kubebuilder:validation:Enum=HostNetwork;"";ContainerNetwork
// +kubebuilder:default=ContainerNetwork
// +optional
NetworkMode NetworkMode `json:"networkMode,omitempty"`

// RuntimeManagement defines policies when managing the runtime
// +optional
RuntimeManagement RuntimeManagement `json:"runtimeManagement,omitempty"`
}

// CacheRuntimeMasterSpec is a description of the CacheRuntime master component
type CacheRuntimeMasterSpec struct {
CacheRuntimeComponentCommonSpec `json:",inline"`

// Replicas is the desired number of replicas of the component.
// If unspecified, defaults to 1.
// +kubebuilder:validation:Minimum=0
// +kubebuilder:default=1
// +optional
Replicas int32 `json:"replicas,omitempty"`
}

// CacheRuntimeWorkerSpec is a description of the CacheRuntime worker component
type CacheRuntimeWorkerSpec struct {
CacheRuntimeComponentCommonSpec `json:",inline"`

// Replicas is the desired number of replicas of the given template.
// If unspecified, defaults to 1.
// +kubebuilder:validation:Minimum=0
// +kubebuilder:default=1
// +optional
Replicas int32 `json:"replicas,omitempty"`

// Tiered storage used by worker
// +optional
TieredStore TieredStore `json:"tieredStore,omitempty"`
}

// CacheRuntimeClientSpec is a description of the CacheRuntime client component
type CacheRuntimeClientSpec struct {
CacheRuntimeComponentCommonSpec `json:",inline"`

// CleanPolicy decides when to clean CacheFS Fuse pods.
// Currently Fluid supports two policies: OnDemand and OnRuntimeDeleted
// OnDemand cleans fuse pod once th fuse pod on some node is not needed
// OnRuntimeDeleted cleans fuse pod only when the cache runtime is deleted
// Defaults to OnRuntimeDeleted
// +kubebuilder:validation:Enum=OnRuntimeDeleted;"";OnDemand
// +kubebuilder:default=OnRuntimeDeleted
// +optional
CleanPolicy FuseCleanPolicy `json:"cleanPolicy,omitempty"`
}

// CacheRuntimeComponentCommonSpec is a common description of the CacheRuntime component
type CacheRuntimeComponentCommonSpec struct {
// If disable CacheRuntime component
// +optional
Disabled bool `json:"disabled,omitempty"`

// WorkloadType is the type of workload, a default workload type is defined in the CacheRuntimeClass
// +optional
WorkloadType metav1.TypeMeta `json:"workloadType,omitempty"`

// The version information that instructs fluid to orchestrate a particular version.
// +optional
RuntimeVersion VersionSpec `json:"runtimeVersion,omitempty"`

// Options is configurable options for Cache System.
// +optional
Options map[string]string `json:"options,omitempty"`

// PodMetadata defines labels and annotations that will be propagated to all CacheRuntime components' pods
// +optional
PodMetadata PodMetadata `json:"podMetadata,omitempty"`

// Resources that will be requested by the CacheRuntime component.
// +optional
Resources corev1.ResourceRequirements `json:"resources,omitempty"`

// Environment variables that will be used by CacheRuntime component.
// +optional
Env map[string]string `json:"env,omitempty"`

// VolumeMounts specifies the volumes listed in ".spec.volumes" to mount into the CacheRuntime component's filesystem.
// +optional
VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"`

// Arguments to the entrypoint.
// +optional
// +listType=atomic
Args []string `json:"args,omitempty"`

// If specified, the pod will be dispatched by specified scheduler.
// If not specified, the pod will be dispatched by default scheduler.
// +optional
SchedulerName string `json:"schedulerName,omitempty"`

// NodeSelector is a selector which must be true for the component pods to fit on a node
// +optional
NodeSelector map[string]string `json:"nodeSelector,omitempty"`

// If specified, the pod's tolerations.
// +optional
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`

// NetworkMode indicates whether to use ContainerNetwork or not
// +kubebuilder:validation:Enum=HostNetwork;"";ContainerNetwork
// +kubebuilder:default=ContainerNetwork
// +optional
NetworkMode NetworkMode `json:"networkMode,omitempty"`

// Advanced config of pod's containers
// +optional
AdvancedContainerConfigs CacheRuntimeComponentAdvancedContainerConfigs `json:"advancedContainerConfigs,omitempty"`
}

type CacheRuntimeComponentAdvancedContainerConfigs struct {
AdvancedContainerConfigs map[string]AdvancedContainerConfig `json:"containerConfigs,omitempty"`
}

type AdvancedContainerConfig struct {
// The version information that instructs fluid to orchestrate a particular version of CacheRuntime Component.
// +optional
RuntimeVersion VersionSpec `json:"runtimeVersion,omitempty"`

// Resources that will be requested by the Cache component. <br>
// +optional
Resources corev1.ResourceRequirements `json:"resources,omitempty"`

// Environment variables that will be used by Cache component. <br>
// +optional
Env map[string]string `json:"env,omitempty"`

// VolumeMounts specifies the volumes listed in ".spec.volumes" to mount into the CacheRuntime component's filesystem.
// +optional
VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"`
}

func init() {
SchemeBuilder.Register(&CacheRuntime{}, &CacheRuntimeList{})
}
Loading