diff --git a/.golangci.yml b/.golangci.yml index 3d0688e5..f321129a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -70,7 +70,6 @@ linters-settings: - name: dot-imports - name: errorf - name: exported - arguments: ["disableStutteringCheck"] # TODO Temporarily disable stuttering check - name: var-declaration - name: blank-imports - name: indent-error-flow diff --git a/cmd/api/app/routes/namespace/handler.go b/cmd/api/app/routes/namespace/handler.go index b728d23f..d585b097 100644 --- a/cmd/api/app/routes/namespace/handler.go +++ b/cmd/api/app/routes/namespace/handler.go @@ -34,7 +34,7 @@ func handleCreateNamespace(c *gin.Context) { common.Fail(c, err) return } - spec := &ns.NamespaceSpec{ + spec := &ns.Spec{ Name: createNamespaceRequest.Name, SkipAutoPropagation: createNamespaceRequest.SkipAutoPropagation, } diff --git a/cmd/api/app/routes/overview/misc.go b/cmd/api/app/routes/overview/misc.go index 0388af39..9a003ebe 100644 --- a/cmd/api/app/routes/overview/misc.go +++ b/cmd/api/app/routes/overview/misc.go @@ -161,7 +161,7 @@ func GetControllerManagerInfo() (*v1.KarmadaInfo, error) { } // GetMemberClusterInfo returns the status of member clusters. -func GetMemberClusterInfo(ds *dataselect.DataSelectQuery) (*v1.MemberClusterStatus, error) { +func GetMemberClusterInfo(ds *dataselect.Query) (*v1.MemberClusterStatus, error) { karmadaClient := client.InClusterKarmadaClient() result, err := cluster.GetClusterList(karmadaClient, ds) if err != nil { diff --git a/cmd/api/app/types/common/request.go b/cmd/api/app/types/common/request.go index d00d0d41..6c187ab2 100644 --- a/cmd/api/app/types/common/request.go +++ b/cmd/api/app/types/common/request.go @@ -50,8 +50,8 @@ func parseSortPathParameter(request *gin.Context) *dataselect.SortQuery { return dataselect.NewSortQuery(strings.Split(request.Query("sortBy"), ",")) } -// ParseDataSelectPathParameter parses query parameters of the request and returns a DataSelectQuery object -func ParseDataSelectPathParameter(request *gin.Context) *dataselect.DataSelectQuery { +// ParseDataSelectPathParameter parses query parameters of the request and returns a Query object +func ParseDataSelectPathParameter(request *gin.Context) *dataselect.Query { paginationQuery := parsePaginationPathParameter(request) sortQuery := parseSortPathParameter(request) filterQuery := parseFilterPathParameter(request) diff --git a/hack/verify-staticcheck.sh b/hack/verify-staticcheck.sh index 612769a9..76310324 100755 --- a/hack/verify-staticcheck.sh +++ b/hack/verify-staticcheck.sh @@ -32,7 +32,7 @@ else curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VER} fi -if golangci-lint run --enable-only goimports,gci,whitespace,misspell,staticcheck,govet,errcheck,gosimple,ineffassign,unused,gocyclo,gosec,revive; then +if golangci-lint run; then echo 'Congratulations! All Go source files have passed staticcheck.' else echo # print one empty line, separate from warning messages. diff --git a/pkg/dataselect/dataselect.go b/pkg/dataselect/dataselect.go index f71f143b..8562f8de 100644 --- a/pkg/dataselect/dataselect.go +++ b/pkg/dataselect/dataselect.go @@ -43,7 +43,7 @@ type DataSelector struct { // GenericDataList hold generic data cells that are being selected. GenericDataList []DataCell // DataSelectQuery holds instructions for data select. - DataSelectQuery *DataSelectQuery + DataSelectQuery *Query } // Implementation of sort.Interface so that we can use built-in sort function (sort.Sort) for sorting SelectableData @@ -74,13 +74,13 @@ func (s DataSelector) Less(i, j int) bool { return false } -// Sort sorts the data inside as instructed by DataSelectQuery and returns itself to allow method chaining. +// Sort sorts the data inside as instructed by Query and returns itself to allow method chaining. func (s *DataSelector) Sort() *DataSelector { sort.Sort(*s) return s } -// Filter the data inside as instructed by DataSelectQuery and returns itself to allow method chaining. +// Filter the data inside as instructed by Query and returns itself to allow method chaining. func (s *DataSelector) Filter() *DataSelector { filteredList := []DataCell{} @@ -102,7 +102,7 @@ func (s *DataSelector) Filter() *DataSelector { return s } -// Paginate paginates the data inside as instructed by DataSelectQuery and returns itself to allow method chaining. +// Paginate paginates the data inside as instructed by Query and returns itself to allow method chaining. func (s *DataSelector) Paginate() *DataSelector { pQuery := s.DataSelectQuery.PaginationQuery dataList := s.GenericDataList @@ -122,8 +122,8 @@ func (s *DataSelector) Paginate() *DataSelector { return s } -// GenericDataSelect takes a list of GenericDataCells and DataSelectQuery and returns selected data as instructed by dsQuery. -func GenericDataSelect(dataList []DataCell, dsQuery *DataSelectQuery) []DataCell { +// GenericDataSelect takes a list of GenericDataCells and Query and returns selected data as instructed by dsQuery. +func GenericDataSelect(dataList []DataCell, dsQuery *Query) []DataCell { SelectableData := DataSelector{ GenericDataList: dataList, DataSelectQuery: dsQuery, @@ -131,8 +131,8 @@ func GenericDataSelect(dataList []DataCell, dsQuery *DataSelectQuery) []DataCell return SelectableData.Sort().Paginate().GenericDataList } -// GenericDataSelectWithFilter takes a list of GenericDataCells and DataSelectQuery and returns selected data as instructed by dsQuery. -func GenericDataSelectWithFilter(dataList []DataCell, dsQuery *DataSelectQuery) ([]DataCell, int) { +// GenericDataSelectWithFilter takes a list of GenericDataCells and Query and returns selected data as instructed by dsQuery. +func GenericDataSelectWithFilter(dataList []DataCell, dsQuery *Query) ([]DataCell, int) { SelectableData := DataSelector{ GenericDataList: dataList, DataSelectQuery: dsQuery, diff --git a/pkg/dataselect/dataselect_test.go b/pkg/dataselect/dataselect_test.go index 0234b60a..c8803acc 100644 --- a/pkg/dataselect/dataselect_test.go +++ b/pkg/dataselect/dataselect_test.go @@ -143,7 +143,7 @@ func TestSort(t *testing.T) { for _, testCase := range testCases { selectableData := DataSelector{ GenericDataList: getDataCellList(), - DataSelectQuery: &DataSelectQuery{SortQuery: testCase.SortQuery}, + DataSelectQuery: &Query{SortQuery: testCase.SortQuery}, } sortedData := fromCells(selectableData.Sort().GenericDataList) order := getOrder(sortedData) @@ -210,7 +210,7 @@ func TestPagination(t *testing.T) { for _, testCase := range testCases { selectableData := DataSelector{ GenericDataList: getDataCellList(), - DataSelectQuery: &DataSelectQuery{PaginationQuery: testCase.PaginationQuery}, + DataSelectQuery: &Query{PaginationQuery: testCase.PaginationQuery}, } paginatedData := fromCells(selectableData.Paginate().GenericDataList) order := getOrder(paginatedData) diff --git a/pkg/dataselect/dataselectquery.go b/pkg/dataselect/dataselectquery.go index 827989bf..3ceac17d 100644 --- a/pkg/dataselect/dataselectquery.go +++ b/pkg/dataselect/dataselectquery.go @@ -14,10 +14,10 @@ package dataselect -// DataSelectQuery is options for GenericDataSelect which takes []GenericDataCell and returns selected data. +// Query is options for GenericDataSelect which takes []GenericDataCell and returns selected data. // Can be extended to include any kind of selection - for example filtering. // Currently included only Pagination and Sort options. -type DataSelectQuery struct { +type Query struct { // PaginationQuery holds options for pagination of data select. PaginationQuery *PaginationQuery // SortQuery holds options for sort functionality of data select. @@ -72,9 +72,9 @@ var NoFilter = &FilterQuery{ // NoDataSelect is an option for no data select (same data will be returned). var NoDataSelect = NewDataSelectQuery(NoPagination, NoSort, NoFilter) -// NewDataSelectQuery creates DataSelectQuery object from simpler data select queries. -func NewDataSelectQuery(paginationQuery *PaginationQuery, sortQuery *SortQuery, filterQuery *FilterQuery) *DataSelectQuery { - return &DataSelectQuery{ +// NewDataSelectQuery creates Query object from simpler data select queries. +func NewDataSelectQuery(paginationQuery *PaginationQuery, sortQuery *SortQuery, filterQuery *FilterQuery) *Query { + return &Query{ PaginationQuery: paginationQuery, SortQuery: sortQuery, FilterQuery: filterQuery, diff --git a/pkg/resource/cluster/cluster.go b/pkg/resource/cluster/cluster.go index 6274dfb2..7c8d53f1 100644 --- a/pkg/resource/cluster/cluster.go +++ b/pkg/resource/cluster/cluster.go @@ -32,17 +32,17 @@ import ( // Cluster the definition of a cluster. type Cluster struct { - ObjectMeta types.ObjectMeta `json:"objectMeta"` - TypeMeta types.TypeMeta `json:"typeMeta"` - Ready metav1.ConditionStatus `json:"ready"` - KubernetesVersion string `json:"kubernetesVersion,omitempty"` - SyncMode v1alpha1.ClusterSyncMode `json:"syncMode"` - NodeSummary *v1alpha1.NodeSummary `json:"nodeSummary,omitempty"` - AllocatedResources ClusterAllocatedResources `json:"allocatedResources"` + ObjectMeta types.ObjectMeta `json:"objectMeta"` + TypeMeta types.TypeMeta `json:"typeMeta"` + Ready metav1.ConditionStatus `json:"ready"` + KubernetesVersion string `json:"kubernetesVersion,omitempty"` + SyncMode v1alpha1.ClusterSyncMode `json:"syncMode"` + NodeSummary *v1alpha1.NodeSummary `json:"nodeSummary,omitempty"` + AllocatedResources AllocatedResources `json:"allocatedResources"` } -// ClusterList contains a list of clusters. -type ClusterList struct { +// List contains a list of clusters. +type List struct { ListMeta types.ListMeta `json:"listMeta"` Clusters []Cluster `json:"clusters"` // List of non-critical errors, that occurred during resource retrieval. @@ -50,7 +50,7 @@ type ClusterList struct { } // GetClusterList returns a list of all Nodes in the cluster. -func GetClusterList(client karmadaclientset.Interface, dsQuery *dataselect.DataSelectQuery) (*ClusterList, error) { +func GetClusterList(client karmadaclientset.Interface, dsQuery *dataselect.Query) (*List, error) { clusters, err := client.ClusterV1alpha1().Clusters().List(context.TODO(), helpers.ListEverything) nonCriticalErrors, criticalError := errors.ExtractErrors(err) if criticalError != nil { @@ -59,8 +59,8 @@ func GetClusterList(client karmadaclientset.Interface, dsQuery *dataselect.DataS return toClusterList(client, clusters.Items, nonCriticalErrors, dsQuery), nil } -func toClusterList(_ karmadaclientset.Interface, clusters []v1alpha1.Cluster, nonCriticalErrors []error, dsQuery *dataselect.DataSelectQuery) *ClusterList { - clusterList := &ClusterList{ +func toClusterList(_ karmadaclientset.Interface, clusters []v1alpha1.Cluster, nonCriticalErrors []error, dsQuery *dataselect.Query) *List { + clusterList := &List{ Clusters: make([]Cluster, 0), ListMeta: types.ListMeta{TotalItems: len(clusters)}, Errors: nonCriticalErrors, @@ -78,7 +78,7 @@ func toClusterList(_ karmadaclientset.Interface, clusters []v1alpha1.Cluster, no } func toCluster(cluster *v1alpha1.Cluster) Cluster { - allocatedResources, err := getclusterAllocatedResources(cluster) + allocatedResources, err := getAllocatedResources(cluster) if err != nil { log.Printf("Couldn't get allocated resources of %s cluster: %s\n", cluster.Name, err) } diff --git a/pkg/resource/cluster/common.go b/pkg/resource/cluster/common.go index 954742e2..f6f6bf35 100644 --- a/pkg/resource/cluster/common.go +++ b/pkg/resource/cluster/common.go @@ -22,11 +22,11 @@ import ( "github.com/karmada-io/dashboard/pkg/dataselect" ) -// ClusterCell is a cell representation of Cluster object. -type ClusterCell v1alpha1.Cluster +// Cell is a cell representation of Cluster object. +type Cell v1alpha1.Cluster // GetProperty returns value of a given property. -func (c ClusterCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { +func (c Cell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: return dataselect.StdComparableString(c.ObjectMeta.Name) @@ -43,7 +43,7 @@ func (c ClusterCell) GetProperty(name dataselect.PropertyName) dataselect.Compar func toCells(std []v1alpha1.Cluster) []dataselect.DataCell { cells := make([]dataselect.DataCell, len(std)) for i := range std { - cells[i] = ClusterCell(std[i]) + cells[i] = Cell(std[i]) } return cells } @@ -51,7 +51,7 @@ func toCells(std []v1alpha1.Cluster) []dataselect.DataCell { func fromCells(cells []dataselect.DataCell) []v1alpha1.Cluster { std := make([]v1alpha1.Cluster, len(cells)) for i := range std { - std[i] = v1alpha1.Cluster(cells[i].(ClusterCell)) + std[i] = v1alpha1.Cluster(cells[i].(Cell)) } return std } diff --git a/pkg/resource/cluster/detail.go b/pkg/resource/cluster/detail.go index 359ff458..c83a6ae6 100644 --- a/pkg/resource/cluster/detail.go +++ b/pkg/resource/cluster/detail.go @@ -28,8 +28,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// ClusterAllocatedResources is the resource summary of a cluster. -type ClusterAllocatedResources struct { +// AllocatedResources is the resource summary of a cluster. +type AllocatedResources struct { // CPUCapacity is specified node CPU capacity in milicores. CPUCapacity int64 `json:"cpuCapacity"` CPUFraction float64 `json:"cpuFraction"` @@ -48,9 +48,9 @@ type ClusterAllocatedResources struct { PodFraction float64 `json:"podFraction"` } -func getclusterAllocatedResources(cluster *v1alpha1.Cluster) (ClusterAllocatedResources, error) { +func getAllocatedResources(cluster *v1alpha1.Cluster) (AllocatedResources, error) { if cluster.Status.ResourceSummary == nil { - return ClusterAllocatedResources{}, nil + return AllocatedResources{}, nil } allocatableCPU := cluster.Status.ResourceSummary.Allocatable.Cpu() allocatedCPU := cluster.Status.ResourceSummary.Allocated.Cpu() @@ -78,7 +78,7 @@ func getclusterAllocatedResources(cluster *v1alpha1.Cluster) (ClusterAllocatedRe if podCapacity > 0 { podFraction = float64(allocatedPod.Value()) / float64(podCapacity) * 100 } - return ClusterAllocatedResources{ + return AllocatedResources{ CPUCapacity: allocatableCPU.Value(), CPUFraction: cpuFraction, MemoryCapacity: allocatedMemory.Value(), @@ -89,20 +89,20 @@ func getclusterAllocatedResources(cluster *v1alpha1.Cluster) (ClusterAllocatedRe }, nil } -// ClusterDetail is the detailed information of a cluster. -type ClusterDetail struct { +// Detail is the detailed information of a cluster. +type Detail struct { Cluster `json:",inline"` Taints []corev1.Taint `json:"taints,omitempty"` } // GetClusterDetail gets details of cluster. -func GetClusterDetail(client karmadaclientset.Interface, clusterName string) (*ClusterDetail, error) { +func GetClusterDetail(client karmadaclientset.Interface, clusterName string) (*Detail, error) { log.Printf("Getting details of %s cluster", clusterName) cluster, err := client.ClusterV1alpha1().Clusters().Get(context.TODO(), clusterName, metav1.GetOptions{}) if err != nil { return nil, err } - return &ClusterDetail{ + return &Detail{ Cluster: toCluster(cluster), Taints: cluster.Spec.Taints, }, nil diff --git a/pkg/resource/clusteroverridepolicy/common.go b/pkg/resource/clusteroverridepolicy/common.go index 154c2919..5fbcf03d 100644 --- a/pkg/resource/clusteroverridepolicy/common.go +++ b/pkg/resource/clusteroverridepolicy/common.go @@ -22,11 +22,11 @@ import ( "github.com/karmada-io/dashboard/pkg/dataselect" ) -// ClusterOverridePolicyCell wraps v1alpha1.ClusterOverridePolicy for data selection. -type ClusterOverridePolicyCell v1alpha1.ClusterOverridePolicy +// Cell wraps v1alpha1.ClusterOverridePolicy for data selection. +type Cell v1alpha1.ClusterOverridePolicy // GetProperty returns a property of the cluster override policy cell. -func (c ClusterOverridePolicyCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { +func (c Cell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: return dataselect.StdComparableString(c.ObjectMeta.Name) @@ -41,7 +41,7 @@ func (c ClusterOverridePolicyCell) GetProperty(name dataselect.PropertyName) dat func toCells(std []v1alpha1.ClusterOverridePolicy) []dataselect.DataCell { cells := make([]dataselect.DataCell, len(std)) for i := range std { - cells[i] = ClusterOverridePolicyCell(std[i]) + cells[i] = Cell(std[i]) } return cells } @@ -49,7 +49,7 @@ func toCells(std []v1alpha1.ClusterOverridePolicy) []dataselect.DataCell { func fromCells(cells []dataselect.DataCell) []v1alpha1.ClusterOverridePolicy { std := make([]v1alpha1.ClusterOverridePolicy, len(cells)) for i := range std { - std[i] = v1alpha1.ClusterOverridePolicy(cells[i].(ClusterOverridePolicyCell)) + std[i] = v1alpha1.ClusterOverridePolicy(cells[i].(Cell)) } return std } diff --git a/pkg/resource/clusteroverridepolicy/detail.go b/pkg/resource/clusteroverridepolicy/detail.go index 1cf12679..e16c10ed 100644 --- a/pkg/resource/clusteroverridepolicy/detail.go +++ b/pkg/resource/clusteroverridepolicy/detail.go @@ -26,8 +26,8 @@ import ( "github.com/karmada-io/dashboard/pkg/common/errors" ) -// ClusterOverridePolicyDetail contains clusterPropagationPolicy details and non-critical errors. -type ClusterOverridePolicyDetail struct { +// Detail contains clusterPropagationPolicy details and non-critical errors. +type Detail struct { // Extends list item structure. ClusterOverridePolicy `json:",inline"` @@ -36,7 +36,7 @@ type ClusterOverridePolicyDetail struct { } // GetClusterOverridePolicyDetail gets clusterPropagationPolicy details. -func GetClusterOverridePolicyDetail(client karmadaclientset.Interface, name string) (*ClusterOverridePolicyDetail, error) { +func GetClusterOverridePolicyDetail(client karmadaclientset.Interface, name string) (*Detail, error) { overridepolicyData, err := client.PolicyV1alpha1().ClusterOverridePolicies().Get(context.TODO(), name, metaV1.GetOptions{}) if err != nil { return nil, err @@ -51,8 +51,8 @@ func GetClusterOverridePolicyDetail(client karmadaclientset.Interface, name stri return &propagationpolicy, nil } -func toOverridePolicyDetail(clusterOverridepolicy *v1alpha1.ClusterOverridePolicy, nonCriticalErrors []error) ClusterOverridePolicyDetail { - return ClusterOverridePolicyDetail{ +func toOverridePolicyDetail(clusterOverridepolicy *v1alpha1.ClusterOverridePolicy, nonCriticalErrors []error) Detail { + return Detail{ ClusterOverridePolicy: toClusterOverridePolicy(clusterOverridepolicy), Errors: nonCriticalErrors, } diff --git a/pkg/resource/clusteroverridepolicy/list.go b/pkg/resource/clusteroverridepolicy/list.go index 7eb50334..d0a0916f 100644 --- a/pkg/resource/clusteroverridepolicy/list.go +++ b/pkg/resource/clusteroverridepolicy/list.go @@ -28,8 +28,8 @@ import ( "github.com/karmada-io/dashboard/pkg/dataselect" ) -// ClusterOverridePolicyList contains a list of overriders in the karmada control-plane. -type ClusterOverridePolicyList struct { +// List contains a list of overriders in the karmada control-plane. +type List struct { ListMeta types.ListMeta `json:"listMeta"` // Unordered list of clusterOverridePolicies. @@ -49,7 +49,7 @@ type ClusterOverridePolicy struct { } // GetClusterOverridePolicyList returns a list of all overiders in the karmada control-plance. -func GetClusterOverridePolicyList(client karmadaclientset.Interface, dsQuery *dataselect.DataSelectQuery) (*ClusterOverridePolicyList, error) { +func GetClusterOverridePolicyList(client karmadaclientset.Interface, dsQuery *dataselect.Query) (*List, error) { clusterOverridePolicies, err := client.PolicyV1alpha1().ClusterOverridePolicies().List(context.TODO(), helpers.ListEverything) nonCriticalErrors, criticalError := errors.ExtractErrors(err) if criticalError != nil { @@ -59,8 +59,8 @@ func GetClusterOverridePolicyList(client karmadaclientset.Interface, dsQuery *da return toClusterOverridePolicyList(clusterOverridePolicies.Items, nonCriticalErrors, dsQuery), nil } -func toClusterOverridePolicyList(clusterOverridePolicies []v1alpha1.ClusterOverridePolicy, nonCriticalErrors []error, dsQuery *dataselect.DataSelectQuery) *ClusterOverridePolicyList { - overridepolicyList := &ClusterOverridePolicyList{ +func toClusterOverridePolicyList(clusterOverridePolicies []v1alpha1.ClusterOverridePolicy, nonCriticalErrors []error, dsQuery *dataselect.Query) *List { + overridepolicyList := &List{ ClusterOverridePolicies: make([]ClusterOverridePolicy, 0), ListMeta: types.ListMeta{TotalItems: len(clusterOverridePolicies)}, } diff --git a/pkg/resource/clusterpropagationpolicy/common.go b/pkg/resource/clusterpropagationpolicy/common.go index 53de069f..7e16bd91 100644 --- a/pkg/resource/clusterpropagationpolicy/common.go +++ b/pkg/resource/clusterpropagationpolicy/common.go @@ -22,11 +22,11 @@ import ( "github.com/karmada-io/dashboard/pkg/dataselect" ) -// ClusterPropagationPolicyCell wraps v1alpha1.ClusterPropagationPolicy for data selection. -type ClusterPropagationPolicyCell v1alpha1.ClusterPropagationPolicy +// Cell wraps v1alpha1.ClusterPropagationPolicy for data selection. +type Cell v1alpha1.ClusterPropagationPolicy // GetProperty returns a property of the cluster propagation policy cell. -func (c ClusterPropagationPolicyCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { +func (c Cell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: return dataselect.StdComparableString(c.ObjectMeta.Name) @@ -41,7 +41,7 @@ func (c ClusterPropagationPolicyCell) GetProperty(name dataselect.PropertyName) func toCells(std []v1alpha1.ClusterPropagationPolicy) []dataselect.DataCell { cells := make([]dataselect.DataCell, len(std)) for i := range std { - cells[i] = ClusterPropagationPolicyCell(std[i]) + cells[i] = Cell(std[i]) } return cells } @@ -49,7 +49,7 @@ func toCells(std []v1alpha1.ClusterPropagationPolicy) []dataselect.DataCell { func fromCells(cells []dataselect.DataCell) []v1alpha1.ClusterPropagationPolicy { std := make([]v1alpha1.ClusterPropagationPolicy, len(cells)) for i := range std { - std[i] = v1alpha1.ClusterPropagationPolicy(cells[i].(ClusterPropagationPolicyCell)) + std[i] = v1alpha1.ClusterPropagationPolicy(cells[i].(Cell)) } return std } diff --git a/pkg/resource/clusterpropagationpolicy/detail.go b/pkg/resource/clusterpropagationpolicy/detail.go index d3efc90e..ebca21f7 100644 --- a/pkg/resource/clusterpropagationpolicy/detail.go +++ b/pkg/resource/clusterpropagationpolicy/detail.go @@ -26,8 +26,8 @@ import ( "github.com/karmada-io/dashboard/pkg/common/errors" ) -// ClusterPropagationPolicyDetail contains clusterPropagationPolicy details. -type ClusterPropagationPolicyDetail struct { +// Detail contains clusterPropagationPolicy details. +type Detail struct { // Extends list item structure. ClusterPropagationPolicy `json:",inline"` @@ -36,7 +36,7 @@ type ClusterPropagationPolicyDetail struct { } // GetClusterPropagationPolicyDetail gets clusterPropagationPolicy details. -func GetClusterPropagationPolicyDetail(client karmadaclientset.Interface, name string) (*ClusterPropagationPolicyDetail, error) { +func GetClusterPropagationPolicyDetail(client karmadaclientset.Interface, name string) (*Detail, error) { propagationpolicyData, err := client.PolicyV1alpha1().ClusterPropagationPolicies().Get(context.TODO(), name, metaV1.GetOptions{}) if err != nil { return nil, err @@ -51,8 +51,8 @@ func GetClusterPropagationPolicyDetail(client karmadaclientset.Interface, name s return &propagationpolicy, nil } -func toPropagationPolicyDetail(clusterPropagationpolicy *v1alpha1.ClusterPropagationPolicy, nonCriticalErrors []error) ClusterPropagationPolicyDetail { - return ClusterPropagationPolicyDetail{ +func toPropagationPolicyDetail(clusterPropagationpolicy *v1alpha1.ClusterPropagationPolicy, nonCriticalErrors []error) Detail { + return Detail{ ClusterPropagationPolicy: toClusterPropagationPolicy(clusterPropagationpolicy), Errors: nonCriticalErrors, } diff --git a/pkg/resource/clusterpropagationpolicy/list.go b/pkg/resource/clusterpropagationpolicy/list.go index 71a33fb9..7488cf67 100644 --- a/pkg/resource/clusterpropagationpolicy/list.go +++ b/pkg/resource/clusterpropagationpolicy/list.go @@ -28,8 +28,8 @@ import ( "github.com/karmada-io/dashboard/pkg/dataselect" ) -// ClusterPropagationPolicyList contains a list of propagation in the karmada control-plane. -type ClusterPropagationPolicyList struct { +// List contains a list of propagation in the karmada control-plane. +type List struct { ListMeta types.ListMeta `json:"listMeta"` // Unordered list of PropagationPolicies. @@ -49,7 +49,7 @@ type ClusterPropagationPolicy struct { } // GetClusterPropagationPolicyList returns a list of all propagations in the karmada control-plance. -func GetClusterPropagationPolicyList(client karmadaclientset.Interface, dsQuery *dataselect.DataSelectQuery) (*ClusterPropagationPolicyList, error) { +func GetClusterPropagationPolicyList(client karmadaclientset.Interface, dsQuery *dataselect.Query) (*List, error) { clusterPropagationPolicies, err := client.PolicyV1alpha1().ClusterPropagationPolicies().List(context.TODO(), helpers.ListEverything) nonCriticalErrors, criticalError := errors.ExtractErrors(err) if criticalError != nil { @@ -59,8 +59,8 @@ func GetClusterPropagationPolicyList(client karmadaclientset.Interface, dsQuery return toClusterPropagationPolicyList(clusterPropagationPolicies.Items, nonCriticalErrors, dsQuery), nil } -func toClusterPropagationPolicyList(clusterPropagationPolicies []v1alpha1.ClusterPropagationPolicy, nonCriticalErrors []error, dsQuery *dataselect.DataSelectQuery) *ClusterPropagationPolicyList { - propagationpolicyList := &ClusterPropagationPolicyList{ +func toClusterPropagationPolicyList(clusterPropagationPolicies []v1alpha1.ClusterPropagationPolicy, nonCriticalErrors []error, dsQuery *dataselect.Query) *List { + propagationpolicyList := &List{ ClusterPropagationPolicies: make([]ClusterPropagationPolicy, 0), ListMeta: types.ListMeta{TotalItems: len(clusterPropagationPolicies)}, } diff --git a/pkg/resource/configmap/common.go b/pkg/resource/configmap/common.go index 17aad750..289acf2c 100644 --- a/pkg/resource/configmap/common.go +++ b/pkg/resource/configmap/common.go @@ -24,11 +24,11 @@ import ( // The code below allows to perform complex data section on []api.ConfigMap -// ConfigMapCell wraps api.ConfigMap for data selection. -type ConfigMapCell api.ConfigMap +// Cell wraps api.ConfigMap for data selection. +type Cell api.ConfigMap // GetProperty returns a property. -func (c ConfigMapCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { +func (c Cell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: return dataselect.StdComparableString(c.ObjectMeta.Name) @@ -45,7 +45,7 @@ func (c ConfigMapCell) GetProperty(name dataselect.PropertyName) dataselect.Comp func toCells(std []api.ConfigMap) []dataselect.DataCell { cells := make([]dataselect.DataCell, len(std)) for i := range std { - cells[i] = ConfigMapCell(std[i]) + cells[i] = Cell(std[i]) } return cells } @@ -53,7 +53,7 @@ func toCells(std []api.ConfigMap) []dataselect.DataCell { func fromCells(cells []dataselect.DataCell) []api.ConfigMap { std := make([]api.ConfigMap, len(cells)) for i := range std { - std[i] = api.ConfigMap(cells[i].(ConfigMapCell)) + std[i] = api.ConfigMap(cells[i].(Cell)) } return std } diff --git a/pkg/resource/configmap/detail.go b/pkg/resource/configmap/detail.go index c765c37d..616fc521 100644 --- a/pkg/resource/configmap/detail.go +++ b/pkg/resource/configmap/detail.go @@ -25,9 +25,9 @@ import ( "k8s.io/client-go/kubernetes" ) -// ConfigMapDetail API resource provides mechanisms to inject containers with configuration data while keeping +// Detail API resource provides mechanisms to inject containers with configuration data while keeping // containers agnostic of Kubernetes -type ConfigMapDetail struct { +type Detail struct { // Extends list item structure. ConfigMap `json:",inline"` @@ -37,7 +37,7 @@ type ConfigMapDetail struct { } // GetConfigMapDetail returns detailed information about a config map -func GetConfigMapDetail(client kubernetes.Interface, namespace, name string) (*ConfigMapDetail, error) { +func GetConfigMapDetail(client kubernetes.Interface, namespace, name string) (*Detail, error) { log.Printf("Getting details of %s config map in %s namespace", name, namespace) rawConfigMap, err := client.CoreV1().ConfigMaps(namespace).Get(context.TODO(), name, metaV1.GetOptions{}) @@ -49,8 +49,8 @@ func GetConfigMapDetail(client kubernetes.Interface, namespace, name string) (*C return getConfigMapDetail(rawConfigMap), nil } -func getConfigMapDetail(rawConfigMap *v1.ConfigMap) *ConfigMapDetail { - return &ConfigMapDetail{ +func getConfigMapDetail(rawConfigMap *v1.ConfigMap) *Detail { + return &Detail{ ConfigMap: toConfigMap(rawConfigMap.ObjectMeta), Data: rawConfigMap.Data, } diff --git a/pkg/resource/configmap/detail_test.go b/pkg/resource/configmap/detail_test.go index 5ad3da44..0d0337eb 100644 --- a/pkg/resource/configmap/detail_test.go +++ b/pkg/resource/configmap/detail_test.go @@ -29,13 +29,13 @@ import ( func TestGetConfigMapDetail(t *testing.T) { cases := []struct { configMaps *v1.ConfigMap - expected *ConfigMapDetail + expected *Detail }{ { &v1.ConfigMap{ Data: map[string]string{"app": "my-name"}, ObjectMeta: metaV1.ObjectMeta{Name: "foo"}, }, - &ConfigMapDetail{ + &Detail{ ConfigMap: ConfigMap{ TypeMeta: types.TypeMeta{Kind: "configmap"}, ObjectMeta: types.ObjectMeta{Name: "foo"}, diff --git a/pkg/resource/configmap/list.go b/pkg/resource/configmap/list.go index 3b90f8f9..aa71ef4c 100644 --- a/pkg/resource/configmap/list.go +++ b/pkg/resource/configmap/list.go @@ -29,8 +29,8 @@ import ( "github.com/karmada-io/dashboard/pkg/resource/common" ) -// ConfigMapList contains a list of Config Maps in the cluster. -type ConfigMapList struct { +// List contains a list of Config Maps in the cluster. +type List struct { ListMeta types.ListMeta `json:"listMeta"` // Unordered list of Config Maps @@ -48,7 +48,7 @@ type ConfigMap struct { } // GetConfigMapList returns a list of all ConfigMaps in the cluster. -func GetConfigMapList(client kubernetes.Interface, nsQuery *common.NamespaceQuery, dsQuery *dataselect.DataSelectQuery) (*ConfigMapList, error) { +func GetConfigMapList(client kubernetes.Interface, nsQuery *common.NamespaceQuery, dsQuery *dataselect.Query) (*List, error) { log.Printf("Getting list config maps in the namespace %s", nsQuery.ToRequestParam()) channels := &common.ResourceChannels{ ConfigMapList: common.GetConfigMapListChannel(client, nsQuery, 1), @@ -58,7 +58,7 @@ func GetConfigMapList(client kubernetes.Interface, nsQuery *common.NamespaceQuer } // GetConfigMapListFromChannels returns a list of all Config Maps in the cluster reading required resource list once from the channels. -func GetConfigMapListFromChannels(channels *common.ResourceChannels, dsQuery *dataselect.DataSelectQuery) (*ConfigMapList, error) { +func GetConfigMapListFromChannels(channels *common.ResourceChannels, dsQuery *dataselect.Query) (*List, error) { configMaps := <-channels.ConfigMapList.List err := <-channels.ConfigMapList.Error nonCriticalErrors, criticalError := errors.ExtractErrors(err) @@ -78,8 +78,8 @@ func toConfigMap(meta metaV1.ObjectMeta) ConfigMap { } } -func toConfigMapList(configMaps []v1.ConfigMap, nonCriticalErrors []error, dsQuery *dataselect.DataSelectQuery) *ConfigMapList { - result := &ConfigMapList{ +func toConfigMapList(configMaps []v1.ConfigMap, nonCriticalErrors []error, dsQuery *dataselect.Query) *List { + result := &List{ Items: make([]ConfigMap, 0), ListMeta: types.ListMeta{TotalItems: len(configMaps)}, Errors: nonCriticalErrors, diff --git a/pkg/resource/configmap/list_test.go b/pkg/resource/configmap/list_test.go index fae5548c..1c00e248 100644 --- a/pkg/resource/configmap/list_test.go +++ b/pkg/resource/configmap/list_test.go @@ -28,14 +28,14 @@ import ( func TestToConfigMapList(t *testing.T) { cases := []struct { configMaps []v1.ConfigMap - expected *ConfigMapList + expected *List }{ - {nil, &ConfigMapList{Items: []ConfigMap{}}}, + {nil, &List{Items: []ConfigMap{}}}, { []v1.ConfigMap{ {Data: map[string]string{"app": "my-name"}, ObjectMeta: metaV1.ObjectMeta{Name: "foo"}}, }, - &ConfigMapList{ + &List{ ListMeta: types.ListMeta{TotalItems: 1}, Items: []ConfigMap{{ TypeMeta: types.TypeMeta{Kind: "configmap"}, diff --git a/pkg/resource/cronjob/common.go b/pkg/resource/cronjob/common.go index 373ac218..56fe67c1 100644 --- a/pkg/resource/cronjob/common.go +++ b/pkg/resource/cronjob/common.go @@ -25,11 +25,11 @@ import ( // The code below allows to perform complex data section on []batch.CronJob -// CronJobCell is a type containing CronJob data -type CronJobCell batch.CronJob +// Cell is a type containing CronJob data +type Cell batch.CronJob -// GetProperty returns specific property of CronJobCell -func (c CronJobCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { +// GetProperty returns specific property of Cell +func (c Cell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: return dataselect.StdComparableString(c.ObjectMeta.Name) @@ -43,20 +43,20 @@ func (c CronJobCell) GetProperty(name dataselect.PropertyName) dataselect.Compar } } -// ToCells converts []batch.CronJob to []CronJobCell +// ToCells converts []batch.CronJob to []Cell func ToCells(std []batch.CronJob) []dataselect.DataCell { cells := make([]dataselect.DataCell, len(std)) for i := range std { - cells[i] = CronJobCell(std[i]) + cells[i] = Cell(std[i]) } return cells } -// FromCells converts []CronJobCell to []batch.CronJob +// FromCells converts []Cell to []batch.CronJob func FromCells(cells []dataselect.DataCell) []batch.CronJob { std := make([]batch.CronJob, len(cells)) for i := range std { - std[i] = batch.CronJob(cells[i].(CronJobCell)) + std[i] = batch.CronJob(cells[i].(Cell)) } return std } diff --git a/pkg/resource/cronjob/detail.go b/pkg/resource/cronjob/detail.go index 451bcc36..8d610027 100644 --- a/pkg/resource/cronjob/detail.go +++ b/pkg/resource/cronjob/detail.go @@ -24,8 +24,8 @@ import ( k8sClient "k8s.io/client-go/kubernetes" ) -// CronJobDetail contains Cron Job details. -type CronJobDetail struct { +// Detail contains Cron Job details. +type Detail struct { // Extends list item structure. CronJob `json:",inline"` @@ -37,7 +37,7 @@ type CronJobDetail struct { } // GetCronJobDetail gets Cron Job details. -func GetCronJobDetail(client k8sClient.Interface, namespace, name string) (*CronJobDetail, error) { +func GetCronJobDetail(client k8sClient.Interface, namespace, name string) (*Detail, error) { rawObject, err := client.BatchV1().CronJobs(namespace).Get(context.TODO(), name, metaV1.GetOptions{}) if err != nil { return nil, err @@ -47,8 +47,8 @@ func GetCronJobDetail(client k8sClient.Interface, namespace, name string) (*Cron return &cj, nil } -func toCronJobDetail(cj *batch.CronJob) CronJobDetail { - return CronJobDetail{ +func toCronJobDetail(cj *batch.CronJob) Detail { + return Detail{ CronJob: toCronJob(cj), ConcurrencyPolicy: string(cj.Spec.ConcurrencyPolicy), StartingDeadLineSeconds: cj.Spec.StartingDeadlineSeconds, diff --git a/pkg/resource/cronjob/events.go b/pkg/resource/cronjob/events.go index c51e4e53..9a299ee2 100644 --- a/pkg/resource/cronjob/events.go +++ b/pkg/resource/cronjob/events.go @@ -25,7 +25,7 @@ import ( ) // GetCronJobEvents gets events associated to cron job. -func GetCronJobEvents(client client.Interface, dsQuery *dataselect.DataSelectQuery, namespace, name string) ( +func GetCronJobEvents(client client.Interface, dsQuery *dataselect.Query, namespace, name string) ( *common.EventList, error) { raw, err := event.GetEvents(client, namespace, name) if err != nil { diff --git a/pkg/resource/cronjob/jobs.go b/pkg/resource/cronjob/jobs.go index 1dd8d19d..3e3f4208 100644 --- a/pkg/resource/cronjob/jobs.go +++ b/pkg/resource/cronjob/jobs.go @@ -39,7 +39,7 @@ const ( CronJobKindName = "cronjob" ) -var emptyJobList = &job.JobList{ +var emptyJobList = &job.List{ Jobs: make([]job.Job, 0), Errors: make([]error, 0), ListMeta: types.ListMeta{ @@ -49,7 +49,7 @@ var emptyJobList = &job.JobList{ // GetCronJobJobs returns list of jobs owned by cron job. func GetCronJobJobs(client client.Interface, - dsQuery *dataselect.DataSelectQuery, namespace, name string, active bool) (*job.JobList, error) { + dsQuery *dataselect.Query, namespace, name string, active bool) (*job.List, error) { cronJob, err := client.BatchV1().CronJobs(namespace).Get(context.TODO(), name, meta.GetOptions{}) if err != nil { return emptyJobList, err diff --git a/pkg/resource/cronjob/list.go b/pkg/resource/cronjob/list.go index 01f1d4ae..9b889d8c 100644 --- a/pkg/resource/cronjob/list.go +++ b/pkg/resource/cronjob/list.go @@ -29,8 +29,8 @@ import ( "github.com/karmada-io/dashboard/pkg/resource/common" ) -// CronJobList contains a list of CronJobs in the cluster. -type CronJobList struct { +// List contains a list of CronJobs in the cluster. +type List struct { ListMeta types.ListMeta `json:"listMeta"` Items []CronJob `json:"items"` @@ -56,7 +56,7 @@ type CronJob struct { // GetCronJobList returns a list of all CronJobs in the cluster. func GetCronJobList(client client.Interface, nsQuery *common.NamespaceQuery, - dsQuery *dataselect.DataSelectQuery) (*CronJobList, error) { + dsQuery *dataselect.Query) (*List, error) { log.Print("Getting list of all cron jobs in the cluster") channels := &common.ResourceChannels{ @@ -68,7 +68,7 @@ func GetCronJobList(client client.Interface, nsQuery *common.NamespaceQuery, // GetCronJobListFromChannels returns a list of all CronJobs in the cluster reading required resource // list once from the channels. -func GetCronJobListFromChannels(channels *common.ResourceChannels, dsQuery *dataselect.DataSelectQuery) (*CronJobList, error) { +func GetCronJobListFromChannels(channels *common.ResourceChannels, dsQuery *dataselect.Query) (*List, error) { cronJobs := <-channels.CronJobList.List err := <-channels.CronJobList.Error nonCriticalErrors, criticalError := errors.ExtractErrors(err) @@ -81,8 +81,8 @@ func GetCronJobListFromChannels(channels *common.ResourceChannels, dsQuery *data return cronJobList, nil } -func toCronJobList(cronJobs []batch.CronJob, nonCriticalErrors []error, dsQuery *dataselect.DataSelectQuery) *CronJobList { - list := &CronJobList{ +func toCronJobList(cronJobs []batch.CronJob, nonCriticalErrors []error, dsQuery *dataselect.Query) *List { + list := &List{ Items: make([]CronJob, 0), ListMeta: types.ListMeta{TotalItems: len(cronJobs)}, Errors: nonCriticalErrors, diff --git a/pkg/resource/daemonset/common.go b/pkg/resource/daemonset/common.go index 561de54c..3ef8e71e 100644 --- a/pkg/resource/daemonset/common.go +++ b/pkg/resource/daemonset/common.go @@ -64,11 +64,11 @@ 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 +// Cell is a type alias for the DaemonSet type from the apps/v1 API. +type Cell apps.DaemonSet // GetProperty returns a comparable value for a specified property name. -func (c DaemonSetCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { +func (c Cell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: return dataselect.StdComparableString(c.ObjectMeta.Name) @@ -86,7 +86,7 @@ func (c DaemonSetCell) GetProperty(name dataselect.PropertyName) dataselect.Comp func ToCells(std []apps.DaemonSet) []dataselect.DataCell { cells := make([]dataselect.DataCell, len(std)) for i := range std { - cells[i] = DaemonSetCell(std[i]) + cells[i] = Cell(std[i]) } return cells } @@ -95,7 +95,7 @@ func ToCells(std []apps.DaemonSet) []dataselect.DataCell { func FromCells(cells []dataselect.DataCell) []apps.DaemonSet { std := make([]apps.DaemonSet, len(cells)) for i := range std { - std[i] = apps.DaemonSet(cells[i].(DaemonSetCell)) + std[i] = apps.DaemonSet(cells[i].(Cell)) } return std } diff --git a/pkg/resource/daemonset/detail.go b/pkg/resource/daemonset/detail.go index 18b4ae30..3b561879 100644 --- a/pkg/resource/daemonset/detail.go +++ b/pkg/resource/daemonset/detail.go @@ -26,8 +26,8 @@ import ( "github.com/karmada-io/dashboard/pkg/resource/common" ) -// DaemonSetDetail represents detailed information about a Daemon Set. -type DaemonSetDetail struct { +// Detail represents detailed information about a Daemon Set. +type Detail struct { // Extends list item structure. DaemonSet `json:",inline"` @@ -38,7 +38,7 @@ type DaemonSetDetail struct { } // GetDaemonSetDetail Returns detailed information about the given daemon set in the given namespace. -func GetDaemonSetDetail(client k8sClient.Interface, namespace, name string) (*DaemonSetDetail, error) { +func GetDaemonSetDetail(client k8sClient.Interface, namespace, name string) (*Detail, error) { log.Printf("Getting details of %s daemon set in %s namespace", name, namespace) daemonSet, err := client.AppsV1().DaemonSets(namespace).Get(context.TODO(), name, metaV1.GetOptions{}) if err != nil { @@ -60,7 +60,7 @@ func GetDaemonSetDetail(client k8sClient.Interface, namespace, name string) (*Da return nil, err } - return &DaemonSetDetail{ + return &Detail{ DaemonSet: toDaemonSet(*daemonSet, podList.Items, eventList.Items), LabelSelector: daemonSet.Spec.Selector, Errors: []error{}, diff --git a/pkg/resource/daemonset/list.go b/pkg/resource/daemonset/list.go index ea3fb4d5..cfac8ebd 100644 --- a/pkg/resource/daemonset/list.go +++ b/pkg/resource/daemonset/list.go @@ -28,8 +28,8 @@ import ( "github.com/karmada-io/dashboard/pkg/resource/event" ) -// DaemonSetList contains a list of Daemon Sets in the cluster. -type DaemonSetList struct { +// List contains a list of Daemon Sets in the cluster. +type List struct { ListMeta types.ListMeta `json:"listMeta"` DaemonSets []DaemonSet `json:"daemonSets"` Status common.ResourceStatus `json:"status"` @@ -48,7 +48,7 @@ type DaemonSet struct { } // GetDaemonSetList returns a list of all Daemon Set in the cluster. -func GetDaemonSetList(client kubernetes.Interface, nsQuery *common.NamespaceQuery, dsQuery *dataselect.DataSelectQuery) (*DaemonSetList, error) { +func GetDaemonSetList(client kubernetes.Interface, nsQuery *common.NamespaceQuery, dsQuery *dataselect.Query) (*List, error) { channels := &common.ResourceChannels{ DaemonSetList: common.GetDaemonSetListChannel(client, nsQuery, 1), ServiceList: common.GetServiceListChannel(client, nsQuery, 1), @@ -61,7 +61,7 @@ func GetDaemonSetList(client kubernetes.Interface, nsQuery *common.NamespaceQuer // GetDaemonSetListFromChannels returns a list of all Daemon Set in the cluster // reading required resource list once from the channels. -func GetDaemonSetListFromChannels(channels *common.ResourceChannels, dsQuery *dataselect.DataSelectQuery) (*DaemonSetList, error) { +func GetDaemonSetListFromChannels(channels *common.ResourceChannels, dsQuery *dataselect.Query) (*List, error) { daemonSets := <-channels.DaemonSetList.List err := <-channels.DaemonSetList.Error nonCriticalErrors, criticalError := errors.ExtractErrors(err) @@ -89,8 +89,8 @@ func GetDaemonSetListFromChannels(channels *common.ResourceChannels, dsQuery *da } func toDaemonSetList(daemonSets []apps.DaemonSet, pods []v1.Pod, events []v1.Event, nonCriticalErrors []error, - dsQuery *dataselect.DataSelectQuery) *DaemonSetList { - daemonSetList := &DaemonSetList{ + dsQuery *dataselect.Query) *List { + daemonSetList := &List{ DaemonSets: make([]DaemonSet, 0), ListMeta: types.ListMeta{TotalItems: len(daemonSets)}, Errors: nonCriticalErrors, diff --git a/pkg/resource/deployment/common.go b/pkg/resource/deployment/common.go index 87889441..eb49cf07 100644 --- a/pkg/resource/deployment/common.go +++ b/pkg/resource/deployment/common.go @@ -25,11 +25,11 @@ import ( "github.com/karmada-io/dashboard/pkg/resource/event" ) -// DeploymentCell is a wrapper for the k8s deployment -type DeploymentCell apps.Deployment +// Cell is a wrapper for the k8s deployment +type Cell apps.Deployment // GetProperty is used to get property of the deployment -func (c DeploymentCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { +func (c Cell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: return dataselect.StdComparableString(c.ObjectMeta.Name) @@ -46,7 +46,7 @@ func (c DeploymentCell) GetProperty(name dataselect.PropertyName) dataselect.Com func toCells(std []apps.Deployment) []dataselect.DataCell { cells := make([]dataselect.DataCell, len(std)) for i := range std { - cells[i] = DeploymentCell(std[i]) + cells[i] = Cell(std[i]) } return cells } @@ -54,7 +54,7 @@ func toCells(std []apps.Deployment) []dataselect.DataCell { func fromCells(cells []dataselect.DataCell) []apps.Deployment { std := make([]apps.Deployment, len(cells)) for i := range std { - std[i] = apps.Deployment(cells[i].(DeploymentCell)) + std[i] = apps.Deployment(cells[i].(Cell)) } return std } diff --git a/pkg/resource/deployment/detail.go b/pkg/resource/deployment/detail.go index 6335b5b6..aa6d9a59 100644 --- a/pkg/resource/deployment/detail.go +++ b/pkg/resource/deployment/detail.go @@ -51,8 +51,8 @@ type StatusInfo struct { Unavailable int32 `json:"unavailable"` } -// DeploymentDetail is a presentation layer view of Kubernetes Deployment resource. -type DeploymentDetail struct { +// Detail is a presentation layer view of Kubernetes Deployment resource. +type Detail struct { // Extends list item structure. Deployment `json:",inline"` @@ -83,7 +83,7 @@ type DeploymentDetail struct { } // GetDeploymentDetail returns model object of deployment and error, if any. -func GetDeploymentDetail(client client.Interface, namespace string, deploymentName string) (*DeploymentDetail, error) { +func GetDeploymentDetail(client client.Interface, namespace string, deploymentName string) (*Detail, error) { log.Printf("Getting details of %s deployment in %s namespace", deploymentName, namespace) deployment, err := client.AppsV1().Deployments(namespace).Get(context.TODO(), deploymentName, metaV1.GetOptions{}) @@ -136,7 +136,7 @@ func GetDeploymentDetail(client client.Interface, namespace string, deploymentNa } } - return &DeploymentDetail{ + return &Detail{ Deployment: toDeployment(deployment, rawRs.Items, rawPods.Items, rawEvents.Items), Selector: deployment.Spec.Selector.MatchLabels, StatusInfo: GetStatusInfo(&deployment.Status), diff --git a/pkg/resource/deployment/list.go b/pkg/resource/deployment/list.go index ceadc6d2..625d6fbb 100644 --- a/pkg/resource/deployment/list.go +++ b/pkg/resource/deployment/list.go @@ -30,8 +30,8 @@ import ( "github.com/karmada-io/dashboard/pkg/resource/event" ) -// DeploymentList contains a list of Deployments in the cluster. -type DeploymentList struct { +// List contains a list of Deployments in the cluster. +type List struct { ListMeta types.ListMeta `json:"listMeta"` // Basic information about resources status on the list. @@ -62,7 +62,7 @@ type Deployment struct { } // GetDeploymentList returns a list of all Deployments in the cluster. -func GetDeploymentList(client client.Interface, nsQuery *common.NamespaceQuery, dsQuery *dataselect.DataSelectQuery) (*DeploymentList, error) { +func GetDeploymentList(client client.Interface, nsQuery *common.NamespaceQuery, dsQuery *dataselect.Query) (*List, error) { log.Print("Getting list of all deployments in the cluster") channels := &common.ResourceChannels{ @@ -77,7 +77,7 @@ func GetDeploymentList(client client.Interface, nsQuery *common.NamespaceQuery, // GetDeploymentListFromChannels returns a list of all Deployments in the cluster // reading required resource list once from the channels. -func GetDeploymentListFromChannels(channels *common.ResourceChannels, dsQuery *dataselect.DataSelectQuery) (*DeploymentList, error) { +func GetDeploymentListFromChannels(channels *common.ResourceChannels, dsQuery *dataselect.Query) (*List, error) { deployments := <-channels.DeploymentList.List err := <-channels.DeploymentList.Error nonCriticalErrors, criticalError := errors.ExtractErrors(err) @@ -113,8 +113,8 @@ func GetDeploymentListFromChannels(channels *common.ResourceChannels, dsQuery *d } func toDeploymentList(deployments []apps.Deployment, pods []v1.Pod, events []v1.Event, rs []apps.ReplicaSet, - nonCriticalErrors []error, dsQuery *dataselect.DataSelectQuery) *DeploymentList { - deploymentList := &DeploymentList{ + nonCriticalErrors []error, dsQuery *dataselect.Query) *List { + deploymentList := &List{ Deployments: make([]Deployment, 0), ListMeta: types.ListMeta{TotalItems: len(deployments)}, Errors: nonCriticalErrors, diff --git a/pkg/resource/endpoint/endpoint.go b/pkg/resource/endpoint/endpoint.go index 66df60a0..bc3f931e 100644 --- a/pkg/resource/endpoint/endpoint.go +++ b/pkg/resource/endpoint/endpoint.go @@ -46,8 +46,8 @@ type Endpoint struct { } // GetServiceEndpoints gets list of endpoints targeted by given label selector in given namespace. -func GetServiceEndpoints(client k8sClient.Interface, namespace, name string) (*EndpointList, error) { - endpointList := &EndpointList{ +func GetServiceEndpoints(client k8sClient.Interface, namespace, name string) (*List, error) { + endpointList := &List{ Endpoints: make([]Endpoint, 0), ListMeta: types.ListMeta{TotalItems: 0}, } diff --git a/pkg/resource/endpoint/list.go b/pkg/resource/endpoint/list.go index 791059a0..2d901b2c 100644 --- a/pkg/resource/endpoint/list.go +++ b/pkg/resource/endpoint/list.go @@ -20,16 +20,16 @@ import ( "github.com/karmada-io/dashboard/pkg/common/types" ) -// EndpointList is a list of endpoints in the cluster. -type EndpointList struct { +// List is a list of endpoints in the cluster. +type List struct { ListMeta types.ListMeta `json:"listMeta"` // List of endpoints Endpoints []Endpoint `json:"endpoints"` } // toEndpointList converts array of api events to endpoint List structure -func toEndpointList(endpoints []v1.Endpoints) *EndpointList { - endpointList := EndpointList{ +func toEndpointList(endpoints []v1.Endpoints) *List { + endpointList := List{ Endpoints: make([]Endpoint, 0), ListMeta: types.ListMeta{TotalItems: len(endpoints)}, } diff --git a/pkg/resource/event/common.go b/pkg/resource/event/common.go index 46c7542b..f0ad3ceb 100644 --- a/pkg/resource/event/common.go +++ b/pkg/resource/event/common.go @@ -117,7 +117,7 @@ func ToEvent(event v1.Event) common.Event { } // GetResourceEvents gets events associated to specified resource. -func GetResourceEvents(client kubernetes.Interface, dsQuery *dataselect.DataSelectQuery, namespace, name string) ( +func GetResourceEvents(client kubernetes.Interface, dsQuery *dataselect.Query, namespace, name string) ( *common.EventList, error) { resourceEvents, err := GetEvents(client, namespace, name) nonCriticalErrors, criticalError := errors.ExtractErrors(err) @@ -131,13 +131,13 @@ func GetResourceEvents(client kubernetes.Interface, dsQuery *dataselect.DataSele } // GetNamespaceEvents gets events associated to a namespace with given name. -func GetNamespaceEvents(client kubernetes.Interface, dsQuery *dataselect.DataSelectQuery, namespace string) (common.EventList, error) { +func GetNamespaceEvents(client kubernetes.Interface, dsQuery *dataselect.Query, namespace string) (common.EventList, error) { events, _ := client.CoreV1().Events(namespace).List(context.TODO(), helpers.ListEverything) return CreateEventList(FillEventsType(events.Items), dsQuery), nil } // CreateEventList converts array of api events to common EventList structure -func CreateEventList(events []v1.Event, dsQuery *dataselect.DataSelectQuery) common.EventList { +func CreateEventList(events []v1.Event, dsQuery *dataselect.Query) common.EventList { eventList := common.EventList{ Events: make([]common.Event, 0), ListMeta: types.ListMeta{TotalItems: len(events)}, @@ -154,11 +154,11 @@ 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 +// Cell wraps v1.Event for data selection. +type Cell v1.Event // GetProperty returns a property of the cell. -func (c EventCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { +func (c Cell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: return dataselect.StdComparableString(c.ObjectMeta.Name) @@ -181,7 +181,7 @@ func (c EventCell) GetProperty(name dataselect.PropertyName) dataselect.Comparab func toCells(std []v1.Event) []dataselect.DataCell { cells := make([]dataselect.DataCell, len(std)) for i := range std { - cells[i] = EventCell(std[i]) + cells[i] = Cell(std[i]) } return cells } @@ -189,7 +189,7 @@ func toCells(std []v1.Event) []dataselect.DataCell { func fromCells(cells []dataselect.DataCell) []v1.Event { std := make([]v1.Event, len(cells)) for i := range std { - std[i] = v1.Event(cells[i].(EventCell)) + std[i] = v1.Event(cells[i].(Cell)) } return std } diff --git a/pkg/resource/ingress/common.go b/pkg/resource/ingress/common.go index f5a7468f..0f5dbeb5 100644 --- a/pkg/resource/ingress/common.go +++ b/pkg/resource/ingress/common.go @@ -24,11 +24,11 @@ import ( // The code below allows to perform complex data section on []extensions.Ingress -// IngressCell wraps v1.Ingress for data selection. -type IngressCell v1.Ingress +// Cell wraps v1.Ingress for data selection. +type Cell v1.Ingress // GetProperty returns a property. -func (c IngressCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { +func (c Cell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: return dataselect.StdComparableString(c.ObjectMeta.Name) @@ -45,7 +45,7 @@ func (c IngressCell) GetProperty(name dataselect.PropertyName) dataselect.Compar func toCells(std []v1.Ingress) []dataselect.DataCell { cells := make([]dataselect.DataCell, len(std)) for i := range std { - cells[i] = IngressCell(std[i]) + cells[i] = Cell(std[i]) } return cells } @@ -53,7 +53,7 @@ func toCells(std []v1.Ingress) []dataselect.DataCell { func fromCells(cells []dataselect.DataCell) []v1.Ingress { std := make([]v1.Ingress, len(cells)) for i := range std { - std[i] = v1.Ingress(cells[i].(IngressCell)) + std[i] = v1.Ingress(cells[i].(Cell)) } return std } diff --git a/pkg/resource/ingress/detail.go b/pkg/resource/ingress/detail.go index 67b883e0..f55c105d 100644 --- a/pkg/resource/ingress/detail.go +++ b/pkg/resource/ingress/detail.go @@ -25,9 +25,9 @@ import ( client "k8s.io/client-go/kubernetes" ) -// IngressDetail API resource provides mechanisms to inject containers with configuration data while keeping +// Detail API resource provides mechanisms to inject containers with configuration data while keeping // containers agnostic of Kubernetes -type IngressDetail struct { +type Detail struct { // Extends list item structure. Ingress `json:",inline"` @@ -42,7 +42,7 @@ type IngressDetail struct { } // GetIngressDetail returns detailed information about an ingress -func GetIngressDetail(client client.Interface, namespace, name string) (*IngressDetail, error) { +func GetIngressDetail(client client.Interface, namespace, name string) (*Detail, error) { log.Printf("Getting details of %s ingress in %s namespace", name, namespace) rawIngress, err := client.NetworkingV1().Ingresses(namespace).Get(context.TODO(), name, metaV1.GetOptions{}) @@ -54,8 +54,8 @@ func GetIngressDetail(client client.Interface, namespace, name string) (*Ingress return getIngressDetail(rawIngress), nil } -func getIngressDetail(i *v1.Ingress) *IngressDetail { - return &IngressDetail{ +func getIngressDetail(i *v1.Ingress) *Detail { + return &Detail{ Ingress: toIngress(i), Spec: i.Spec, Status: i.Status, diff --git a/pkg/resource/ingress/list.go b/pkg/resource/ingress/list.go index 1710f35f..cee3d5c8 100644 --- a/pkg/resource/ingress/list.go +++ b/pkg/resource/ingress/list.go @@ -39,8 +39,8 @@ type Ingress struct { Hosts []string `json:"hosts"` } -// IngressList - response structure for a queried ingress list. -type IngressList struct { +// List - response structure for a queried ingress list. +type List struct { types.ListMeta `json:"listMeta"` // Unordered list of Ingresss. @@ -52,7 +52,7 @@ type IngressList struct { // GetIngressList returns all ingresses in the given namespace. func GetIngressList(client client.Interface, namespace *common.NamespaceQuery, - dsQuery *dataselect.DataSelectQuery) (*IngressList, error) { + dsQuery *dataselect.Query) (*List, error) { ingressList, err := client.NetworkingV1().Ingresses(namespace.ToRequestParam()).List(context.TODO(), helpers.ListEverything) nonCriticalErrors, criticalError := errors.ExtractErrors(err) @@ -103,9 +103,9 @@ 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{ +// ToIngressList converts a list of Ingresss to List +func ToIngressList(ingresses []v1.Ingress, nonCriticalErrors []error, dsQuery *dataselect.Query) *List { + newIngressList := &List{ ListMeta: types.ListMeta{TotalItems: len(ingresses)}, Items: make([]Ingress, 0), Errors: nonCriticalErrors, diff --git a/pkg/resource/job/common.go b/pkg/resource/job/common.go index d4c04100..247dae2c 100644 --- a/pkg/resource/job/common.go +++ b/pkg/resource/job/common.go @@ -26,11 +26,11 @@ 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 +// Cell represents a job cell that implements the DataCell interface. +type Cell batch.Job // GetProperty returns a comparable value for a specified property name. -func (c JobCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { +func (c Cell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: return dataselect.StdComparableString(c.ObjectMeta.Name) @@ -48,7 +48,7 @@ func (c JobCell) GetProperty(name dataselect.PropertyName) dataselect.Comparable func ToCells(std []batch.Job) []dataselect.DataCell { cells := make([]dataselect.DataCell, len(std)) for i := range std { - cells[i] = JobCell(std[i]) + cells[i] = Cell(std[i]) } return cells } @@ -57,7 +57,7 @@ func ToCells(std []batch.Job) []dataselect.DataCell { func FromCells(cells []dataselect.DataCell) []batch.Job { std := make([]batch.Job, len(cells)) for i := range std { - std[i] = batch.Job(cells[i].(JobCell)) + std[i] = batch.Job(cells[i].(Cell)) } return std } diff --git a/pkg/resource/job/detail.go b/pkg/resource/job/detail.go index 102aaf2c..47e40c62 100644 --- a/pkg/resource/job/detail.go +++ b/pkg/resource/job/detail.go @@ -27,8 +27,8 @@ import ( "github.com/karmada-io/dashboard/pkg/resource/common" ) -// JobDetail is a presentation layer view of Kubernetes Job resource. -type JobDetail struct { +// Detail is a presentation layer view of Kubernetes Job resource. +type Detail struct { // Extends list item structure. Job `json:",inline"` @@ -40,7 +40,7 @@ type JobDetail struct { } // GetJobDetail gets job details. -func GetJobDetail(client k8sClient.Interface, namespace, name string) (*JobDetail, error) { +func GetJobDetail(client k8sClient.Interface, namespace, name string) (*Detail, error) { jobData, err := client.BatchV1().Jobs(namespace).Get(context.TODO(), name, metaV1.GetOptions{}) if err != nil { return nil, err @@ -56,8 +56,8 @@ func GetJobDetail(client k8sClient.Interface, namespace, name string) (*JobDetai return &job, nil } -func toJobDetail(job *batch.Job, podInfo common.PodInfo, nonCriticalErrors []error) JobDetail { - return JobDetail{ +func toJobDetail(job *batch.Job, podInfo common.PodInfo, nonCriticalErrors []error) Detail { + return Detail{ Job: toJob(job, &podInfo), Completions: job.Spec.Completions, Errors: nonCriticalErrors, diff --git a/pkg/resource/job/events.go b/pkg/resource/job/events.go index 4842d667..57222959 100644 --- a/pkg/resource/job/events.go +++ b/pkg/resource/job/events.go @@ -25,7 +25,7 @@ import ( ) // GetJobEvents gets events associated to job. -func GetJobEvents(client client.Interface, dsQuery *dataselect.DataSelectQuery, namespace, name string) ( +func GetJobEvents(client client.Interface, dsQuery *dataselect.Query, namespace, name string) ( *common.EventList, error) { jobEvents, err := event.GetEvents(client, namespace, name) if err != nil { diff --git a/pkg/resource/job/list.go b/pkg/resource/job/list.go index 6bf13568..5ac509f3 100644 --- a/pkg/resource/job/list.go +++ b/pkg/resource/job/list.go @@ -30,8 +30,8 @@ import ( "github.com/karmada-io/dashboard/pkg/resource/event" ) -// JobList contains a list of Jobs in the cluster. -type JobList struct { +// List contains a list of Jobs in the cluster. +type List struct { ListMeta types.ListMeta `json:"listMeta"` // Basic information about resources status on the list. @@ -44,22 +44,22 @@ type JobList struct { Errors []error `json:"errors"` } -// JobStatusType is a valid value for JobStatus.Status. -type JobStatusType string +// StatusType is a valid value for Status.Status. +type StatusType string const ( // JobStatusRunning means the job is still running. - JobStatusRunning JobStatusType = "Running" + JobStatusRunning StatusType = "Running" // JobStatusComplete means the job has completed its execution. - JobStatusComplete JobStatusType = "Complete" + JobStatusComplete StatusType = "Complete" // JobStatusFailed means the job has failed its execution. - JobStatusFailed JobStatusType = "Failed" + JobStatusFailed StatusType = "Failed" ) -// JobStatus contains inferred job status based on job conditions -type JobStatus struct { +// Status contains inferred job status based on job conditions +type Status struct { // Short, machine understandable job status code. - Status JobStatusType `json:"status"` + Status StatusType `json:"status"` // A human-readable description of the status of related job. Message string `json:"message"` // Conditions describe the state of a job after it finishes. @@ -85,12 +85,12 @@ type Job struct { Parallelism *int32 `json:"parallelism"` // JobStatus contains inferred job status based on job conditions - JobStatus JobStatus `json:"jobStatus"` + JobStatus Status `json:"jobStatus"` } // GetJobList returns a list of all Jobs in the cluster. func GetJobList(client client.Interface, nsQuery *common.NamespaceQuery, - dsQuery *dataselect.DataSelectQuery) (*JobList, error) { + dsQuery *dataselect.Query) (*List, error) { log.Print("Getting list of all jobs in the cluster") channels := &common.ResourceChannels{ @@ -103,7 +103,7 @@ func GetJobList(client client.Interface, nsQuery *common.NamespaceQuery, } // GetJobListFromChannels returns a list of all Jobs in the cluster reading required resource list once from the channels. -func GetJobListFromChannels(channels *common.ResourceChannels, dsQuery *dataselect.DataSelectQuery) (*JobList, error) { +func GetJobListFromChannels(channels *common.ResourceChannels, dsQuery *dataselect.Query) (*List, error) { jobs := <-channels.JobList.List err := <-channels.JobList.Error nonCriticalErrors, criticalError := errors.ExtractErrors(err) @@ -132,8 +132,8 @@ func GetJobListFromChannels(channels *common.ResourceChannels, dsQuery *datasele // 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{ + dsQuery *dataselect.Query) *List { + jobList := &List{ Jobs: make([]Job, 0), ListMeta: types.ListMeta{TotalItems: len(jobs)}, Errors: nonCriticalErrors, @@ -166,8 +166,8 @@ func toJob(job *batch.Job, podInfo *common.PodInfo) Job { } } -func getJobStatus(job *batch.Job) JobStatus { - jobStatus := JobStatus{Status: JobStatusRunning, Conditions: getJobConditions(job)} +func getJobStatus(job *batch.Job) Status { + jobStatus := Status{Status: JobStatusRunning, Conditions: getJobConditions(job)} for _, condition := range job.Status.Conditions { if condition.Type == batch.JobComplete && condition.Status == v1.ConditionTrue { jobStatus.Status = JobStatusComplete diff --git a/pkg/resource/namespace/common.go b/pkg/resource/namespace/common.go index 9a7c44e0..08f2ca0e 100644 --- a/pkg/resource/namespace/common.go +++ b/pkg/resource/namespace/common.go @@ -31,8 +31,8 @@ const ( skipAutoPropagationLable = "namespace.karmada.io/skip-auto-propagation" ) -// NamespaceSpec is a specification of namespace to create. -type NamespaceSpec struct { +// Spec is a specification of namespace to create. +type Spec struct { // Name of the namespace. Name string `json:"name"` // Whether skip auto propagation @@ -40,7 +40,7 @@ type NamespaceSpec struct { } // CreateNamespace creates namespace based on given specification. -func CreateNamespace(spec *NamespaceSpec, client kubernetes.Interface) error { +func CreateNamespace(spec *Spec, client kubernetes.Interface) error { // todo add namespace.karmada.io/skip-auto-propagation: "true" to avoid auto-propagation // https://karmada.io/docs/userguide/bestpractices/namespace-management/#labeling-the-namespace log.Printf("Creating namespace %s", spec.Name) @@ -60,11 +60,11 @@ 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 +// Cell is a cell representation of Namespace object. +type Cell api.Namespace -// GetProperty returns specific property of NamespaceCell. -func (c NamespaceCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { +// GetProperty returns specific property of Cell. +func (c Cell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: return dataselect.StdComparableString(c.ObjectMeta.Name) @@ -81,7 +81,7 @@ func (c NamespaceCell) GetProperty(name dataselect.PropertyName) dataselect.Comp func toCells(std []api.Namespace) []dataselect.DataCell { cells := make([]dataselect.DataCell, len(std)) for i := range std { - cells[i] = NamespaceCell(std[i]) + cells[i] = Cell(std[i]) } return cells } @@ -89,7 +89,7 @@ func toCells(std []api.Namespace) []dataselect.DataCell { func fromCells(cells []dataselect.DataCell) []api.Namespace { std := make([]api.Namespace, len(cells)) for i := range std { - std[i] = api.Namespace(cells[i].(NamespaceCell)) + std[i] = api.Namespace(cells[i].(Cell)) } return std } diff --git a/pkg/resource/namespace/detail.go b/pkg/resource/namespace/detail.go index 3ee80292..7bd85a51 100644 --- a/pkg/resource/namespace/detail.go +++ b/pkg/resource/namespace/detail.go @@ -25,9 +25,9 @@ import ( k8sClient "k8s.io/client-go/kubernetes" ) -// NamespaceDetail is a presentation layer view of Kubernetes Namespace resource. This means it is Namespace plus +// Detail is a presentation layer view of Kubernetes Namespace resource. This means it is Namespace plus // additional augmented data we can get from other sources. -type NamespaceDetail struct { +type Detail struct { // Extends list item structure. Namespace `json:",inline"` @@ -36,7 +36,7 @@ type NamespaceDetail struct { } // GetNamespaceDetail gets namespace details. -func GetNamespaceDetail(client k8sClient.Interface, name string) (*NamespaceDetail, error) { +func GetNamespaceDetail(client k8sClient.Interface, name string) (*Detail, error) { log.Printf("Getting details of %s namespace\n", name) namespace, err := client.CoreV1().Namespaces().Get(context.TODO(), name, metaV1.GetOptions{}) @@ -48,8 +48,8 @@ func GetNamespaceDetail(client k8sClient.Interface, name string) (*NamespaceDeta return &namespaceDetails, nil } -func toNamespaceDetail(namespace v1.Namespace) NamespaceDetail { - return NamespaceDetail{ +func toNamespaceDetail(namespace v1.Namespace) Detail { + return Detail{ Namespace: toNamespace(namespace), } } diff --git a/pkg/resource/namespace/list.go b/pkg/resource/namespace/list.go index 2a667472..64f7012f 100644 --- a/pkg/resource/namespace/list.go +++ b/pkg/resource/namespace/list.go @@ -29,8 +29,8 @@ import ( "github.com/karmada-io/dashboard/pkg/dataselect" ) -// NamespaceList contains a list of namespaces in the cluster. -type NamespaceList struct { +// List contains a list of namespaces in the cluster. +type List struct { ListMeta types.ListMeta `json:"listMeta"` // Unordered list of Namespaces. @@ -52,7 +52,7 @@ type Namespace struct { } // GetNamespaceList returns a list of all namespaces in the cluster. -func GetNamespaceList(client kubernetes.Interface, dsQuery *dataselect.DataSelectQuery) (*NamespaceList, error) { +func GetNamespaceList(client kubernetes.Interface, dsQuery *dataselect.Query) (*List, error) { log.Println("Getting list of namespaces") namespaces, err := client.CoreV1().Namespaces().List(context.TODO(), helpers.ListEverything) @@ -64,8 +64,8 @@ func GetNamespaceList(client kubernetes.Interface, dsQuery *dataselect.DataSelec return toNamespaceList(namespaces.Items, nonCriticalErrors, dsQuery), nil } -func toNamespaceList(namespaces []v1.Namespace, nonCriticalErrors []error, dsQuery *dataselect.DataSelectQuery) *NamespaceList { - namespaceList := &NamespaceList{ +func toNamespaceList(namespaces []v1.Namespace, nonCriticalErrors []error, dsQuery *dataselect.Query) *List { + namespaceList := &List{ Namespaces: make([]Namespace, 0), ListMeta: types.ListMeta{TotalItems: len(namespaces)}, } diff --git a/pkg/resource/node/common.go b/pkg/resource/node/common.go index 99bdce2f..066e1893 100644 --- a/pkg/resource/node/common.go +++ b/pkg/resource/node/common.go @@ -22,11 +22,11 @@ import ( "github.com/karmada-io/dashboard/pkg/dataselect" ) -// NodeCell wraps api.Node for data selection. -type NodeCell api.Node +// Cell wraps api.Node for data selection. +type Cell api.Node // GetProperty returns a property of the cell. -func (c NodeCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { +func (c Cell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: return dataselect.StdComparableString(c.ObjectMeta.Name) @@ -43,7 +43,7 @@ func (c NodeCell) GetProperty(name dataselect.PropertyName) dataselect.Comparabl func toCells(std []api.Node) []dataselect.DataCell { cells := make([]dataselect.DataCell, len(std)) for i := range std { - cells[i] = NodeCell(std[i]) + cells[i] = Cell(std[i]) } return cells } @@ -51,7 +51,7 @@ func toCells(std []api.Node) []dataselect.DataCell { func fromCells(cells []dataselect.DataCell) []api.Node { std := make([]api.Node, len(cells)) for i := range std { - std[i] = api.Node(cells[i].(NodeCell)) + std[i] = api.Node(cells[i].(Cell)) } return std } diff --git a/pkg/resource/node/list.go b/pkg/resource/node/list.go index 73b96ec4..1c5abcd5 100644 --- a/pkg/resource/node/list.go +++ b/pkg/resource/node/list.go @@ -38,8 +38,8 @@ type Node struct { Status v1.NodeStatus `json:"status"` } -// NodeList contains a list of node. -type NodeList struct { +// List contains a list of node. +type List struct { ListMeta types.ListMeta `json:"listMeta"` // Unordered list of Nodes @@ -50,7 +50,7 @@ type NodeList struct { } // GetNodeList returns a list of all Nodes in all cluster. -func GetNodeList(client kubernetes.Interface, dsQuery *dataselect.DataSelectQuery) (*NodeList, error) { +func GetNodeList(client kubernetes.Interface, dsQuery *dataselect.Query) (*List, error) { log.Printf("Getting nodes") channels := &common.ResourceChannels{ NodeList: common.GetNodeListChannel(client, 1), @@ -60,7 +60,7 @@ func GetNodeList(client kubernetes.Interface, dsQuery *dataselect.DataSelectQuer } // GetNodeListFromChannels returns a list of all Nodes in the cluster reading required resource list once from the channels. -func GetNodeListFromChannels(channels *common.ResourceChannels, dsQuery *dataselect.DataSelectQuery) (*NodeList, error) { +func GetNodeListFromChannels(channels *common.ResourceChannels, dsQuery *dataselect.Query) (*List, error) { nodes := <-channels.NodeList.List err := <-channels.NodeList.Error nonCriticalErrors, criticalError := errors.ExtractErrors(err) @@ -81,8 +81,8 @@ func toNode(meta metav1.ObjectMeta, status v1.NodeStatus) Node { } } -func toNodeList(nodes []v1.Node, nonCriticalErrors []error, dsQuery *dataselect.DataSelectQuery) *NodeList { - result := &NodeList{ +func toNodeList(nodes []v1.Node, nonCriticalErrors []error, dsQuery *dataselect.Query) *List { + result := &List{ Items: make([]Node, 0), ListMeta: types.ListMeta{TotalItems: len(nodes)}, Errors: nonCriticalErrors, diff --git a/pkg/resource/overridepolicy/common.go b/pkg/resource/overridepolicy/common.go index a747fb50..c3de069f 100644 --- a/pkg/resource/overridepolicy/common.go +++ b/pkg/resource/overridepolicy/common.go @@ -22,11 +22,11 @@ import ( "github.com/karmada-io/dashboard/pkg/dataselect" ) -// OverridePolicyCell represents an OverridePolicy that implements the DataCell interface. -type OverridePolicyCell v1alpha1.OverridePolicy +// Cell represents an OverridePolicy that implements the DataCell interface. +type Cell v1alpha1.OverridePolicy // GetProperty returns a comparable value for a specified property name. -func (c OverridePolicyCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { +func (c Cell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: return dataselect.StdComparableString(c.ObjectMeta.Name) @@ -44,7 +44,7 @@ func (c OverridePolicyCell) GetProperty(name dataselect.PropertyName) dataselect func toCells(std []v1alpha1.OverridePolicy) []dataselect.DataCell { cells := make([]dataselect.DataCell, len(std)) for i := range std { - cells[i] = OverridePolicyCell(std[i]) + cells[i] = Cell(std[i]) } return cells } @@ -52,7 +52,7 @@ func toCells(std []v1alpha1.OverridePolicy) []dataselect.DataCell { func fromCells(cells []dataselect.DataCell) []v1alpha1.OverridePolicy { std := make([]v1alpha1.OverridePolicy, len(cells)) for i := range std { - std[i] = v1alpha1.OverridePolicy(cells[i].(OverridePolicyCell)) + std[i] = v1alpha1.OverridePolicy(cells[i].(Cell)) } return std } diff --git a/pkg/resource/overridepolicy/detail.go b/pkg/resource/overridepolicy/detail.go index 41a5c59e..4c00d119 100644 --- a/pkg/resource/overridepolicy/detail.go +++ b/pkg/resource/overridepolicy/detail.go @@ -26,9 +26,9 @@ import ( "github.com/karmada-io/dashboard/pkg/common/errors" ) -// OverridePolicyDetail is a presentation layer view of Karmada OverridePolicy resource. This means it is OverridePolicy plus +// Detail is a presentation layer view of Karmada OverridePolicy resource. This means it is OverridePolicy plus // additional augmented data we can get from other sources. -type OverridePolicyDetail struct { +type Detail struct { // Extends list item structure. OverridePolicy `json:",inline"` @@ -37,7 +37,7 @@ type OverridePolicyDetail struct { } // GetOverridePolicyDetail gets Overridepolicy details. -func GetOverridePolicyDetail(client karmadaclientset.Interface, namespace, name string) (*OverridePolicyDetail, error) { +func GetOverridePolicyDetail(client karmadaclientset.Interface, namespace, name string) (*Detail, error) { OverridepolicyData, err := client.PolicyV1alpha1().OverridePolicies(namespace).Get(context.TODO(), name, metaV1.GetOptions{}) if err != nil { return nil, err @@ -52,8 +52,8 @@ func GetOverridePolicyDetail(client karmadaclientset.Interface, namespace, name return &Overridepolicy, nil } -func toOverridePolicyDetail(Overridepolicy *v1alpha1.OverridePolicy, nonCriticalErrors []error) OverridePolicyDetail { - return OverridePolicyDetail{ +func toOverridePolicyDetail(Overridepolicy *v1alpha1.OverridePolicy, nonCriticalErrors []error) Detail { + return Detail{ OverridePolicy: toOverridePolicy(Overridepolicy), Errors: nonCriticalErrors, } diff --git a/pkg/resource/overridepolicy/list.go b/pkg/resource/overridepolicy/list.go index f8468500..3f1a53b8 100644 --- a/pkg/resource/overridepolicy/list.go +++ b/pkg/resource/overridepolicy/list.go @@ -31,8 +31,8 @@ import ( "github.com/karmada-io/dashboard/pkg/resource/common" ) -// OverridePolicyList contains a list of propagation in the karmada control-plance. -type OverridePolicyList struct { +// List contains a list of propagation in the karmada control-plance. +type List struct { ListMeta types.ListMeta `json:"listMeta"` // Unordered list of OverridePolicys. @@ -52,7 +52,7 @@ type OverridePolicy struct { } // GetOverridePolicyList returns a list of all override policies in the Karmada control-plane. -func GetOverridePolicyList(client karmadaclientset.Interface, k8sClient kubernetes.Interface, nsQuery *common.NamespaceQuery, dsQuery *dataselect.DataSelectQuery) (*OverridePolicyList, error) { +func GetOverridePolicyList(client karmadaclientset.Interface, k8sClient kubernetes.Interface, nsQuery *common.NamespaceQuery, dsQuery *dataselect.Query) (*List, error) { log.Println("Getting list of overridepolicy") overridePolicies, err := client.PolicyV1alpha1().OverridePolicies(nsQuery.ToRequestParam()).List(context.TODO(), helpers.ListEverything) nonCriticalErrors, criticalError := errors.ExtractErrors(err) @@ -63,8 +63,8 @@ func GetOverridePolicyList(client karmadaclientset.Interface, k8sClient kubernet return toOverridePolicyList(k8sClient, overridePolicies.Items, nonCriticalErrors, dsQuery), nil } -func toOverridePolicyList(_ kubernetes.Interface, overridepolicies []v1alpha1.OverridePolicy, nonCriticalErrors []error, dsQuery *dataselect.DataSelectQuery) *OverridePolicyList { - overridepolicyList := &OverridePolicyList{ +func toOverridePolicyList(_ kubernetes.Interface, overridepolicies []v1alpha1.OverridePolicy, nonCriticalErrors []error, dsQuery *dataselect.Query) *List { + overridepolicyList := &List{ OverridePolicys: make([]OverridePolicy, 0), ListMeta: types.ListMeta{TotalItems: len(overridepolicies)}, } diff --git a/pkg/resource/pod/common.go b/pkg/resource/pod/common.go index 13866d51..214a1dbc 100644 --- a/pkg/resource/pod/common.go +++ b/pkg/resource/pod/common.go @@ -22,11 +22,11 @@ import ( "github.com/karmada-io/dashboard/pkg/dataselect" ) -// PodCell wraps api.Pod for data selection. -type PodCell api.Pod +// Cell wraps api.Pod for data selection. +type Cell api.Pod // GetProperty returns a property. -func (c PodCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { +func (c Cell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: return dataselect.StdComparableString(c.ObjectMeta.Name) @@ -43,7 +43,7 @@ func (c PodCell) GetProperty(name dataselect.PropertyName) dataselect.Comparable func toCells(std []api.Pod) []dataselect.DataCell { cells := make([]dataselect.DataCell, len(std)) for i := range std { - cells[i] = PodCell(std[i]) + cells[i] = Cell(std[i]) } return cells } @@ -51,7 +51,7 @@ func toCells(std []api.Pod) []dataselect.DataCell { func fromCells(cells []dataselect.DataCell) []api.Pod { std := make([]api.Pod, len(cells)) for i := range std { - std[i] = api.Pod(cells[i].(PodCell)) + std[i] = api.Pod(cells[i].(Cell)) } return std } diff --git a/pkg/resource/pod/detail.go b/pkg/resource/pod/detail.go index 0b212b6d..4d2caad7 100644 --- a/pkg/resource/pod/detail.go +++ b/pkg/resource/pod/detail.go @@ -24,8 +24,8 @@ import ( "k8s.io/client-go/kubernetes" ) -// PodDetail is a pod detail -type PodDetail struct { +// Detail is a pod detail +type Detail struct { ObjectMeta metaV1.ObjectMeta `json:"objectMeta"` TypeMeta metaV1.TypeMeta `json:"typeMeta"` Spec v1.PodSpec `json:"podSpec"` diff --git a/pkg/resource/pod/list.go b/pkg/resource/pod/list.go index 94391b55..29ffada1 100644 --- a/pkg/resource/pod/list.go +++ b/pkg/resource/pod/list.go @@ -36,8 +36,8 @@ type Pod struct { Status v1.PodStatus `json:"status"` } -// PodList contains a list of pod. -type PodList struct { +// List contains a list of pod. +type List struct { ListMeta types.ListMeta `json:"listMeta"` // Unordered list of Pods @@ -48,7 +48,7 @@ type PodList struct { } // GetPodList returns a list of all Pods in all cluster. -func GetPodList(client kubernetes.Interface, nsQuery *common.NamespaceQuery, dsQuery *dataselect.DataSelectQuery) (*PodList, error) { +func GetPodList(client kubernetes.Interface, nsQuery *common.NamespaceQuery, dsQuery *dataselect.Query) (*List, error) { log.Printf("Getting pods") channels := &common.ResourceChannels{ PodList: common.GetPodListChannel(client, nsQuery, 1), @@ -58,7 +58,7 @@ func GetPodList(client kubernetes.Interface, nsQuery *common.NamespaceQuery, dsQ } // GetPodListFromChannels returns a list of all Pods in the cluster reading required resource list once from the channels. -func GetPodListFromChannels(channels *common.ResourceChannels, dsQuery *dataselect.DataSelectQuery) (*PodList, error) { +func GetPodListFromChannels(channels *common.ResourceChannels, dsQuery *dataselect.Query) (*List, error) { pods := <-channels.PodList.List err := <-channels.PodList.Error nonCriticalErrors, criticalError := errors.ExtractErrors(err) @@ -79,8 +79,8 @@ func toPod(meta metav1.ObjectMeta, status v1.PodStatus) Pod { } } -func toPodList(pods []v1.Pod, nonCriticalErrors []error, dsQuery *dataselect.DataSelectQuery) *PodList { - result := &PodList{ +func toPodList(pods []v1.Pod, nonCriticalErrors []error, dsQuery *dataselect.Query) *List { + result := &List{ Items: make([]Pod, 0), ListMeta: types.ListMeta{TotalItems: len(pods)}, Errors: nonCriticalErrors, diff --git a/pkg/resource/propagationpolicy/common.go b/pkg/resource/propagationpolicy/common.go index 5a829d1b..8539ff5e 100644 --- a/pkg/resource/propagationpolicy/common.go +++ b/pkg/resource/propagationpolicy/common.go @@ -22,11 +22,11 @@ import ( "github.com/karmada-io/dashboard/pkg/dataselect" ) -// PropagationPolicyCell is a wrapper around PropagationPolicy type -type PropagationPolicyCell v1alpha1.PropagationPolicy +// Cell is a wrapper around PropagationPolicy type +type Cell v1alpha1.PropagationPolicy // GetProperty returns the given property of the PropagationPolicy. -func (c PropagationPolicyCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { +func (c Cell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: @@ -45,7 +45,7 @@ func (c PropagationPolicyCell) GetProperty(name dataselect.PropertyName) datasel func toCells(std []v1alpha1.PropagationPolicy) []dataselect.DataCell { cells := make([]dataselect.DataCell, len(std)) for i := range std { - cells[i] = PropagationPolicyCell(std[i]) + cells[i] = Cell(std[i]) } return cells } @@ -53,7 +53,7 @@ func toCells(std []v1alpha1.PropagationPolicy) []dataselect.DataCell { func fromCells(cells []dataselect.DataCell) []v1alpha1.PropagationPolicy { std := make([]v1alpha1.PropagationPolicy, len(cells)) for i := range std { - std[i] = v1alpha1.PropagationPolicy(cells[i].(PropagationPolicyCell)) + std[i] = v1alpha1.PropagationPolicy(cells[i].(Cell)) } return std } diff --git a/pkg/resource/propagationpolicy/detail.go b/pkg/resource/propagationpolicy/detail.go index 66c4e6b7..c05c8520 100644 --- a/pkg/resource/propagationpolicy/detail.go +++ b/pkg/resource/propagationpolicy/detail.go @@ -26,9 +26,9 @@ import ( "github.com/karmada-io/dashboard/pkg/common/errors" ) -// PropagationPolicyDetail is a presentation layer view of Karmada PropagationPolicy resource. This means it is PropagationPolicy plus +// Detail is a presentation layer view of Karmada PropagationPolicy resource. This means it is PropagationPolicy plus // additional augmented data we can get from other sources. -type PropagationPolicyDetail struct { +type Detail struct { // Extends list item structure. PropagationPolicy `json:",inline"` @@ -37,7 +37,7 @@ type PropagationPolicyDetail struct { } // GetPropagationPolicyDetail gets propagationpolicy details. -func GetPropagationPolicyDetail(client karmadaclientset.Interface, namespace, name string) (*PropagationPolicyDetail, error) { +func GetPropagationPolicyDetail(client karmadaclientset.Interface, namespace, name string) (*Detail, error) { propagationpolicyData, err := client.PolicyV1alpha1().PropagationPolicies(namespace).Get(context.TODO(), name, metaV1.GetOptions{}) if err != nil { return nil, err @@ -52,8 +52,8 @@ func GetPropagationPolicyDetail(client karmadaclientset.Interface, namespace, na return &propagationpolicy, nil } -func toPropagationPolicyDetail(propagationpolicy *v1alpha1.PropagationPolicy, nonCriticalErrors []error) PropagationPolicyDetail { - return PropagationPolicyDetail{ +func toPropagationPolicyDetail(propagationpolicy *v1alpha1.PropagationPolicy, nonCriticalErrors []error) Detail { + return Detail{ PropagationPolicy: toPropagationPolicy(propagationpolicy), Errors: nonCriticalErrors, } diff --git a/pkg/resource/propagationpolicy/list.go b/pkg/resource/propagationpolicy/list.go index 3a74b5fa..18c50ecb 100644 --- a/pkg/resource/propagationpolicy/list.go +++ b/pkg/resource/propagationpolicy/list.go @@ -35,8 +35,8 @@ import ( "github.com/karmada-io/dashboard/pkg/resource/common" ) -// PropagationPolicyList contains a list of propagation in the karmada control-plance. -type PropagationPolicyList struct { +// List contains a list of propagation in the karmada control-plance. +type List struct { ListMeta types.ListMeta `json:"listMeta"` // Unordered list of PropagationPolicys. @@ -57,7 +57,7 @@ type PropagationPolicy struct { } // GetPropagationPolicyList returns a list of all propagations in the karmada control-plance. -func GetPropagationPolicyList(client karmadaclientset.Interface, k8sClient kubernetes.Interface, nsQuery *common.NamespaceQuery, dsQuery *dataselect.DataSelectQuery) (*PropagationPolicyList, error) { +func GetPropagationPolicyList(client karmadaclientset.Interface, k8sClient kubernetes.Interface, nsQuery *common.NamespaceQuery, dsQuery *dataselect.Query) (*List, error) { log.Println("Getting list of namespaces") propagationpolicies, err := client.PolicyV1alpha1().PropagationPolicies(nsQuery.ToRequestParam()).List(context.TODO(), helpers.ListEverything) nonCriticalErrors, criticalError := errors.ExtractErrors(err) @@ -68,8 +68,8 @@ func GetPropagationPolicyList(client karmadaclientset.Interface, k8sClient kuber return toPropagationPolicyList(k8sClient, propagationpolicies.Items, nonCriticalErrors, dsQuery), nil } -func toPropagationPolicyList(k8sClient kubernetes.Interface, propagationpolicies []v1alpha1.PropagationPolicy, nonCriticalErrors []error, dsQuery *dataselect.DataSelectQuery) *PropagationPolicyList { - propagationpolicyList := &PropagationPolicyList{ +func toPropagationPolicyList(k8sClient kubernetes.Interface, propagationpolicies []v1alpha1.PropagationPolicy, nonCriticalErrors []error, dsQuery *dataselect.Query) *List { + propagationpolicyList := &List{ PropagationPolicys: make([]PropagationPolicy, 0), ListMeta: types.ListMeta{TotalItems: len(propagationpolicies)}, } diff --git a/pkg/resource/secret/common.go b/pkg/resource/secret/common.go index f8894806..4151dd57 100644 --- a/pkg/resource/secret/common.go +++ b/pkg/resource/secret/common.go @@ -22,11 +22,11 @@ import ( "github.com/karmada-io/dashboard/pkg/dataselect" ) -// SecretCell wraps api.Secret for data selection. -type SecretCell api.Secret +// Cell wraps api.Secret for data selection. +type Cell api.Secret // GetProperty returns a property of the secret cell. -func (c SecretCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { +func (c Cell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: return dataselect.StdComparableString(c.ObjectMeta.Name) @@ -43,7 +43,7 @@ func (c SecretCell) GetProperty(name dataselect.PropertyName) dataselect.Compara func toCells(std []api.Secret) []dataselect.DataCell { cells := make([]dataselect.DataCell, len(std)) for i := range std { - cells[i] = SecretCell(std[i]) + cells[i] = Cell(std[i]) } return cells } @@ -51,7 +51,7 @@ func toCells(std []api.Secret) []dataselect.DataCell { func fromCells(cells []dataselect.DataCell) []api.Secret { std := make([]api.Secret, len(cells)) for i := range std { - std[i] = api.Secret(cells[i].(SecretCell)) + std[i] = api.Secret(cells[i].(Cell)) } return std } diff --git a/pkg/resource/secret/detail.go b/pkg/resource/secret/detail.go index c4f66fb8..a5bd1a8b 100644 --- a/pkg/resource/secret/detail.go +++ b/pkg/resource/secret/detail.go @@ -25,9 +25,9 @@ import ( "k8s.io/client-go/kubernetes" ) -// SecretDetail API resource provides mechanisms to inject containers with configuration data while keeping +// Detail API resource provides mechanisms to inject containers with configuration data while keeping // containers agnostic of Kubernetes -type SecretDetail struct { +type Detail struct { // Extends list item structure. Secret `json:",inline"` @@ -39,7 +39,7 @@ type SecretDetail struct { } // GetSecretDetail returns detailed information about a secret -func GetSecretDetail(client kubernetes.Interface, namespace, name string) (*SecretDetail, error) { +func GetSecretDetail(client kubernetes.Interface, namespace, name string) (*Detail, error) { log.Printf("Getting details of %s secret in %s namespace\n", name, namespace) rawSecret, err := client.CoreV1().Secrets(namespace).Get(context.TODO(), name, metaV1.GetOptions{}) @@ -50,8 +50,8 @@ func GetSecretDetail(client kubernetes.Interface, namespace, name string) (*Secr return getSecretDetail(rawSecret), nil } -func getSecretDetail(rawSecret *v1.Secret) *SecretDetail { - return &SecretDetail{ +func getSecretDetail(rawSecret *v1.Secret) *Detail { + return &Detail{ Secret: toSecret(rawSecret), Data: rawSecret.Data, } diff --git a/pkg/resource/secret/list.go b/pkg/resource/secret/list.go index f9027ca7..b544cde2 100644 --- a/pkg/resource/secret/list.go +++ b/pkg/resource/secret/list.go @@ -31,15 +31,15 @@ import ( "github.com/karmada-io/dashboard/pkg/resource/common" ) -// SecretSpec is a common interface for the specification of different secrets. -type SecretSpec interface { +// Spec is a common interface for the specification of different secrets. +type Spec interface { GetName() string GetType() v1.SecretType GetNamespace() string GetData() map[string][]byte } -// ImagePullSecretSpec is a specification of an image pull secret implements SecretSpec +// ImagePullSecretSpec is a specification of an image pull secret implements Spec type ImagePullSecretSpec struct { Name string `json:"name"` Namespace string `json:"namespace"` @@ -75,8 +75,8 @@ type Secret struct { Type v1.SecretType `json:"type"` } -// SecretList is a response structure for a queried secrets list. -type SecretList struct { +// List is a response structure for a queried secrets list. +type List struct { types.ListMeta `json:"listMeta"` // Unordered list of Secrets. @@ -88,7 +88,7 @@ type SecretList struct { // GetSecretList returns all secrets in the given namespace. func GetSecretList(client kubernetes.Interface, namespace *common.NamespaceQuery, - dsQuery *dataselect.DataSelectQuery) (*SecretList, error) { + dsQuery *dataselect.Query) (*List, error) { log.Printf("Getting list of secrets in %s namespace\n", namespace) secretList, err := client.CoreV1().Secrets(namespace.ToRequestParam()).List(context.TODO(), helpers.ListEverything) @@ -101,7 +101,7 @@ func GetSecretList(client kubernetes.Interface, namespace *common.NamespaceQuery } // CreateSecret creates a single secret using the cluster API client -func CreateSecret(client kubernetes.Interface, spec SecretSpec) (*Secret, error) { +func CreateSecret(client kubernetes.Interface, spec Spec) (*Secret, error) { namespace := spec.GetNamespace() secret := &v1.Secret{ ObjectMeta: metaV1.ObjectMeta{ @@ -124,9 +124,9 @@ func toSecret(secret *v1.Secret) Secret { } } -// ToSecretList converts a list of Secrets to SecretList -func ToSecretList(secrets []v1.Secret, nonCriticalErrors []error, dsQuery *dataselect.DataSelectQuery) *SecretList { - newSecretList := &SecretList{ +// ToSecretList converts a list of Secrets to List +func ToSecretList(secrets []v1.Secret, nonCriticalErrors []error, dsQuery *dataselect.Query) *List { + newSecretList := &List{ ListMeta: types.ListMeta{TotalItems: len(secrets)}, Secrets: make([]Secret, 0), Errors: nonCriticalErrors, diff --git a/pkg/resource/service/common.go b/pkg/resource/service/common.go index d818d410..3ba31eaa 100644 --- a/pkg/resource/service/common.go +++ b/pkg/resource/service/common.go @@ -24,11 +24,11 @@ import ( // The code below allows to perform complex data section on []api.Service -// ServiceCell wraps v1.Service for data selection. -type ServiceCell v1.Service +// Cell wraps v1.Service for data selection. +type Cell v1.Service // GetProperty returns a property of the service cell. -func (c ServiceCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { +func (c Cell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: return dataselect.StdComparableString(c.ObjectMeta.Name) @@ -47,7 +47,7 @@ func (c ServiceCell) GetProperty(name dataselect.PropertyName) dataselect.Compar func toCells(std []v1.Service) []dataselect.DataCell { cells := make([]dataselect.DataCell, len(std)) for i := range std { - cells[i] = ServiceCell(std[i]) + cells[i] = Cell(std[i]) } return cells } @@ -55,7 +55,7 @@ func toCells(std []v1.Service) []dataselect.DataCell { func fromCells(cells []dataselect.DataCell) []v1.Service { std := make([]v1.Service, len(cells)) for i := range std { - std[i] = v1.Service(cells[i].(ServiceCell)) + std[i] = v1.Service(cells[i].(Cell)) } return std } diff --git a/pkg/resource/service/detail.go b/pkg/resource/service/detail.go index 67fbea23..825b430c 100644 --- a/pkg/resource/service/detail.go +++ b/pkg/resource/service/detail.go @@ -28,13 +28,13 @@ import ( "github.com/karmada-io/dashboard/pkg/resource/endpoint" ) -// ServiceDetail is a representation of a service. -type ServiceDetail struct { +// Detail is a representation of a service. +type Detail struct { // Extends list item structure. Service `json:",inline"` // List of Endpoint obj. that are endpoints of this Service. - EndpointList endpoint.EndpointList `json:"endpointList"` + EndpointList endpoint.List `json:"endpointList"` // Show the value of the SessionAffinity of the Service. SessionAffinity v1.ServiceAffinity `json:"sessionAffinity"` @@ -44,7 +44,7 @@ type ServiceDetail struct { } // GetServiceDetail gets service details. -func GetServiceDetail(client k8sClient.Interface, namespace, name string) (*ServiceDetail, error) { +func GetServiceDetail(client k8sClient.Interface, namespace, name string) (*Detail, error) { log.Printf("Getting details of %s service in %s namespace", name, namespace) serviceData, err := client.CoreV1().Services(namespace).Get(context.TODO(), name, metaV1.GetOptions{}) if err != nil { @@ -61,8 +61,8 @@ func GetServiceDetail(client k8sClient.Interface, namespace, name string) (*Serv return &service, nil } -func toServiceDetail(service *v1.Service, endpointList endpoint.EndpointList, nonCriticalErrors []error) ServiceDetail { - return ServiceDetail{ +func toServiceDetail(service *v1.Service, endpointList endpoint.List, nonCriticalErrors []error) Detail { + return Detail{ Service: toService(service), EndpointList: endpointList, SessionAffinity: service.Spec.SessionAffinity, diff --git a/pkg/resource/service/events.go b/pkg/resource/service/events.go index e4234947..3bccbc80 100644 --- a/pkg/resource/service/events.go +++ b/pkg/resource/service/events.go @@ -28,7 +28,7 @@ import ( ) // GetServiceEvents returns model events for a service with the given name in the given namespace. -func GetServiceEvents(client client.Interface, dsQuery *dataselect.DataSelectQuery, namespace, name string) ( +func GetServiceEvents(client client.Interface, dsQuery *dataselect.Query, namespace, name string) ( *common.EventList, error) { eventList := common.EventList{ Events: make([]common.Event, 0), diff --git a/pkg/resource/service/list.go b/pkg/resource/service/list.go index 6396f3e1..06ffb157 100644 --- a/pkg/resource/service/list.go +++ b/pkg/resource/service/list.go @@ -52,8 +52,8 @@ type Service struct { ClusterIP string `json:"clusterIP"` } -// ServiceList contains a list of services in the cluster. -type ServiceList struct { +// List contains a list of services in the cluster. +type List struct { ListMeta types.ListMeta `json:"listMeta"` // Unordered list of services. @@ -65,7 +65,7 @@ type ServiceList struct { // GetServiceList returns a list of all services in the cluster. func GetServiceList(client client.Interface, nsQuery *common.NamespaceQuery, - dsQuery *dataselect.DataSelectQuery) (*ServiceList, error) { + dsQuery *dataselect.Query) (*List, error) { log.Print("Getting list of all services in the cluster") channels := &common.ResourceChannels{ @@ -77,7 +77,7 @@ func GetServiceList(client client.Interface, nsQuery *common.NamespaceQuery, // GetServiceListFromChannels returns a list of all services in the cluster. func GetServiceListFromChannels(channels *common.ResourceChannels, - dsQuery *dataselect.DataSelectQuery) (*ServiceList, error) { + dsQuery *dataselect.Query) (*List, error) { services := <-channels.ServiceList.List err := <-channels.ServiceList.Error nonCriticalErrors, criticalError := errors.ExtractErrors(err) @@ -101,8 +101,8 @@ func toService(service *v1.Service) Service { } // CreateServiceList returns paginated service list based on given service array and pagination query. -func CreateServiceList(services []v1.Service, nonCriticalErrors []error, dsQuery *dataselect.DataSelectQuery) *ServiceList { - serviceList := &ServiceList{ +func CreateServiceList(services []v1.Service, nonCriticalErrors []error, dsQuery *dataselect.Query) *List { + serviceList := &List{ Services: make([]Service, 0), ListMeta: types.ListMeta{TotalItems: len(services)}, Errors: nonCriticalErrors, diff --git a/pkg/resource/statefulset/common.go b/pkg/resource/statefulset/common.go index 4a8e6d5f..f66edc48 100644 --- a/pkg/resource/statefulset/common.go +++ b/pkg/resource/statefulset/common.go @@ -27,11 +27,11 @@ import ( // The code below allows to perform complex data section on []apps.StatefulSet -// StatefulSetCell wraps apps.StatefulSet for data selection. -type StatefulSetCell apps.StatefulSet +// Cell wraps apps.StatefulSet for data selection. +type Cell apps.StatefulSet // GetProperty returns a property. -func (c StatefulSetCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { +func (c Cell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: return dataselect.StdComparableString(c.ObjectMeta.Name) @@ -48,7 +48,7 @@ func (c StatefulSetCell) GetProperty(name dataselect.PropertyName) dataselect.Co func toCells(std []apps.StatefulSet) []dataselect.DataCell { cells := make([]dataselect.DataCell, len(std)) for i := range std { - cells[i] = StatefulSetCell(std[i]) + cells[i] = Cell(std[i]) } return cells } @@ -56,7 +56,7 @@ func toCells(std []apps.StatefulSet) []dataselect.DataCell { func fromCells(cells []dataselect.DataCell) []apps.StatefulSet { std := make([]apps.StatefulSet, len(cells)) for i := range std { - std[i] = apps.StatefulSet(cells[i].(StatefulSetCell)) + std[i] = apps.StatefulSet(cells[i].(Cell)) } return std } diff --git a/pkg/resource/statefulset/detail.go b/pkg/resource/statefulset/detail.go index 3a76d3ef..3668c116 100644 --- a/pkg/resource/statefulset/detail.go +++ b/pkg/resource/statefulset/detail.go @@ -28,8 +28,8 @@ import ( "github.com/karmada-io/dashboard/pkg/resource/common" ) -// StatefulSetDetail is a presentation layer view of Kubernetes Stateful Set resource. This means it is Stateful -type StatefulSetDetail struct { +// Detail is a presentation layer view of Kubernetes Stateful Set resource. This means it is Stateful +type Detail struct { // Extends list item structure. StatefulSet `json:",inline"` @@ -39,7 +39,7 @@ type StatefulSetDetail struct { // GetStatefulSetDetail gets Stateful Set details. func GetStatefulSetDetail(client kubernetes.Interface, namespace, - name string) (*StatefulSetDetail, error) { + name string) (*Detail, error) { log.Printf("Getting details of %s statefulset in %s namespace", name, namespace) ss, err := client.AppsV1().StatefulSets(namespace).Get(context.TODO(), name, metaV1.GetOptions{}) @@ -57,8 +57,8 @@ func GetStatefulSetDetail(client kubernetes.Interface, namespace, return &ssDetail, nil } -func getStatefulSetDetail(statefulSet *apps.StatefulSet, podInfo *common.PodInfo, nonCriticalErrors []error) StatefulSetDetail { - return StatefulSetDetail{ +func getStatefulSetDetail(statefulSet *apps.StatefulSet, podInfo *common.PodInfo, nonCriticalErrors []error) Detail { + return Detail{ StatefulSet: toStatefulSet(statefulSet, podInfo), Errors: nonCriticalErrors, } diff --git a/pkg/resource/statefulset/list.go b/pkg/resource/statefulset/list.go index 4f5dfdf0..dc4c1f34 100644 --- a/pkg/resource/statefulset/list.go +++ b/pkg/resource/statefulset/list.go @@ -30,8 +30,8 @@ import ( "github.com/karmada-io/dashboard/pkg/resource/event" ) -// StatefulSetList contains a list of Stateful Sets in the cluster. -type StatefulSetList struct { +// List contains a list of Stateful Sets in the cluster. +type List struct { ListMeta types.ListMeta `json:"listMeta"` Status common.ResourceStatus `json:"status"` @@ -52,7 +52,7 @@ type StatefulSet struct { // GetStatefulSetList returns a list of all Stateful Sets in the cluster. func GetStatefulSetList(client kubernetes.Interface, nsQuery *common.NamespaceQuery, - dsQuery *dataselect.DataSelectQuery) (*StatefulSetList, error) { + dsQuery *dataselect.Query) (*List, error) { log.Print("Getting list of all stateful sets in the cluster") channels := &common.ResourceChannels{ @@ -66,7 +66,7 @@ func GetStatefulSetList(client kubernetes.Interface, nsQuery *common.NamespaceQu // GetStatefulSetListFromChannels returns a list of all Stateful Sets in the cluster reading // required resource list once from the channels. -func GetStatefulSetListFromChannels(channels *common.ResourceChannels, dsQuery *dataselect.DataSelectQuery) (*StatefulSetList, error) { +func GetStatefulSetListFromChannels(channels *common.ResourceChannels, dsQuery *dataselect.Query) (*List, error) { statefulSets := <-channels.StatefulSetList.List err := <-channels.StatefulSetList.Error nonCriticalErrors, criticalError := errors.ExtractErrors(err) @@ -94,8 +94,8 @@ func GetStatefulSetListFromChannels(channels *common.ResourceChannels, dsQuery * } func toStatefulSetList(statefulSets []apps.StatefulSet, pods []v1.Pod, events []v1.Event, nonCriticalErrors []error, - dsQuery *dataselect.DataSelectQuery) *StatefulSetList { - statefulSetList := &StatefulSetList{ + dsQuery *dataselect.Query) *List { + statefulSetList := &List{ StatefulSets: make([]StatefulSet, 0), ListMeta: types.ListMeta{TotalItems: len(statefulSets)}, Errors: nonCriticalErrors,