Skip to content

Commit

Permalink
upgrade devbox runtime crd, rewrite devbox controller. (#5066)
Browse files Browse the repository at this point in the history
* upgrade devbox runtime crd, rewrite devbox controller.

* fix comment.

* fix license

* remove duplicate get

* fix event massage

* add new commit history if pod is not in devbox commit historys.

* fix SEALOS_DEVBOX_NAME env

* add label to devbox controller predicate

* fix go version

* fix lint
  • Loading branch information
lingdie authored Sep 11, 2024
1 parent e10a76e commit 7a19c64
Show file tree
Hide file tree
Showing 14 changed files with 557 additions and 395 deletions.
23 changes: 17 additions & 6 deletions controllers/devbox/api/v1alpha1/devbox_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const (
ResourceCPU ResourceName = "cpu"
// ResourceMemory Memory, in bytes. (500Gi = 500GiB = 500 * 1024 * 1024 * 1024)
ResourceMemory ResourceName = "memory"
// FinalizerName is the finalizer for Devbox
FinalizerName = "devbox.sealos.io/finalizer"
DevBoxPartOf = "devbox"
)

type DevboxState string
Expand Down Expand Up @@ -135,12 +138,20 @@ const (
)

type CommitHistory struct {
Image string `json:"image"`
Time metav1.Time `json:"time"`
Pod string `json:"pod"`
Status CommitStatus `json:"status"`
Node string `json:"node"`
ContainerID string `json:"containerID"`
// Image is the image of the commit
Image string `json:"image"`
// Time is the time when the commit is created
Time metav1.Time `json:"time"`
// Pod is the pod name
Pod string `json:"pod"`
// status will be set based on expectedStatus after devbox pod delete or stop. if expectedStatus is still pending, it means the pod is not running successfully, so we need to set it to `failed`
Status CommitStatus `json:"status"`
// predicatedStatus default `pending`, will be set to `success` if pod status is running successfully.
PredicatedStatus CommitStatus `json:"predicatedStatus"`
// Node is the node name
Node string `json:"node"`
// ContainerID is the container id
ContainerID string `json:"containerID"`
}

type DevboxPhase string
Expand Down
16 changes: 13 additions & 3 deletions controllers/devbox/api/v1alpha1/runtime_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,24 @@ type Config struct {
Volumes []corev1.Volume `json:"volumes,omitempty"`
}

type Component struct {
// +kubebuilder:validation:Required
Name string `json:"name"`
// +kubebuilder:validation:Required
Version string `json:"version"`
}

// RuntimeSpec defines the desired state of Runtime
type RuntimeSpec struct {
// +kubebuilder:validation:Required
Title string `json:"title"`
// +kubebuilder:validation:Optional
Category []string `json:"category,omitempty"`
Version string `json:"version"`
// +kubebuilder:validation:Required
ClassRef string `json:"classRef"`

// +kubebuilder:validation:Optional
Components []Component `json:"components,omitempty"`
// +kubebuilder:validation:Optional
Category []string `json:"category,omitempty"`
// +kube:validation:Optional
Description string `json:"description,omitempty"`

Expand Down
20 changes: 20 additions & 0 deletions controllers/devbox/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions controllers/devbox/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func main() {
var registryPassword string
var authAddr string
var ephemeralStorage string
var debugMode bool
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 @@ -79,6 +80,7 @@ func main() {
"If set, the metrics endpoint is served securely via HTTPS. Use --metrics-secure=false to use HTTP instead.")
flag.BoolVar(&enableHTTP2, "enable-http2", false,
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
flag.BoolVar(&debugMode, "debug", false, "If set, debug mode will be enabled")
flag.StringVar(&ephemeralStorage, "ephemeral-storage", "2000Mi", "The maximum value of equatorial storage in devbox.")
opts := zap.Options{
Development: true,
Expand Down Expand Up @@ -161,6 +163,7 @@ func main() {
CommitImageRegistry: registryAddr,
Recorder: mgr.GetEventRecorderFor("devbox-controller"),
EquatorialStorage: ephemeralStorage,
DebugMode: debugMode,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Devbox")
os.Exit(1)
Expand Down
14 changes: 14 additions & 0 deletions controllers/devbox/config/crd/bases/devbox.sealos.io_devboxes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2733,23 +2733,37 @@ spec:
items:
properties:
containerID:
description: ContainerID is the container id
type: string
image:
description: Image is the image of the commit
type: string
node:
description: Node is the node name
type: string
pod:
description: Pod is the pod name
type: string
predicatedStatus:
description: predicatedStatus default `pending`, will be set
to `success` if pod status is running successfully.
type: string
status:
description: status will be set based on expectedStatus after
devbox pod delete or stop. if expectedStatus is still pending,
it means the pod is not running successfully, so we need to
set it to `failed`
type: string
time:
description: Time is the time when the commit is created
format: date-time
type: string
required:
- containerID
- image
- node
- pod
- predicatedStatus
- status
- time
type: object
Expand Down
16 changes: 14 additions & 2 deletions controllers/devbox/config/crd/bases/devbox.sealos.io_runtimes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ spec:
type: array
classRef:
type: string
components:
items:
properties:
name:
type: string
version:
type: string
required:
- name
- version
type: object
type: array
config:
properties:
annotations:
Expand Down Expand Up @@ -1896,12 +1908,12 @@ spec:
type: object
description:
type: string
title:
version:
type: string
required:
- classRef
- config
- title
- version
type: object
status:
description: RuntimeStatus defines the observed state of Runtime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ spec:
category:
- ubuntu
- java
- spring-boot
- spring-boot
60 changes: 44 additions & 16 deletions controllers/devbox/deploy/manifests/deploy.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# Copyright © 2024 sealos.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
/*
Copyright 2024.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

apiVersion: v1
kind: Namespace
Expand Down Expand Up @@ -2741,23 +2743,37 @@ spec:
items:
properties:
containerID:
description: ContainerID is the container id
type: string
image:
description: Image is the image of the commit
type: string
node:
description: Node is the node name
type: string
pod:
description: Pod is the pod name
type: string
predicatedStatus:
description: predicatedStatus default `pending`, will be set
to `success` if pod status is running successfully.
type: string
status:
description: status will be set based on expectedStatus after
devbox pod delete or stop. if expectedStatus is still pending,
it means the pod is not running successfully, so we need to
set it to `failed`
type: string
time:
description: Time is the time when the commit is created
format: date-time
type: string
required:
- containerID
- image
- node
- pod
- predicatedStatus
- status
- time
type: object
Expand Down Expand Up @@ -2808,7 +2824,7 @@ spec:
scope: Namespaced
versions:
- additionalPrinterColumns:
- jsonPath: .spec.devboxNamåe
- jsonPath: .spec.devboxName
name: DevboxName
type: string
- jsonPath: .spec.newTag
Expand Down Expand Up @@ -3028,6 +3044,18 @@ spec:
type: array
classRef:
type: string
components:
items:
properties:
name:
type: string
version:
type: string
required:
- name
- version
type: object
type: array
config:
properties:
annotations:
Expand Down Expand Up @@ -4865,12 +4893,12 @@ spec:
type: object
description:
type: string
title:
version:
type: string
required:
- classRef
- config
- title
- version
type: object
status:
description: RuntimeStatus defines the observed state of Runtime
Expand Down
Loading

0 comments on commit 7a19c64

Please sign in to comment.