Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:devbox websocket. #5266

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions controllers/devbox/api/v1alpha1/devbox_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ const (
type NetworkType string

const (
NetworkTypeNodePort NetworkType = "NodePort"
NetworkTypeTailnet NetworkType = "Tailnet"
NetworkTypeNodePort NetworkType = "NodePort"
NetworkTypeTailnet NetworkType = "Tailnet"
NetworkTypeWebSocket NetworkType = "WebSocket"
)

type ResourceList map[ResourceName]resource.Quantity
Expand All @@ -63,12 +64,20 @@ type RuntimeRef struct {

type NetworkSpec struct {
// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum=NodePort;Tailnet
// +kubebuilder:validation:Enum=NodePort;Tailnet;WebSocket
Type NetworkType `json:"type"`
// +kubebuilder:validation:Optional
ExtraPorts []corev1.ContainerPort `json:"extraPorts"`
}

type AutoShutdownSpec struct {
// +kubebuilder:validation:Optional
// +kubebuilder:default=false
Enable bool `json:"type"`
// +kubebuilder:validation:Optional
Time string `json:"time"`
}

// DevboxSpec defines the desired state of Devbox
type DevboxSpec struct {
// +kubebuilder:validation:Required
Expand All @@ -87,6 +96,9 @@ type DevboxSpec struct {
// +kubebuilder:validation:Required
NetworkSpec NetworkSpec `json:"network,omitempty"`

// +kubebuilder:validation:Optional
AutoShutdownSpec AutoShutdownSpec `json:"autoShutdown,omitempty"`

// todo add rewrite labels and annotations...
// +kubebuilder:validation:Optional
ExtraLabels map[string]string `json:"extraLabels,omitempty"`
Expand Down Expand Up @@ -117,12 +129,15 @@ type DevboxSpec struct {

type NetworkStatus struct {
// +kubebuilder:default=NodePort
// +kubebuilder:validation:Enum=NodePort;Tailnet
Copy link
Collaborator

Choose a reason for hiding this comment

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

make manifest to generate crd.

// +kubebuilder:validation:Enum=NodePort;Tailnet;WebSocket
Type NetworkType `json:"type"`

// +kubebuilder:validation:Optional
NodePort int32 `json:"nodePort"`

// +kubebuilder:validation:Optional
WebSocket string `json:"webSocket"`

// todo TailNet
// +kubebuilder:validation:Optional
TailNet string `json:"tailnet"`
Expand Down
18 changes: 18 additions & 0 deletions controllers/devbox/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ func main() {
var requestEphemeralStorage string
var limitEphemeralStorage string
var debugMode bool
var webSocketImage string
var websocketProxyDomain string
var ingressClass string
var enableAutoShutdown bool
var shutdownServerKey string
var shutdownServerAddr string
flag.StringVar(&registryAddr, "registry-addr", "sealos.hub:5000", "The address of the registry")
flag.StringVar(&registryUser, "registry-user", "admin", "The user of the registry")
flag.StringVar(&registryPassword, "registry-password", "passw0rd", "The password of the registry")
Expand All @@ -93,6 +99,12 @@ func main() {
flag.Float64Var(&requestMemoryRate, "request-memory-rate", 10, "The request rate of memory limit in devbox.")
flag.StringVar(&requestEphemeralStorage, "request-ephemeral-storage", "500Mi", "The request value of ephemeral storage in devbox.")
flag.StringVar(&limitEphemeralStorage, "limit-ephemeral-storage", "10Gi", "The limit value of ephemeral storage in devbox.")
flag.StringVar(&webSocketImage, "websocket-image", "cbluebird/wst:v0.0.4", "The image name of devbox websocket proxy pod.")
flag.StringVar(&websocketProxyDomain, "websocket-proxy-domain", "sealoshzh.site", "The websocket proxy domain of devbox ingress.")
flag.StringVar(&ingressClass, "ingress-class", "nginx", "The ingress class name.")
flag.BoolVar(&enableAutoShutdown, "enable-auto-shutdown", true, "If set, Devbox auto shutdown will be enabled.")
flag.StringVar(&shutdownServerKey, "shutdown-server-key", "sealos-devbox-shutdown", "The server key used to shutdown the server.")
flag.StringVar(&shutdownServerAddr, "shutdown-server-addr", "http://shutdown-service:8082", "The shutdown server address.")
opts := zap.Options{
Development: true,
}
Expand Down Expand Up @@ -192,6 +204,12 @@ func main() {
RequestEphemeralStorage: requestEphemeralStorage,
LimitEphemeralStorage: limitEphemeralStorage,
DebugMode: debugMode,
WebSocketImage: webSocketImage,
WebsocketProxyDomain: websocketProxyDomain,
IngressClass: ingressClass,
EnableAutoShutdown: enableAutoShutdown,
ShutdownServerKey: shutdownServerKey,
ShutdownServerAddr: shutdownServerAddr,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Devbox")
os.Exit(1)
Expand Down
Loading
Loading