first-commit
This commit is contained in:
51
modules/k8s/client/client.go
Normal file
51
modules/k8s/client/client.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
appsv1 "code.gitea.io/gitea/modules/k8s/api/devcontainer/v1"
|
||||
)
|
||||
|
||||
// DevStarClient 提供操作 DevContainerApp 资源的方法
|
||||
type DevStarClient struct {
|
||||
client client.Client
|
||||
}
|
||||
|
||||
// NewDevStarClient 创建一个新的客户端
|
||||
func NewDevStarClient(c client.Client) *DevStarClient {
|
||||
return &DevStarClient{
|
||||
client: c,
|
||||
}
|
||||
}
|
||||
|
||||
// GetDevContainerApp 获取 DevContainerApp 资源
|
||||
func (c *DevStarClient) GetDevContainerApp(ctx context.Context, name, namespace string) (*appsv1.DevcontainerApp, error) {
|
||||
app := &appsv1.DevcontainerApp{}
|
||||
err := c.client.Get(ctx, types.NamespacedName{Name: name, Namespace: namespace}, app)
|
||||
return app, err
|
||||
}
|
||||
|
||||
// CreateDevContainerApp 创建 DevContainerApp 资源
|
||||
func (c *DevStarClient) CreateDevContainerApp(ctx context.Context, app *appsv1.DevcontainerApp) error {
|
||||
return c.client.Create(ctx, app)
|
||||
}
|
||||
|
||||
// UpdateDevContainerApp 更新 DevContainerApp 资源
|
||||
func (c *DevStarClient) UpdateDevContainerApp(ctx context.Context, app *appsv1.DevcontainerApp) error {
|
||||
return c.client.Update(ctx, app)
|
||||
}
|
||||
|
||||
// DeleteDevContainerApp 删除 DevContainerApp 资源
|
||||
func (c *DevStarClient) DeleteDevContainerApp(ctx context.Context, app *appsv1.DevcontainerApp) error {
|
||||
return c.client.Delete(ctx, app)
|
||||
}
|
||||
|
||||
// ListDevContainerApps 列出 DevContainerApp 资源
|
||||
func (c *DevStarClient) ListDevContainerApps(ctx context.Context, namespace string) (*appsv1.DevcontainerAppList, error) {
|
||||
list := &appsv1.DevcontainerAppList{}
|
||||
err := c.client.List(ctx, list, client.InNamespace(namespace))
|
||||
return list, err
|
||||
}
|
Reference in New Issue
Block a user