diff --git a/cmd/api/app/router/middleware.go b/cmd/api/app/router/middleware.go index 0259601a..0fa31c7c 100644 --- a/cmd/api/app/router/middleware.go +++ b/cmd/api/app/router/middleware.go @@ -25,6 +25,7 @@ import ( "net/http" ) +// EnsureMemberClusterMiddleware ensures that the member cluster exists. func EnsureMemberClusterMiddleware() gin.HandlerFunc { return func(c *gin.Context) { karmadaClient := client.InClusterKarmadaClient() diff --git a/cmd/api/app/router/setup.go b/cmd/api/app/router/setup.go index ee1a6863..b3a8db70 100644 --- a/cmd/api/app/router/setup.go +++ b/cmd/api/app/router/setup.go @@ -46,14 +46,17 @@ func init() { }) } +// V1 returns the router group for API version 1 endpoints. func V1() *gin.RouterGroup { return v1 } +// Router returns the main Gin engine instance. func Router() *gin.Engine { return router } +// MemberV1 returns the router group for member cluster specific endpoints. func MemberV1() *gin.RouterGroup { return member } diff --git a/cmd/api/app/routes/cluster/accesscluster.go b/cmd/api/app/routes/cluster/accesscluster.go index c7c89f4c..ddc5892f 100644 --- a/cmd/api/app/routes/cluster/accesscluster.go +++ b/cmd/api/app/routes/cluster/accesscluster.go @@ -41,9 +41,11 @@ const ( // KarmadaAgentServiceAccountName is the name of karmada-agent serviceaccount KarmadaAgentServiceAccountName = "karmada-agent-sa" // KarmadaAgentName is the name of karmada-agent - KarmadaAgentName = "karmada-agent" + KarmadaAgentName = "karmada-agent" + // KarmadaAgentImage is the image of karmada-agent KarmadaAgentImage = "karmada/karmada-agent:latest" - ClusterNamespace = "karmada-cluster" + // ClusterNamespace is the namespace of cluster + ClusterNamespace = "karmada-cluster" ) var ( @@ -52,6 +54,7 @@ var ( timeout = 5 * time.Minute ) +// PullModeOption is the option for pull mode type PullModeOption struct { karmadaClient karmadaclientset.Interface karmadaAgentCfg *clientcmdapi.Config @@ -236,6 +239,7 @@ func (o PullModeOption) makeKarmadaAgentDeployment() *appsv1.Deployment { return karmadaAgent } +// AccessClusterInPullMode access cluster in pull mode func AccessClusterInPullMode(opts *PullModeOption) error { _, exist, err := karmadautil.GetClusterWithKarmadaClient(opts.karmadaClient, opts.memberClusterName) if err != nil { @@ -268,6 +272,7 @@ func AccessClusterInPullMode(opts *PullModeOption) error { return nil } +// PushModeOption is the option for push mode type PushModeOption struct { karmadaClient karmadaclientset.Interface clusterName string @@ -275,6 +280,7 @@ type PushModeOption struct { memberClusterRestConfig *rest.Config } +// AccessClusterInPushMode access cluster in push mode func AccessClusterInPushMode(opts *PushModeOption) error { registerOption := karmadautil.ClusterRegisterOption{ ClusterNamespace: ClusterNamespace, diff --git a/cmd/api/app/routes/config/handler.go b/cmd/api/app/routes/config/handler.go index ac8e9c9c..b44e7306 100644 --- a/cmd/api/app/routes/config/handler.go +++ b/cmd/api/app/routes/config/handler.go @@ -26,11 +26,13 @@ import ( "k8s.io/klog/v2" ) +// GetDashboardConfig handles the request to retrieve the dashboard configuration. func GetDashboardConfig(c *gin.Context) { dashboardConfig := config.GetDashboardConfig() common.Success(c, dashboardConfig) } +// SetDashboardConfig handles the request to update the dashboard configuration. func SetDashboardConfig(c *gin.Context) { setDashboardConfigRequest := new(v1.SetDashboardConfigRequest) if err := c.ShouldBind(setDashboardConfigRequest); err != nil { diff --git a/cmd/api/app/routes/overview/misc.go b/cmd/api/app/routes/overview/misc.go index 19b1fdc4..bd8c2346 100644 --- a/cmd/api/app/routes/overview/misc.go +++ b/cmd/api/app/routes/overview/misc.go @@ -40,6 +40,7 @@ const ( app = "karmada-controller-manager" ) +// GetControllerManagerVersionInfo returns the version info of karmada-controller-manager. func GetControllerManagerVersionInfo() (*version.Info, error) { kubeClient := client.InClusterClient() restConfig, _, err := client.GetKubeConfig() @@ -90,6 +91,7 @@ func GetControllerManagerVersionInfo() (*version.Info, error) { return parseVersion, nil } +// ParseVersion parses the version string to version.Info. func ParseVersion(versionStr string) *version.Info { versionInfo := &version.Info{} leftBraceIdx := strings.IndexByte(versionStr, '{') @@ -127,6 +129,7 @@ func ParseVersion(versionStr string) *version.Info { return versionInfo } +// GetControllerManagerInfo returns the version info of karmada-controller-manager. func GetControllerManagerInfo() (*v1.KarmadaInfo, error) { versionInfo, err := GetControllerManagerVersionInfo() if err != nil { @@ -153,6 +156,7 @@ func GetControllerManagerInfo() (*v1.KarmadaInfo, error) { return karmadaInfo, nil } +// GetMemberClusterInfo returns the status of member clusters. func GetMemberClusterInfo(ds *dataselect.DataSelectQuery) (*v1.MemberClusterStatus, error) { karmadaClient := client.InClusterKarmadaClient() result, err := cluster.GetClusterList(karmadaClient, ds) @@ -185,6 +189,7 @@ func GetMemberClusterInfo(ds *dataselect.DataSelectQuery) (*v1.MemberClusterStat return memberClusterStatus, nil } +// GetClusterResourceStatus returns the status of cluster resources. func GetClusterResourceStatus() (*v1.ClusterResourceStatus, error) { clusterResourceStatus := &v1.ClusterResourceStatus{} ctx := context.TODO() diff --git a/cmd/api/app/types/api/v1/auth.go b/cmd/api/app/types/api/v1/auth.go index 6894e5cb..b556ce9d 100644 --- a/cmd/api/app/types/api/v1/auth.go +++ b/cmd/api/app/types/api/v1/auth.go @@ -16,19 +16,23 @@ limitations under the License. package v1 +// LoginRequest is the request for login. type LoginRequest struct { Token string `json:"token"` } +// LoginResponse is the response for login. type LoginResponse struct { Token string `json:"token"` } +// User is the user info. type User struct { Name string `json:"name,omitempty"` Authenticated bool `json:"authenticated"` } +// ServiceAccount is the service account info. type ServiceAccount struct { Name string `json:"name"` UID string `json:"uid"` diff --git a/cmd/api/app/types/api/v1/cluster.go b/cmd/api/app/types/api/v1/cluster.go index 0aadb5ba..8506e0b8 100644 --- a/cmd/api/app/types/api/v1/cluster.go +++ b/cmd/api/app/types/api/v1/cluster.go @@ -21,6 +21,7 @@ import ( corev1 "k8s.io/api/core/v1" ) +// PostClusterRequest is the request body for creating a cluster. type PostClusterRequest struct { MemberClusterKubeConfig string `json:"memberClusterKubeconfig" binding:"required"` SyncMode v1alpha1.ClusterSyncMode `json:"syncMode" binding:"required"` @@ -32,26 +33,37 @@ type PostClusterRequest struct { ClusterZones []string `json:"clusterZones"` } +// PostClusterResponse is the response body for creating a cluster. type PostClusterResponse struct { } +// LabelRequest is the request body for labeling a cluster. type LableRequest struct { Key string `json:"key"` Value string `json:"value"` } + +// TaintRequest is the request body for tainting a cluster. type TaintRequest struct { Effect corev1.TaintEffect `json:"effect"` Key string `json:"key"` Value string `json:"value"` } + +// PutClusterRequest is the request body for updating a cluster. type PutClusterRequest struct { Labels *[]LableRequest `json:"labels"` Taints *[]TaintRequest `json:"taints"` } + +// PutClusterResponse is the response body for updating a cluster. type PutClusterResponse struct{} +// DeleteClusterRequest is the request body for deleting a cluster. type DeleteClusterRequest struct { MemberClusterName string `uri:"name" binding:"required"` } + +// DeleteClusterResponse is the response body for deleting a cluster. type DeleteClusterResponse struct { } diff --git a/cmd/api/app/types/api/v1/deployment.go b/cmd/api/app/types/api/v1/deployment.go index acefb18f..55ba8ccf 100644 --- a/cmd/api/app/types/api/v1/deployment.go +++ b/cmd/api/app/types/api/v1/deployment.go @@ -16,9 +16,12 @@ limitations under the License. package v1 +// CreateDeploymentRequest defines the request structure for creating a deployment. type CreateDeploymentRequest struct { Namespace string `json:"namespace"` Name string `json:"name"` Content string `json:"content"` } + +// CreateDeploymentResponse defines the response structure for creating a deployment. type CreateDeploymentResponse struct{} diff --git a/cmd/api/app/types/api/v1/namespace.go b/cmd/api/app/types/api/v1/namespace.go index 6bd0c98a..557b82b9 100644 --- a/cmd/api/app/types/api/v1/namespace.go +++ b/cmd/api/app/types/api/v1/namespace.go @@ -16,8 +16,11 @@ limitations under the License. package v1 +// CreateNamesapceRequest is the request body for creating a namespace. type CreateNamesapceRequest struct { Name string `json:"name" required:"true"` SkipAutoPropagation bool `json:"skipAutoPropagation"` } + +// CreateNamesapceResponse is the response body for creating a namespace. type CreateNamesapceResponse struct{} diff --git a/cmd/api/app/types/api/v1/overridepolicy.go b/cmd/api/app/types/api/v1/overridepolicy.go index 39753bbd..b1a86cf4 100644 --- a/cmd/api/app/types/api/v1/overridepolicy.go +++ b/cmd/api/app/types/api/v1/overridepolicy.go @@ -16,15 +16,18 @@ limitations under the License. package v1 +// PostOverridePolicyRequest is the request body for creating an override policy. type PostOverridePolicyRequest struct { OverrideData string `json:"overrideData" binding:"required"` IsClusterScope bool `json:"isClusterScope"` Namespace string `json:"namespace"` } +// PostOverridePolicyResponse is the response body for creating an override policy. type PostOverridePolicyResponse struct { } +// PutOverridePolicyRequest is the request body for updating an override policy. type PutOverridePolicyRequest struct { OverrideData string `json:"overrideData" binding:"required"` IsClusterScope bool `json:"isClusterScope"` @@ -32,14 +35,17 @@ type PutOverridePolicyRequest struct { Name string `json:"name" binding:"required"` } +// PutOverridePolicyResponse is the response body for updating an override policy. type PutOverridePolicyResponse struct { } +// DeleteOverridePolicyRequest is the request body for deleting an override policy. type DeleteOverridePolicyRequest struct { IsClusterScope bool `json:"isClusterScope"` Namespace string `json:"namespace"` Name string `json:"name" binding:"required"` } +// DeleteOverridePolicyResponse is the response body for deleting an override policy. type DeleteOverridePolicyResponse struct { } diff --git a/cmd/api/app/types/api/v1/overview.go b/cmd/api/app/types/api/v1/overview.go index 4b481940..84466555 100644 --- a/cmd/api/app/types/api/v1/overview.go +++ b/cmd/api/app/types/api/v1/overview.go @@ -21,35 +21,45 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +// OverviewResponse represents the response structure for the overview API. type OverviewResponse struct { KarmadaInfo *KarmadaInfo `json:"karmadaInfo"` MemberClusterStatus *MemberClusterStatus `json:"memberClusterStatus"` ClusterResourceStatus *ClusterResourceStatus `json:"clusterResourceStatus"` } +// KarmadaInfo contains information about the Karmada system. type KarmadaInfo struct { Version *version.Info `json:"version"` Status string `json:"status"` CreateTime metav1.Time `json:"createTime"` } +// NodeSummary provides a summary of node statistics. type NodeSummary struct { TotalNum int32 `json:"totalNum"` ReadyNum int32 `json:"readyNum"` } + +// CPUSummary provides a summary of CPU resource usage. type CPUSummary struct { TotalCPU int64 `json:"totalCPU"` AllocatedCPU float64 `json:"allocatedCPU"` } + +// MemorySummary provides a summary of memory resource usage. type MemorySummary struct { TotalMemory int64 `json:"totalMemory"` // Kib => 8 * KiB AllocatedMemory float64 `json:"allocatedMemory"` } + +// PodSummary provides a summary of pod statistics. type PodSummary struct { TotalPod int64 `json:"totalPod"` AllocatedPod int64 `json:"allocatedPod"` } +// MemberClusterStatus represents the status of member clusters. type MemberClusterStatus struct { NodeSummary *NodeSummary `json:"nodeSummary"` CPUSummary *CPUSummary `json:"cpuSummary"` @@ -57,6 +67,7 @@ type MemberClusterStatus struct { PodSummary *PodSummary `json:"podSummary"` } +// ClusterResourceStatus represents the status of various resources in the cluster. type ClusterResourceStatus struct { PropagationPolicyNum int `json:"propagationPolicyNum"` OverridePolicyNum int `json:"overridePolicyNum"` diff --git a/cmd/api/app/types/api/v1/propagationpolicy.go b/cmd/api/app/types/api/v1/propagationpolicy.go index 55a43ca4..df95f52e 100644 --- a/cmd/api/app/types/api/v1/propagationpolicy.go +++ b/cmd/api/app/types/api/v1/propagationpolicy.go @@ -16,6 +16,7 @@ limitations under the License. package v1 +// PostPropagationPolicyRequest defines the request structure for creating a propagation policy. // todo this is only a simple version of pp request, just for POC type PostPropagationPolicyRequest struct { PropagationData string `json:"propagationData" binding:"required"` @@ -23,9 +24,11 @@ type PostPropagationPolicyRequest struct { Namespace string `json:"namespace"` } +// PostPropagationPolicyResponse defines the response structure for creating a propagation policy. type PostPropagationPolicyResponse struct { } +// PutPropagationPolicyRequest defines the request structure for updating a propagation policy. type PutPropagationPolicyRequest struct { PropagationData string `json:"propagationData" binding:"required"` IsClusterScope bool `json:"isClusterScope"` @@ -33,14 +36,17 @@ type PutPropagationPolicyRequest struct { Name string `json:"name" binding:"required"` } +// PutPropagationPolicyResponse defines the response structure for updating a propagation policy. type PutPropagationPolicyResponse struct { } +// DeletePropagationPolicyRequest defines the request structure for deleting a propagation policy. type DeletePropagationPolicyRequest struct { IsClusterScope bool `json:"isClusterScope"` Namespace string `json:"namespace"` Name string `json:"name" binding:"required"` } +// DeletePropagationPolicyResponse defines the response structure for deleting a propagation policy. type DeletePropagationPolicyResponse struct { } diff --git a/cmd/metrics-scraper/app/db/consts.go b/cmd/metrics-scraper/app/db/consts.go index 0109d956..4acb6d09 100644 --- a/cmd/metrics-scraper/app/db/consts.go +++ b/cmd/metrics-scraper/app/db/consts.go @@ -17,11 +17,18 @@ limitations under the License. package db const ( + // Namespace is the namespace of karmada. Namespace = "karmada-system" + // KarmadaAgent is the name of karmada agent. KarmadaAgent = "karmada-agent" + // KarmadaScheduler is the name of karmada scheduler. KarmadaScheduler = "karmada-scheduler" + // KarmadaSchedulerEstimator is the name of karmada scheduler estimator. KarmadaSchedulerEstimator = "karmada-scheduler-estimator" + // KarmadaControllerManager is the name of karmada controller manager. KarmadaControllerManager = "karmada-controller-manager" + // SchedulerPort is the port of karmada scheduler. SchedulerPort = "10351" + // ControllerManagerPort is the port of karmada controller manager. ControllerManagerPort = "8080" ) diff --git a/cmd/metrics-scraper/app/db/models.go b/cmd/metrics-scraper/app/db/models.go index 43424b5c..9d70fc17 100644 --- a/cmd/metrics-scraper/app/db/models.go +++ b/cmd/metrics-scraper/app/db/models.go @@ -16,10 +16,12 @@ limitations under the License. package db +// PodInfo is the pod info. type PodInfo struct { Name string `json:"name"` } +// Metric is the metric info. type Metric struct { Name string `json:"name"` Help string `json:"help"` @@ -27,12 +29,14 @@ type Metric struct { Values []MetricValue `json:"values,omitempty"` } +// MetricValue is the metric value info. type MetricValue struct { Labels map[string]string `json:"labels,omitempty"` Value string `json:"value"` Measure string `json:"measure"` } +// ParsedData is the parsed data info. type ParsedData struct { CurrentTime string `json:"currentTime"` Metrics map[string]*Metric `json:"metrics"` diff --git a/pkg/client/client.go b/pkg/client/client.go index ffdb0357..6617040d 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -84,6 +84,7 @@ func LoadApiConfig(kubeconfig string, currentContext string) (*clientcmdapi.Conf return apiConfig, nil } +// LoadeRestConfigFromKubeConfig creates a rest.Config from a kubeconfig string. func LoadeRestConfigFromKubeConfig(kubeconfig string) (*rest.Config, error) { apiConfig, err := clientcmd.Load([]byte(kubeconfig)) if err != nil { @@ -97,6 +98,7 @@ func LoadeRestConfigFromKubeConfig(kubeconfig string) (*rest.Config, error) { return restConfig, nil } +// KubeClientSetFromKubeConfig creates a Kubernetes clientset from a kubeconfig string. func KubeClientSetFromKubeConfig(kubeconfig string) (*kubeclient.Clientset, error) { restConfig, err := LoadeRestConfigFromKubeConfig(kubeconfig) if err != nil { @@ -106,6 +108,7 @@ func KubeClientSetFromKubeConfig(kubeconfig string) (*kubeclient.Clientset, erro return kubeClient, nil } +// GetKarmadaClientFromRequest creates a Karmada clientset from an HTTP request. func GetKarmadaClientFromRequest(request *http.Request) (karmadaclientset.Interface, error) { if !isKarmadaInitialized() { return nil, fmt.Errorf("client package not initialized") diff --git a/pkg/client/init.go b/pkg/client/init.go index 4b915cca..45acb634 100644 --- a/pkg/client/init.go +++ b/pkg/client/init.go @@ -51,26 +51,31 @@ type configBuilder struct { userAgent string } +// Option is a function that configures a configBuilder. type Option func(*configBuilder) +// WithUserAgent is an option to set the user agent. func WithUserAgent(agent string) Option { return func(c *configBuilder) { c.userAgent = agent } } +// WithKubeconfig is an option to set the kubeconfig path. func WithKubeconfig(path string) Option { return func(c *configBuilder) { c.kubeconfigPath = path } } +// WithKubeContext is an option to set the kubeconfig context. func WithKubeContext(kubecontext string) Option { return func(c *configBuilder) { c.kubeContext = kubecontext } } +// WithInsecureTLSSkipVerify is an option to set the insecure tls skip verify. func WithInsecureTLSSkipVerify(insecure bool) Option { return func(c *configBuilder) { c.insecure = insecure @@ -127,6 +132,7 @@ func isKubeInitialized() bool { return true } +// InitKubeConfig initializes the kubernetes client config. func InitKubeConfig(options ...Option) { builder := newConfigBuilder(options...) // prefer InClusterConfig, if something wrong, use explict kubeconfig path @@ -158,6 +164,7 @@ func InitKubeConfig(options ...Option) { } +// InClusterClient returns a kubernetes client. func InClusterClient() kubeclient.Interface { if !isKubeInitialized() { return nil @@ -178,6 +185,7 @@ func InClusterClient() kubeclient.Interface { return inClusterClient } +// GetKubeConfig returns the kubernetes client config. func GetKubeConfig() (*rest.Config, *clientcmdapi.Config, error) { if !isKubeInitialized() { return nil, nil, fmt.Errorf("client package not initialized") @@ -193,6 +201,7 @@ func isKarmadaInitialized() bool { return true } +// InitKarmadaConfig initializes the karmada client config. func InitKarmadaConfig(options ...Option) { builder := newConfigBuilder(options...) restConfig, err := builder.buildRestConfig() @@ -217,6 +226,7 @@ func InitKarmadaConfig(options ...Option) { karmadaMemberConfig = memberConfig } +// InClusterKarmadaClient returns a karmada client. func InClusterKarmadaClient() karmadaclientset.Interface { if !isKarmadaInitialized() { return nil @@ -235,6 +245,7 @@ func InClusterKarmadaClient() karmadaclientset.Interface { return inClusterKarmadaClient } +// GetKarmadaConfig returns the karmada client config. func GetKarmadaConfig() (*rest.Config, *clientcmdapi.Config, error) { if !isKarmadaInitialized() { return nil, nil, fmt.Errorf("client package not initialized") @@ -242,6 +253,7 @@ func GetKarmadaConfig() (*rest.Config, *clientcmdapi.Config, error) { return karmadaRestConfig, karmadaApiConfig, nil } +// GetMemberConfig returns the member client config. func GetMemberConfig() (*rest.Config, error) { if !isKarmadaInitialized() { return nil, fmt.Errorf("client package not initialized") @@ -249,6 +261,7 @@ func GetMemberConfig() (*rest.Config, error) { return karmadaMemberConfig, nil } +// InClusterClientForKarmadaApiServer returns a kubernetes client for karmada apiserver. func InClusterClientForKarmadaApiServer() kubeclient.Interface { if !isKarmadaInitialized() { return nil @@ -270,6 +283,7 @@ func InClusterClientForKarmadaApiServer() kubeclient.Interface { return inClusterClientForKarmadaApiServer } +// InClusterClientForMemberCluster returns a kubernetes client for member apiserver. func InClusterClientForMemberCluster(clusterName string) kubeclient.Interface { if !isKarmadaInitialized() { return nil @@ -307,6 +321,7 @@ func InClusterClientForMemberCluster(clusterName string) kubeclient.Interface { return inClusterClientForMemberApiServer } +// ConvertRestConfigToAPIConfig converts a rest.Config to a clientcmdapi.Config. func ConvertRestConfigToAPIConfig(restConfig *rest.Config) *clientcmdapi.Config { // 将 rest.Config 转换为 clientcmdapi.Config clientcmdConfig := clientcmdapi.NewConfig() diff --git a/pkg/config/config.go b/pkg/config/config.go index 8338c5a6..10648384 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -46,6 +46,7 @@ var ( } ) +// GetConfigKey returns the configuration key based on the environment name. func GetConfigKey() string { envName := os.Getenv("ENV_NAME") if envName == "" { @@ -54,6 +55,7 @@ func GetConfigKey() string { return fmt.Sprintf("%s.yaml", envName) } +// InitDashboardConfig initializes the dashboard configuration using a Kubernetes client. func InitDashboardConfig(k8sClient kubernetes.Interface, stopper <-chan struct{}) { factory := informers.NewSharedInformerFactory(k8sClient, 0) resource, err := factory.ForResource(configmapGVR) @@ -97,6 +99,7 @@ func InitDashboardConfig(k8sClient kubernetes.Interface, stopper <-chan struct{} klog.Infof("ConfigMap informer started, waiting for ConfigMap events...") } +// GetDashboardConfig returns a copy of the current dashboard configuration. func GetDashboardConfig() DashboardConfig { return DashboardConfig{ DockerRegistries: dashboardConfig.DockerRegistries, @@ -106,6 +109,7 @@ func GetDashboardConfig() DashboardConfig { } } +// UpdateDashboardConfig updates the dashboard configuration in the Kubernetes ConfigMap. func UpdateDashboardConfig(k8sClient kubernetes.Interface, newDashboardConfig DashboardConfig) error { ctx := context.TODO() oldConfigMap, err := k8sClient.CoreV1().ConfigMaps(configNamespace).Get(ctx, configName, metav1.GetOptions{}) @@ -128,6 +132,7 @@ func UpdateDashboardConfig(k8sClient kubernetes.Interface, newDashboardConfig Da return nil } +// InitDashboardConfigFromMountFile initializes the dashboard configuration from a mounted file. func InitDashboardConfigFromMountFile(mountPath string) error { _, err := os.Stat(mountPath) if os.IsNotExist(err) { diff --git a/pkg/config/model.go b/pkg/config/model.go index ebbba5c7..a8411f41 100644 --- a/pkg/config/model.go +++ b/pkg/config/model.go @@ -39,6 +39,7 @@ type MenuConfig struct { Children []MenuConfig `yaml:"children" json:"children,omitempty"` } +// DashboardConfig represents the configuration structure for the Karmada dashboard. type DashboardConfig struct { DockerRegistries []DockerRegistry `yaml:"docker_registries" json:"docker_registries"` ChartRegistries []ChartRegistry `yaml:"chart_registries" json:"chart_registries"` diff --git a/pkg/dataselect/dataselectquery.go b/pkg/dataselect/dataselectquery.go index f7552bf0..23a11588 100644 --- a/pkg/dataselect/dataselectquery.go +++ b/pkg/dataselect/dataselectquery.go @@ -18,38 +18,54 @@ package dataselect // Can be extended to include any kind of selection - for example filtering. // Currently included only Pagination and Sort options. type DataSelectQuery struct { + // PaginationQuery holds options for pagination of data select. PaginationQuery *PaginationQuery + // SortQuery holds options for sort functionality of data select. SortQuery *SortQuery + // FilterQuery holds options for filter functionality of data select. FilterQuery *FilterQuery //MetricQuery *MetricQuery } // SortQuery holds options for sort functionality of data select. type SortQuery struct { + // SortByList is a list of sort criteria for data selection. SortByList []SortBy } // SortBy holds the name of the property that should be sorted and whether order should be ascending or descending. type SortBy struct { + // Property is the name of the field or attribute to sort by. Property PropertyName + // Ascending determines the sort order Ascending bool } // NoSort is as option for no sort. var NoSort = &SortQuery{ + // SortByList is a list of sort criteria for data selection. SortByList: []SortBy{}, } +// FilterQuery holds options for filter functionality of data select. type FilterQuery struct { + // FilterByList is a list of filter criteria for data selection. FilterByList []FilterBy } +// FilterBy defines a filter criterion for data selection. +// It specifies a property to filter on and the value to compare against. type FilterBy struct { + // Property is the name of the field or attribute to filter by. Property PropertyName - Value ComparableValue + + // Value is the comparable value to match against the specified property. + Value ComparableValue } +// NoFilter is an option for no filter. var NoFilter = &FilterQuery{ + // FilterByList is a list of filter criteria for data selection. FilterByList: []FilterBy{}, } diff --git a/pkg/dataselect/stdcomparabletypes.go b/pkg/dataselect/stdcomparabletypes.go index 94761254..307c31f9 100644 --- a/pkg/dataselect/stdcomparabletypes.go +++ b/pkg/dataselect/stdcomparabletypes.go @@ -25,24 +25,30 @@ import ( // You can convert basic types to these types to support auto sorting etc. // If you cant find your type compare here you will have to implement it yourself :) +// StdComparableInt is a wrapper for int that implements ComparableValueInterface type StdComparableInt int +// Compare compares two ints. func (self StdComparableInt) Compare(otherV ComparableValue) int { other := otherV.(StdComparableInt) return intsCompare(int(self), int(other)) } +// Contains checks if other is contained in self. func (self StdComparableInt) Contains(otherV ComparableValue) bool { return self.Compare(otherV) == 0 } +// StdComparableString is a wrapper for string that implements ComparableValueInterface type StdComparableString string +// Compare compares two strings. func (self StdComparableString) Compare(otherV ComparableValue) int { other := otherV.(StdComparableString) return strings.Compare(string(self), string(other)) } +// Contains checks if other is contained in self. func (self StdComparableString) Contains(otherV ComparableValue) bool { other := otherV.(StdComparableString) return strings.Contains(string(self), string(other)) @@ -51,6 +57,7 @@ func (self StdComparableString) Contains(otherV ComparableValue) bool { // StdComparableRFC3339Timestamp takes RFC3339 Timestamp strings and compares them as TIMES. In case of time parsing error compares values as strings. type StdComparableRFC3339Timestamp string +// Compare compares two RFC3339 Timestamp strings. In case of time parsing error compares values as strings. func (self StdComparableRFC3339Timestamp) Compare(otherV ComparableValue) int { other := otherV.(StdComparableRFC3339Timestamp) // try to compare as timestamp (earlier = smaller) @@ -64,17 +71,21 @@ func (self StdComparableRFC3339Timestamp) Compare(otherV ComparableValue) int { return ints64Compare(selfTime.Unix(), otherTime.Unix()) } +// Contains checks if other is contained in self. func (self StdComparableRFC3339Timestamp) Contains(otherV ComparableValue) bool { return self.Compare(otherV) == 0 } +// StdComparableTime takes time.Time and compares them as TIMES. type StdComparableTime time.Time +// Compare compares two time.Time. func (self StdComparableTime) Compare(otherV ComparableValue) int { other := otherV.(StdComparableTime) return ints64Compare(time.Time(self).Unix(), time.Time(other).Unix()) } +// Contains checks if other is contained in self. func (self StdComparableTime) Contains(otherV ComparableValue) bool { return self.Compare(otherV) == 0 } diff --git a/pkg/environment/version.go b/pkg/environment/version.go index aeb41619..a0a4264b 100644 --- a/pkg/environment/version.go +++ b/pkg/environment/version.go @@ -33,10 +33,12 @@ var ( buildDate = "unknown" // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ') ) +// IsDev returns true if the version is dev. func IsDev() bool { return Version == dev } +// UserAgent returns the user agent of this binary. func UserAgent() string { return fmt.Sprintf("%s:%s", userAgent, Version) } diff --git a/pkg/resource/cluster/cluster.go b/pkg/resource/cluster/cluster.go index d7d0f8dc..b6ab1c43 100644 --- a/pkg/resource/cluster/cluster.go +++ b/pkg/resource/cluster/cluster.go @@ -28,6 +28,7 @@ import ( "log" ) +// Cluster the definition of a cluster. type Cluster struct { ObjectMeta types.ObjectMeta `json:"objectMeta"` TypeMeta types.TypeMeta `json:"typeMeta"` diff --git a/pkg/resource/cluster/common.go b/pkg/resource/cluster/common.go index 5b391da3..0696d9ef 100644 --- a/pkg/resource/cluster/common.go +++ b/pkg/resource/cluster/common.go @@ -21,8 +21,10 @@ import ( "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1" ) +// ClusterCell is a cell representation of Cluster object. type ClusterCell v1alpha1.Cluster +// GetProperty returns value of a given property. func (self ClusterCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: diff --git a/pkg/resource/cluster/detail.go b/pkg/resource/cluster/detail.go index 0a21149a..c518edb3 100644 --- a/pkg/resource/cluster/detail.go +++ b/pkg/resource/cluster/detail.go @@ -27,6 +27,7 @@ import ( "log" ) +// ClusterAllocatedResources is the resource summary of a cluster. type ClusterAllocatedResources struct { // CPUCapacity is specified node CPU capacity in milicores. CPUCapacity int64 `json:"cpuCapacity"` @@ -87,6 +88,7 @@ func getclusterAllocatedResources(cluster *v1alpha1.Cluster) (ClusterAllocatedRe }, nil } +// ClusterDetail is the detailed information of a cluster. type ClusterDetail struct { Cluster `json:",inline"` Taints []corev1.Taint `json:"taints,omitempty"` diff --git a/pkg/resource/clusterpropagationpolicy/list.go b/pkg/resource/clusterpropagationpolicy/list.go index d41b2eb1..71a33fb9 100644 --- a/pkg/resource/clusterpropagationpolicy/list.go +++ b/pkg/resource/clusterpropagationpolicy/list.go @@ -18,12 +18,14 @@ package clusterpropagationpolicy import ( "context" + + "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1" + karmadaclientset "github.com/karmada-io/karmada/pkg/generated/clientset/versioned" + "github.com/karmada-io/dashboard/pkg/common/errors" "github.com/karmada-io/dashboard/pkg/common/helpers" "github.com/karmada-io/dashboard/pkg/common/types" "github.com/karmada-io/dashboard/pkg/dataselect" - "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1" - karmadaclientset "github.com/karmada-io/karmada/pkg/generated/clientset/versioned" ) // ClusterPropagationPolicyList contains a list of propagation in the karmada control-plane. @@ -37,6 +39,7 @@ type ClusterPropagationPolicyList struct { Errors []error `json:"errors"` } +// ClusterPropagationPolicy represents a cluster propagation policy. type ClusterPropagationPolicy struct { ObjectMeta types.ObjectMeta `json:"objectMeta"` TypeMeta types.TypeMeta `json:"typeMeta"` diff --git a/pkg/resource/cronjob/common.go b/pkg/resource/cronjob/common.go index 4e386f2c..4ad6e00a 100644 --- a/pkg/resource/cronjob/common.go +++ b/pkg/resource/cronjob/common.go @@ -24,8 +24,10 @@ import ( // The code below allows to perform complex data section on []batch.CronJob +// CronJobCell is a type containing CronJob data type CronJobCell batch.CronJob +// GetProperty returns specific property of CronJobCell func (self CronJobCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: @@ -40,6 +42,7 @@ func (self CronJobCell) GetProperty(name dataselect.PropertyName) dataselect.Com } } +// ToCells converts []batch.CronJob to []CronJobCell func ToCells(std []batch.CronJob) []dataselect.DataCell { cells := make([]dataselect.DataCell, len(std)) for i := range std { @@ -48,6 +51,7 @@ func ToCells(std []batch.CronJob) []dataselect.DataCell { return cells } +// FromCells converts []CronJobCell to []batch.CronJob func FromCells(cells []dataselect.DataCell) []batch.CronJob { std := make([]batch.CronJob, len(cells)) for i := range std { diff --git a/pkg/resource/daemonset/common.go b/pkg/resource/daemonset/common.go index 51000408..496784a6 100644 --- a/pkg/resource/daemonset/common.go +++ b/pkg/resource/daemonset/common.go @@ -64,8 +64,10 @@ func GetServicesForDSDeletion(client client.Interface, labelSelector labels.Sele // The code below allows to perform complex data section on Daemon Set +// DaemonSetCell is a type alias for the DaemonSet type from the apps/v1 API. type DaemonSetCell apps.DaemonSet +// GetProperty returns a comparable value for a specified property name. func (self DaemonSetCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: @@ -80,6 +82,7 @@ func (self DaemonSetCell) GetProperty(name dataselect.PropertyName) dataselect.C } } +// ToCells converts a slice of DaemonSets to a slice of DataCells. func ToCells(std []apps.DaemonSet) []dataselect.DataCell { cells := make([]dataselect.DataCell, len(std)) for i := range std { @@ -88,6 +91,7 @@ func ToCells(std []apps.DaemonSet) []dataselect.DataCell { return cells } +// FromCells converts a slice of DataCells to a slice of DaemonSets. func FromCells(cells []dataselect.DataCell) []apps.DaemonSet { std := make([]apps.DaemonSet, len(cells)) for i := range std { diff --git a/pkg/resource/job/common.go b/pkg/resource/job/common.go index b69d2c85..16537957 100644 --- a/pkg/resource/job/common.go +++ b/pkg/resource/job/common.go @@ -25,8 +25,10 @@ import ( // The code below allows to perform complex data section on []batch.Job +// JobCell represents a job cell that implements the DataCell interface. type JobCell batch.Job +// GetProperty returns a comparable value for a specified property name. func (self JobCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: @@ -41,6 +43,7 @@ func (self JobCell) GetProperty(name dataselect.PropertyName) dataselect.Compara } } +// ToCells converts a slice of Jobs to a slice of DataCells. func ToCells(std []batch.Job) []dataselect.DataCell { cells := make([]dataselect.DataCell, len(std)) for i := range std { @@ -49,6 +52,7 @@ func ToCells(std []batch.Job) []dataselect.DataCell { return cells } +// FromCells converts a slice of DataCells to a slice of Jobs. func FromCells(cells []dataselect.DataCell) []batch.Job { std := make([]batch.Job, len(cells)) for i := range std { diff --git a/pkg/resource/namespace/common.go b/pkg/resource/namespace/common.go index 151e3394..58043273 100644 --- a/pkg/resource/namespace/common.go +++ b/pkg/resource/namespace/common.go @@ -58,8 +58,10 @@ func CreateNamespace(spec *NamespaceSpec, client kubernetes.Interface) error { // The code below allows to perform complex data section on []api.Namespace +// NamespaceCell is a cell representation of Namespace object. type NamespaceCell api.Namespace +// GetProperty returns specific property of NamespaceCell. func (self NamespaceCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: diff --git a/pkg/resource/node/list.go b/pkg/resource/node/list.go index 7e990934..4bcb91d1 100644 --- a/pkg/resource/node/list.go +++ b/pkg/resource/node/list.go @@ -29,6 +29,7 @@ import ( "k8s.io/client-go/kubernetes" ) +// Node represents a Kubernetes node with additional metadata. type Node struct { ObjectMeta types.ObjectMeta `json:"objectMeta"` TypeMeta types.TypeMeta `json:"typeMeta"` @@ -97,6 +98,7 @@ func toNodeList(nodes []v1.Node, nonCriticalErrors []error, dsQuery *dataselect. return result } +// NewStatus returns a new status object. func NewStatus(status v1.NodeStatus) v1.NodeStatus { return v1.NodeStatus{ Capacity: status.Capacity, diff --git a/pkg/resource/overridepolicy/common.go b/pkg/resource/overridepolicy/common.go index 11336404..9bf4f64f 100644 --- a/pkg/resource/overridepolicy/common.go +++ b/pkg/resource/overridepolicy/common.go @@ -21,8 +21,10 @@ import ( "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1" ) +// OverridePolicyCell represents an OverridePolicy that implements the DataCell interface. type OverridePolicyCell v1alpha1.OverridePolicy +// GetProperty returns a comparable value for a specified property name. func (self OverridePolicyCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: diff --git a/pkg/resource/propagationpolicy/common.go b/pkg/resource/propagationpolicy/common.go index 8cbfd5f6..2a06eb63 100644 --- a/pkg/resource/propagationpolicy/common.go +++ b/pkg/resource/propagationpolicy/common.go @@ -21,8 +21,10 @@ import ( "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1" ) +// PropagationPolicyCell is a wrapper around PropagationPolicy type type PropagationPolicyCell v1alpha1.PropagationPolicy +// GetProperty returns the given property of the PropagationPolicy. func (self PropagationPolicyCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: