Skip to content

Commit

Permalink
add release old tag (#5053)
Browse files Browse the repository at this point in the history
* add release old tag

* add release old tag

* add release old tag

* add release old tag
  • Loading branch information
bearslyricattack authored Sep 9, 2024
1 parent 4fabfc9 commit d47170c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
10 changes: 6 additions & 4 deletions controllers/devbox/api/v1alpha1/devboxrelease_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -66,6 +79,8 @@ spec:
status:
description: DevBoxReleaseStatus defines the observed state of DevBoxRelease
properties:
originalImage:
type: string
phase:
default: Pending
type: string
Expand Down
17 changes: 16 additions & 1 deletion controllers/devbox/deploy/manifests/deploy.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2845,6 +2858,8 @@ spec:
status:
description: DevBoxReleaseStatus defines the observed state of DevBoxRelease
properties:
originalImage:
type: string
phase:
default: Pending
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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")
}
Expand Down

0 comments on commit d47170c

Please sign in to comment.