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

chore: format code about exported function should have comment #183

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions cmd/api/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Options struct {
OpenAPIEnabled bool
}

// NewOptions returns initialized Options.
func NewOptions() *Options {
return &Options{}
}
Expand Down
1 change: 1 addition & 0 deletions cmd/api/app/types/api/v1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1

import "github.com/karmada-io/dashboard/pkg/config"

// SetDashboardConfigRequest is the request for setting dashboard config
type SetDashboardConfigRequest struct {
DockerRegistries []config.DockerRegistry `json:"docker_registries"`
ChartRegistries []config.ChartRegistry `json:"chart_registries"`
Expand Down
2 changes: 2 additions & 0 deletions cmd/api/app/types/common/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/gin-gonic/gin"
)

// BaseResponse is the base response
type BaseResponse struct {
Code int `json:"code"`
Msg string `json:"message"`
Expand All @@ -38,6 +39,7 @@ func Fail(c *gin.Context, err error) {
Response(c, err, nil)
}

// Response generate response
func Response(c *gin.Context, err error, data interface{}) {
code := 200 // biz status code
message := "success" // biz status message
Expand Down
1 change: 1 addition & 0 deletions cmd/metrics-scraper/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Options struct {
OpenAPIEnabled bool
}

// NewOptions returns initialized Options.
func NewOptions() *Options {
return &Options{}
}
Expand Down
1 change: 1 addition & 0 deletions cmd/metrics-scraper/app/routes/metrics/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

var requests = make(chan scrape.SaveRequest)

// GetMetrics returns the metrics for the given app name
func GetMetrics(c *gin.Context) {
appName := c.Param("app_name")
queryType := c.Query("type")
Expand Down
2 changes: 2 additions & 0 deletions cmd/metrics-scraper/app/routes/metrics/handlerqueries.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ import (
"github.com/karmada-io/dashboard/cmd/metrics-scraper/app/scrape"
)

// MetricInfo represents the information about a metric.
type MetricInfo struct {
Help string `json:"help"`
Type string `json:"type"`
}

// QueryMetrics handles the querying of metrics.
func QueryMetrics(c *gin.Context) {
appName := c.Param("app_name")
podName := c.Param("pod_name")
Expand Down
3 changes: 2 additions & 1 deletion cmd/metrics-scraper/app/scrape/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ import (
"github.com/karmada-io/dashboard/pkg/client"
)

// Define a struct for save requests
// SaveRequest Define a struct for save requests
type SaveRequest struct {
appName string
podName string
data *db.ParsedData
result chan error
}

// FetchMetrics fetches metrics from all pods of the given app name
func FetchMetrics(ctx context.Context, appName string, requests chan SaveRequest) (map[string]*db.ParsedData, []string, error) {
kubeClient := client.InClusterClient()
podsMap, errors := getKarmadaPods(ctx, appName) // Pass context here
Expand Down
3 changes: 3 additions & 0 deletions cmd/metrics-scraper/app/scrape/scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func startAppMetricsFetcher(appName string) {
}
}

// CheckAppStatus checks the status of all registered apps and returns a map of app names to their status.
func CheckAppStatus(c *gin.Context) {
statusMap := make(map[string]bool)

Expand Down Expand Up @@ -107,6 +108,7 @@ func CheckAppStatus(c *gin.Context) {
c.JSON(http.StatusOK, statusMap)
}

// HandleSyncOperation handles the sync operation for a specific app or all apps.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// HandleSyncOperation handles the sync operation for a specific app, if not specified, it handles the sync operation for all apps

func HandleSyncOperation(c *gin.Context, appName string, syncValue int, queryType string) {
if appName == "" {
// Stop all apps
Expand Down Expand Up @@ -188,6 +190,7 @@ func HandleSyncOperation(c *gin.Context, appName string, syncValue int, queryTyp
}
}

// InitDatabase initializes the database and starts the metrics fetchers.
func InitDatabase() {
// Initialize contexts and cancel functions
appContexts = make(map[string]context.Context)
Expand Down
1 change: 1 addition & 0 deletions cmd/web/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Options struct {
DashboardConfigPath string
}

// NewOptions creates a new Options object with default parameters.
func NewOptions() *Options {
return &Options{}
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/client/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func buildAuthInfo(request *http.Request) (*clientcmdapi.AuthInfo, error) {
return authInfo, nil
}

// HasAuthorizationHeader checks if the request has an authorization header.
func HasAuthorizationHeader(req *http.Request) bool {
header := req.Header.Get(authorizationHeader)
if len(header) == 0 {
Expand All @@ -92,11 +93,13 @@ func HasAuthorizationHeader(req *http.Request) bool {
return strings.HasPrefix(header, authorizationTokenPrefix) && len(token) > 0
}

// GetBearerToken returns the bearer token from the authorization header.
func GetBearerToken(req *http.Request) string {
header := req.Header.Get(authorizationHeader)
return extractBearerToken(header)
}

// SetAuthorizationHeader sets the authorization header for the given request.
func SetAuthorizationHeader(req *http.Request, token string) {
req.Header.Set(authorizationHeader, authorizationTokenPrefix+token)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/client/verber.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func (v *resourceVerber) Create(object *unstructured.Unstructured) (*unstructure
return v.client.Resource(gvr).Namespace(namespace).Create(context.TODO(), object, metav1.CreateOptions{})
}

// VerberClient returns a resourceVerber client.
func VerberClient(request *http.Request) (ResourceVerber, error) {
// todo currently ignore rest.config from http.Request
restConfig, _, err := GetKarmadaConfig()
Expand Down
12 changes: 1 addition & 11 deletions pkg/common/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func NewUnauthorized(reason string) *k8serrors.StatusError {
return k8serrors.NewUnauthorized(reason)
}

// NewForbidden returns an error indicating the client is not authorized to perform the requested
func NewForbidden(name string, err error) *k8serrors.StatusError {
return k8serrors.NewForbidden(schema.GroupResource{}, name, err)
}
Expand All @@ -48,17 +49,6 @@ func NewTokenExpired(reason string) *k8serrors.StatusError {
}
}

func NewCSRFValidationFailed() *k8serrors.StatusError {
return &k8serrors.StatusError{
ErrStatus: metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusUnauthorized,
Reason: metav1.StatusReasonInvalid,
Message: MsgCSRFValidationError,
},
}
}

// NewBadRequest creates an error that indicates that the request is invalid and can not be processed.
func NewBadRequest(reason string) *k8serrors.StatusError {
return k8serrors.NewBadRequest(reason)
Expand Down
1 change: 1 addition & 0 deletions pkg/common/errors/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
// silenced and displayed to the user as a warning on the frontend side.
var nonCriticalErrors = []int32{http.StatusForbidden}

// HandleError processes the incoming error and returns the corresponding HTTP status code and error message based on the error type.
func HandleError(err error) (int, error) {
if IsUnauthorized(err) {
return http.StatusUnauthorized, NewUnauthorized(MsgLoginUnauthorizedError)
Expand Down
1 change: 1 addition & 0 deletions pkg/common/errors/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ func IsForbidden(err error) bool {
return k8serrors.IsForbidden(err)
}

// IsNotFound checks if the given error is of type NotFound.
func IsNotFound(err error) bool { return k8serrors.IsNotFound(err) }
3 changes: 3 additions & 0 deletions pkg/config/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.

package config

// DockerRegistry represents a Docker registry configuration.
type DockerRegistry struct {
Name string `yaml:"name" json:"name"`
Url string `yaml:"url" json:"url"`
Expand All @@ -24,6 +25,7 @@ type DockerRegistry struct {
AddTime int64 `yaml:"add_time" json:"add_time"`
}

// ChartRegistry represents a Helm chart registry configuration.
type ChartRegistry struct {
Name string `yaml:"name" json:"name"`
Url string `yaml:"url" json:"url"`
Expand All @@ -32,6 +34,7 @@ type ChartRegistry struct {
AddTime int64 `yaml:"add_time" json:"add_time"`
}

// MenuConfig represents a menu configuration.
type MenuConfig struct {
Path string `yaml:"path" json:"path"`
Enable bool `yaml:"enable" json:"enable"`
Expand Down
2 changes: 2 additions & 0 deletions pkg/resource/clusteroverridepolicy/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import (
"github.com/karmada-io/dashboard/pkg/dataselect"
)

// ClusterOverridePolicyCell wraps v1alpha1.ClusterOverridePolicy for data selection.
type ClusterOverridePolicyCell v1alpha1.ClusterOverridePolicy

// GetProperty returns a property of the cluster override policy cell.
func (self ClusterOverridePolicyCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue {
switch name {
case dataselect.NameProperty:
Expand Down
1 change: 1 addition & 0 deletions pkg/resource/clusteroverridepolicy/detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/karmada-io/dashboard/pkg/common/errors"
)

// ClusterOverridePolicyDetail contains clusterPropagationPolicy details and non-critical errors.
type ClusterOverridePolicyDetail struct {
// Extends list item structure.
ClusterOverridePolicy `json:",inline"`
Expand Down
1 change: 1 addition & 0 deletions pkg/resource/clusteroverridepolicy/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type ClusterOverridePolicyList struct {
Errors []error `json:"errors"`
}

// ClusterOverridePolicy contains information about a single clusterOverridePolicy.
type ClusterOverridePolicy struct {
ObjectMeta types.ObjectMeta `json:"objectMeta"`
TypeMeta types.TypeMeta `json:"typeMeta"`
Expand Down
2 changes: 2 additions & 0 deletions pkg/resource/clusterpropagationpolicy/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import (
"github.com/karmada-io/dashboard/pkg/dataselect"
)

// ClusterPropagationPolicyCell wraps v1alpha1.ClusterPropagationPolicy for data selection.
type ClusterPropagationPolicyCell v1alpha1.ClusterPropagationPolicy

// GetProperty returns a property of the cluster propagation policy cell.
func (self ClusterPropagationPolicyCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue {
switch name {
case dataselect.NameProperty:
Expand Down
1 change: 1 addition & 0 deletions pkg/resource/clusterpropagationpolicy/detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/karmada-io/dashboard/pkg/common/errors"
)

// ClusterPropagationPolicyDetail contains clusterPropagationPolicy details.
type ClusterPropagationPolicyDetail struct {
// Extends list item structure.
ClusterPropagationPolicy `json:",inline"`
Expand Down
2 changes: 2 additions & 0 deletions pkg/resource/configmap/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import (

// The code below allows to perform complex data section on []api.ConfigMap

// ConfigMapCell is a cell in the table of configmaps.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConfigMapCell wraps api.ConfigMap for data selection.

type ConfigMapCell api.ConfigMap

// GetProperty returns a property.
func (self ConfigMapCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue {
switch name {
case dataselect.NameProperty:
Expand Down
4 changes: 3 additions & 1 deletion pkg/resource/cronjob/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ import (
)

const (
// CronJobAPIVersion is the version of the api for the cronjob.
CronJobAPIVersion = "v1"
CronJobKindName = "cronjob"
// CronJobKindName is the kind name of the api for the cronjob.
CronJobKindName = "cronjob"
)

var emptyJobList = &job.JobList{
Expand Down
1 change: 1 addition & 0 deletions pkg/resource/deployment/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/karmada-io/dashboard/pkg/resource/event"
)

// DeploymentCell is a wrapper for the k8s deployment
type DeploymentCell apps.Deployment

// GetProperty is used to get property of the deployment
Expand Down
1 change: 1 addition & 0 deletions pkg/resource/endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/karmada-io/dashboard/pkg/resource/common"
)

// Endpoint represents an endpoint in a Kubernetes cluster.
type Endpoint struct {
ObjectMeta types.ObjectMeta `json:"objectMeta"`
TypeMeta types.TypeMeta `json:"typeMeta"`
Expand Down
1 change: 1 addition & 0 deletions pkg/resource/endpoint/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/karmada-io/dashboard/pkg/common/types"
)

// EndpointList is a list of endpoints in the cluster.
type EndpointList struct {
ListMeta types.ListMeta `json:"listMeta"`
// List of endpoints
Expand Down
2 changes: 2 additions & 0 deletions pkg/resource/event/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ func CreateEventList(events []v1.Event, dsQuery *dataselect.DataSelectQuery) com

// The code below allows to perform complex data section on []api.Event

// EventCell wraps v1.Event for data selection.
type EventCell v1.Event

// GetProperty returns a property of the cell.
func (self EventCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue {
switch name {
case dataselect.NameProperty:
Expand Down
2 changes: 2 additions & 0 deletions pkg/resource/ingress/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import (

// The code below allows to perform complex data section on []extensions.Ingress

// IngressCell is a cell in the table of ingress.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// IngressCell wraps v1.Ingress for data selection.

type IngressCell v1.Ingress

// GetProperty returns a property.
func (self IngressCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue {
switch name {
case dataselect.NameProperty:
Expand Down
1 change: 1 addition & 0 deletions pkg/resource/ingress/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/karmada-io/dashboard/pkg/common/types"
)

// FilterIngressByService filters the given ingresses based on the service name.
func FilterIngressByService(ingresses []networkingv1.Ingress, serviceName string) []networkingv1.Ingress {
var matchingIngresses []networkingv1.Ingress
for _, ingress := range ingresses {
Expand Down
1 change: 1 addition & 0 deletions pkg/resource/ingress/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func toIngress(ingress *v1.Ingress) Ingress {
}
}

// ToIngressList converts a list of Ingresss to IngressList
func ToIngressList(ingresses []v1.Ingress, nonCriticalErrors []error, dsQuery *dataselect.DataSelectQuery) *IngressList {
newIngressList := &IngressList{
ListMeta: types.ListMeta{TotalItems: len(ingresses)},
Expand Down
3 changes: 3 additions & 0 deletions pkg/resource/job/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type JobList struct {
Errors []error `json:"errors"`
}

// JobStatusType is a valid value for JobStatus.Status.
type JobStatusType string

const (
Expand All @@ -55,6 +56,7 @@ const (
JobStatusFailed JobStatusType = "Failed"
)

// JobStatus contains inferred job status based on job conditions
type JobStatus struct {
// Short, machine understandable job status code.
Status JobStatusType `json:"status"`
Expand Down Expand Up @@ -128,6 +130,7 @@ func GetJobListFromChannels(channels *common.ResourceChannels, dsQuery *datasele
return jobList, nil
}

// ToJobList returns a list of all Jobs in the cluster reading required resource list once from the channel.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about the following description
// ToJobList returns a list of Jobs in the cluster by reading required resource list returned from the channel.

func ToJobList(jobs []batch.Job, pods []v1.Pod, events []v1.Event, nonCriticalErrors []error,
dsQuery *dataselect.DataSelectQuery) *JobList {
jobList := &JobList{
Expand Down
2 changes: 2 additions & 0 deletions pkg/resource/node/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import (
"github.com/karmada-io/dashboard/pkg/dataselect"
)

// NodeCell represents a cell in the table of nodes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// NodeCell wraps api.Node for data selection.

type NodeCell api.Node

// GetProperty returns a property of the cell.
func (self NodeCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue {
switch name {
case dataselect.NameProperty:
Expand Down
1 change: 1 addition & 0 deletions pkg/resource/overridepolicy/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type OverridePolicyList struct {
Errors []error `json:"errors"`
}

// OverridePolicy contains information about a single propagation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a single propagation should be corrected to a single override.

type OverridePolicy struct {
ObjectMeta types.ObjectMeta `json:"objectMeta"`
TypeMeta types.TypeMeta `json:"typeMeta"`
Expand Down
2 changes: 2 additions & 0 deletions pkg/resource/pod/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import (
"github.com/karmada-io/dashboard/pkg/dataselect"
)

// PodCell is a cell for pod.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// PodCell wraps api.Pod for data selection.

type PodCell api.Pod

// GetProperty returns a property.
func (self PodCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue {
switch name {
case dataselect.NameProperty:
Expand Down
3 changes: 2 additions & 1 deletion pkg/resource/pod/detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import (
"k8s.io/client-go/kubernetes"
)

type PodDeatil struct {
// PodDetail is a pod detail
type PodDetail struct {
ObjectMeta metaV1.ObjectMeta `json:"objectMeta"`
TypeMeta metaV1.TypeMeta `json:"typeMeta"`
Spec v1.PodSpec `json:"podSpec"`
Expand Down
Loading