diff --git a/controllers/devbox/api/v1alpha1/devboxrelease_types.go b/controllers/devbox/api/v1alpha1/devboxrelease_types.go index ab8d8257fbd..7ac9e126773 100644 --- a/controllers/devbox/api/v1alpha1/devboxrelease_types.go +++ b/controllers/devbox/api/v1alpha1/devboxrelease_types.go @@ -41,19 +41,21 @@ const ( DevboxReleasePhaseFailed DevboxReleasePhase = "Failed" ) -// +kubebuilder:printcolumn:name="DevboxName",type="string",JSONPath=".spec.devboxName" -// +kubebuilder:printcolumn:name="NewTag",type="string",JSONPath=".spec.newTag" -// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase" - // DevBoxReleaseStatus defines the observed state of DevBoxRelease type DevBoxReleaseStatus struct { // +kubebuilder:validation:Optional // +kubebuilder:default=Pending Phase DevboxReleasePhase `json:"phase"` + // +kubebuilder:validation:Optional + OriginalImage string `json:"originalImage"` } // +kubebuilder:object:root=true // +kubebuilder:subresource:status +// +kubebuilder:printcolumn:name="DevboxName",type="string",JSONPath=".spec.devboxName" +// +kubebuilder:printcolumn:name="NewTag",type="string",JSONPath=".spec.newTag" +// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase" +// +kubebuilder:printcolumn:name="OriginalImage",type="string",JSONPath=".status.originalImage" // DevBoxRelease is the Schema for the devboxreleases API type DevBoxRelease struct { diff --git a/controllers/devbox/config/crd/bases/devbox.sealos.io_devboxreleases.yaml b/controllers/devbox/config/crd/bases/devbox.sealos.io_devboxreleases.yaml index 930780f3a77..6ef4ad257b4 100644 --- a/controllers/devbox/config/crd/bases/devbox.sealos.io_devboxreleases.yaml +++ b/controllers/devbox/config/crd/bases/devbox.sealos.io_devboxreleases.yaml @@ -28,7 +28,20 @@ spec: singular: devboxrelease scope: Namespaced versions: - - name: v1alpha1 + - additionalPrinterColumns: + - jsonPath: .spec.devboxName + name: DevboxName + type: string + - jsonPath: .spec.newTag + name: NewTag + type: string + - jsonPath: .status.phase + name: Phase + type: string + - jsonPath: .status.originalImage + name: OriginalImage + type: string + name: v1alpha1 schema: openAPIV3Schema: description: DevBoxRelease is the Schema for the devboxreleases API @@ -66,6 +79,8 @@ spec: status: description: DevBoxReleaseStatus defines the observed state of DevBoxRelease properties: + originalImage: + type: string phase: default: Pending type: string diff --git a/controllers/devbox/deploy/manifests/deploy.yaml.tmpl b/controllers/devbox/deploy/manifests/deploy.yaml.tmpl index 940befc1709..7332eb18296 100644 --- a/controllers/devbox/deploy/manifests/deploy.yaml.tmpl +++ b/controllers/devbox/deploy/manifests/deploy.yaml.tmpl @@ -2807,7 +2807,20 @@ spec: singular: devboxrelease scope: Namespaced versions: - - name: v1alpha1 + - additionalPrinterColumns: + - jsonPath: .spec.devboxNamåe + name: DevboxName + type: string + - jsonPath: .spec.newTag + name: NewTag + type: string + - jsonPath: .status.phase + name: Phase + type: string + - jsonPath: .status.originalImage + name: OriginalImage + type: string + name: v1alpha1 schema: openAPIV3Schema: description: DevBoxRelease is the Schema for the devboxreleases API @@ -2845,6 +2858,8 @@ spec: status: description: DevBoxReleaseStatus defines the observed state of DevBoxRelease properties: + originalImage: + type: string phase: default: Pending type: string diff --git a/controllers/devbox/internal/controller/devboxrelease_controller.go b/controllers/devbox/internal/controller/devboxrelease_controller.go index 19aee91a25b..a443078f293 100644 --- a/controllers/devbox/internal/controller/devboxrelease_controller.go +++ b/controllers/devbox/internal/controller/devboxrelease_controller.go @@ -113,11 +113,16 @@ func (r *DevBoxReleaseReconciler) CreateReleaseTag(ctx context.Context, devboxRe if err := r.Get(ctx, devboxInfo, devbox); err != nil { return err } - hostName, imageName, oldTag, err := r.GetHostAndImageAndTag(devbox) + hostName, imageName, oldTag, err := r.GetRegistryInfo(devbox) if err != nil { return err } logger.Info("Tagging image", "host", hostName, "image", imageName, "oldTag", oldTag, "newTag", devboxRelease.Spec.NewTag) + devboxRelease.Status.OriginalImage = imageName + ":" + oldTag + if err = r.Status().Update(ctx, devboxRelease); err != nil { + logger.Error(err, "Failed to update status", "devbox", devboxRelease.Spec.DevboxName, "newTag", devboxRelease.Spec.NewTag) + return err + } return r.Registry.TagImage(hostName, imageName, oldTag, devboxRelease.Spec.NewTag) } @@ -126,7 +131,7 @@ func (r *DevBoxReleaseReconciler) DeleteReleaseTag(_ context.Context, _ *devboxv return nil } -func (r *DevBoxReleaseReconciler) GetHostAndImageAndTag(devbox *devboxv1alpha1.Devbox) (string, string, string, error) { +func (r *DevBoxReleaseReconciler) GetRegistryInfo(devbox *devboxv1alpha1.Devbox) (string, string, string, error) { if len(devbox.Status.CommitHistory) == 0 { return "", "", "", fmt.Errorf("commit history is empty") }