Skip to content

Commit

Permalink
format code about exported function should have comment
Browse files Browse the repository at this point in the history
Signed-off-by: chaosi-zju <[email protected]>
  • Loading branch information
chaosi-zju committed Jan 23, 2025
1 parent c08f8a0 commit 548342a
Show file tree
Hide file tree
Showing 32 changed files with 159 additions and 5 deletions.
1 change: 1 addition & 0 deletions cmd/api/app/router/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions cmd/api/app/router/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 8 additions & 2 deletions cmd/api/app/routes/cluster/accesscluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -268,13 +272,15 @@ func AccessClusterInPullMode(opts *PullModeOption) error {
return nil
}

// PushModeOption is the option for push mode
type PushModeOption struct {
karmadaClient karmadaclientset.Interface
clusterName string
karmadaRestConfig *rest.Config
memberClusterRestConfig *rest.Config
}

// AccessClusterInPushMode access cluster in push mode
func AccessClusterInPushMode(opts *PushModeOption) error {
registerOption := karmadautil.ClusterRegisterOption{
ClusterNamespace: ClusterNamespace,
Expand Down
2 changes: 2 additions & 0 deletions cmd/api/app/routes/config/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions cmd/api/app/routes/overview/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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, '{')
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions cmd/api/app/types/api/v1/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
12 changes: 12 additions & 0 deletions cmd/api/app/types/api/v1/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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 {
}
3 changes: 3 additions & 0 deletions cmd/api/app/types/api/v1/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
3 changes: 3 additions & 0 deletions cmd/api/app/types/api/v1/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
6 changes: 6 additions & 0 deletions cmd/api/app/types/api/v1/overridepolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,36 @@ 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"`
Namespace string `json:"namespace"`
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 {
}
11 changes: 11 additions & 0 deletions cmd/api/app/types/api/v1/overview.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,53 @@ 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"`
MemorySummary *MemorySummary `json:"memorySummary"`
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"`
Expand Down
6 changes: 6 additions & 0 deletions cmd/api/app/types/api/v1/propagationpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,37 @@ 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"`
IsClusterScope bool `json:"isClusterScope"`
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"`
Namespace string `json:"namespace"`
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 {
}
7 changes: 7 additions & 0 deletions cmd/metrics-scraper/app/db/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
4 changes: 4 additions & 0 deletions cmd/metrics-scraper/app/db/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@ 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"`
Type string `json:"type"`
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"`
Expand Down
Loading

0 comments on commit 548342a

Please sign in to comment.