Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions modules/api/pkg/args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ limitations under the License.
package args

import (
"flag"
"net"
"strconv"

"github.com/spf13/pflag"
"k8s.io/klog/v2"
)

const (
Expand All @@ -38,6 +40,14 @@ var (
)

func init() {
// Init klog
fs := flag.NewFlagSet("", flag.PanicOnError)
klog.InitFlags(fs)

// Default log level to 1
_ = fs.Set("v", "1")

pflag.CommandLine.AddGoFlagSet(fs)
pflag.Parse()
}

Expand Down
8 changes: 5 additions & 3 deletions modules/api/pkg/resource/configmap/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ import (

// ConfigMapListItem is the lightweight view returned by list API.
type ConfigMapListItem struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
CreationTimestamp string `json:"creationTimestamp"`
Name string `json:"name"`
Namespace string `json:"namespace"`
CreationTimestamp string `json:"creationTimestamp"`
Labels map[string]string `json:"labels,omitempty"`
}

func ConfigMapToListItem(cm corev1.ConfigMap) ConfigMapListItem {
return ConfigMapListItem{
Name: cm.GetName(),
Namespace: cm.GetNamespace(),
CreationTimestamp: cm.GetCreationTimestamp().Time.Format(time.RFC3339Nano),
Labels: cm.GetLabels(),
}
}

Expand Down
4 changes: 4 additions & 0 deletions modules/api/pkg/resource/device/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ type DeviceListItem struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
DeviceModelRef string `json:"deviceModelRef"`
NodeName string `json:"nodeName"`
NodeSelector string `json:"nodeSelector"`
Protocol string `json:"protocol"`
Status string `json:"status"`
CreationTimestamp time.Time `json:"creationTimestamp"`
Labels map[string]string `json:"labels,omitempty"`
Expand All @@ -55,7 +57,9 @@ func DeviceToListItem(d devicev1beta1.Device) DeviceListItem {
Name: d.ObjectMeta.Name,
Namespace: d.ObjectMeta.Namespace,
DeviceModelRef: deviceModelRef,
NodeName: d.Spec.NodeName,
NodeSelector: nodeSelector,
Protocol: d.Spec.Protocol.ProtocolName,
Status: status,
CreationTimestamp: d.ObjectMeta.CreationTimestamp.Time,
Labels: d.ObjectMeta.Labels,
Expand Down
24 changes: 15 additions & 9 deletions modules/api/pkg/resource/serviceaccount/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,28 @@ import (

// ServiceAccountListItem represents a simplified ServiceAccount for list responses
type ServiceAccountListItem struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
Secrets int `json:"secrets"`
Age string `json:"age"`
CreationTimestamp time.Time `json:"creationTimestamp"`
Name string `json:"name"`
Namespace string `json:"namespace"`
Secrets []string `json:"secrets"`
Age string `json:"age"`
CreationTimestamp time.Time `json:"creationTimestamp"`
Labels map[string]string `json:"labels,omitempty"`
}

// ServiceAccountToListItem converts a ServiceAccount to ServiceAccountListItem
func ServiceAccountToListItem(sa corev1.ServiceAccount) ServiceAccountListItem {
age := time.Since(sa.ObjectMeta.CreationTimestamp.Time).Truncate(time.Second).String()

return ServiceAccountListItem{
Name: sa.ObjectMeta.Name,
Namespace: sa.ObjectMeta.Namespace,
Secrets: len(sa.Secrets),
Name: sa.ObjectMeta.Name,
Namespace: sa.ObjectMeta.Namespace,
Secrets: func() []string {
secrets := make([]string, len(sa.Secrets))
for i, secret := range sa.Secrets {
secrets[i] = secret.Name
}
return secrets
}(),
Age: age,
CreationTimestamp: sa.ObjectMeta.CreationTimestamp.Time,
Labels: sa.ObjectMeta.Labels,
Expand Down
23 changes: 6 additions & 17 deletions modules/web/src/api/clusterRole.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
import { request } from '@/helper/request';
import { useQuery } from '@/hook/useQuery';
import { Status } from '@/types/common';
import { ClusterRole, ClusterRoleList } from '@/types/clusterRole';
import { ClusterRole, ClusterRoleList, ConciseClusterRoleList } from '@/types/clusterRole';

export function useListClusterRoles(params?: Record<string, string | number | undefined>) {
const searchParams = new URLSearchParams();
let url = '/clusterrole';

if (params) {
Object.entries(params).forEach(([key, value]) => {
if (value !== undefined) {
searchParams.append(key, String(value));
}
});
}

const finalUrl = searchParams.toString() ? `${url}?${searchParams.toString()}` : url;

return useQuery<ClusterRoleList>('listClusterRoles', finalUrl, {
method: 'GET',
});
return useQuery<ConciseClusterRoleList>(
'listClusterRoles',
'/clusterrole',
{ method: 'GET', params },
);
}

export function getClusterRole(name: string) {
Expand Down
23 changes: 6 additions & 17 deletions modules/web/src/api/clusterRoleBinding.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
import { request } from '@/helper/request';
import { useQuery } from '@/hook/useQuery';
import { ClusterRoleBinding, ClusterRoleBindingList } from '@/types/clusterRoleBinding';
import { ClusterRoleBinding, ConciseClusterRoleBindingList } from '@/types/clusterRoleBinding';
import { Status } from '@/types/common';

export function useListClusterRoleBindings(params?: Record<string, string | number | undefined>) {
const searchParams = new URLSearchParams();
let url = '/clusterrolebinding';

if (params) {
Object.entries(params).forEach(([key, value]) => {
if (value !== undefined) {
searchParams.append(key, String(value));
}
});
}

const finalUrl = searchParams.toString() ? `${url}?${searchParams.toString()}` : url;

return useQuery<ClusterRoleBindingList>('listClusterRoleBindings', finalUrl, {
method: 'GET',
});
return useQuery<ConciseClusterRoleBindingList>(
'listClusterRoleBindings',
'/clusterrolebinding',
{ method: 'GET', params },
);
}

export function getClusterRoleBinding(name: string) {
Expand Down
26 changes: 9 additions & 17 deletions modules/web/src/api/configMap.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
import { request } from '@/helper/request';
import { useQuery } from '@/hook/useQuery';
import { Status } from '@/types/common';
import { ConfigMap } from '@/types/configMap';
import { ConciseConfigMapList, ConfigMap } from '@/types/configMap';

export function useListConfigMaps(params?: Record<string, string | number | undefined>) {
let path = '/configmap';
// Optional namespace path parameter for compatibility
const namespace = params?.namespace as string | undefined;
if (namespace) {
path = `/configmap/${namespace}`;
}
const search = new URLSearchParams();
Object.entries(params || {}).forEach(([k, v]) => {
if (v !== undefined && v !== null && `${v}` !== '' && k !== 'namespace') {
search.set(k, String(v));
}
});
const qs = search.toString();
if (qs) path += `?${qs}`;
return useQuery<any>(`listConfigMaps:${path}`, path, { method: 'GET' });
export function useListConfigMaps(namespace?: string, params?: Record<string, string | number | undefined>) {
const path = namespace ? `/configmap/${namespace}` : '/configmap';

return useQuery<ConciseConfigMapList>(
`listConfigMaps`,
path,
{ method: 'GET', params },
);
}

export function getConfigMap(namespace: string, name: string) {
Expand Down
23 changes: 6 additions & 17 deletions modules/web/src/api/customResourceDefinition.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
import { request } from '@/helper/request';
import { useQuery } from '@/hook/useQuery';
import { CustomResourceDefinition, CustomResourceDefinitionList } from '@/types/customResourceDefinition';
import { CustomResourceDefinition, ConciseCustomResourceDefinitionList } from '@/types/customResourceDefinition';

export function useListCustomResourceDefinitions(params?: Record<string, string | number | undefined>) {
const searchParams = new URLSearchParams();
let url = '/crd';

if (params) {
Object.entries(params).forEach(([key, value]) => {
if (value !== undefined) {
searchParams.append(key, String(value));
}
});
}

const finalUrl = searchParams.toString() ? `${url}?${searchParams.toString()}` : url;

return useQuery<CustomResourceDefinitionList>('listCustomResourceDefinitions', finalUrl, {
method: 'GET',
});
return useQuery<ConciseCustomResourceDefinitionList>(
`listCustomResourceDefinitions`,
'/crd',
{ method: 'GET', params, },
);
}

export function getCustomResourceDefinition(name: string) {
Expand Down
26 changes: 9 additions & 17 deletions modules/web/src/api/deployment.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
import { request } from '@/helper/request';
import { useQuery } from '@/hook/useQuery';
import { Status } from '@/types/common';
import { Deployment } from '@/types/deployment';
import { ConciseDeploymentList, Deployment } from '@/types/deployment';

export function useListDeployments(params?: Record<string, string | number | undefined>) {
let path = '/deployment';
// Optional namespace path parameter for compatibility
const namespace = params?.namespace as string | undefined;
if (namespace) {
path = `/deployment/${namespace}`;
}
const search = new URLSearchParams();
Object.entries(params || {}).forEach(([k, v]) => {
if (v !== undefined && v !== null && `${v}` !== '' && k !== 'namespace') {
search.set(k, String(v));
}
});
const qs = search.toString();
if (qs) path += `?${qs}`;
return useQuery<any>(`listDeployments:${path}`, path, { method: 'GET' });
export function useListDeployments(namespace?: string, params?: Record<string, string | number | undefined>) {
const path = namespace ? `/deployment/${namespace}` : '/deployment';

return useQuery<ConciseDeploymentList>(
'listDeployments',
path,
{ method: 'GET', params },
);
}

export function getDeployment(namespace: string, name: string) {
Expand Down
20 changes: 4 additions & 16 deletions modules/web/src/api/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,10 @@ import { useQuery } from '@/hook/useQuery';
import { Status } from '@/types/common';
import { Device, DeviceList } from '@/types/device';

export function useListDevices(params?: Record<string, string | number | undefined>) {
let path = '/device';
// Optional namespace path parameter for compatibility
const namespace = params?.namespace as string | undefined;
if (namespace) {
path = `/device/${namespace}`;
}
const search = new URLSearchParams();
Object.entries(params || {}).forEach(([k, v]) => {
if (v !== undefined && v !== null && `${v}` !== '' && k !== 'namespace') {
search.set(k, String(v));
}
});
const qs = search.toString();
if (qs) path += `?${qs}`;
return useQuery<any>(`listDevices:${path}`, path, { method: 'GET' });
export function useListDevices(namespace?: string, params?: Record<string, string | number | undefined>) {
const path = namespace ? `/device/${namespace}` : '/device';

return useQuery<any>(`listDevices`, path, { method: 'GET', params });
}

export function getDevice(namespace: string, name: string) {
Expand Down
30 changes: 11 additions & 19 deletions modules/web/src/api/deviceModel.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
import { request } from '@/helper/request';
import { useQuery } from '@/hook/useQuery';
import { Status } from '@/types/common';
import { DeviceModel, DeviceModelList } from '@/types/deviceModel';
import { ConciseDeviceModelList, DeviceModel } from '@/types/deviceModel';

export function useListDeviceModels(params?: Record<string, string | number | undefined>) {
let path = '/devicemodel';
// Optional namespace path parameter for compatibility
const namespace = params?.namespace as string | undefined;
if (namespace) {
path = `/devicemodel/${namespace}`;
}
const search = new URLSearchParams();
Object.entries(params || {}).forEach(([k, v]) => {
if (v !== undefined && v !== null && `${v}` !== '' && k !== 'namespace') {
search.set(k, String(v));
}
});
const qs = search.toString();
if (qs) path += `?${qs}`;
return useQuery<any>(`listDeviceModels:${path}`, path, { method: 'GET' });
export function useListDeviceModels(namespace?: string, params?: Record<string, string | number | undefined>) {
const path = namespace ? `/devicemodel/${namespace}` : '/devicemodel';

return useQuery<ConciseDeviceModelList>(
`listDeviceModels`,
path,
{ method: 'GET', params },
);
}

export function getDeviceModel(namespace: string, name: string) {
Expand Down Expand Up @@ -47,8 +39,8 @@ export function deleteDeviceModel(namespace: string, name: string) {
});
}

export async function listDeviceModels(namespace?: string): Promise<DeviceModelList> {
export async function listDeviceModels(namespace?: string): Promise<ConciseDeviceModelList> {
const url = namespace ? `/devicemodel/${namespace}` : 'devicemodel';
const res = await request<DeviceModelList>(url, { method: 'GET' });
const res = await request<ConciseDeviceModelList>(url, { method: 'GET' });
return res.data;
}
7 changes: 4 additions & 3 deletions modules/web/src/api/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { useQuery } from '@/hook/useQuery';
import { NamespaceList } from '@/types/namespace';

export function useListNamespaces() {
return useQuery<NamespaceList>('listNamespaces', '/namespace', {
method: 'GET',
});
return useQuery<NamespaceList>(
'listNamespaces',
'/namespace',
{ method: 'GET' });
}

export async function listNamespaces() {
Expand Down
21 changes: 8 additions & 13 deletions modules/web/src/api/node.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import { request } from '@/helper/request';
import { useQuery } from '@/hook/useQuery';
import { Status } from '@/types/common';
import type { Node, NodeList } from '@/types/node';
import type { ConciseNodeList, Node } from '@/types/node';

export function useListNodes(params?: Record<string, string | number | undefined>) {
let path = '/node';
if (params) {
const search = new URLSearchParams();
Object.entries(params).forEach(([k, v]) => {
if (v !== undefined && v !== null && `${v}` !== '') search.set(k, String(v));
});
const qs = search.toString();
if (qs) path += `?${qs}`;
}
return useQuery<any>(`listNodes:${path}`, path, { method: 'GET' });
return useQuery<ConciseNodeList>(
'listNodes',
'/node',
{ method: 'GET', params },
);
}

export function getNode(name: string) {
Expand All @@ -35,8 +30,8 @@ export function deleteNode(name: string) {
});
}

export async function listNodes(namespace?: string): Promise<NodeList> {
export async function listNodes(namespace?: string): Promise<ConciseNodeList> {
const url = namespace ? `/node/${namespace}` : '/node';
const res = await request<NodeList>(url, { method: 'GET' });
const res = await request<ConciseNodeList>(url, { method: 'GET' });
return res.data;
}
Loading