update search proposal
Signed-off-by: carlory <baofa.fan@daocloud.io>
This commit is contained in:
parent
ae56e41822
commit
bf6789ee01
|
@ -47,82 +47,58 @@ Goals:
|
||||||
|
|
||||||
### Define the scope of the cached resource
|
### Define the scope of the cached resource
|
||||||
|
|
||||||
#### New ClusterCache API
|
#### New Search APIGroup
|
||||||
|
|
||||||
|
We propose a new commponent named `karmada-search`, it provides a new api group called `search.karmada.io`, the reason why select the `search` word is because it's more to [OpenSearch](https://opensearch.org) which is a community-driven, Apache 2.0-licensed open source search and analytics suite.
|
||||||
|
|
||||||
|
The `karmada-search` component currently supports two types of backend stores, namely `cache` and `opensearch`. It uses the `cache` type as the default backend store of the caching layer for Karamda.
|
||||||
|
|
||||||
|
We introduce a new resource type called `ResourceRegistry` in `search.karmada.io` group, it requires end users to manually specify the clusters and resources that need to be cached
|
||||||
|
|
||||||
We propose a new CR in `cluster.karmada.io` group.
|
|
||||||
|
|
||||||
```golang
|
```golang
|
||||||
|
|
||||||
package v1alpha1
|
package v1alpha1
|
||||||
|
|
||||||
import (
|
// +genclient
|
||||||
corev1 "k8s.io/api/core/v1"
|
// +genclient:nonNamespaced
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||||
)
|
|
||||||
|
|
||||||
|
// ResourceRegistry represents the configuration of the cache scope, mainly describes which resources in
|
||||||
//+kubebuilder:object:root=true
|
// which clusters should be cached.
|
||||||
//+kubebuilder:subresource:status
|
type ResourceRegistry struct {
|
||||||
|
|
||||||
// ClusterCache is the Schema for the cluster cache API
|
|
||||||
type ClusterCache struct {
|
|
||||||
metav1.TypeMeta `json:",inline"`
|
metav1.TypeMeta `json:",inline"`
|
||||||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||||
|
|
||||||
Spec ClusterCacheSpec `json:"spec,omitempty"`
|
// Spec represents the desired behavior of ResourceRegistry.
|
||||||
Status ClusterCacheStatus `json:"status,omitempty"`
|
Spec ResourceRegistrySpec `json:"spec,omitempty"`
|
||||||
|
|
||||||
|
// Status represents the status of ResourceRegistry.
|
||||||
|
// +optional
|
||||||
|
Status ResourceRegistryStatus `json:"status,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClusterCacheSpec defines the desired state of ClusterCache
|
// ResourceRegistrySpec defines the desired state of ResourceRegistry.
|
||||||
type ClusterCacheSpec struct {
|
type ResourceRegistrySpec struct {
|
||||||
// ClusterSelectors represents the filter to select clusters.
|
// TargetCluster specifies the clusters where the cache system collect resource from.
|
||||||
// +required
|
// +required
|
||||||
ClusterSelectors []ClusterSelector `json:"clusterSelectors"`
|
TargetCluster policyv1alpha1.ClusterAffinity `json:"targetCluster"`
|
||||||
|
|
||||||
// ResourceSelectors used to select resources.
|
// ResourceSelectors specifies the resources type that should be cached by cache system.
|
||||||
// +required
|
// +required
|
||||||
ResourceSelectors []ResourceSelector `json:"resourceSelectors"`
|
ResourceSelectors []ResourceSelector `json:"resourceSelectors"`
|
||||||
|
|
||||||
// StatusUpdatePeriodSeconds is the period to update the status of the resource.
|
// BackendStore specifies the location where to store the cached items.
|
||||||
// default is 10s.
|
|
||||||
// +optional
|
// +optional
|
||||||
StatusUpdatePeriodSeconds uint32 `json:"statusUpdatePeriodSeconds,omitempty"`
|
BackendStore *BackendStoreConfig `json:"backendStore,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClusterSelector represents the filter to select clusters.
|
// ResourceSelector specifies the resources type and its scope.
|
||||||
type ClusterSelector struct {
|
|
||||||
// LabelSelector is a filter to select member clusters by labels.
|
|
||||||
// If non-nil and non-empty, only the clusters match this filter will be selected.
|
|
||||||
// +optional
|
|
||||||
LabelSelector *metav1.LabelSelector `json:"labelSelector,omitempty"`
|
|
||||||
|
|
||||||
// FieldSelector is a filter to select member clusters by fields.
|
|
||||||
// If non-nil and non-empty, only the clusters match this filter will be selected.
|
|
||||||
// +optional
|
|
||||||
FieldSelector *FieldSelector `json:"fieldSelector,omitempty"`
|
|
||||||
|
|
||||||
// ClusterNames is the list of clusters to be selected.
|
|
||||||
// +optional
|
|
||||||
ClusterNames []string `json:"clusterNames,omitempty"`
|
|
||||||
|
|
||||||
// ExcludedClusters is the list of clusters to be ignored.
|
|
||||||
// +optional
|
|
||||||
ExcludeClusters []string `json:"exclude,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// FieldSelector is a field filter.
|
|
||||||
type FieldSelector struct {
|
|
||||||
// A list of field selector requirements.
|
|
||||||
MatchExpressions []corev1.NodeSelectorRequirement `json:"matchExpressions,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResourceSelector the resources will be selected.
|
|
||||||
type ResourceSelector struct {
|
type ResourceSelector struct {
|
||||||
// APIVersion represents the API version of the target resources.
|
// APIVersion represents the API version of the target resources.
|
||||||
// +required
|
// +required
|
||||||
APIVersion string `json:"apiVersion"`
|
APIVersion string `json:"apiVersion"`
|
||||||
|
|
||||||
// Kind represents the Kind of the target resources.
|
// Kind represents the kind of the target resources.
|
||||||
// +required
|
// +required
|
||||||
Kind string `json:"kind"`
|
Kind string `json:"kind"`
|
||||||
|
|
||||||
|
@ -132,101 +108,84 @@ type ResourceSelector struct {
|
||||||
Namespace string `json:"namespace,omitempty"`
|
Namespace string `json:"namespace,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClusterCacheStatus defines the observed state of ClusterCache
|
// BackendStoreConfig specifies backend store.
|
||||||
type ClusterCacheStatus struct {
|
type BackendStoreConfig struct {
|
||||||
|
// OpenSearch is a community-driven, open source search and analytics suite.
|
||||||
|
// Refer to website(https://opensearch.org/) for more details about OpenSearch.
|
||||||
// +optional
|
// +optional
|
||||||
Resources []ResourceStatusRef `json:"resources,omitempty"`
|
OpenSearch *OpenSearchConfig `json:"openSearch,omitempty"`
|
||||||
// +optional
|
|
||||||
StartTime *metav1.Time `json:"startTime,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResourceStatusRef struct {
|
// OpenSearchConfig holds the necessary configuration for client to access and config an OpenSearch server.
|
||||||
|
type OpenSearchConfig struct {
|
||||||
|
// Addresses is a list of node endpoint(e.g. 'https://localhost:9200') to use.
|
||||||
|
// For the 'node' concept, please refer to:
|
||||||
|
// https://opensearch.org/docs/latest/opensearch/index/#clusters-and-nodes
|
||||||
// +required
|
// +required
|
||||||
Cluster string `json:"cluster"`
|
Addresses []string `json:"addresses"`
|
||||||
// +optional
|
|
||||||
APIVersion string `json:"apiVersion,omitempty"`
|
// SecretRef represents the secret contains mandatory credentials to access the server.
|
||||||
|
// The secret should hold credentials as follows:
|
||||||
|
// - secret.data.userName
|
||||||
|
// - secret.data.password
|
||||||
// +required
|
// +required
|
||||||
Kind string `json:"kind"`
|
SecretRef clusterv1alpha1.LocalSecretReference `json:"secretRef,omitempty"`
|
||||||
// +optional
|
|
||||||
Namespace string `json:"namespace,omitempty"`
|
// More configurations such as transport, index should be added from here.
|
||||||
// +required
|
|
||||||
State CachePhase `json:"state"`
|
|
||||||
// +required
|
|
||||||
TotalNum int32 `json:"totalNum"`
|
|
||||||
// +required
|
|
||||||
UpdateTime *metav1.Time `json:"updateTime"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CachePhase is the current state of the cache
|
// ResourceRegistryStatus defines the observed state of ResourceRegistry
|
||||||
// +enum
|
type ResourceRegistryStatus struct {
|
||||||
type CachePhase string
|
// Conditions contain the different condition statuses.
|
||||||
|
|
||||||
// These are the valid statuses of cache.
|
|
||||||
const (
|
|
||||||
CacheRunning CachePhase = "Running"
|
|
||||||
CacheFailed CachePhase = "Failed"
|
|
||||||
CacheUnknown CachePhase = "Unknown"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ResourceStateRef struct {
|
|
||||||
// +required
|
|
||||||
Phase CachePhase `json:"phase"`
|
|
||||||
// +optional
|
// +optional
|
||||||
Reason string `json:"reason"`
|
Conditions []metav1.Condition `json:"conditions,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//+kubebuilder:object:root=true
|
// +kubebuilder:resource:scope="Cluster"
|
||||||
|
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||||
|
|
||||||
// ClusterCacheList contains a list of ClusterCache
|
// ResourceRegistryList if a collection of ResourceRegistry.
|
||||||
type ClusterCacheList struct {
|
type ResourceRegistryList struct {
|
||||||
metav1.TypeMeta `json:",inline"`
|
metav1.TypeMeta `json:",inline"`
|
||||||
metav1.ListMeta `json:"metadata,omitempty"`
|
metav1.ListMeta `json:"metadata,omitempty"`
|
||||||
Items []ClusterCache `json:"items"`
|
|
||||||
|
// Items holds a list of ResourceRegistry.
|
||||||
|
Items []ResourceRegistry `json:"items"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||||
SchemeBuilder.Register(&ClusterCache{}, &ClusterCacheList{})
|
|
||||||
|
// Search define a flag for resource search that do not have actual resources.
|
||||||
|
type Search struct {
|
||||||
|
metav1.TypeMeta `json:",inline"`
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
|
|
||||||
The following example shows how to create a ClusterCache CRD.
|
The following example shows how to create a ResourceRegistry CR.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
apiVersion: clustercaches.karmada.io/v1alpha1
|
apiVersion: search.karmada.io/v1alpha1
|
||||||
kind: ClusterCache
|
kind: ResourceRegistry
|
||||||
metadata:
|
metadata:
|
||||||
name: clustercache-sample
|
name: clustercache-sample
|
||||||
spec:
|
spec:
|
||||||
clusterSelectors:
|
targetCluster:
|
||||||
- clusterNames:
|
clusterNames:
|
||||||
- member1
|
- member1
|
||||||
- member2
|
- member2
|
||||||
- member3
|
- member3
|
||||||
resourceSelectors:
|
resourceSelectors:
|
||||||
- kind: Pod
|
- kind: Pod
|
||||||
|
apiVersion: v1
|
||||||
- kind: Ingress
|
- kind: Ingress
|
||||||
apiVersion: networking.k8s.io/v1
|
apiVersion: networking.k8s.io/v1
|
||||||
- kind: DaemonSet
|
- kind: DaemonSet
|
||||||
|
apiVersion: apps/v1
|
||||||
namespace: kube-system
|
namespace: kube-system
|
||||||
- kind: Deployment
|
- kind: Deployment
|
||||||
status:
|
apiVersion: apps/v1
|
||||||
startTime: "2020-05-01T00:00:00Z"
|
|
||||||
resources:
|
|
||||||
- cluster: member1
|
|
||||||
kind: Pod
|
|
||||||
totalNum: 700
|
|
||||||
state:
|
|
||||||
phase: Running
|
|
||||||
updateTime: "2022-01-01T00:00:00Z"
|
|
||||||
- cluster: member1
|
|
||||||
kind: Ingress
|
|
||||||
totalNum: 0
|
|
||||||
state:
|
|
||||||
phase: Failed
|
|
||||||
reason: the server doesn't have a resource type ingresses
|
|
||||||
updateTime: "2022-01-01T00:00:00Z"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Test Plan
|
### Test Plan
|
||||||
|
|
Loading…
Reference in New Issue